1.. _faq: 2 3 4Frequently Asked Questions 5========================== 6 7.. contents:: 8 :depth: 2 9 :local: 10 :backlinks: none 11 12Version & Installation 13---------------------- 14 15.. _determining-version: 16 17How can I tell what version of yt I'm using? 18^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 19 20If you run into problems with yt and you're writing to the mailing list 21or contacting developers on Slack, they will likely want to know what version of 22yt you're using. Often times, you'll want to know both the yt version, 23as well as the last changeset that was committed to the branch you're using. 24To reveal this, go to a command line and type: 25 26.. code-block:: bash 27 28 $ yt version 29 30The result will look something like this: 31 32.. code-block:: bash 33 34 yt module located at: 35 /Users/mitchell/src/yt-conda/src/yt-git 36 37 The current version of yt is: 38 39 --- 40 Version = 4.0.dev0 41 Changeset = 9f947a930ab4 42 --- 43 This installation CAN be automatically updated. 44 45 46For more information on this topic, see :ref:`updating`. 47 48.. _yt-3.0-problems: 49 50I upgraded to yt 4.0 but my code no longer works. What do I do? 51^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 52 53We've tried to keep the number of backward-incompatible changes to a minimum 54with the release of yt-4.0, but because of the wide-reaching changes to how 55yt manages data, there may be updates you have to make. 56You can see many of the changes in :ref:`yt4differences`, and 57in :ref:`transitioning-to-4.0` there are helpful tips on how to modify your scripts to update them. 58 59Code Errors and Failures 60------------------------ 61 62Python fails saying that it cannot import yt modules 63^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 64 65This is commonly exhibited with an error about not being able to import code 66that is part of yt. This is likely because the code that is failing to import 67needs to be compiled or recompiled. 68 69This error tends to occur when there are changes in the underlying Cython files 70that need to be rebuilt, like after a major code update or when switching 71between distant branches. 72 73This is solved by running the install command again. See 74:ref:`install-from-source`. 75 76 77.. _faq-mpi4py: 78 79yt complains that it needs the mpi4py module 80^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 81 82For yt to be able to incorporate parallelism on any of its analysis (see 83:ref:`parallel-computation`), it needs to be able to use MPI libraries. 84This requires the ``mpi4py`` module to be installed in your version of python. 85Unfortunately, installation of ``mpi4py`` is *just* tricky enough to elude the 86yt batch installer. So if you get an error in yt complaining about mpi4py 87like: 88 89.. code-block:: bash 90 91 ImportError: No module named mpi4py 92 93then you should install ``mpi4py``. The easiest way to install it is through 94the pip interface. At the command line, type: 95 96.. code-block:: bash 97 98 $ python -m pip install mpi4py 99 100What this does is it finds your default installation of Python (presumably 101in the yt source directory), and it installs the mpi4py module. If this 102action is successful, you should never have to worry about your aforementioned 103problems again. If, on the other hand, this installation fails (as it does on 104such machines as NICS Kraken, NASA Pleaides and more), then you will have to 105take matters into your own hands. Usually when it fails, it is due to pip 106being unable to find your MPI C/C++ compilers (look at the error message). 107If this is the case, you can specify them explicitly as per: 108 109.. code-block:: bash 110 111 $ env MPICC=/path/to/MPICC python -m pip install mpi4py 112 113So for example, on Kraken, I switch to the gnu C compilers (because yt 114doesn't work with the portland group C compilers), then I discover that 115cc is the mpi-enabled C compiler (and it is in my path), so I run: 116 117.. code-block:: bash 118 119 $ module swap PrgEnv-pgi PrgEnv-gnu 120 $ env MPICC=cc python -m pip install mpi4py 121 122And voila! It installs! If this *still* fails for you, then you can 123build and install from source and specify the mpi-enabled c and c++ 124compilers in the mpi.cfg file. See the 125`mpi4py installation page <https://mpi4py.readthedocs.io/en/stable/install.html>`_ 126for details. 127 128 129Units 130----- 131 132.. _conversion-factors: 133 134How do I convert between code units and physical units for my dataset? 135^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 136 137Starting with yt-3.0, and continuing to yt-4.0, yt uses an internal symbolic 138unit system. In yt-3.0 this was bundled with the main yt codebase, and with 139yt-4.0 it is now available as a separate package called `unyt 140<https://unyt.readthedocs.org/>`_. Conversion factors are tied up in the 141``length_unit``, ``times_unit``, ``mass_unit``, and ``velocity_unit`` 142attributes, which can be converted to any arbitrary desired physical unit: 143 144.. code-block:: python 145 146 print("Length unit: ", ds.length_unit) 147 print("Time unit: ", ds.time_unit) 148 print("Mass unit: ", ds.mass_unit) 149 print("Velocity unit: ", ds.velocity_unit) 150 151 print("Length unit: ", ds.length_unit.in_units("code_length")) 152 print("Time unit: ", ds.time_unit.in_units("code_time")) 153 print("Mass unit: ", ds.mass_unit.in_units("kg")) 154 print("Velocity unit: ", ds.velocity_unit.in_units("Mpc/year")) 155 156So to accomplish the example task of converting a scalar variable ``x`` in 157code units to kpc in yt-4.0, you can do one of two things. If ``x`` is 158already a YTQuantity with units in ``code_length``, you can run: 159 160.. code-block:: python 161 162 x.in_units("kpc") 163 164However, if ``x`` is just a numpy array or native python variable without 165units, you can convert it to a YTQuantity with units of ``kpc`` by running: 166 167.. code-block:: python 168 169 x = x * ds.length_unit.in_units("kpc") 170 171For more information about unit conversion, see :ref:`units`. 172 173How do I make a YTQuantity tied to a specific dataset's units? 174^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 175 176If you want to create a variable or array that is tied to a particular dataset 177(and its specific conversion factor to code units), use the ``ds.quan`` (for 178individual variables) and ``ds.arr`` (for arrays): 179 180.. code-block:: python 181 182 import yt 183 184 ds = yt.load(filename) 185 one_Mpc = ds.quan(1, "Mpc") 186 x_vector = ds.arr([1, 0, 0], "code_length") 187 188You can then naturally exploit the units system: 189 190.. code-block:: python 191 192 print("One Mpc in code_units:", one_Mpc.in_units("code_length")) 193 print("One Mpc in AU:", one_Mpc.in_units("AU")) 194 print("One Mpc in comoving kpc:", one_Mpc.in_units("kpccm")) 195 196For more information about unit conversion, see :ref:`units`. 197 198.. _accessing-unitless-data: 199 200How do I access the unitless data in a YTQuantity or YTArray? 201^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 202 203While there are numerous benefits to having units tied to individual 204quantities in yt, they can also produce issues when simply trying to combine 205YTQuantities with numpy arrays or native python floats that lack units. A 206simple example of this is:: 207 208 # Create a YTQuantity that is 1 kpc in length and tied to the units of 209 # dataset ds 210 >>> x = ds.quan(1, 'kpc') 211 212 # Try to add this to some non-dimensional quantity 213 >>> print(x + 1) 214 215 YTUnitOperationError: The addition operator for YTArrays with units (kpc) and (1) is not well defined. 216 217The solution to this means using the YTQuantity and YTArray objects for all 218of one's computations, but this isn't always feasible. A quick fix for this 219is to just grab the unitless data out of a YTQuantity or YTArray object with 220the ``value`` and ``v`` attributes, which return a copy, or with the ``d`` 221attribute, which returns the data itself: 222 223.. code-block:: python 224 225 x = ds.quan(1, "kpc") 226 x_val = x.v 227 print(x_val) 228 229 array(1.0) 230 231 # Try to add this to some non-dimensional quantity 232 print(x + 1) 233 234 2.0 235 236For more information about this functionality with units, see :ref:`units`. 237 238Fields 239------ 240 241.. _faq-handling-log-vs-linear-space: 242 243How do I modify whether or not yt takes the log of a particular field? 244^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 245 246yt sets up defaults for many fields for whether or not a field is presented 247in log or linear space. To override this behavior, you can modify the 248``field_info`` dictionary. For example, if you prefer that ``density`` not be 249logged, you could type: 250 251.. code-block:: python 252 253 ds = load("my_data") 254 ds.index 255 ds.field_info["gas", "density"].take_log = False 256 257From that point forward, data products such as slices, projections, etc., would 258be presented in linear space. Note that you have to instantiate ds.index before 259you can access ds.field info. For more information see the documentation on 260:ref:`fields` and :ref:`creating-derived-fields`. 261 262.. _faq-new-field: 263 264I added a new field to my simulation data, can yt see it? 265^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 266 267Yes! yt identifies all the fields in the simulation's output file 268and will add them to its ``field_list`` even if they aren't listed in 269:ref:`field-list`. These can then be accessed in the usual manner. For 270example, if you have created a field for the potential called 271``PotentialField``, you could type: 272 273.. code-block:: python 274 275 ds = load("my_data") 276 ad = ds.all_data() 277 potential_field = ad["PotentialField"] 278 279The same applies to fields you might derive inside your yt script 280via :ref:`creating-derived-fields`. To check what fields are 281available, look at the properties ``field_list`` and ``derived_field_list``: 282 283.. code-block:: python 284 285 print(ds.field_list) 286 print(ds.derived_field_list) 287 288or for a more legible version, try: 289 290.. code-block:: python 291 292 for field in ds.derived_field_list: 293 print(field) 294 295.. _faq-add-field-diffs: 296 297What is the difference between ``yt.add_field()`` and ``ds.add_field()``? 298^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 299 300The global ``yt.add_field()`` 301(:meth:`~yt.fields.field_info_container.FieldInfoContainer.add_field`) 302function is for adding a field for every subsequent dataset that is loaded 303in a particular python session, whereas ``ds.add_field()`` 304(:meth:`~yt.data_objects.static_output.Dataset.add_field`) will only add it 305to dataset ``ds``. 306 307Data Objects 308------------ 309 310.. _ray-data-ordering: 311 312Why are the values in my Ray object out of order? 313^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 314 315Using the Ray objects 316(:class:`~yt.data_objects.selection_data_containers.YTOrthoRay` and 317:class:`~yt.data_objects.selection_data_containers.YTRay`) with AMR data 318gives non-contiguous cell information in the Ray's data array. The 319higher-resolution cells are appended to the end of the array. Unfortunately, 320due to how data is loaded by chunks for data containers, there is really no 321easy way to fix this internally. However, there is an easy workaround. 322 323One can sort the ``Ray`` array data by the ``t`` field, which is the value of 324the parametric variable that goes from 0 at the start of the ray to 1 at the 325end. That way the data will always be ordered correctly. As an example you can: 326 327.. code-block:: python 328 329 my_ray = ds.ray(...) 330 ray_sort = np.argsort(my_ray["t"]) 331 density = my_ray["gas", "density"][ray_sort] 332 333There is also a full example in the :ref:`manual-line-plots` section of the 334docs. 335 336Developing 337---------- 338 339.. _making-a-PR: 340 341Someone asked me to make a Pull Request (PR) to yt. How do I do that? 342^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 343 344A pull request is the action by which you contribute code to yt. You make 345modifications in your local copy of the source code, then *request* that 346other yt developers review and accept your changes to the main code base. 347For a full description of the steps necessary to successfully contribute 348code and issue a pull request (or manage multiple versions of the source code) 349please see :ref:`sharing-changes`. 350 351.. _making-an-issue: 352 353Someone asked me to file an issue or a bug report for a bug I found. How? 354^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 355 356See :ref:`reporting-a-bug` and :ref:`sharing-changes`. 357 358Miscellaneous 359------------- 360 361.. _getting-sample-data: 362 363How can I get some sample data for yt? 364^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 365 366Many different sample datasets can be found at https://yt-project.org/data/ . 367These can be downloaded, unarchived, and they will each create their own 368directory. It is generally straight forward to load these datasets, but if 369you have any questions about loading data from a code with which you are 370unfamiliar, please visit :ref:`loading-data`. 371 372To make things easier to load these sample datasets, you can add the parent 373directory to your downloaded sample data to your *yt path*. 374If you set the option ``test_data_dir``, in the section ``[yt]``, 375in ``~/.config/yt/yt.toml``, yt will search this path for them. 376 377This means you can download these datasets to ``/big_drive/data_for_yt`` , add 378the appropriate item to ``~/.config/yt/yt.toml``, and no matter which directory you are 379in when running yt, it will also check in *that* directory. 380 381In many cases, these are also available using the ``load_sample`` command, 382described in :ref:`loading-sample-data`. 383 384 385.. _faq-scroll-up: 386 387I can't scroll-up to previous commands inside python 388^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 389 390If the up-arrow key does not recall the most recent commands, there is 391probably an issue with the readline library. To ensure the yt python 392environment can use readline, run the following command: 393 394.. code-block:: bash 395 396 $ python -m pip install gnureadline 397 398.. _faq-old-data: 399 400.. _faq-log-level: 401 402How can I change yt's log level? 403^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 404 405yt's default log level is ``INFO``. However, you may want less voluminous logging, 406especially if you are in an IPython notebook or running a long or parallel script. 407On the other hand, you may want it to output a lot more, since you can't figure out 408exactly what's going wrong, and you want to output some debugging information. 409The default yt log level can be changed using the :ref:`configuration-file`, 410either by setting it in the ``$HOME/.config/yt/yt.toml`` file: 411 412.. code-block:: bash 413 414 $ yt config set yt log_level 10 # This sets the log level to "DEBUG" 415 416which would produce debug (as well as info, warning, and error) messages, or at runtime: 417 418.. code-block:: python 419 420 yt.set_log_level("error") 421 422This is the same as doing: 423 424.. code-block:: python 425 426 yt.set_log_level(40) 427 428which in this case would suppress everything below error messages. For reference, 429the numerical values corresponding to different log levels are: 430 431.. csv-table:: 432 :header: Level, Numeric Value 433 :widths: 10, 10 434 435 ``CRITICAL``,50 436 ``ERROR``,40 437 ``WARNING``,30 438 ``INFO``,20 439 ``DEBUG``,10 440 ``NOTSET``,0 441 442Can I always load custom data objects, fields, quantities, and colormaps with every dataset? 443^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 444 445The :ref:`plugin-file` provides a means for always running custom code whenever 446yt is loaded up. This custom code can be new data objects, or fields, or 447colormaps, which will then be accessible in any future session without having 448modified the source code directly. See the description in :ref:`plugin-file` 449for more details. 450 451How do I cite yt? 452^^^^^^^^^^^^^^^^^ 453 454If you use yt in a publication, we'd very much appreciate a citation! You 455should feel free to cite the `ApJS paper 456<https://ui.adsabs.harvard.edu/abs/2011ApJS..192....9T>`_ with the following BibTeX 457entry: :: 458 459 @ARTICLE{2011ApJS..192....9T, 460 author = {{Turk}, M.~J. and {Smith}, B.~D. and {Oishi}, J.~S. and {Skory}, S. and 461 {Skillman}, S.~W. and {Abel}, T. and {Norman}, M.~L.}, 462 title = "{yt: A Multi-code Analysis Toolkit for Astrophysical Simulation Data}", 463 journal = {The Astrophysical Journal Supplement Series}, 464 archivePrefix = "arXiv", 465 eprint = {1011.3514}, 466 primaryClass = "astro-ph.IM", 467 keywords = {cosmology: theory, methods: data analysis, methods: numerical }, 468 year = 2011, 469 month = jan, 470 volume = 192, 471 eid = {9}, 472 pages = {9}, 473 doi = {10.1088/0067-0049/192/1/9}, 474 adsurl = {https://ui.adsabs.harvard.edu/abs/2011ApJS..192....9T}, 475 adsnote = {Provided by the SAO/NASA Astrophysics Data System} 476 } 477