[yt-users] Custom units.

Kuo-Chuan Pan pankuoch at msu.edu
Tue Nov 1 13:00:47 PDT 2016


Dear Nathan,

Thank you very much for your help.
I was using ds.add_field()

I have pasted my script and error message here:
http://paste.yt-project.org/show/wToLggLnTYVpMxeqJtln/

Many thanks,
Kuo-Chuan


> On Nov 1, 2016, at 3:50 PM, Nathan Goldbaum <nathan12343 at gmail.com> wrote:
> 
> 
> 
> On Tue, Nov 1, 2016 at 2:40 PM, Kuo-Chuan Pan <pankuoch at msu.edu <mailto:pankuoch at msu.edu>> wrote:
> Dear Nathan,
> 
> Thanks very much for your email and suggestions.
> I followed your suggested code but it is not working.
> yt gives an error message:
> 	yt : [ERROR ] 2016-11-01 15:25:27,650 YTFieldUnitParseError: The field '('gas', 'Entropy')' has unparseable units 'kB’. 
> 
> Did you use ds.add_field as I showed in my previous e-mail or yt.add_field as you originally had in your last e-mail? You need to use ds.add_field as I showed in my code snippet for my workaround to work properly.
> 
> If you *did* use ds.add_field, can you pastebin the full script, along with any error messages and tracebacks you received upon running the script?
> 
> We have paste.yt-project.org <http://paste.yt-project.org/> set up for this purpose.
> 
> -Nathan
>  
> 
> The vales of my “entr” field is already in “kB/baryon” (specific entropy) but the unit is incorrect.
> Following your suggestions, I want to create two new units called “kB” and “baryon” (1.674e-24 g) 
> and override the “entr” and “Entropy” units to “kB/baryon” (from dimensionless). 
> Is it possible to do that?
> 
> Many thanks,
> Kuo-Chuan
> 
> 
>> On Nov 1, 2016, at 2:52 PM, Nathan Goldbaum <nathan12343 at gmail.com <mailto:nathan12343 at gmail.com>> wrote:
>> 
>> 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 <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 <mailto: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 <mailto: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 <mailto: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 <mailto:yt-users at lists.spacepope.org>
>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org <http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org>
>>> 
>>> _______________________________________________
>>> yt-users mailing list
>>> yt-users at lists.spacepope.org <mailto:yt-users at lists.spacepope.org>
>>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org <http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org>
>> 
>> 
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org <mailto:yt-users at lists.spacepope.org>
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org <http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org>
>> 
>> 
>> _______________________________________________
>> yt-users mailing list
>> yt-users at lists.spacepope.org <mailto:yt-users at lists.spacepope.org>
>> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org <http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org>
> 
> 
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org <mailto:yt-users at lists.spacepope.org>
> http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org <http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org>
> 
> 
> _______________________________________________
> yt-users mailing list
> yt-users at lists.spacepope.org <mailto:yt-users at lists.spacepope.org>
> http://lists.spacepope.org/listinfo.cgi/yt-users-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/260eb594/attachment-0001.htm>


More information about the yt-users mailing list