Dear Nathan, Thanks very much for your help. That was a stupid mistake and the error message is different with the previous one I said. If I changed to kb, the error message is: P014 yt : [ERROR ] 2016-11-01 16:11:53,531 YTFieldUnitParseError: The field '('gas', 'Entropy')' has unparseable units 'kB'. File "volume_rendering.py", line 164, in <module> plot_a_vr(fn,cycle,rotate=False) File "volume_rendering.py", line 101, in plot_a_vr tfh.set_bounds() File "/Users/pan/anaconda2/lib/python2.7/site-packages/yt/visualization/volume_rendering/transfer_function_helper.py", line 66, in set_bounds bounds = self.ds.h.all_data().quantities['Extrema'](self.field, non_zero=True) File "/Users/pan/anaconda2/lib/python2.7/site-packages/yt/data_objects/derived_quantities.py", line 510, in __call__ rv = super(Extrema, self).__call__(fields, non_zero) File "/Users/pan/anaconda2/lib/python2.7/site-packages/yt/data_objects/derived_quantities.py", line 67, in __call__ sto.result = self.process_chunk(ds, *args, **kwargs) File "/Users/pan/anaconda2/lib/python2.7/site-packages/yt/data_objects/derived_quantities.py", line 518, in process_chunk fd = data[field] File "/Users/pan/anaconda2/lib/python2.7/site-packages/yt/data_objects/data_containers.py", line 272, in __getitem__ self.get_data(f) File "/Users/pan/anaconda2/lib/python2.7/site-packages/yt/data_objects/data_containers.py", line 1192, in get_data self._generate_fields(fields_to_generate) File "/Users/pan/anaconda2/lib/python2.7/site-packages/yt/data_objects/data_containers.py", line 1245, in _generate_fields raise YTFieldUnitParseError(fi) P015 yt : [ERROR ] 2016-11-01 16:11:53,572 YTFieldUnitParseError: The field '('gas', 'Entropy')' has unparseable units 'kB'. -------------------------------------------------------------------------- Many thanks, Kuo-Chuan
On Nov 1, 2016, at 4:03 PM, Nathan Goldbaum <nathan12343@gmail.com> wrote:
At the top of your script, you have:
from yt.units import kb
but later you have:
return kB*entrdens
It should be:
return kb*entrdens
On Tue, Nov 1, 2016 at 3:00 PM, Kuo-Chuan Pan <pankuoch@msu.edu <mailto:pankuoch@msu.edu>> wrote: 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/ <http://paste.yt-project.org/show/wToLggLnTYVpMxeqJtln/>
Many thanks, Kuo-Chuan
On Nov 1, 2016, at 3:50 PM, Nathan Goldbaum <nathan12343@gmail.com <mailto:nathan12343@gmail.com>> wrote:
On Tue, Nov 1, 2016 at 2:40 PM, Kuo-Chuan Pan <pankuoch@msu.edu <mailto:pankuoch@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@gmail.com <mailto:nathan12343@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@msu.edu <mailto:pankuoch@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@gmail.com <mailto:nathan12343@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@msu.edu <mailto:pankuoch@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@lists.spacepope.org <mailto:yt-users@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@lists.spacepope.org <mailto:yt-users@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@lists.spacepope.org <mailto:yt-users@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@lists.spacepope.org <mailto:yt-users@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@lists.spacepope.org <mailto:yt-users@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@lists.spacepope.org <mailto:yt-users@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@lists.spacepope.org <mailto:yt-users@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@lists.spacepope.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org