[yt-dev] KeyError accessing field_units from profile?

Nathan Goldbaum nathan12343 at gmail.com
Mon May 23 11:41:49 PDT 2016


Hi Rasmi,

Is there any chance you can make a small test script that triggers the
error you're seeing, using one of the public test datasets on
yt-project.org/data? There are several Enzo datasets there that should be
usable.

That will make it much easier for one of us to reproduce the error you're
seeing.

-Nathan

On Mon, May 23, 2016 at 1:36 PM, Rasmi Elasmar <re2300 at columbia.edu> wrote:

> 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:
>
>> 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
>
> _______________________________________________
> yt-dev mailing list
> yt-dev at lists.spacepope.org
> http://lists.spacepope.org/listinfo.cgi/yt-dev-spacepope.org
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.spacepope.org/pipermail/yt-dev-spacepope.org/attachments/20160523/96c37d8d/attachment.html>


More information about the yt-dev mailing list