[yt-users] Custom units.

Nathan Goldbaum nathan12343 at gmail.com
Tue Nov 1 11:52:15 PDT 2016


One could argue that it would be useful for save_annotated to optionally
take a fully user-specified colorbar label. That's not the case now but it
would be a relatively easy modification.

Your 'entr' field isn't being recognized by yt with units because it's not
a field that is "known" by yt in the FLASH frontend:

https://bitbucket.org/yt_analysis/yt/src/334cceb2c6e197acf1a8c7f273ee9dd0bd592f58/yt/frontends/flash/fields.py?at=yt&fileviewer=file-view-default#fields.py-43

Specifically, it does not appear in the known_other_fields tuple in the
flash fields.py file. If entr is not specific to your version of FLASH it
may be worthwhile to add an entry there so that the entr field is read in
with the correct units.

Similarly, kB isn't a unit that the yt unit system understands out of the
box (although I think one could make a case that it's worth including).
There is a way to add new units to the unit system though:

    from yt.units import kb
    from yt.units.dimensions import energy, temperature

    # load your dataset
    ds = yt.load(...)

    ds.unit_registry.add('kB', 1.3806488e-16,
dimensions=energy/temperature, tex_repr='k_{B}')

    def _entrdens(field,data):
         """
         create a new derived field to show both entropy and density
         """
         dens = data["dens"]
         entr = data["entr"]
         entrdens = entr*(np.exp(-(dens.in_cgs()/PNS_DENSITY)**5))+PNS_ENTR
         return kb*entrdens
    ds.add_field("Entropy",function=_entrdens, units="kB",
display_name="Entropy per Baryon")

And then make your volume rendering as you were doing before. It should
show up in the label as "Entropy per baryon" and with units of "kB".

Please feel free to open issues or pull requests about any of the things I
raised above.

-Nathan


On Tue, Nov 1, 2016 at 1:25 PM, Kuo-Chuan Pan <pankuoch at msu.edu> wrote:

> Dear Nathan,
>
> Thanks very much for your help.
> entropy is a filed in my FLASH dataset. The unit of entropy is kB/baryon
> in the code but it is recognised as dimensionless in yt.
>
> The field “entr" is the entropy in my dataset. The derived field “Entropy”
> is the one I want to visualise.
> PNS_DENSITY and PNS_ENTR are just constants.
>
> Many thanks,
> Kuo-Chuan
>
>   11 def _entrdens(field,data):
>   12     """
>   13     create a new derived field to show both entropy and density
>   14     """
>   15     dens = data["dens"]
>   16     entr = data["entr"]
>   17     entrdens = entr*(np.exp(-(dens.in_cgs()/
> PNS_DENSITY)**5))+PNS_ENTR
>   18     return entrdens
>   19 yt.add_field("Entropy",function=_entrdens,units="dimensionless")
>
>
> On Nov 1, 2016, at 2:20 PM, Nathan Goldbaum <nathan12343 at gmail.com> wrote:
>
> Hi Kuo-Chuan,
>
> Can you show us how you've defined your derived field?
>
> Is entropy a derived field as well or is it a field that's included in
> your dataset? This is the entropy per baryon, right?
>
> -Nathan
>
> On Tue, Nov 1, 2016 at 1:09 PM, Kuo-Chuan Pan <pankuoch at msu.edu> wrote:
>
>> Dear all,
>>
>> I have a custom new derived field based on density (g/cm^3) and entropy
>> (kB/baryon but it is recognised as dimensionless).
>> Currently, this new derived field is set to dimensionless (it should be
>> kB/baryon).
>>
>> Could anyone teach me how to set this new derived filed to its correct
>> unit (which should be kB/baryon)?
>> Or is it possible to simply override the field label in my volume
>> rendering plot before using save_annotated()?
>>
>> Many thanks,
>> Kuo-Chuan
>> _______________________________________________
>> 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
>
>
>
> _______________________________________________
> 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/20161101/e4a9f37e/attachment-0001.htm>


More information about the yt-users mailing list