<div dir="ltr">Hi Junhwan,<div><br></div><div><br><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jan 4, 2015 at 7:20 PM, Junhwan Choi (최준환) <span dir="ltr"><<a href="mailto:choi.junhwan@gmail.com" target="_blank">choi.junhwan@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Hi yt user,<br>
<br>
I start to use yt-3.x version for the gadget analyses.<br>
Although I have previously used the yt-2.6x version for the enzo<br>
analyses, I find that there are many differences between two.<br>
[Now, I find that new yt is significantly improved than previous one<br>
but I need some adjustment..]<br>
Here, I have a question regarding to derived field.<br>
Since, my gadegt outputs only have InterenalEnergy, I need to make a<br>
derived field for temperature as follow:</blockquote><div><br></div><div><div>There are a couple things wrong here.  First, is this data in the Gadget binary format or is it in the HDF5 format?  If it's the former, the "Gas" particle type should have all of the fields you're referencing.  That means that where you have data["gas","ElectronAbundance"], you should instead have data["Gas", "ElectronAbundance"] (note the change from "g" to "G") .  If this is Gadget HDF5 data, instead of "Gas", you should be referencing "PartType0".</div><div><br></div><div>The "gas" field type represents fluid quantities defined on a space-filling mesh.  The "Gas" (or "PartType0") field type represents quantities only defined at the location of SPH particles. You should never mix particle and mesh fields, since they're not defined at the same locations in space.  To get around this, yt provides a number of internal facilities for creating a mesh field from a particle field using a smoothing or deposition operation.  For example, the ("gas", "density") field is generated by yt using an SPH smoothing operation for SPH datasets.  We will need to do something similar here in the end to create a ("gas", "temperature") field from the internal ("Gas", "InternalEnergy") field.</div></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"> </blockquote><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
==============<br>
@derived_field(name=("gas","temperature"), units="K")<br>
def _temperature(field, data):<br>
    BOLTZMANN   = 1.3806e-16<br>
    PROTONMASS  = 1.6726e-24<br>
    GAMMA       = 5.0 / 3.0<br>
    H_MASSFRAC = 0.76<br>
    mu = 4.0 / (3.0 * H_MASSFRAC + 1.0 + 4.0 * H_MASSFRAC *<br>
data["gas","ElectronAbundance"])<br>
    return data["gas","InternalEnergy"]*(GAMMA-1)*mu*PROTONMASS/BOLTZMANN<br></blockquote><div><br></div><div>Next, In order to make the units work out correctly, you're going to need to ensure that all of the quantities in the expression have correct units.</div><div><br></div><div>There are two things we'll have to fix here in order for that to work.</div><div><br></div><div>First, it seems the InternalEnergy field is being read in with dimensionless units.  I don't think that's correct and it's something we'll need to fix in yt.</div><div><br></div><div>Looking at the gadget frontend, it seems the InternalEnergy field is indeed hard-coded to have dimensionless units (see line 32 in yt/frontends/sph/fields.py).  I think this is a bug.  Do you happen to know what units Gadget writes the InternalEnergy field out to disk in?  That section of the SPH frontend should be rewritten to use the correct units.</div><div><br></div><div>Next, the hard-coded constants you're using should be quantities with units rather than floats.  In addition, for consistency with the rest of yt you should use the physical constant definitions provided in the yt.utilities.physical_constants module.  If you import from here, you'll get quantities with units for free.</div><div><br></div><div>Last, as I alluded to above, once you create a derived Temperature field defined for all of the SPH particles, you will also need to create the ("gas", "temperature") field via an SPH smoothing operation. There's an example of how to do this in the OWLS frontend, inside the setup_particle_fields function in yt/frontends/owls/fields.py.  In fact, some of the logic in the OWLS frontend that sets up extra smoothed fields could probably be better suited for living in the generic gadget frontend, which the OWLS frontend subclasses.</div><div><br></div><div>In the end, I think wanting a proper temperature field set up for all gadget datasets is probably something that we should have set up in the gadget frontend itself, obviating the need for future users in your footsteps to need to define a derived field.  If you'd like, you could file a bug about this issue and one of us might take a crack at setting this up once and for all. Doing this yourself would probably also be a good way to get more familiarity with the internals of the gadget frontend.<br></div><div><br></div><div>Sorry that I don't have easy solutions for you here.</div><div><br></div><div>-Nathan</div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
================<br>
<br>
and try to make phase diagram and got the following error message:<br>
.....<br>
yt : [INFO     ] 2015-01-04 19:56:35,791 Max Value is 4.03205e-21 at<br>
30150.5327224731445312 31066.5464401245117188 29380.5456161499023438<br>
Traceback (most recent call last):<br>
  File "phase.py", line 32, in <module><br>
    weight_field=None)<br>
  File "/Users/jhchoi/common/src/yt/yt/visualization/profile_plotter.py",<br>
line 699, in __init__<br>
    fractional=fractional)<br>
  File "/Users/jhchoi/common/src/yt/yt/data_objects/profiles.py", line<br>
1331, in create_profile<br>
    for f, l in zip(bin_fields, logs)]<br>
  File "/Users/jhchoi/common/src/yt/yt/data_objects/derived_quantities.py",<br>
line 482, in __call__<br>
    rv = super(Extrema, self).__call__(fields, non_zero)<br>
  File "/Users/jhchoi/common/src/yt/yt/data_objects/derived_quantities.py",<br>
line 56, in __call__<br>
    sto.result = self.process_chunk(ds, *args, **kwargs)<br>
  File "/Users/jhchoi/common/src/yt/yt/data_objects/derived_quantities.py",<br>
line 490, in process_chunk<br>
    fd = data[field]<br>
  File "/Users/jhchoi/common/src/yt/yt/data_objects/data_containers.py",<br>
line 240, in __getitem__<br>
    self.get_data(f)<br>
  File "/Users/jhchoi/common/src/yt/yt/data_objects/data_containers.py",<br>
line 661, in get_data<br>
    self._generate_fields(fields_to_generate)<br>
  File "/Users/jhchoi/common/src/yt/yt/data_objects/data_containers.py",<br>
line 687, in _generate_fields<br>
    fd.convert_to_units(fi.units)<br>
  File "/Users/jhchoi/common/src/yt/yt/units/yt_array.py", line 416,<br>
in convert_to_units<br>
    new_units = self._unit_repr_check_same(units)<br>
  File "/Users/jhchoi/common/src/yt/yt/units/yt_array.py", line 402,<br>
in _unit_repr_check_same<br>
    self.units, self.units.dimensions, units, units.dimensions)<br>
yt.utilities.exceptions.YTUnitConversionError: Unit dimensionalities<br>
do not match. Tried to convert between dimensionless (dim 1) and K<br>
(dim (temperature)).<br>
<br>
It looks that new yt become a bit picky on the units.<br>
In this derived field, the unit contribution from BOLTZMANN and<br>
PROTONMASS is not recognized and it causes error, I think.<br>
How can I resolve this error?<br>
Moreover, how can I make derived field without sensitive unit matching?<br>
Sometimes, I used derived field when I need to convert log units for<br>
visualization, and when dealing with the dimensionless field.<br>
<br>
Thank you for help,<br>
Junhwan<br>
_______________________________________________<br>
yt-users mailing list<br>
<a href="mailto:yt-users@lists.spacepope.org">yt-users@lists.spacepope.org</a><br>
<a href="http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org" target="_blank">http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org</a><br>
</blockquote></div><br></div></div></div>