[yt-users] quan

Nathan Goldbaum nathan12343 at gmail.com
Thu Nov 5 14:03:55 PST 2015


Hi Dave,

This is documented here:

http://yt-project.org/doc/analyzing/units/comoving_units_and_code_units.html#The-unit-registry

Since some units (e.g. "unitary", "code_length", or any other "code" unit)
depend on knowledge about the dataset, we created two shortcuts, "ds.quan"
and "ds.arr" to create YTQuantity instances (floats with units) and YTarray
instances (numpy arrays with units) without needing to think about unit
registries, which carry around all of the dataset-specific unit metadata.

This snippet:

    my_quan = ds.quan(3, 'code_length')

is 100% equivalent to:

    from yt import YTQuantity

    my_quan = YTQuantity(3, 'code_length', registry=ds.unit_registry)

You can see how the former is easier to read, although it's certainly a bit
"magic". It *does* communicate that the unit "comes from" the dataset
somehow, since you need a dataset instance to use it at all.

There's also ds.arr, which is similar to ds.quan, except it can work with
array data, so you can do:

    my_arr = ds.arr([1, 2, 3], 'code_length')

Note that this song and dance is only necessary for units that depend on
knowledge of a dataset. For physical units, you can always do something
like:

    from yt.units import kpc

    three_kiloparsecs = 3*kpc

Hope that helps!

-Nathan


On Thu, Nov 5, 2015 at 3:55 PM, Dave Semeraro <semeraro at tacc.utexas.edu>
wrote:

> Hey YT crowd,
>
>
>
> What does the quan method of a dataset do? If I have a dataset ds and I
> call ds.quan(0.1,’unitary’) (got that from an example somewhere) what does
> that return? I am tired of cutting and pasting from examples. I would like
> to know what I am doing for a change.
>
>
>
> Thanks,
>
> Dave
>
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20151105/5a4f053e/attachment.htm>


More information about the yt-users mailing list