yt documentation - read the docsyt documentation, release 0.1 3.2.1supplying length and center type...

45
YT Documentation Release 0.1 John ZuHone August 25, 2014

Upload: others

Post on 09-Feb-2021

10 views

Category:

Documents


0 download

TRANSCRIPT

  • YT DocumentationRelease 0.1

    John ZuHone

    August 25, 2014

  • Contents

    1 What is YT? 11.1 What YT Does . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 What YT Doesn’t Do (and Probably Won’t) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

    2 Installing YT 3

    3 YT Users’ Guide 53.1 Datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.2 Data Containers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.3 Arrays, Quantities, and Units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.4 Profiles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 193.5 Plotting and Images . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 233.6 In-Memory Datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

    4 Indices and tables 41

    i

  • ii

  • CHAPTER 1

    What is YT?

    YT is a Julia interface to yt. yt is a Python package for the analysis and visualization of volumetric simulation data.For more information about yt, check out http://yt-project.org.

    1.1 What YT Does

    YT exposes a number of the essential features of yt from within a Julia environment. These include:

    • Datasets

    • Data objects (e.g., spheres, rectangular regions, slices, projections, profiles, etc.)

    • Unit-aware quantities and arrays

    • Simple visualization tools (e.g., SlicePlot, ProjectionPlot, FixedResolutionBuffer)

    YT enables the end-user to “ask” physically-motivated questions of volumetric data and work with the “answers” fromwithin a Julia environment.

    1.2 What YT Doesn’t Do (and Probably Won’t)

    YT is not intended to be a full exposure of everything yt does. yt boasts many features, and exposing all of themwould be somewhat redundant, especially those features that don’t involve a lot of additional coding on the part of theend-user. Some of these features include:

    • Analysis modules (e.g., particle trajectories, two-point functions, halo finders, simulated observations, etc.)

    • Initial conditions generation

    • Volume rendering

    • Utilities for cosmology, image writing, generating streamlines, clump finding, etc.

    yt does a great job at handling these tasks already, and so if you are looking to use these features, working with ytdirectly from within a Python environment is the way to go. The purpose of YT is to expose the basic data loading andexamining features of yt, as well as a few handy visualization tools, so that those who want to take advantage of thestrengths of both Julia and yt strengths can do so.

    Note: This documentation does not exhaustively cover the API of the Python methods of yt that may be accessedvia YT. For that, consulting the yt Documentation is recommended.

    1

    http://yt-project.orghttp://yt-project.org/docs/3.0

  • YT Documentation, Release 0.1

    2 Chapter 1. What is YT?

  • CHAPTER 2

    Installing YT

    YT requires Julia version 0.3 or later, and may be installed just like any other Julia package:

    julia> Pkg.add("YT")

    This will also install the following dependencies, if you don’t have them installed already:

    • PyCall

    • PyPlot

    • SymPy

    However, for YT to work, yt itself must be installed. YT requires yt version 3.0 or higher. The best ways to installyt are via the install script or via the Anaconda Python Distribution.

    Once YT is installed, either

    julia> import YT

    to use it as a library, or

    julia> using YT

    to use it as an application, loading its methods into the current session’s namespace.

    3

    http://github.com/stevengj/PyCall.jlhttp://github.com/stevengj/PyPlot.jlhttp://github.com/jverzani/SymPy.jlhttp://yt-project.org/#getythttps://store.continuum.io/cshop/anaconda/

  • YT Documentation, Release 0.1

    4 Chapter 2. Installing YT

  • CHAPTER 3

    YT Users’ Guide

    3.1 Datasets

    The most basic YT object is the Dataset. This is a collection of volumetric data that may be stored on disk, orcreated in-memory. To load a Dataset from disk, we use load:

    julia> ds = YT.load("sloshing_nomag2_hdf5_plt_cnt_0100")yt : [WARNING ] 2014-03-31 23:46:27,765 integer runtime parameter checkpointfilenumber overwrites a simulation scalar of the same nameyt : [WARNING ] 2014-03-31 23:46:27,765 integer runtime parameter plotfilenumber overwrites a simulation scalar of the same nameyt : [INFO ] 2014-03-31 23:46:27,768 Parameters: current_time = 7.89058001997e+16yt : [INFO ] 2014-03-31 23:46:27,768 Parameters: domain_dimensions = [16 16 16]yt : [INFO ] 2014-03-31 23:46:27,769 Parameters: domain_left_edge = [ -3.70272000e+24 -3.70272000e+24 -3.70272000e+24]yt : [INFO ] 2014-03-31 23:46:27,770 Parameters: domain_right_edge = [ 3.70272000e+24 3.70272000e+24 3.70272000e+24]yt : [INFO ] 2014-03-31 23:46:27,770 Parameters: cosmological_simulation = 0.0yt : [INFO ] 2014-03-31 23:46:28,340 Loading field plugins.yt : [INFO ] 2014-03-31 23:46:28,340 Loaded angular_momentum (8 new fields)yt : [INFO ] 2014-03-31 23:46:28,340 Loaded astro (14 new fields)yt : [INFO ] 2014-03-31 23:46:28,340 Loaded cosmology (20 new fields)yt : [INFO ] 2014-03-31 23:46:28,341 Loaded fluid (55 new fields)yt : [INFO ] 2014-03-31 23:46:28,341 Loaded fluid_vector (87 new fields)yt : [INFO ] 2014-03-31 23:46:28,342 Loaded geometric (102 new fields)yt : [INFO ] 2014-03-31 23:46:28,342 Loaded local (102 new fields)yt : [INFO ] 2014-03-31 23:46:28,342 Loaded magnetic_field (108 new fields)"sloshing_nomag2_hdf5_plt_cnt_0100"

    where you can see that the yt log has been outputted. The Dataset object ds now contains all of the basic metadataabout the data stored in the file "sloshing_nomag2_hdf5_plt_cnt_0100". Attached to ds are several usefulattributes, as well as a number of methods for creating DataContainers.

    3.1.1 Parameters

    Each simulation Dataset normally has a number of runtime parameters associated with it. This is stored in theparameters dictionary:

    julia> collect(keys(ds.parameters))293-element Array{Any,1}:"min_particles_per_blk""zmax""maxcondentr""usemassdiffusivity""saturatedconduction"

    5

  • YT Documentation, Release 0.1

    "zmin"

    "flux_correct""nxb""plotfilenumber""log_file""e_modification""order"

    julia> ds.parameters["nxb"]0-dimensional Array{Int32,0}:16

    3.1.2 Methods

    print_stats may be used to get a quick synopsis of the structure of the Dataset. In this case, it is a FLASHAMR dataset, so statistics regarding the grids and cells are printed:

    julia> YT.print_stats(ds)level # grids # cells # cells^3----------------------------------------------

    0 1 4096 151 8 32768 312 64 262144 633 512 2097152 1274 256 1048576 1015 256 1048576 1016 256 1048576 101

    ----------------------------------------------

    t = 7.89058002e+16 = 7.89058002e+16 s = 2.50037393e+09 years

    Smallest Cell:

    get_smallest_dx returns the length scale of the smallest cell or SPH smoothing length:

    julia> YT.get_smallest_dx(ds)7.231875e21 code_length

    Note: These methods apply to Datasets loaded from disk files and to Datasets created from generic in-memorydata. For details on how to create the latter, see In-Memory Datasets.

    3.2 Data Containers

    The most useful methods for Datasets are those that create DataContainer objects: physically meaningfulspatial objects that contain cells or particles with field data. YT implements a number of the data container objectsavailable in yt, and attempts to match the API of these objects as closely as possible. All of these objects can becreated from a Dataset object, typically with some additional information supplied.

    6 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    3.2.1 Supplying Length and Center Type Arguments to Data Containers

    A general note will be helpful before diving into the various DataContainer objects that are available. SpecialUnion types, Length and Center, have been defined for the various methods below for creating different objects.

    A Length-type argument is for length quantities such as radius or height and can be one of the following:

    • A Real number. If so, the assumed units are "code_length".

    • A (value, unit) tuple, e.g., (1.5,"Mpc").

    • A YTQuantity.

    A Center-type argument is for the center of an object and can be one of the following:

    • A String, e.g., "max" (or "m"), "center" (or "c").

    • An Array of Real numbers. If so, the assumed units are "code_length".

    • A YTArray.

    Note: All of the DataContainer objects take additional optional arguments, which are not documented here.Information on these can be found in the yt Documentation on data container objects.

    3.2.2 Available Data Containers

    All Data

    The simplest data container is one that represents all of the data in the Dataset. It requires no parameters to create,except the Dataset object:

    function AllData(ds::Dataset; args...)

    Examples:

    julia> dd = YT.AllData(ds)

    Sphere

    A Sphere is an object with a center and a radius.

    function Sphere(ds::Dataset, center::Center, radius::Length; args...)

    Examples:

    julia> sp = YT.Sphere(ds, "max", (100.,"kpc"))

    julia> R = YT.YTQuantity(200.,"kpc")

    julia> sp = YT.Sphere(ds, [0.0,0.0,0.0], R)

    Region

    A Region is a rectangular prism with a left_edge, a right_edge, and a center (that can be anywhere in thedomain). The edges can be YTArrays, or Arrays of Reals, in which case they will be assumed to be in units ofcode_length.

    3.2. Data Containers 7

    http://yt-project.org/docs/3.0/analyzing/objects.html

  • YT Documentation, Release 0.1

    function Region(ds::Dataset, center::Center, left_edge::Union(YTArray,Array),right_edge::Union(YTArray,Array); args...)

    Examples:

    julia> reg = YT.Region(ds, "c", [-3.0e23,-3.0e23,-3.0e23], [3.0e23,3.0e23, 3.0e23])

    julia> a = YT.YTArray([-0.5,-0.2,-0.3], "unitary")

    julia> b = YT.YTArray([0.4,0.1,0.4], "unitary")

    julia> reg = YT.Region(ds, [0.0,0.0,0.0], a, b)

    Disk

    A Disk is a disk or cylinder-shaped region with the z-axis of the cylinder pointing along a normal vector, with aradius, a center, and a height:

    function Disk(ds::Dataset, center::Center, normal::Array, radius::Length,height::Length; args...)

    Examples:

    julia> dk = YT.Disk(ds, "c", [1.0,0.2,-0.3], (100,"kpc"), (0.5,"Mpc"))

    Ray

    A Ray is a 1-dimensional object that starts at the start_point in code_length units and ends at theend_point in code_length units.

    function Ray(ds::Dataset, start_point::Array, end_point::Array; args...)

    Examples:

    julia> ray = Ray(ds, [0.0,0.0,0.0], [3.0e23,3.0e23,3.0e23])

    Slice

    A Slice is a 2-dimensional slice perpendicular to an axis, which can be either a string (“x”,”y”,”z”) or an integer(0,1,2), centered at some coordinate coord along that axis in code_length units.

    function Slice(ds::Dataset, axis::Union(Integer,String),coord::Real; args...)

    Examples:

    julia> slc = YT.Slice(ds, 2, 0.0)

    Proj

    A Proj is an integral of a given field along a sight line corresponding to axis.

    function Proj(ds::Dataset, field, axis::Union(Integer,String);weight_field=nothing, data_source=nothing, args...)

    8 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    The optional arguments weight_field (a field name) and data_source (a DataContainer) allow the pro-jection to be weighted and a subselection of the domain to be projected.

    Examples:

    julia> prj = YT.Proj(ds, "density", "z")

    julia> sp = YT.Sphere(ds, "max", (100.,"kpc"))

    julia> prj = YT.Proj(ds, "temperature", 1, weight_field="density", data_source=sp)

    Cutting

    A Cutting is a 2-dimensional slice perpendicular to an arbitrary normal vector centered at some center coordi-nate.

    function Cutting(ds::Dataset, normal::Array, center::Center; args...)

    Examples:

    julia> ct = YT.Cutting(ds, [1.0,0.2,-0.3], "c")

    julia> ct = YT.Cutting(ds, [-1.0,3.0,-4.0], [3.0e23,1.0e23,0.0])

    julia> c = YT.YTArray([100.,100.,100], "kpc")

    julia> ct = YT.Cutting(ds, [1.0,1.0,1.0], c)

    The normal vector will be normalized to unity if it isn’t already.

    CutRegion

    A CutRegion is a subset of another DataContainer dc, which is determined by an array of conditions onfields in the container.

    function CutRegion(dc::DataContainer, conditions::Array; args...)

    conditions is a list of conditionals that will be evaluated. In the namespace available, these conditionals willhave access to ‘obj’ which is a data object of unknown shape, and they must generate a boolean array. For instance,conditionals = [“obj[‘temperature’] < 1e3”]

    Examples:

    julia> sp = YT.Sphere(ds, "max", (100.,"kpc"))

    julia> cr = YT.CutRegion(sp, ["obj[’temperature’] > 4.0e7", "obj[’temperature’] < 5.0e7"])

    where it can be easily verified that this produces a DataContainer with "temperature" in between thoselimits:

    julia> minimum(cr["temperature"])4.0000196e7 K

    julia> maximum(cr["temperature"])4.9999116e7 K

    3.2. Data Containers 9

  • YT Documentation, Release 0.1

    CoveringGrid

    A CoveringGrid is a 3D DataContainer of cells extracted at a fixed resolution.

    function CoveringGrid(ds::Dataset, level::Integer, left_edge::Array, dims::Array; args...)

    level is the refinement level at which to extract the data, left_edge is the left edge of the grid in code_lengthunits, and dims is the number of cells on a side.

    Examples:

    julia> cg = YT.CoveringGrid(ds, 5, [-3.0856e23,-3.0856e23,-3.0856e23], [64,64,64])

    The fields of this DataContainer are 3D YTArrays:

    julia> cg["velocity_x"]64x64x64 YTArray (cm/s):[:, :, 1] =-9.45944e6 -9.22163e6 -8.97506e6 ... -4.54556e6 -5.2798e6-9.64798e6 -9.40576e6 -9.14971e6 -4.38682e6 -5.13215e6-9.82901e6 -9.57772e6 -9.30941e6 -4.25022e6 -5.00537e6-9.9932e6 -9.72978e6 -9.45173e6 -4.13942e6 -4.90191e6-1.01421e7 -9.86609e6 -9.57824e6 -4.04788e6 -4.81652e6-1.02767e7 -9.99092e6 -9.69512e6 ... -3.98365e6 -4.75448e6-1.03932e7 -1.01006e7 -9.79921e6 -3.9392e6 -4.71177e6-1.04856e7 -1.01875e7 -9.87844e6 -3.92483e6 -4.69586e6-1.05589e7 -1.02484e7 -9.92279e6 -3.93876e6 -4.70134e6-1.06159e7 -1.0293e7 -9.94764e6 -3.98234e6 -4.73101e6-1.06488e7 -1.03028e7 -9.94144e6 ... -4.05713e6 -4.79151e6-1.06532e7 -1.02881e7 -9.90535e6 -4.1667e6 -4.88172e6-1.06367e7 -1.0246e7 -9.84756e6 -4.30115e6 -4.99339e6

    -1.07594e7 -1.00079e7 -9.23378e6 -2.4916e6 -2.63372e6-1.10205e7 -1.02792e7 -9.51947e6 -1.95956e6 -2.26497e6-1.12805e7 -1.05476e7 -9.79831e6 -1.95956e6 -2.26497e6-1.15351e7 -1.08149e7 -1.0073e7 ... -1.24862e6 -1.56333e6-1.17823e7 -1.10766e7 -1.03451e7 -1.24862e6 -1.56333e6-1.20202e7 -1.13275e7 -1.06126e7 -567435.0 -850258.0-1.22529e7 -1.15684e7 -1.08709e7 -567435.0 -850258.0-1.24835e7 -1.18055e7 -1.11232e7 26094.7 -200632.0-1.27079e7 -1.20408e7 -1.13734e7 ... 26094.7 -200632.0-1.2922e7 -1.22686e7 -1.16157e7 537401.0 358841.0-1.31273e7 -1.24859e7 -1.1844e7 537401.0 358841.0-1.33282e7 -1.26955e7 -1.20595e7 973392.0 829474.0

    ...

    Grids

    If your simulation is grid-based, you can also get at the data in the individual grids using the Grids object:

    function Grids(ds::Dataset)

    Grids objects are Arrays, so the length() can be determined and they can be indexed. You can access theindividual fields of a single Grid object as well:

    julia> grids = Grids(ds)[ FLASHGrid_0001 ([16 16 16]),

    FLASHGrid_0002 ([16 16 16]),

    10 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    FLASHGrid_0003 ([16 16 16]),FLASHGrid_0004 ([16 16 16]),...FLASHGrid_1350 ([16 16 16]),FLASHGrid_1351 ([16 16 16]),FLASHGrid_1352 ([16 16 16]),FLASHGrid_1353 ([16 16 16]) ]

    julia> length(grids)1353

    julia> my_grid = grids[1000]FLASHGrid_1000 ([16 16 16])

    julia> my_grid["velocity_x"]16x16x16 YTArray (cm/s):[:, :, 1] =

    -1.2075387e7 -1.241014e7 ... -1.4580984e7-1.021574e7 -1.0516409e7 -1.2799518e7-8.3335155e6 -8.598048e6 -1.124706e7-6.415593e6 -6.70807e6 -9.730029e6-4.564453e6 -4.8659225e6 -8.137291e6-2.8466195e6 -3.1491e6 ... -6.434752e6-1.0172061875e6 -1.354249625e6 -4.6243535e6

    ...

    3.2.3 Accessing the Data Within Containers

    Data can be accessed from containers in Dict-like fashion, the same way as in yt:

    julia> sp["density"]325405-element YTArray (g/cm**3):1.2992312619628604e-261.2946242834614906e-261.3086558386643183e-261.28922012403754e-261.3036428741306716e-261.2999706649871096e-261.3180126226317337e-261.2829197138546694e-261.297694215792844e-261.2945722063157944e-26

    1.6265898946277187e-261.6606648338733776e-261.649533421018006e-261.6093269371270004e-261.64592576904618e-261.606223724726208e-261.6415200117053996e-261.622938177378765e-261.6194386856326155e-261.595660076018442e-26

    You can also specify a field names as a ftype, fname tuple, where the first string is the field type. The"density" field has a field type of "gas":

    3.2. Data Containers 11

  • YT Documentation, Release 0.1

    julia> sp["gas","density"]325405-element YTArray (g/cm**3):1.2992312619628604e-261.2946242834614906e-261.3086558386643183e-261.28922012403754e-261.3036428741306716e-261.2999706649871096e-261.3180126226317337e-261.2829197138546694e-261.297694215792844e-261.2945722063157944e-26

    1.6265898946277187e-261.6606648338733776e-261.649533421018006e-261.6093269371270004e-261.64592576904618e-261.606223724726208e-261.6415200117053996e-261.622938177378765e-261.6194386856326155e-261.595660076018442e-26

    whereas you could get at the original FLASH field like this:

    julia> sp["flash","dens"]325405-element YTArray (code_mass/code_length**3):1.2992312619628604e-261.2946242834614906e-261.3086558386643183e-261.28922012403754e-261.3036428741306716e-261.2999706649871096e-261.3180126226317337e-261.2829197138546694e-261.297694215792844e-261.2945722063157944e-26

    1.6265898946277187e-261.6606648338733776e-261.649533421018006e-261.6093269371270004e-261.64592576904618e-261.606223724726208e-261.6415200117053996e-261.622938177378765e-261.6194386856326155e-261.595660076018442e-26

    which in the case of FLASH datasets is trivial because code units are equivalent to cgs units.

    3.2.4 Field Parameters

    Some complex fields rely on “field parameters” in their definitions. Field parameters can be literally anything, includ-ing strings, integers, real numbers, YTArrays, etc. To set a field parameter for a particular DataContainer, useset_field_parameter:

    12 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    julia> sp = YT.Sphere(ds, "max", (100.,"kpc"))

    julia> bulk_velocity = YT.YTArray(ds, [100.,-200.,300.], "km/s")

    julia> YT.set_field_parameter(sp, "bulk_velocity", bulk_velocity)

    Similarly, get_field_parameter returns a specific parameter based on its key:

    julia> YT.get_field_parameter(sp, "bulk_velocity")3-element YTArray (km/s):

    100.0-200.0300.0

    has_field_parameter can be used to check for the existence of a parameter:

    julia> YT.has_field_parameter(sp, "center")true

    To get a dictionary containing all of the field parameters for a dataset, use get_field_parameters:

    julia> fp = YT.get_field_parameters(sp)

    julia> fp["center"]3-element YTArray (code_length):-1.08478e223.61594e213.61594e21

    For more information about field parameters, consult the yt Documentation on field parameters.

    3.3 Arrays, Quantities, and Units

    Whenever YT returns physical data, it is typically associated with certain units (e.g., density in grams per cubiccentimeter, temperature in Kelvin, and so on). YT exposes the YTArray, YTQuantity, and units facilities from ytso that “unitful” objects may be manipulated and operated on.

    3.3.1 Arrays

    If we grab the "density" field from a sphere, it will be returned as a YTArray in g/cm3:

    julia> sp = YT.Sphere(ds, "c", (100.,"kpc"))YTSphere (sloshing_nomag2_hdf5_plt_cnt_0100): center=[ 0. 0. 0.] code_length,radius=100.0 kpc

    julia> sp["density"]325184-element YTArray (g/cm**3):1.3086558386643183e-261.28922012403754e-261.3036428741306716e-261.2999706649871096e-261.3180126226317337e-261.2829197138546694e-261.297694215792844e-261.2945722063157944e-261.3124175650316954e-26

    3.3. Arrays, Quantities, and Units 13

    http://yt-project.org/doc/analyzing/fields.html#field-parameters

  • YT Documentation, Release 0.1

    1.3088245501274466e-26

    1.6093269371270004e-261.64592576904618e-261.606223724726208e-261.6415200117053996e-261.635422055278283e-261.622938177378765e-261.5840914000284966e-261.6194386856326155e-261.6152527924542866e-261.595660076018442e-26

    A YTArray can be manipulated in many of the same ways that normal Julia arrays are, and the units are retained.The following are some simple examples of this.

    Finding the maximum density:

    julia> maximum(sp["density"])9.256136409265674e-26 g/cm**3

    Multiplying the temperature by a constant unitless number:

    julia> sp["temperature"]*5325184-element YTArray (K):4.41628e84.4457548e84.4363016e84.4104716e84.4259016e84.464104e84.4553836e84.429778e84.4458e84.4192136e8

    3.42009e83.3811488e83.3988892e83.3605176e83.341696e83.410656e83.4288464e83.390078e83.369208e83.4209352e8

    Adding two YTArrays:

    julia> sp["velocity_magnitude"]+sp["sound_speed"]325184-element YTArray (cm/s):1.7494106880789694e81.750480854794736e81.7491905482683247e81.7463744560410416e81.7477896725137833e81.7498621058854717e81.7486426825557864e81.7463176707801563e81.7473392939487094e8

    14 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    1.7449670611457497e8

    1.4691744928089392e81.448218647261667e81.4619022766526273e81.4414687202610317e81.4354279490019822e81.4629026827881128e81.4767689116216296e81.45570568978103e81.4486893148240653e81.471462895473701e8

    Multiplying element-wise one YTArray by another:

    julia> sp["density"].*sp["temperature"]325184-element YTArray (K*g/cm**3):1.1558781214352911e-181.1463113109392978e-181.1566705936668994e-181.1466967397517522e-181.1666788350651973e-181.145417405259497e-181.1563451053716595e-181.1469334957898334e-181.1669492021235823e-181.1567950503874187e-18

    1.1008085928797365e-181.1130239877799136e-181.0918752941511363e-181.1032713780176403e-181.0930166680870434e-181.1070567664611898e-181.0863212188517341e-181.0980046921024092e-181.0884245260718644e-181.0917299442572327e-18

    However, attempting to perform an operation that doesn’t make sense will throw an error. For example, suppose thatyou tried to instead add "density" and "temperature", which aren’t the same type of physical quantity:

    julia> sp["density"]+sp["temperature"]ERROR: The + operator for YTArrays with units(g/cm**3) and (K) is not well defined.in + at /Users/jzuhone/.julia/YT/src/array.jl:141

    It is also possible to create a YTArray from a regular Julia Array, like so:

    julia> a = YT.YTArray(randn(10), "erg")10-element YTArray (erg):-0.14854525691731818-0.44315729646073715-1.8669284316708383-1.4228733016999084-0.09340200195694140.0296605525220978130.4280709348298647

    -0.05755731738462625

    3.3. Arrays, Quantities, and Units 15

  • YT Documentation, Release 0.1

    1.0328743620117720.17854214710697325

    If your YTArray needs to know about code units associated with a specific dataset, you’ll have to create it with aDataset object passed in:

    julia> a = YT.YTArray(ds, [1.0,1.0,1.0], "code_length")3-element YTArray (code_length):1.01.01.0

    3.3.2 Quantities

    A YTQuantity is just a scalar version of a YTArray. They can be manipulated in the same way:

    julia> a = YT.YTQuantity(3.14159, "radian")3.14159 radian

    julia> b = YT.YTQuantity(12, "cm")12.0 cm

    julia> a/b0.26179916666666664 radian/cm

    julia> a\b3.8197218605865184 cm/radian

    julia> c = YT.YTQuantity(13,"m")13.0 m

    julia> b+c1312.0 cm

    julia> d = YT.YTQuantity(ds, 1.0, "code_length")1.0 code_length

    3.3.3 Changing Units

    Occasionally you will want to change the units of an array or quantity to something more appropriate. Taking densityas the example, we can change it to units of solar masses per kiloparsec:

    julia> a = YT.in_units(sp["density"], "Msun/kpc**3")325184-element YTArray (Msun/kpc**3):193361.43661723754190489.69785225237192620.74223809008192078.1521891412194743.95533346717189558.77596412544191741.79371078173191280.49883112026193917.25335152834193386.3647075119

    237787.32295826814

    16 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    243195.01114436015237328.8054548747242544.03512482112241643.02694502342239798.46209161723234058.62702232625239281.3920328031238662.9022094481235767.96552301125

    We can switch back to cgs units rather easily:

    julia> YT.in_cgs(a)325184-element YTArray (g/cm**3):1.3086558386643183e-261.28922012403754e-261.303642874130672e-261.2999706649871096e-261.318012622631734e-261.2829197138546696e-261.297694215792844e-261.2945722063157944e-261.3124175650316954e-261.308824550127447e-26

    1.6093269371270004e-261.64592576904618e-261.606223724726208e-261.6415200117053996e-261.6354220552782833e-261.622938177378765e-261.5840914000284966e-261.6194386856326155e-261.6152527924542868e-261.595660076018442e-26

    or to MKS units:

    julia> YT.in_mks(a)325184-element YTArray (kg/m**3):1.3086558386643184e-231.2892201240375402e-231.3036428741306718e-231.2999706649871097e-231.3180126226317338e-231.2829197138546696e-231.297694215792844e-231.2945722063157945e-231.3124175650316956e-231.3088245501274467e-23

    1.6093269371270004e-231.64592576904618e-231.6062237247262084e-231.6415200117053996e-231.6354220552782833e-231.6229381773787652e-231.584091400028497e-231.6194386856326155e-23

    3.3. Arrays, Quantities, and Units 17

  • YT Documentation, Release 0.1

    1.6152527924542868e-231.595660076018442e-23

    3.3.4 Physical Constants

    Some physical constants are represented in YT. They are available via the YT.physical_constants submodule,and are unitful quantities which can be used with other quantities and arrays:

    julia> kb = YT.physical_constants.kboltz # Boltzmann constant1.3806488e-16 erg/K

    julia> kT = YT.in_units(kb*sp["temperature"], "keV") # computing kT in kilo-electronvolts325184-element YTArray (keV):7.6113105472628927.662109377074067.6458171037432517.6012999645591877.627893052348977.69373360821289957.67870429111879557.6345738978128927.6621872777589667.616366508529263

    5.89441047433322755.8272966214337125.8578716061793935.7917394397870115.7593010430829165.8781512915588385.9095018362206195.8426857983288865.8067170528867095.895867148202309

    The physical constants implemented in YT.physical_constants are (in cgs units):

    • G: Newton’s constant of gravitation

    • kboltz: Boltzmann’s constant

    • clight: Speed of light in vacuum

    • me: mass of the electron

    • mp: mass of the proton

    • qp: charge of the proton

    • hcgs: Planck’s constant

    • sigma_thompson: Thompson cross section

    • amu_cgs: Atomic mass unit

    • Na: Avogadro’s number

    • Tcmb: Cosmic microwave background temperature

    • stefan_boltzmann: Stefan-Boltzmann constant

    18 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    3.4 Profiles

    yt allows for data container objects to be binned up into profiles along some dimension defined by a field. These canbe in 1D, 2D, or 3D. YT reproduces this functionality via the YTProfile type:

    function YTProfile(data_source::DataContainer, bin_fields, fields;n_bins=64, extrema=nothing, logs=nothing,units=nothing, weight_field="cell_mass",accumulation=false, fractional=false)

    YTProfile takes the following arguments:

    • data_source: The DataContainer object containing the data from which the profile is to be created.

    • bin_fields: An Array of field names over which the binning will occur. The number of fields decideswhether or not this will be a 1D, 2D, or 3D profile. If a single field string is given, it assumed to be 1D.

    • fields: A single field or list of fields to be binned.

    • n_bins: A single integer or tuple of 2 or 3 integers, to determine the number of bins along each dimension.

    • extrema: A dictionary of tuples (with the field names as the keys) that determine the maximum and minimumof the bin ranges, e.g. [”density”=>(1.0e-30, 1.0e-25)]. If a field’s extrema are not specified, the extrema of thefield in the data_source are assumed. The extrema are assumed to be in the units of the field in the unitsargument unless it is not specified, otherwise they are in the field’s default units.

    • logs: A dictionary of tuples (with the field names as the keys) that determine whether the bins are in logspaceor linear space, e.g. [”radius”=>false]. If not set, the take_log attribute for the field determines this.

    • units: A dictionary of tuples (with the field names as the keys) that determine the units of the field. If not setthen the default units for the field are used.

    • weight_field: The field to weight the binned fields by when binning. Can be a field name or nothing, toproduce an unweighted profile. "cell_mass" is the default.

    • accumulation: If true, the profile values for a bin n are the cumulative sum of all the values from bin 1to n. If the profile is 2D or 3D, an Array of values can be given to control the summation in each dimensionindependently.

    • fractional: If true, the profile values are divided by the sum of all of the values.

    For example, to construct a 1D radial profile from a Sphere, with the bins in linear space and with the units of theradius in kpc:

    julia> sp = YT.Sphere(ds, "max", (1.0,"Mpc"))

    julia> units=["radius"=>"kpc"]

    julia> logs=["radius"=>false]

    julia> fields=["density","temperature"]

    julia> profile = YT.YTProfile(sp, "radius", fields, n_bins=100, units=units, logs=logs)

    The bin_fields can be accessed from the YTProfile object as attributes, e.g.:

    julia> profile.x100-element YTArray (kpc):

    4.9999114.999724.9995

    3.4. Profiles 19

  • YT Documentation, Release 0.1

    34.999344.999254.99964.998874.998684.998494.9982104.998114.998124.998

    884.983894.983904.983914.983924.983934.982944.982954.982964.982974.982984.981994.981

    where the attributes x, y, and z correspond to the bin_fields of 1D, 2D, and 3D profiles. The fields of theprofile are accessed in the same way as DataContainers:

    julia> profile["temperature"]100-element YTArray (K):4.78287e74.78144e75.55494e75.98079e76.20128e76.41538e76.73181e77.28897e77.67484e77.6859e77.65575e77.60974e77.55863e7

    5.15882e75.16148e75.15205e75.15374e75.15363e75.17031e75.15198e75.1652e75.16727e75.17993e75.18381e75.1944e7

    The resulting profile data can be plotted with a plotting program like PyPlot or Winston:

    20 Chapter 3. YT Users’ Guide

    http://github.com/stevengj/PyPlot.jlhttp://github.com/nolta/Winston.jl

  • YT Documentation, Release 0.1

    julia> using PyPlot

    julia> plot(profile.x.value, profile["density"].value)

    julia> xscale("log")

    julia> yscale("log")

    julia> xlabel("radius")

    julia> ylabel("density")

    The variance of a given field can be computed as well:

    julia> YT.variance(profile, "density")100-element YTArray (g/cm**3):8.88606e-271.00439e-261.05204e-267.17655e-277.2972e-278.29273e-277.97938e-275.74176e-273.73228e-27

    3.4. Profiles 21

  • YT Documentation, Release 0.1

    3.28493e-272.91421e-272.58537e-272.27903e-27

    1.28528e-281.28161e-281.25986e-281.25587e-281.24444e-281.24095e-281.21943e-281.21903e-281.20435e-281.20124e-281.18991e-281.18264e-28

    The units of the bin_fields can be changed using one of the set_x_unit, set_y_unit, or set_z_unitmethods:

    julia> YT.set_x_unit(profile, "Mpc")

    julia> profile.x100-element YTArray (Mpc):0.004999910.01499970.02499950.03499930.04499920.0549990.06499880.07499860.08499840.09499820.1049980.1149980.124998

    0.8849830.8949830.9049830.9149830.9249830.9349820.9449820.9549820.9649820.9749820.9849810.994981

    Similarly, the units of the fields can be changed with set_field_unit:

    julia> YT.set_field_unit(profile, "density", "Msun/kpc**3")

    julia> profile["density"]100-element YTArray (Msun/kpc**3):1.16056e6

    22 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    1.00365e6754309.0602161.0519959.0457351.0390482.0315199.0264284.0238734.0217263.0198420.0181572.0

    5663.045563.155426.815324.815220.55140.145011.734930.844834.154757.824663.74584.25

    3.5 Plotting and Images

    3.5.1 Plots

    YT provides an interface to two of the most common plotting routines in yt: SlicePlot and ProjectionPlot:

    function SlicePlot(ds::Dataset, axis, fields; center="c", args...)

    function ProjectionPlot(ds::Dataset, axis, fields; center="c", data_source=nothing, args...)

    Unlike other methods in YT, these return the native yt Python-based objects. This is mainly for convenience; it allowsone to use all of the annotation and plot modification methods that hang off these objects. The API for these objects isthe same as it is in yt, which can be found in the yt plotting documentation.

    We’ll illustrate the plotting functionality with a SlicePlot as an example:

    julia> slc = YT.SlicePlot(ds, "z", ["density","temperature"], width=(500.,"kpc"))

    3.5. Plotting and Images 23

    http://yt-project.org/docs/3.0/visualizing/plots.html

  • YT Documentation, Release 0.1

    24 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    which produces a SlicePlot PyObject of the fields “density” and “temperature”, along the “z” axis. Theoptional argument width has been used to zoom on on the central 500 kpc of the domain. The SlicePlot objecthas available to it all of the methods for annotating the plot that one would have access to in yt. For example, one canannotate grids:

    julia> slc.annotate_grids()

    3.5. Plotting and Images 25

  • YT Documentation, Release 0.1

    26 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    or velocity vectors:

    julia> slc.annotate_velocity()

    3.5. Plotting and Images 27

  • YT Documentation, Release 0.1

    28 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    Logging can be set for specific fields:

    julia> slc.set_log("temperature", false)

    3.5. Plotting and Images 29

  • YT Documentation, Release 0.1

    or the colormap can be changed:

    julia> slc.set_cmap("density", "kamae")

    30 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    To save a plot:

    julia> slc.save("my_awesome_plot.png")

    If one is in the IJulia notebook, the show_plot method can be used to display the plot inline:

    julia> YT.show_plot(slc)

    The full set of options for these plots can be found in the yt plotting documentation.

    3.5.2 Images

    To create a raw 2D image from a Slice or Proj object, one can create a FixedResolutionBuffer objectusing the to_frb method:

    function to_frb(cont::Union(Slice,Proj), width::Length,nx::Union(Integer,(Integer,Integer)); center=nothing, height=nothing,args...)

    3.5. Plotting and Images 31

    http://github.com/JuliaLang/IJulia.jlhttp://yt-project.org/docs/3.0/visualizing/plots.html

  • YT Documentation, Release 0.1

    where cont is the Slice or Proj object, width is the width of the plot, nx is the resolution of the image, centeris the center of the image (defaults to the center of the cont), and height is the height of the image (defaults tothe width). The resolution nx can either be a single value or a tuple of two values, depending on how you want toset the width and height. This is an example of how to create a FixedResolutionBuffer from a Slice:

    julia> slc = YT.Slice(ds, "z", 0.0)YTSlice (sloshing_nomag2_hdf5_plt_cnt_0100): axis=2, coord=0.0

    julia> frb = YT.to_frb(slc, (500.,"kpc"), 800)FixedResolutionBuffer (800x800):

    -7.714193952405812e23 code_length imagesc(frb["kT"].value)

    which yields the following image:

    32 Chapter 3. YT Users’ Guide

    http://github.com/stevengj/PyPlot.jlhttp://github.com/nolta/Winston.jl

  • YT Documentation, Release 0.1

    3.6 In-Memory Datasets

    This section shows how to load generic array (grid-based) and particle data that resides in memory into YT to createDataset objects.

    Note: This section is essentially a copy of the IPython notebooks Loading Generic Array Data and Loading GenericParticle Data from the yt Documentation. They have been reproduced here using Julia code to show how to generategeneric Datasets for use with YT.

    3.6. In-Memory Datasets 33

    http://yt-project.org/docs/3.0/examining/generic_array_data.htmlhttp://yt-project.org/docs/3.0/examining/generic_particle_data.htmlhttp://yt-project.org/docs/3.0/examining/generic_particle_data.htmlhttp://yt-project.org/docs/3.0

  • YT Documentation, Release 0.1

    3.6.1 Generic Unigrid Data

    The most common example on in-memory or “generic” data is that of data that is generated in memory from thecurrently running script or notebook. In this example, we’ll just create a 3-D array of random floating-point data:

    arr = rand(64,64,64)

    To load this data into YT, we need to associate it with a field. The data dictionary consists of one or more fields, eachconsisting of a tuple of an Array and a unit string. Then, we can call load_uniform_grid:

    data = Dict()data["density"] = (arr, "g/cm**3")bbox = [-1.5 1.5; -1.5 1.5; -1.5 1.5]ds = YT.load_uniform_grid(data, [64,64,64]; length_unit="Mpc", bbox=bbox, nprocs=64)

    load_uniform_grid takes the following arguments and optional keywords:

    • data : This is a dict of numpy arrays, where the keys are the field names

    • domain_dimensions : The domain dimensions of the unigrid

    • length_unit : The unit that corresponds to code_length, can be a string, tuple, or floating-point number

    • bbox : Size of computational domain in units of code_length

    • nprocs : If greater than 1, will create this number of subarrays out of data

    • sim_time : The simulation time in seconds

    • mass_unit : The unit that corresponds to code_mass, can be a string, tuple, or floating-point number

    • time_unit : The unit that corresponds to code_time, can be a string, tuple, or floating-point number

    • velocity_unit : The unit that corresponds to code_velocity

    • magnetic_unit : The unit that corresponds to code_magnetic, i.e. the internal units used to representmagnetic field strengths.

    • periodicity : A tuple of booleans that determines whether the data will be treated as periodic along eachaxis

    This example creates a yt-native dataset ds that will treat your array as a density field in cubic domain of 3 Mpc edgesize and simultaneously divide the domain into nprocs = 64 chunks, so that you can take advantage of the underlyingparallelism.

    The optional unit keyword arguments allow for the default units of the dataset to be set. They can be:

    • A string, e.g. length_unit="Mpc"

    • A tuple, e.g. mass_unit=(1.0e14, "Msun")

    • A floating-point value, e.g. time_unit=3.1557e13

    In the latter case, the unit is assumed to be cgs.

    The resulting ds functions exactly like a dataset like any other YT can handle–it can be sliced, and we can show thegrid boundaries:

    slc = YT.SlicePlot(ds, "z", ["density"])slc.set_cmap("density", "Blues")slc.annotate_grids(cmap=nothing)YT.show_plot(slc)

    34 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    Particle fields are detected as one-dimensional fields. The number of particles is set by the number_of_particleskey in data. Particle fields are then added as one-dimensional Arrays in a similar manner as the three-dimensionalgrid fields:

    arr = rand(64,64,64)posx_arr = 3*rand(10000)-1.5posy_arr = 3*rand(10000)-1.5posz_arr = 3*rand(10000)-1.5data = Dict()data["density"] = (arr, "Msun/kpc**3")data["number_of_particles"] = 10000data["particle_position_x"] = (posx_arr, "code_length")data["particle_position_y"] = (posy_arr, "code_length")data["particle_position_z"] = (posz_arr, "code_length")bbox = [-1.5 1.5; -1.5 1.5; -1.5 1.5]lu = (1.0,"Mpc")mu = (1.0,"Msun")ds = YT.load_uniform_grid(data, [64,64,64]; length_unit=lu, mass_unit=mu, bbox=bbox, nprocs=4)

    In this example only the particle position fields have been assigned. number_of_particles must be the samesize as the particle arrays. If no particle arrays are supplied then number_of_particles is assumed to be zero.Take a slice, and overlay particle positions:

    3.6. In-Memory Datasets 35

  • YT Documentation, Release 0.1

    slc = YT.SlicePlot(ds, "z", ["density"])slc.set_cmap("density", "Blues")slc.annotate_particles(0.25, p_size=12.0, col="Red")YT.show_plot(slc)

    3.6.2 Generic AMR Data

    In a similar fashion to unigrid data, data gridded into rectangular patches at varying levels of resolution may also beloaded into YT. In this case, a list of grid dictionaries should be provided, with the requisite information about eachgrid’s properties. This example sets up two grids: a top-level grid (level == 0) covering the entire domain and asubgrid at level == 1.

    grid_data = [["left_edge"=>[0.0, 0.0, 0.0],"right_edge"=>[1.0, 1.0, 1.0],"level"=>0,"dimensions"=>[32, 32, 32]],

    ["left_edge"=>[0.25, 0.25, 0.25],"right_edge"=>[0.75, 0.75, 0.75],"level"=>1,

    36 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    "dimensions"=>[32, 32, 32]]]

    We’ll just fill each grid with random density data, with a scaling with the grid refinement level.

    for g in grid_datag["density"] = rand(g["dimensions"]...) * 2^g["level"]

    end

    Particle fields are supported by adding 1-dimensional arrays to each grid and setting the number_of_particleskey in each grid‘s dict. If a grid has no particles, set number_of_particles = 0, but the particle fields stillhave to be defined since they are defined elsewhere; set them to empty Float64 Arrays:

    grid_data[1]["number_of_particles"] = 0 # Set no particles in the top-level gridgrid_data[1]["particle_position_x"] = Float64[] # No particles, so set empty arraysgrid_data[1]["particle_position_y"] = Float64[]grid_data[1]["particle_position_z"] = Float64[]grid_data[2]["number_of_particles"] = 1000grid_data[2]["particle_position_x"] = 0.5*rand(1000)+0.25grid_data[2]["particle_position_y"] = 0.5*rand(1000)+0.25grid_data[2]["particle_position_z"] = 0.5*rand(1000)+0.25

    We need to specify the field units in a field_units Dict:

    field_units = [’’density’’=>’’code_mass/code_length**3’’,

    Then, call load_amr_grids:

    ds = YT.load_amr_grids(grid_data, [32, 32, 32]; field_units=field_units)

    load_amr_grids also takes the same keywords bbox and sim_time as load_uniform_grid. We couldhave also specified the length, time, velocity, and mass units in the same manner as before. Let’s take a slice:

    slc = YT.SlicePlot(ds, "z", ["density"])slc.annotate_particles(0.25, p_size=15.0, col="Pink")YT.show_plot(slc)

    3.6. In-Memory Datasets 37

  • YT Documentation, Release 0.1

    Caveats for Loading Generic Array Data

    • Particles may be difficult to integrate.

    • Data must already reside in memory before loading it in to YT, whether it is generated at runtime or loaded fromdisk.

    • No consistency checks are performed on the hierarchy

    • Consistency between particle positions and grids is not checked; load_amr_grids assumes that particlepositions associated with one grid are not bounded within another grid at a higher level, so this must be ensuredby the user prior to loading the grid data.

    3.6.3 Generic Particle Data

    This example creates a fake in-memory particle dataset and then loads it as a YT dataset using the load_particlesfunction.

    Our “fake” dataset will be Arrays filled with normally distributed random particle positions and uniform particlemasses. Since real data is often scaled, we arbitrarily multiply by 1e6 to show how to deal with scaled data.

    38 Chapter 3. YT Users’ Guide

  • YT Documentation, Release 0.1

    The load_particles function accepts a dictionary populated with particle data fields loaded in memory asArrays:

    n_particles = 5000000data = Dict()data["particle_position_x"] = 1.0e6*randn(n_particles)data["particle_position_y"] = 1.0e6*randn(n_particles)data["particle_position_z"] = 1.0e6*randn(n_particles)data["particle_mass"] = ones(n_particles)

    To hook up with yt‘s internal field system, the dictionary keys must be ’particle_position_x’,’particle_position_y’, ’particle_position_z’, and ’particle_mass’, as well as any other par-ticle field provided by one of the particle frontends.

    The load_particles function transforms the data dictionary into an in-memory YT Dataset object, providingan interface for further analysis with YT. The example below illustrates how to load the data dictionary we createdabove.

    bbox = 1.1*[minimum(data["particle_position_x"]) maximum(data["particle_position_x"]);minimum(data["particle_position_y"]) maximum(data["particle_position_y"]);minimum(data["particle_position_z"]) maximum(data["particle_position_z"])]

    ds = YT.load_particles(data, length_unit="pc", mass_unit=(1e8, "Msun"), n_ref=256, bbox=bbox)

    The length_unit and mass_unit are the conversion from the units used in the data dictionary to CGS. I’vearbitrarily chosen one parsec and 108𝑀⊙ for this example.

    The n_ref parameter controls how many particle it takes to accumulate in an oct-tree cell to trigger refinement.Larger n_ref will decrease poisson noise at the cost of resolution in the octree.

    Finally, the bbox parameter is a bounding box in the units of the dataset that contains all of the particles. This is usedto set the size of the base octree block.

    This new dataset acts like any other YT Dataset object, and can be used to create data objects and query for YTfields. This example shows how to access “deposit” fields:

    ad = YT.AllData(ds)cic_density = ad["deposit", "all_cic"]nn_density = ad["deposit", "all_density"]nn_deposited_mass = ad["deposit", "all_mass"]particle_count_per_cell = ad["deposit", "all_count"]

    Finally, we’ll slice through the "all_cic" deposited particle field:

    slc = YT.SlicePlot(ds, 2, ("deposit", "all_cic"))slc.set_width((8, "Mpc"))YT.show_plot(slc)

    3.6. In-Memory Datasets 39

  • YT Documentation, Release 0.1

    40 Chapter 3. YT Users’ Guide

  • CHAPTER 4

    Indices and tables

    • genindex

    • search

    41

    What is YT?What YT DoesWhat YT Doesn't Do (and Probably Won't)

    Installing YTYT Users' GuideDatasetsData ContainersArrays, Quantities, and UnitsProfilesPlotting and ImagesIn-Memory Datasets

    Indices and tables