[yt-users] volume rendering annotation error for a derived field

tazkera haque h.tazkera at gmail.com
Sun Aug 28 13:09:31 PDT 2016


Hi Nathan,

Thank you very much for the quick solution, As an appreciation I am
uploading the new render for the derived field. A bit of work has to be
done with the LaTex labeling I guess,  but for now I will just customize
the label.

Thanks
Tazkera

On Sun, Aug 28, 2016 at 11:04 AM, Nathan Goldbaum <nathan12343 at gmail.com>
wrote:

> On Sat, Aug 27, 2016 at 8:43 PM, tazkera haque <h.tazkera at gmail.com>
> wrote:
>
>> Hi yt people,
>>
>> I just updated to yt 3.3.1 to use all the new features of volume
>> rendering. I am trying to render ejected density which is a derived field
>> and draw the coordinate triads, domain boundary along with labels showing
>> the log range of ejected density. my code is attached. While my code worked
>> fine with default field 'density', the following figure was produced for
>> 'density', but I am getting error when the source field is set to
>> 'ejected_density'.
>>
>
> Hi Tazkera,
>
> First, very nice rendering!
>
> As for your error, this is due to a bug in yt --- thank you for the
> report! I have issued a pull request so this bug can be fixed for yt 3.3.2:
>
> https://bitbucket.org/yt_analysis/yt/pull-requests/2351
>
> For your specific use case, the easiest way to work around this without
> applying my bugfix is to change how you're creating the ejected_density
> derived field. Instead of using the @derived_field decorator, it will work
> correctly if you use the ds.add_field function. To make that explicit,
> where you currently have:
>
>     @derived_field(name = "ejected_density", units = "g/cm**3")
>     def _get_ejected_density(field, data):
>         E = 0.5* data["cell_mass"]* (data["velx"]**2+data["vely"]**2+data["velz"]**2)+
> data["gpot"]*data["cell_mass"]
>         return ((np.array(E)>=0)*1)*data["density"]
>
>     ds = yt.load(...)
>
> You will instead have:
>
>     def _get_ejected_density(field, data):
>         E = 0.5* data["cell_mass"]* (data["velx"]**2+data["vely"]**2+data["velz"]**2)+
> data["gpot"]*data["cell_mass"]
>         return ((np.array(E)>=0)*1)*data["density"]
>
>     ds = yt.load(...)
>
>     ds.add_field(function=_get_ejected_density, name='ejected_density',
> units='g/cm**3')
>
> What's happening is that if you use the @derived_field decorator, yt's
> field machinery doesn't associate the derived field you add to a specific
> dataset. This is normally fine, but when the field tries to generate a nice
> LaTeX label for the field, it assumes that a dataset is available (e.g. for
> fields with units like 'code_mass/code_length**3' where we need to have a
> dataset available to know what 'code_mass' or 'code_length' mean). This
> isn't true for locally defined fields, causing the crash you're seeing.
>
> Sorry about the need for the workaround, but thank you again for the
> detailed report and script, which were key for me to be able to see what
> was going wrong and reproduced the bug locally.
>
> Also the 'density' figure still does not show either the coordinate triads
>> or the domain boundary. I would appreciate your help to fix the error and
>> thanks in advance.
>>
>
> This is probably because the alpha values you're setting in annotate_axes
> and annotate_domain are too low for this rendering. Try increasing them.
>
>
>>
>> *Traceback (most recent call last):*
>> *  File "volume_render_test.py", line 117, in <module>*
>> *    text_annotate=[[(.1, 1.05), text_string]])*
>> *  File
>> "/work/03858/thaque56/sw/yt-new-3.3/yt-conda/lib/python2.7/site-packages/yt/visualization/volume_rendering/scene.py",
>> line 395, in save_annotated*
>> *    label = rs.data_source.ds._get_field_info(rs.field).get_label()*
>> *  File
>> "/work/03858/thaque56/sw/yt-new-3.3/yt-conda/lib/python2.7/site-packages/yt/fields/derived_field.py",
>> line 225, in get_label*
>> *    units = Unit(self.units, registry=self.ds.unit_registry)*
>> *AttributeError: 'NoneType' object has no attribute 'unit_registry'*
>>
>>
>> *Thanks*
>> *Tazkera*
>>
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org
>>
>>
>
> _______________________________________________
> 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/20160828/525390f8/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: vol_annotated (11).png
Type: image/png
Size: 220739 bytes
Desc: not available
URL: <http://lists.spacepope.org/pipermail/yt-users-spacepope.org/attachments/20160828/525390f8/attachment-0002.png>


More information about the yt-users mailing list