### Example embree.cfg File Content Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/unstructured_mesh_rendering.rst An example of the content for an `embree.cfg` file, which specifies the installation path of Embree. This file can be placed in the yt-git directory for automatic detection by the setup script, provided EMBREE_DIR is not set. ```bash /opt/local/ ``` -------------------------------- ### Start Jupyter Lab for yt Quickstart Source: https://github.com/yt-project/yt/blob/main/doc/source/quickstart/index.rst Navigate to the quickstart directory within the yt repository and launch Jupyter Lab to access the tutorial notebooks. This command will provide information about the notebook server and how to access it. ```bash cd yt/doc/source/quickstart jupyter lab ``` -------------------------------- ### Install yt with Intel Distribution for Python Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst After setting up the Intel Python dependencies, install yt using pip. This installation method is recommended for parallel computation on Intel architectures, offering significant performance gains. ```bash $ python -m install --user yt ``` -------------------------------- ### Build and install yt from source using Git and pip Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Clones the yt repository from GitHub and installs it in editable mode, which is ideal for development. This process requires Git and a C compiler (like gcc or clang) to be pre-installed on your system. ```Bash $ git clone https://github.com/yt-project/yt $ cd yt $ python -m pip install --user -e . ``` -------------------------------- ### Clone yt Repository Source: https://github.com/yt-project/yt/blob/main/doc/source/quickstart/index.rst Instructions on how to obtain the yt repository using Git for local execution of the quickstart tutorial. ```bash git clone https://github.com/yt-project/yt ``` -------------------------------- ### Install yt stable release with all optional runtime dependencies Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Installs the stable release of yt including all optional runtime dependencies such as h5py, mpi4py, astropy, or scipy. This is achieved by appending '[full]' to the target name when calling pip, ensuring a comprehensive installation. ```Bash $ python -m pip install --user yt[full] ``` -------------------------------- ### Install yt from source with all optional runtime dependencies Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Installs yt from source in editable mode, including all optional runtime dependencies. This method is particularly useful for developers who require all features and integrations enabled from the outset for their workflow. ```Bash $ python -m pip install --user -e .[full] ``` -------------------------------- ### Install yt Documentation Build Dependencies Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/building_the_docs.rst This command installs the essential Python packages required to build the yt documentation. It uses `pip` to install the current project in editable mode (`-e .`) and all additional dependencies specified in the `requirements/docs.txt` file, ensuring all necessary tools for Sphinx and other documentation features are available. ```bash python -m pip install -e . -r requirements/docs.txt ``` -------------------------------- ### Verify yt installation by importing the library Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Tests if the yt library has been installed correctly by attempting to import it within a Python interpreter. A successful import without errors indicates that yt is properly set up and ready for use. ```Bash $ python -c "import yt" ``` -------------------------------- ### Update yt from source (git) Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst For yt installations from source via Git, use this command to pull the latest changes from GitHub and recompile yt if necessary, ensuring your local build is up-to-date. ```bash $ yt update ``` -------------------------------- ### Install Intel Python dependencies for yt Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Before installing yt with the Intel Distribution for Python, install essential dependencies from the Intel conda channel. This step is crucial for leveraging Intel's optimized libraries. ```bash $ conda install -c intel numpy scipy mpi4py cython git sympy ipython matplotlib netCDF4 ``` -------------------------------- ### Start Python Interactive Shell Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/python_introduction.rst Demonstrates how to launch the Python interactive interpreter from the command line using the 'python' command. ```bash $ python ``` -------------------------------- ### Build a Cython Extension with setup.py Source: https://github.com/yt-project/yt/blob/main/doc/source/analyzing/_static/axes_calculator_setup.txt This Python script configures and builds a Cython extension module. It specifies the extension name, source files (including a .pyx file and C source files), external libraries, include directories, and preprocessor defines. The `setup` function from `distutils` is used with `build_ext` from `Cython.Distutils` to handle the compilation. ```Python NAME = "axes_calculator" EXT_SOURCES = ["axes.c"] EXT_LIBRARIES = [] EXT_LIBRARY_DIRS = [] EXT_INCLUDE_DIRS = [] DEFINES = [] from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [Extension(NAME, [NAME+".pyx"] + EXT_SOURCES, libraries = EXT_LIBRARIES, library_dirs = EXT_LIBRARY_DIRS, include_dirs = EXT_INCLUDE_DIRS, define_macros = DEFINES) ] setup( name = NAME, cmdclass = {'build_ext': build_ext}, ext_modules = ext_modules ) ``` -------------------------------- ### Install yt with specific data format dependencies via pip Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Installs yt along with additional dependencies required for parsing specific data file formats, such as 'ramses'. Multiple formats can be specified by separating them with commas (e.g., 'yt[ramses,enzo_e]'). ```Bash $ python -m pip install --user "yt[ramses]" ``` -------------------------------- ### Exporting an Example Dataset to Firefly using yt Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/visualizing_particle_datasets_with_firefly.rst This example demonstrates how to load a dataset using yt, create a spherical region, export it to Firefly format using `create_firefly_object` with specified fields and units, and then adjust visualization settings like color and decimation factor before writing the output files to disk. ```python ramses_ds = yt.load("DICEGalaxyDisk_nonCosmological/output_00002/info_00002.txt") region = ramses_ds.sphere(ramses_ds.domain_center, (1000, "kpc")) reader = region.create_firefly_object( "IsoGalaxyRamses", fields_to_include=["particle_extra_field_1", "particle_extra_field_2"], fields_units=["dimensionless", "dimensionless"], ) ## adjust some of the options reader.settings["color"]["io"] = [1, 1, 0, 1] ## set default color reader.particleGroups[0].decimation_factor = 100 ## increase the decimation factor ## dump files to ## ~/IsoGalaxyRamses/Dataio000.ffly ## ~/IsoGalaxyRamses/filenames.json ## ~/IsoGalaxyRamses/DataSettings.json reader.writeToDisk() ``` -------------------------------- ### Install grin for Faster Code Searching Source: https://github.com/yt-project/yt/blob/main/doc/source/help/index.rst Instructions to install the `grin` utility using pip, which is recommended for a faster and cleaner experience when searching the yt codebase compared to `grep -r *`. ```bash python -m pip install grin ``` -------------------------------- ### Verify yt Installation Source: https://github.com/yt-project/yt/blob/main/doc/source/yt3differences.rst After updating or installing yt, use this command to quickly test if the library is correctly installed and importable within a Python environment. ```bash $ python -c "import yt" ``` -------------------------------- ### Install mpi4py for yt Parallelism Source: https://github.com/yt-project/yt/blob/main/doc/source/faq/index.rst These snippets provide various methods to install the `mpi4py` module, which is essential for yt's parallel computation capabilities. The easiest method uses `pip`. If `pip` fails due to an inability to find MPI C/C++ compilers, you can explicitly specify the `MPICC` environment variable. A specific example for Kraken is also provided. ```bash $ python -m pip install mpi4py ``` ```bash $ env MPICC=/path/to/MPICC python -m pip install mpi4py ``` ```bash $ module swap PrgEnv-pgi PrgEnv-gnu $ env MPICC=cc python -m pip install mpi4py ``` -------------------------------- ### Starting the yt Mapserver from Command Line Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/mapserver.rst This command starts the yt mapserver, which spawns a micro-webserver on your localhost. It takes a dataset path (e.g., 'DD0050/DD0050') and can be configured with options similar to the 'plot' subcommand, such as field, projection, weight, and axis. The URL to connect to the server will be output to standard output. ```bash yt mapserver DD0050/DD0050 ``` -------------------------------- ### Update yt via pip Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Upgrade an existing yt installation that was installed using pip to its latest version. This command ensures you have the most recent features and bug fixes. ```bash $ python -m pip install --upgrade yt ``` -------------------------------- ### Load Sample Data Automatically with yt.load_sample Source: https://github.com/yt-project/yt/blob/main/doc/source/quickstart/1)_Introduction.ipynb Demonstrates how to use the `yt.load_sample` command to automatically download and load sample datasets. This command utilizes the built-in pooch auto-downloader and is ideal for tutorials or when working with pre-defined sample data. ```python ds = yt.load_sample("IsolatedGalaxy") ``` -------------------------------- ### Install yt stable release using pip Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Installs the latest stable release of the yt library from PyPI using pip. It is strongly recommended to run this command within an isolated Python environment to manage dependencies effectively. ```Bash $ python -m pip install --user yt ``` -------------------------------- ### Start IPython Notebook Server Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/notebook_tutorial.rst This command initiates the IPython notebook server. Upon execution, it typically opens a web browser directed to the notebook dashboard. If the browser does not open automatically, manual connection might be required. ```bash $ ipython notebook ``` -------------------------------- ### Manually Load Data with yt.load Source: https://github.com/yt-project/yt/blob/main/doc/source/quickstart/1)_Introduction.ipynb Illustrates the standard `yt.load` command for manually loading datasets. This method requires providing the full path to the parameter file and is the most common way to interact with `yt` for custom or local datasets. ```python ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") ``` -------------------------------- ### Install pyembree with Custom Embree Paths Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/unstructured_mesh_rendering.rst Installs pyembree, specifying custom include and library paths for Embree if it's not in default system paths. This is necessary when Embree is installed in non-standard locations, ensuring the pyembree setup script can locate the required Embree files. ```bash CFLAGS='-I/opt/local/include' LDFLAGS='-L/opt/local/lib' python setup.py install ``` -------------------------------- ### Install yt stable release using Conda Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Installs the latest stable release of the yt library using the Anaconda/Miniconda distribution via the conda-forge channel. This command should be executed in an activated conda environment for proper package management. ```Bash $ conda install --channel conda-forge yt ``` -------------------------------- ### Build Cython Extension Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/external_analysis.rst This bash command is used to build the Cython extension defined in the setup.py file. The '-i' flag installs the extension in place. ```bash $ python axes_calculator_setup.py build_ext -i ``` -------------------------------- ### Check yt Version and Changeset Source: https://github.com/yt-project/yt/blob/main/doc/source/faq/index.rst This snippet shows how to determine the installed version of yt and the last committed changeset using the `yt version` command. It also provides an example of the expected output, including the module location, version number, and changeset ID. ```bash $ yt version ``` ```bash yt module located at: /Users/mitchell/src/yt-conda/src/yt-git The current version of yt is: --- Version = 4.0.dev0 Changeset = 9f947a930ab4 --- This installation CAN be automatically updated. ``` -------------------------------- ### Enzo-E Data File Structure Example Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst Illustrates the typical file structure of an Enzo-E dataset, showing the directory and various associated files, including the block list and HDF5 data files. ```none hello-0200/ hello-0200/hello-0200.block_list hello-0200/hello-0200.file_list hello-0200/hello-0200.hello-c0020-p0000.h5 ``` -------------------------------- ### Install yt with Pip Source: https://github.com/yt-project/yt/blob/main/README.md This command installs the yt library using the Python package installer, pip. It is a common and straightforward method for installing Python packages directly into your environment. ```shell python -m pip install yt ``` -------------------------------- ### Initialize yt Clump Finder Source: https://github.com/yt-project/yt/blob/main/doc/source/analyzing/domain_analysis/clump_finding.rst Demonstrates how to load a dataset and initialize the base `Clump` object, which serves as the starting point for the clump finding process. It requires a data source and a field for contouring. ```python import yt from yt.data_objects.level_sets.api import * ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") data_source = ds.disk([0.5, 0.5, 0.5], [0.0, 0.0, 1.0], (8, "kpc"), (1, "kpc")) master_clump = Clump(data_source, ("gas", "density")) ``` -------------------------------- ### Example RAMSES hydro_file_descriptor.txt Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst This snippet provides an example of a `hydro_file_descriptor.txt` file, which recent RAMSES versions automatically generate. It defines field names, their corresponding variable numbers, and data types (e.g., 'd' for double, 'i' for integer). This file helps yt understand the data layout. ```none # version: 1 # ivar, variable_name, variable_type 1, position_x, d 2, position_y, d 3, position_z, d 4, velocity_x, d 5, velocity_y, d 6, velocity_z, d 7, mass, d 8, identity, i 9, levelp, i 10, birth_time, d 11, metallicity, d ``` -------------------------------- ### Loading RAMSES Dataset with yt Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst Provides an example of loading a RAMSES dataset into yt using the `yt.load` command, specifying the `info*.txt` file. ```python import yt ds = yt.load("output_00007/info_00007.txt") ``` -------------------------------- ### Example RAMSES Output Directory Structure Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst Displays the typical file organization within a RAMSES simulation output directory, highlighting the `info*.txt` file used for loading. ```none output_00007 output_00007/amr_00007.out00001 output_00007/grav_00007.out00001 output_00007/hydro_00007.out00001 output_00007/info_00007.txt output_00007/part_00007.out00001 ``` -------------------------------- ### Install yt with Conda Source: https://github.com/yt-project/yt/blob/main/README.md This command installs the yt library using the Conda package manager from the conda-forge channel. It is a recommended method for users who prefer Conda for environment management and dependency resolution. ```shell conda install -c conda-forge yt ``` -------------------------------- ### Example of Incorrect Direct Formatter Usage Source: https://github.com/yt-project/yt/blob/main/CONTRIBUTING.rst Illustrates an example of how not to run code formatters directly on the command line (e.g., 'black yt'), as they should typically be integrated and run via pre-commit hooks for consistency and automation. ```bash $ black yt ``` -------------------------------- ### APIDOC: yt Command-Line instinfo and version Subcommands Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/command-line.rst The `instinfo` and `version` subcommands provide details about the `yt` installation, including its location, the version number, and the changeset being used. This information is crucial for debugging and ensuring compatibility. ```APIDOC instinfo and version: Description: Gives information about where your yt installation is, what version and changeset you're using and more. ``` -------------------------------- ### Uninstall yt via pip Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Remove yt from your Python environment if it was installed using pip, whether from PyPI or directly from source. This command cleans up the installed package. ```bash $ python -m pip uninstall yt ``` -------------------------------- ### ART Dataset File Naming Convention Example Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst Illustrates a typical file naming convention for ART datasets, specifically showing the gas mesh file name within a sample snapshot. ```none 10MpcBox_HartGal_csf_a0.500.d #Gas mesh ``` -------------------------------- ### Load a Tipsy dataset using yt (Python) Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst This basic Python example shows how to load a Tipsy simulation dataset into yt using the `load` function. The path to the dataset file is provided as an argument. ```python ds = load("./halo1e11_run1.00400") ``` -------------------------------- ### Update yt via conda Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Update an existing yt installation that was installed using conda. This command updates the yt package within your conda environment to its latest available version. ```bash $ conda update yt ``` -------------------------------- ### Get Help for a Specific yt Subcommand Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/command-line.rst To understand the options and arguments associated with a particular `yt` subcommand, use this command. It provides detailed usage information specific to the chosen subcommand. ```bash yt -h ``` -------------------------------- ### Generate Quick HTML Documentation for yt Project Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/building_the_docs.rst Navigate to the `yt` documentation source directory and run `make html` to compile a static HTML version of the documentation. This process creates an `index.html` and related files in the `$YT_GIT/doc/build/html` directory, suitable for local browsing. ```bash cd $YT_GIT/doc make html ``` -------------------------------- ### Python Dictionary Initialization and Key-Value Access Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/python_introduction.rst Illustrates the creation of an empty dictionary and the assignment of various key-value pairs. It shows how different data types can be used as keys and values, and how to retrieve a value using its corresponding key. ```python my_dict = {} my_dict["A"] = 1.0 my_dict["B"] = 154.014 my_dict[14001] = "This number is great" print(my_dict["A"]) ``` -------------------------------- ### Load Enzo Dataset with yt.load Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst This Python example shows how to load an Enzo dataset using the `yt.load` command. The input to `yt.load` should be the path to the main data file (e.g., `DD0010/data0010`) without any file extension. ```python import yt ds = yt.load("DD0010/data0010") ``` -------------------------------- ### Get General Help for yt Command-Line Tool Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/command-line.rst This command displays a list of all available subcommands for the `yt` command-line tool. It's the first step to discover what functionalities are accessible directly from the terminal. ```bash yt -h ``` -------------------------------- ### Load Uniform Grid and Particle Data into yt Dataset Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/Loading_Generic_Array_Data.ipynb Extends the uniform grid loading example to include particle position fields, demonstrating how to integrate both grid and particle data into a single yt dataset. ```python posx_arr = prng.uniform(low=-1.5, high=1.5, size=10000) posy_arr = prng.uniform(low=-1.5, high=1.5, size=10000) posz_arr = prng.uniform(low=-1.5, high=1.5, size=10000) data = { "density": (prng.random(size=(64, 64, 64)), "Msun/kpc**3"), "particle_position_x": (posx_arr, "code_length"), "particle_position_y": (posy_arr, "code_length"), "particle_position_z": (posz_arr, "code_length") } bbox = np.array([[-1.5, 1.5], [-1.5, 1.5], [-1.5, 1.5]]) ds = yt.load_uniform_grid( data, data["density"][0].shape, length_unit=(1.0, "Mpc"), mass_unit=(1.0, "Msun"), bbox=bbox, nprocs=4 ) ``` -------------------------------- ### Cython setup file for external C/C++ code linking Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/external_analysis.rst This Python script (`axes_calculator_setup.py`) provides the boilerplate for setting up a Cython extension using `distutils` and `Cython.Distutils.build_ext`. It specifies the extension name, external sources, libraries, library directories, include directories, and defines, enabling the compilation and linking of Cython code with external C/C++/Fortran libraries. ```python NAME = "axes_calculator" EXT_SOURCES = [] EXT_LIBRARIES = ["axes_utils", "m"] EXT_LIBRARY_DIRS = ["/home/rincewind/axes_calculator/"] EXT_INCLUDE_DIRS = [] DEFINES = [] from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [ ``` -------------------------------- ### Execute a yt script with mpirun for 16 processes Source: https://github.com/yt-project/yt/blob/main/doc/source/analyzing/parallel_computation.rst Command to run the `my_script.py` example on 16 MPI processes using mpirun, leveraging yt's parallel capabilities. ```bash $ mpirun -np 16 python my_script.py ``` -------------------------------- ### Uninstall yt via conda Source: https://github.com/yt-project/yt/blob/main/doc/source/installing.rst Remove yt from your conda environment if it was installed using conda. This command uninstalls the yt package and its dependencies managed by conda. ```bash $ conda uninstall yt ``` -------------------------------- ### Initialize yt Scene for Volume Rendering Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb Loads a dataset and creates a basic Scene object using `yt.create_scene`. This sets up the default `('gas', 'density')` field for rendering. It also imports necessary modules like `yt` and `TransferFunctionHelper`. ```python import yt from yt.visualization.volume_rendering.transfer_function_helper import ( TransferFunctionHelper, ) ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") sc = yt.create_scene(ds) ``` -------------------------------- ### Initialize yt and Define Image Display Helper Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/TransferFunctionHelper_Tutorial.ipynb This snippet imports necessary libraries including yt and TransferFunctionHelper, then defines a utility function `showme`. The `showme` function is designed to display volume renderings inline in a notebook by handling NaN values and converting the image data into a displayable bitmap. ```python import numpy as np from IPython.core.display import Image import yt from yt.visualization.volume_rendering.transfer_function_helper import ( TransferFunctionHelper, ) def showme(im): # screen out NaNs im[im != im] = 0.0 # Create an RGBA bitmap to display imb = yt.write_bitmap(im, None) return Image(imb) ``` -------------------------------- ### Generate Full HTML Documentation for yt Project Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/building_the_docs.rst After ensuring all `yt` analysis module dependencies (e.g., Sphinx, Jupyter, pandoc) and the full `yt` test data are installed and configured, navigate to the documentation directory and execute `make html`. This command initiates a lengthy process of dynamically executing recipes and notebooks to generate the complete HTML documentation. ```bash cd $YT_GIT/doc make html ``` -------------------------------- ### Example ImportError for Missing mpi4py Module Source: https://github.com/yt-project/yt/blob/main/doc/source/faq/index.rst This snippet shows the common `ImportError` message encountered when the `mpi4py` module, required for parallel computation in yt, is not installed in the Python environment. ```bash ImportError: No module named mpi4py ``` -------------------------------- ### Importing yt for Colormap Operations Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/colormaps/index.rst Shows the basic import statement for the yt library, which is a prerequisite for any colormap-related functions. This snippet is presented as the start of an example for outputting original yt colormaps to an image file. ```python import yt ``` -------------------------------- ### Example Global yt Configuration File Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/configuration.rst This TOML snippet shows a sample global configuration for yt, setting the logging level to 1 for more verbose output and increasing the maximum number of stored datasets to 10000. This file is typically located at `$HOME/.config/yt/yt.toml`. ```toml [yt] log_level = 1 maximum_stored_datasets = 10000 ``` -------------------------------- ### Install mpi4py with conda for Anaconda Source: https://github.com/yt-project/yt/blob/main/doc/source/analyzing/parallel_computation.rst Instructions for installing mpi4py using conda, specifically for Anaconda installations when no MPI library is present. Note that this installs MPICH2 and may interfere with other MPI libraries. ```bash $ conda install mpi4py ``` -------------------------------- ### Load Geographic Dataset with Default Mollweide Projection in yt Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/geographic_projections_and_transforms.rst This example illustrates loading a uniform grid dataset with geographic geometry in yt without explicitly defining a plot projection. When no projection is specified, yt defaults to displaying the data using the 'Mollweide' projection. This is a common starting point for visualizing spherical geographic data. ```python ds = yt.load_uniform_grid(data, sizes, 1.0, geometry=("geographic", dims), bbox=bbox) p = yt.SlicePlot(ds, "altitude", "AIRDENS") ``` -------------------------------- ### Creating Cython wrapper files for external C/C++ code Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/external_analysis.rst This bash snippet shows the commands to create the necessary `.pyx` (Cython source) and `_setup.py` (Python build script) files required for building a Cython wrapper around external non-Python code. These files are essential for linking Python with C/C++/Fortran routines. ```bash axes_calculator.pyx axes_calculator_setup.py ``` -------------------------------- ### Execute Python script and enter interactive interpreter Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/python_introduction.rst Shows how to run a Python script and then automatically enter the interactive Python interpreter. This allows users to inspect variables and continue working with the script's state after it has finished executing. ```bash $ python -i my_first_script.py ``` -------------------------------- ### Display yt Scene Object Information Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb Prints a summary of the Scene object, including details about its Sources, Camera, and Lens. This provides an overview of the current rendering configuration. ```python print(sc) ``` -------------------------------- ### Install mpi4py with pip Source: https://github.com/yt-project/yt/blob/main/doc/source/analyzing/parallel_computation.rst Instructions for installing mpi4py using pip, which is generally preferred for systems with existing MPI libraries. ```bash $ python -m pip install mpi4py ``` -------------------------------- ### Creating and Performing Operations on Python Numbers Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/python_introduction.rst Illustrates how to define integer and floating-point numbers and perform basic arithmetic operations such as exponentiation, addition, and division. Python handles type promotion automatically in mixed-type operations. ```python a = 10 ``` ```python print(a) ``` ```python print(a**2) ``` ```python print(a + 5) ``` ```python print(a + 5.1) ``` ```python print(a / 2.0) ``` -------------------------------- ### Example: Robinson projection Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/geographic_xforms_and_projections.ipynb Demonstrates setting a 'Robinson' projection on a SlicePlot using a string argument, as part of a series of different projection examples. ```python p.set_mpl_projection("Robinson") p.render() p.plots["AIRDENS"].axes.set_global() p.plots["AIRDENS"].axes.coastlines() p.show() ``` -------------------------------- ### Execute a Python script from the command line Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/python_introduction.rst Provides the standard command-line instruction to run a Python script. This is used for non-interactive execution of Python programs. ```bash $ python my_first_script.py ``` -------------------------------- ### Example: RotatedPole projection with arguments Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/geographic_xforms_and_projections.ipynb Shows an example of setting a 'RotatedPole' projection on a SlicePlot using a tuple with arguments (177.5, 37.5) for customization. ```python p.set_mpl_projection(("RotatedPole", (177.5, 37.5))) p.redner() p.plots["AIRDENS"].axes.set_global() p.plots["AIRDENS"].axes.coastlines() p.show() ``` -------------------------------- ### Example: RotatedPole projection with keyword arguments Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/geographic_xforms_and_projections.ipynb Shows an example of setting a 'RotatedPole' projection on a SlicePlot using a tuple with keyword arguments (`pole_latitude`, `pole_longitude`) for customization. ```python p.set_mpl_projection( ("RotatedPole", (), {"pole_latitude": 37.5, "pole_longitude": 177.5}) ) p.render() p.plots["AIRDENS"].axes.set_global() p.plots["AIRDENS"].axes.coastlines() p.show() ``` -------------------------------- ### Cython Extension Configuration Variables Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/external_analysis.rst Documentation for the key variables used in the setup.py configuration for Cython extensions, detailing their purpose and expected values. ```APIDOC NAME: Description: The base name of the source file (minus .pyx) and the module to be imported. EXT_SOURCES: Description: A list of additional source files (e.g., .c files) to be linked with the extension. EXT_LIBRARIES: Description: A list of external libraries to link against (e.g., 'm' for libm.so), specified without 'lib' prefix or '.so' suffix. EXT_LIBRARY_DIRS: Description: A list of directories where the external libraries listed in EXT_LIBRARIES reside. Example: ["/usr/local/lib", "/home/rincewind/luggage/"] EXT_INCLUDE_DIRS: Description: A list of directories containing header files that are included by the extension. DEFINES: Description: A list of define macros to be passed to the C compiler. For simple definitions, specify as ('MACRO_NAME', None). Example: [("TWOFLOWER", None)] ``` -------------------------------- ### Manage Local yt Configuration with CLI Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/configuration.rst These shell commands illustrate how to use the `yt config --local` helper to manage local yt configuration files. It shows how to get help, list local settings, set a local option, remove a local option, and print the path to the local configuration file. If no local file exists, these commands will create an empty one in the current working directory. ```bash $ yt config -h $ yt config list --local $ yt config set --local yt log_level 1 $ yt config rm --local yt maximum_stored_datasets $ yt config print-path --local ``` -------------------------------- ### Installing gnureadline for Python Scroll-Up Functionality Source: https://github.com/yt-project/yt/blob/main/doc/source/faq/index.rst If the up-arrow key does not recall previous commands in your Python environment, it indicates an issue with the readline library. This Bash command installs 'gnureadline' to resolve the problem, enabling command history navigation. ```bash $ python -m pip install gnureadline ``` -------------------------------- ### Example AMReX/BoxLib Plotfile Directory Structure Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst This example illustrates the typical directory and file organization for an AMReX/BoxLib plotfile. It shows the presence of an 'inputs' file and hierarchical 'Level_X' directories containing 'Cell_H' files, which are essential for yt to load the dataset. ```none inputs pltgmlcs5600/ pltgmlcs5600/Header pltgmlcs5600/Level_0 pltgmlcs5600/Level_0/Cell_H pltgmlcs5600/Level_1 pltgmlcs5600/Level_1/Cell_H pltgmlcs5600/Level_2 pltgmlcs5600/Level_2/Cell_H pltgmlcs5600/Level_3 pltgmlcs5600/Level_3/Cell_H pltgmlcs5600/Level_4 pltgmlcs5600/Level_4/Cell_H ``` -------------------------------- ### Manage Global yt Configuration with CLI Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/configuration.rst These shell commands demonstrate how to use the `yt config --global` helper to manage the global yt configuration file. Examples include displaying help, listing current settings, setting a specific option like `log_level`, and removing an option like `maximum_stored_datasets`. ```bash $ yt config -h $ yt config list $ yt config set yt log_level 1 $ yt config rm yt maximum_stored_datasets ``` -------------------------------- ### Install Pre-Commit Hooks Source: https://github.com/yt-project/yt/blob/main/CONTRIBUTING.rst Installs pre-commit hooks from the repository's top level, enabling automatic code style validation and fixing on every commit. This is a recommended step for contributors to ensure code quality. ```bash $ pre-commit install ``` -------------------------------- ### Display yt Scene in Notebook Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb Renders and displays the current Scene in a Jupyter notebook environment. This shows the initial visualization of the loaded dataset with default settings. ```python sc.show() ``` -------------------------------- ### Create Fixed-Resolution 1D Off-Axis Ray (Python) Source: https://github.com/yt-project/yt/blob/main/doc/source/analyzing/objects.rst Shows how to create a fixed-resolution off-axis ray. By adding an imaginary step value (e.g., `100j`) to the start:end slice, the ray will contain the specified number of points interpolated between the start and end. ```python start = [0.1, 0.2, 0.3] # interpreted in code_length end = [0.4, 0.5, 0.6] # interpreted in code_length ray = ds.r[start:end:100j] ``` -------------------------------- ### Loading Gadget Raw Binary Data Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst Shows how to load Gadget simulation data stored in raw binary format (SnapFormat 1 or 2) using the 'yt.load' command. ```python import yt ds = yt.load("snapshot_061") ``` -------------------------------- ### Define Cython Extension in setup.py Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/external_analysis.rst This Python snippet shows how to define a Cython extension using setuptools.Extension within a setup.py file. It specifies the extension name, source files, libraries, library directories, include directories, and preprocessor macros for compilation. ```python Extension( NAME, [NAME + ".pyx"] + EXT_SOURCES, libraries=EXT_LIBRARIES, library_dirs=EXT_LIBRARY_DIRS, include_dirs=EXT_INCLUDE_DIRS, define_macros=DEFINES, ) setup(name=NAME, cmdclass={"build_ext": build_ext}, ext_modules=ext_modules) ``` -------------------------------- ### Define Derived Field using the derived_field Decorator in yt Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/creating_derived_fields.rst This example shows an alternative, often more convenient, way to define a derived field using the `@derived_field` decorator. This decorator takes the same arguments as `yt.add_field` and is equivalent to the previous example, providing a shorthand for global field definitions. ```python from yt import derived_field @derived_field(name="pressure", sampling_type="cell", units="dyne/cm**2") def _pressure(field, data): return ( (data.ds.gamma - 1.0) * data["gas", "density"] * data["gas", "specific_thermal_energy"] ) ``` -------------------------------- ### Loading Gadget dataset with units and bounding box Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/yt_gadget_analysis.ipynb Loads the Gadget HDF5 dataset, defining physical units and a bounding box to encompass all particles. The data is then flattened into 'ad' for direct access to raw simulation data. ```python fname = "GadgetDiskGalaxy/snapshot_200.hdf5" unit_base = { "UnitLength_in_cm": 3.08568e21, "UnitMass_in_g": 1.989e43, "UnitVelocity_in_cm_per_s": 100000, } bbox_lim = 1e5 # kpc bbox = [[-bbox_lim, bbox_lim], [-bbox_lim, bbox_lim], [-bbox_lim, bbox_lim]] ds = yt.load(fname, unit_base=unit_base, bounding_box=bbox) ds.index ad = ds.all_data() ``` -------------------------------- ### NumPy Style Docstring Template in reStructuredText Source: https://github.com/yt-project/yt/blob/main/CONTRIBUTING.rst This comprehensive example provides a template for NumPy-style docstrings written in Sphinx reStructuredText format. It illustrates the expected structure, including a one-line summary, extended description, parameters, returns, other parameters, raises, see also, notes, and references sections, along with inline math examples. ```rest r"""A one-line summary that does not use variable names or the function name. Several sentences providing an extended description. Refer to variables using back-ticks, e.g. ``var``. Parameters ---------- var1 : array_like Array_like means all those objects -- lists, nested lists, etc. -- that can be converted to an array. We can also refer to variables like ``var1``. var2 : int The type above can either refer to an actual Python type (e.g. ``int``), or describe the type of the variable in more detail, e.g. ``(N,) ndarray`` or ``array_like``. Long_variable_name : {'hi', 'ho'}, optional Choices in brackets, default first when optional. Returns ------- describe : type Explanation output : type Explanation tuple : type Explanation items : type even more explaining Other Parameters ---------------- only_seldom_used_keywords : type Explanation common_parameters_listed_above : type Explanation Raises ------ BadException Because you shouldn't have done that. See Also -------- otherfunc : relationship (optional) newfunc : Relationship (optional), which could be fairly long, in which case the line wraps here. thirdfunc, fourthfunc, fifthfunc Notes ----- Notes about the implementation algorithm (if needed). This can have multiple paragraphs. You may include some math: .. math:: X(e^{j\omega } ) = x(n)e^{ - j\omega n} And even use a greek symbol like :math:`omega` inline. References ``` -------------------------------- ### Load Sample Gadget OWLS Snapshot Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/yt_gadget_owls_analysis.ipynb Loads a sample Gadget OWLS snapshot dataset named "snapshot_033" using yt.load_sample(). This function provides a convenient way to access pre-packaged datasets for testing and examples, returning a dataset object for further analysis and manipulation. ```python ds = yt.load_sample("snapshot_033") ``` -------------------------------- ### Creating a PyNE Mesh Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst Demonstrates how to initialize a structured PyNE mesh using `pyne.mesh.Mesh` with specified divisions and coordinates. ```python from pyne.mesh import Mesh num_divisions = 50 coords = linspace(-1, 1, num_divisions) m = Mesh(structured=True, structured_coords=[coords, coords, coords]) ``` -------------------------------- ### Configure yt Volume Rendering with Transfer Function (Overdense Opaque) Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/volume_rendering.rst This Python example showcases an alternative transfer function configuration for yt volume rendering. Similar to the previous example, it loads data and sets up a scene. However, `grey_opacity` is set to `False`, which emphasizes overdense regions in the final rendering. The transfer function is plotted, and the image is saved with a different sigma clip value. ```python import yt ds = yt.load("Enzo_64/DD0043/data0043") sc = yt.create_scene(ds, lens_type="perspective") source = sc[0] # Set transfer function properties source.tfh.set_bounds((3e-31, 5e-27)) source.tfh.set_log(True) source.tfh.grey_opacity = False source.tfh.plot("transfer_function.png", profile_field=("gas", "density")) sc.save("rendering.png", sigma_clip=4.0) ``` -------------------------------- ### Listing available fields in the dataset Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/yt_gadget_analysis.ipynb Displays a sorted list of all physical fields that can be queried or analyzed within the loaded `yt` dataset, such as 'gas', 'density', etc. ```python sorted(ds.field_list) ``` -------------------------------- ### Example: Gnomonic projection Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/geographic_xforms_and_projections.ipynb Demonstrates setting a 'Gnomonic' projection on a SlicePlot using a string argument. ```python p.set_mpl_projection("Gnomonic") p.render() p.plots["AIRDENS"].axes.set_global() p.plots["AIRDENS"].axes.coastlines() p.show() ``` -------------------------------- ### Importing the yt Library Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/tipsy_and_yt.ipynb Demonstrates how to import the `yt` library, which is essential for data loading and analysis in astrophysical simulations. ```python import yt ``` -------------------------------- ### Example: InterruptedGoodeHomolosine projection Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/geographic_xforms_and_projections.ipynb Demonstrates setting an 'InterruptedGoodeHomolosine' projection on a SlicePlot using a string argument. ```python p.set_mpl_projection("InterruptedGoodeHomolosine") p.render() p.plots["AIRDENS"].axes.set_global() p.plots["AIRDENS"].axes.coastlines() p.show() ``` -------------------------------- ### Example: AlbersEqualArea projection Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/geographic_xforms_and_projections.ipynb Demonstrates setting an 'AlbersEqualArea' projection on a SlicePlot using a string argument. ```python p.set_mpl_projection("AlbersEqualArea") p.render() p.plots["AIRDENS"].axes.set_global() p.plots["AIRDENS"].axes.coastlines() p.show() ``` -------------------------------- ### Example: NorthPolarStereo projection Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/geographic_xforms_and_projections.ipynb Demonstrates setting a 'NorthPolarStereo' projection on a SlicePlot using a string argument. ```python p.set_mpl_projection("NorthPolarStereo") p.render() p.plots["AIRDENS"].axes.set_global() p.plots["AIRDENS"].axes.coastlines() p.show() ``` -------------------------------- ### Load yt Library and Sample Galaxy Dataset Source: https://github.com/yt-project/yt/blob/main/doc/source/quickstart/6)_Volume_Rendering.ipynb Initializes the `yt` library and loads a pre-defined 'IsolatedGalaxy' sample dataset, which serves as the data source for subsequent volume rendering operations. ```python import yt ds = yt.load_sample("IsolatedGalaxy") ``` -------------------------------- ### Register yt Frontends as Extensions Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/extensions.rst These code snippets demonstrate how to register external `Dataset` subclasses as yt frontends, making them automatically discoverable and loadable by yt. This is achieved by defining entry points in either a `setup.py` file using Python or a `pyproject.toml` file using TOML, under the `yt.frontends` namespace. ```python setup( # ..., entry_points={ "yt.frontends": [ "myFrontend = my_frontend.api.MyFrontendDataset", "myOtherFrontend = my_frontend.api.MyOtherFrontendDataset", ] } ) ``` ```toml [project.entry-points."yt.frontends"] myFrontend = "my_frontend.api:MyFrontendDataset" myOtherFrontend = "my_frontend.api:MyOtherFrontendDataset" ``` -------------------------------- ### Integrate and Visualize 3D Streamlines in yt Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/streamlines.rst This Python script demonstrates how to load a dataset, define random starting positions for streamlines, and then use the yt.visualization.api.Streamlines class to integrate 3D velocity fields through the volume. The resulting streamline paths are then plotted in 3D using Matplotlib and saved to an image file. It shows how to initialize Streamlines with a dataset, starting positions, vector field components, and integration length. ```python import matplotlib.pyplot as plt import numpy as np from mpl_toolkits.mplot3d import Axes3D import yt from yt.units import Mpc from yt.visualization.api import Streamlines # Load the dataset ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # Define c: the center of the box, N: the number of streamlines, # scale: the spatial scale of the streamlines relative to the boxsize, # and then pos: the random positions of the streamlines. c = ds.domain_center N = 100 scale = ds.domain_width[0] pos_dx = np.random.random((N, 3)) * scale - scale / 2.0 pos = c + pos_dx # Create streamlines of the 3D vector velocity and integrate them through # the box defined above streamlines = Streamlines( ds, pos, ("gas", "velocity_x"), ("gas", "velocity_y"), ("gas", "velocity_z"), length=1.0 * Mpc, get_magnitude=True, ) streamlines.integrate_through_volume() # Create a 3D plot, trace the streamlines through the 3D volume of the plot fig = plt.figure() ax = Axes3D(fig, auto_add_to_figure=False) fig.add_axes(ax) for stream in streamlines.streamlines: stream = stream[np.all(stream != 0.0, axis=1)] ax.plot3D(stream[:, 0], stream[:, 1], stream[:, 2], alpha=0.1) # Save the plot to disk. plt.savefig("streamlines.png") ``` -------------------------------- ### Display pytest help options Source: https://github.com/yt-project/yt/blob/main/doc/source/developing/testing.rst This command shows all available command-line options and flags for the pytest executable. It's useful for discovering additional functionalities and configurations. ```bash $ pytest --help ``` -------------------------------- ### cmocean Colormap Integration Source: https://github.com/yt-project/yt/blob/main/doc/source/reference/changelog.rst yt now integrates colormaps from the `cmocean` package, making them available as native yt colormaps if the package is installed. ```APIDOC yt: Colormaps: Description: Integrates colormaps from the cmocean package if installed. Dependency: cmocean package ``` -------------------------------- ### List all available sample datasets with yt.load_sample Source: https://github.com/yt-project/yt/blob/main/doc/source/examining/loading_data.rst Shows how to retrieve a list of all available sample datasets by calling `yt.load_sample` without any arguments. The function returns a list of names that can be used for loading. ```python import yt yt.load_sample() ``` -------------------------------- ### Initialize TransferFunctionHelper with Dataset Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/TransferFunctionHelper_Tutorial.ipynb This snippet initializes an instance of the TransferFunctionHelper class, passing the previously loaded dataset 'ds' to its constructor. This helper object will be used to intelligently choose transfer function bounds and facilitate the visualization and manipulation of transfer functions. ```python tfh = TransferFunctionHelper(ds) ``` -------------------------------- ### Define an Arbitrarily-Aligned Ray (1D) in yt Source: https://github.com/yt-project/yt/blob/main/doc/source/analyzing/objects.rst Creates a 1D line of data cells defined by arbitrary start and end coordinates within the dataset. ```APIDOC YTRay.ray(start_coord, end_coord, ds=None, field_parameters=None, data_source=None) A line (of data cells) defined by arbitrary start and end coordinates. ``` -------------------------------- ### Rendering and Displaying a Scene with Sigma Clipping Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/Volume_Rendering_Tutorial.ipynb Executes the rendering process for the current scene. The sc.show() method then displays the rendered image, applying a sigma_clip of 4.0 to filter out extreme data values for clearer visualization. ```python sc.render() sc.show(sigma_clip=4.0) ``` -------------------------------- ### Importing Libraries for Data Visualization Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/tipsy_and_yt.ipynb Imports `matplotlib.pyplot` for plotting functionalities and `numpy` for numerical operations, preparing the environment for advanced data visualization tasks. ```python %matplotlib inline import matplotlib.pyplot as plt import numpy as np ``` -------------------------------- ### 1D Profiles Over Time Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/simple_plots.rst This is a simple example of overplotting multiple 1D profiles from a number of datasets to show how they evolve over time. See :ref:`how-to-make-1d-profiles` for more information. ```Python import yt # This example assumes you have multiple datasets in a time series. # For demonstration, we'll simulate loading a single dataset. ds = yt.load("IsolatedGalaxy/galaxy0030/galaxy0030") # Create a profile profile = yt.create_profile(ds.all_data(), "density", fields=[("gas", "mass")], n_bins=128) # In a real scenario, you would loop through datasets and plot profiles. # For this placeholder, we just show a single profile plot. profile.plot() print("This script would typically loop through multiple datasets to show time evolution.") ``` -------------------------------- ### Load Enzo Cosmological Simulation Dataset Source: https://github.com/yt-project/yt/blob/main/doc/source/visualizing/TransferFunctionHelper_Tutorial.ipynb This code loads a low-resolution Enzo cosmological simulation dataset. The loaded dataset, named 'ds', will serve as the primary data source for subsequent transfer function visualization and volume rendering operations. ```python ds = yt.load("Enzo_64/DD0043/data0043") ``` -------------------------------- ### Run Python script in parallel with mpirun Source: https://github.com/yt-project/yt/blob/main/doc/source/analyzing/parallel_computation.rst Example command to launch a Python script using mpirun on an 8-core desktop, enabling parallel execution. ```bash $ mpirun -np 8 python script.py ``` -------------------------------- ### Get Colorbar Object from Plot Source: https://github.com/yt-project/yt/blob/main/doc/source/cookbook/custom_colorbar_tickmarks.ipynb Accesses the `matplotlib` colorbar object associated with the extracted plot. This object is necessary for customizing the colorbar's appearance, such as tickmarks. ```python colorbar = plot.cb ``` -------------------------------- ### Listing Available Fields in yt Dataset Source: https://github.com/yt-project/yt/blob/main/doc/source/faq/index.rst Demonstrates how to list all available fields in a yt dataset using the `ds.field_list` and `ds.derived_field_list` properties. ```python print(ds.field_list) print(ds.derived_field_list) ```