Issue #1336: Field parameters that yt doesn't know about are assumed to be dimensionless (yt_analysis/yt)

New issue 1336: Field parameters that yt doesn't know about are assumed to be dimensionless https://bitbucket.org/yt_analysis/yt/issues/1336/field-parameters-that-yt-do... Nathan Goldbaum: Consider the following script: ``` import yt from yt.fields.derived_field import ValidateParameter def _overdensity(field, data): rhobar = data.get_field_parameter('rhobar') return data[('ramses', 'Density')]/rhobar - 1. ds = yt.load('output_00080/info_00080.txt') ad = ds.all_data() rhobar = ad.mean(('ramses', 'Density')) ad.set_field_parameter('rhobar', rhobar) ds.add_field(("gas", "overdensity"), function=_overdensity, take_log=False, force_override=True, validators=[ValidateParameter('rhobar')]) print(ad['overdensity']) ``` Right now this dies with the following traceback: ``` Traceback (most recent call last): File "test.py", line 16, in <module> validators=[ValidateParameter('rhobar')]) File "/usr/local/lib/python3.5/site-packages/yt/data_objects/static_output.py", line 1090, in add_field deps, _ = self.field_info.check_derived_fields([name]) File "/usr/local/lib/python3.5/site-packages/yt/fields/field_info_container.py", line 362, in check_derived_fields fd = fi.get_dependencies(ds = self.ds) File "/usr/local/lib/python3.5/site-packages/yt/fields/derived_field.py", line 178, in get_dependencies e[self.name] File "/usr/local/lib/python3.5/site-packages/yt/fields/field_detector.py", line 99, in __missing__ vv = finfo(self) File "/usr/local/lib/python3.5/site-packages/yt/fields/derived_field.py", line 204, in __call__ dd = self._function(self, data) File "test.py", line 6, in _overdensity return data[('ramses', 'Density')]/rhobar - 1. File "/usr/local/lib/python3.5/site-packages/yt/units/yt_array.py", line 927, in __sub__ ro = sanitize_units_add(self, right_object, "subtraction") File "/usr/local/lib/python3.5/site-packages/yt/units/yt_array.py", line 163, in sanitize_units_add raise YTUnitOperationError(op_string, inp.units, dimensionless) yt.utilities.exceptions.YTUnitOperationError: The subtraction operator for YTArrays with units (code_density) and (1) is not well defined. ``` What's going wrong here is the field detection system doesn't know that `rhobar` is a possible name for a field parameter, so it assumes it must be dimensionless. We should make the way the field detection system handles field parameters a bit smarter. Responsible: ngoldbaum
participants (1)
-
Nathan Goldbaum