What are the units of AveMomtX right now? It seems it's getting read in as dimensionless, probably because it's not a field yt knows about. To fix this error you will need to apply units to the AveMomtX field in your field definition. If you've modified the Enzo code to add this new field to your Enzo outputs, you could also modify yt's Enzo frontend to "teach" yt about the new field you've added. See yt/frontends/enzo/fields.py, specifically the known_other_fields tuple.
On Thu, Aug 3, 2017 at 3:28 AM Wolfram Schmidt < email@example.com> wrote:
I encountered a problem when defining a the fluctuation of the velocity with respect to a smoothed velocity as derived field in yt:
def _fluc_velocity_x(field, data): return data["x-velocity"] - data["AveMomtX"]/data["density"]
ds.add_field("fluc_velocity_x", function=_fluc_velocity_x, force_override=True)
Here x-velocity and density are standard baryon fields defined in Enzo and AveMomtX is an additional baryon field for smoothed momentum.
When I load a data dump and execute the above definition, I get the following error:
/lrz/sys/tools/python/2.7_anaconda_nompi/lib/python2.7/site-packages/yt/units/yt_array.py in sanitize_units_add(this_object, other_object, op_string) 126 if isinstance(ret, YTArray): 127 if not inp.units.same_dimensions_as(ret.units): --> 128 raise YTUnitOperationError(op_string, inp.units, ret.units) 129 ret = ret.in_units(inp.units) 130 # If the other object is not a YTArray, the only valid case is adding
YTUnitOperationError: The subtraction operator for YTArrays with units (code_velocity) and (code_length**3/code_mass) is not well defined.
After looking into http://yt-project.org/doc/analyzing/units/fields_and_unit_conversion.html, I tried
ds.add_field("fluc_velocity_x", units="cm/s", function=_fluc_velocity_x, force_override=True)
but this results in the same error as before. Apparently, the problem is that yt does not recognize that momentum divided by density is a velocity and therefore cannot match the units to the first term (x-velocity).
There are unit conversion functions such as .in_cgs(), but they are not applicable to the data objects in the above definition.
So can anyone tell me how to fix this?
yt-users mailing list firstname.lastname@example.org http://lists.spacepope.org/listinfo.cgi/yt-users-spacepope.org