[yt-dev] KeyError accessing field_units from profile?

Rasmi Elasmar re2300 at columbia.edu
Mon May 23 11:36:34 PDT 2016


Hi all,

I'm using yt 3.2.3. I've created some derived fields (specifically
'dark_matter' and 'stars'), and I'm trying to plot radial profiles of
('gas', 'density'), ('deposit', 'dark_matter_density'), and ('deposit',
'stars_density'). I'm using yt.create_profile(sphere, 'radius', field)
(where field is one of the above) and appending each of those profiles to a
list called profiles. Those are created fine, and accessing
profile[1].field_units (for example) gives '{('deposit', 'stars_density'):
g/cm**3}', which is what I expect.

The issue occurs when I call yt.ProfilePlot.from_profiles(profiles,
labels=labels) -- I get an error in profile_plotter.py when accessing
profile.field_units on a profile
<https://bitbucket.org/yt_analysis/yt/src/b3c23ff06040ef967b7c9ac041d5ad3dc4edb79a/yt/visualization/profile_plotter.py?at=yt&fileviewer=file-view-default#profile_plotter.py-631>
:

> Traceback (most recent call last):
>   File "/work/03330/tg826294/applications/scripts/halo_profiles.py", line
> 50, in <module>
>     plot = yt.ProfilePlot.from_profiles(profiles, labels=labels)
>   File
> "/work/03330/tg826294/applications/pythonenv/lib/python2.7/site-packages/yt/visualization/profile_plotter.py",
> line 415, in from_profiles
>     return cls._initialize_instance(obj, profiles, labels, plot_specs,
> y_log)
>   File
> "/work/03330/tg826294/applications/pythonenv/lib/python2.7/site-packages/yt/visualization/profile_plotter.py",
> line 365, in _initialize_instance
>     obj._setup_plots()
>   File
> "/work/03330/tg826294/applications/pythonenv/lib/python2.7/site-packages/yt/visualization/profile_plotter.py",
> line 339, in _setup_plots
>     xtitle, ytitle = self._get_field_title(fname, profile)
>   File
> "/work/03330/tg826294/applications/pythonenv/lib/python2.7/site-packages/yt/visualization/profile_plotter.py",
> line 633, in _get_field_title
>     y_unit = profile.field_units[field_y]
> KeyError: ('gas', 'density')


I tried explicitly passing the units in yt.create_profile(sphere, 'radius',
field, units={field: units[field]}) (where units is a dictionary and
units[field] gives 'g/cm**3'), but I still get the error. I also tried
adding the units to ds.field_units, and that didn't help either.

You can see my code here
<https://gist.github.com/rasmi/6d936b077527e245025b73059e59b9c0>.

I also tried creating all the profiles at once with:

> profile = yt.Profile1D(sp, 'radius', 32, minimum, maximum, True,
> weight_field=None)
> profile.add_values(fields.values())


But everything was 0, and I got errors with other approaches (I can detail
them if you're curious, but I think the yt.ProfilePlot.from_profiles() is
probably the best approach, right?).

Any ideas? Thanks for your help!

Rasmi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-dev-spacepope.org/attachments/20160523/99a757ba/attachment.htm>


More information about the yt-dev mailing list