[yt-users] YT 2.7 - Getting field values in code units

Nathan Goldbaum nathan12343 at gmail.com
Fri Jul 3 21:53:23 PDT 2015


On Friday, July 3, 2015, James Larrue-Baulch <james.larrue at diopolis.com>
wrote:

> Hello,
>
> I have been working on a system with YT 2.7-dev (changeset 1b93a1840f38)
> and trying to graph field values in code units, specifically the density,
> but I cannot figure out how to convert to code units in YT 2.  My data is
> from an Enzo cosmology simulation (i.e. expansion ON).
>
> If I were using YT 3, I believe the following would work to convert to any
> units desired:
>
> dataSet = load(inputDataFileName);
> hierarchy = dataSet.index;
> maxValue = hierarchy.find_max(dataFieldName)
> ray = hierarchy.ortho_ray(0, (maxValue[1][1], maxValue[1][2]));
> ray[xFieldName].convert_to_units(xAxisUnit);
> // use "code_mass", "code_length", "code_time", etc. to get code units.
>
> With YT 2, I am trying:
>
> dataSet = load(inputDataFileName);
> hierarchy = dataSet.hierarchy;
> maxValue = hierarchy.find_max(dataFieldName)
> ray = hierarchy.ortho_ray(0, (maxValue[1][1], maxValue[1][2]));
> ray[xFieldName] = ray[xFieldName] * dataSet.units[xAxisUnit];
>
> This works fine, if my "xAxisUnit" is a length unit, but no other units
> seem to be recognized.  While testing density, I tried to convert from cgs
> to mks:
>
> KeyError: 'kg/m^3'
>
> I listed the values in dataSet.units and they look to be only length units.
>
> Should I just give up on YT 2 and move to a machine that has YT 3, or is
> it possible to convert density units with YT 2?
>
>
Specifically for Enzo this is really awkward in yt 2.7. Since Enzo field
named are used everywhere internally, and we expect them to be CGS, getting
the Enzo data in code units is actually really awkward.

There a way to do it by hard-coding the CGS conversion factors to
unity (sorry I don't remember the precise syntax offhand, I think Dave
Collins asked about something similar a year or two ago), but honestly it
would likely be easier to just move to update your yt installation.

Usually these days the first thing I do on a cluster is set up a bare-bones
Python environment in my home folder using miniconda. I then install yt's
dependencies, and then yt itself. Everything is in my home folder, so I
don't need root privileges. Since conda packages are binaries, this process
is also a lot faster than running the install script. If you need to run
the development version of yt, you can install mercurial, clone the yt
repository and install it using "setup.py develop" for easy in-place
hacking.

Hope that helps,

Nathan



> Regards,
>
> James
>
> PS The full script I am using is:
>
>
> https://bitbucket.org/james_larrue/enzo-3.0-experimental/src/f425b7d5a10bf0da7cfd2fc146a464305f83d256/src/python/enzo-dataExporter.py?at=enzo-dev
>
> but it contains much more code than my immediate goal.
> _______________________________________________
> 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/20150703/c7a63f12/attachment.html>


More information about the yt-users mailing list