[yt-users] quan

Dave Semeraro semeraro at tacc.utexas.edu
Fri Nov 6 06:51:06 PST 2015


Thanks, that clears it up.

From: yt-users [mailto:yt-users-bounces at lists.spacepope.org] On Behalf Of Nathan Goldbaum
Sent: Thursday, November 5, 2015 4:04 PM
To: Discussion of the yt analysis package <yt-users at lists.spacepope.org>
Subject: Re: [yt-users] quan

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<mailto: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<mailto: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/20151106/d0713068/attachment.html>


More information about the yt-users mailing list