OK, I see what's happening. In your script you're reading the ages from a
file with a fixed shape and then passing that fixed shape array back to yt
whenever yt calls the _stellar_age field function. That doesn't work
because yt field functions operate on chunks of the dataset, not the full
dataset, so in order for your field function to work, you need a way to map
from particle IDs in the original ramses output file to the particle
indexes in the data file you're reading. The error you're getting is
telling you that the size of the chunk (1170 particles) does not agree with
the size of the stellar_age field returned by your field function (31990).
I'm not sure how you're generating your original fortran file so I don't
know if this will necessarily work for you, but I was able to get your
output_00080 test script to work by modifying your `_stellar_age` function
to look like this:
def _stellar_age(field, data):
data_ids = data['stars', 'particle_identity']
_, mask, _ = np.intersect1d(ids, data_ids, return_indices=True)
return YTArray(ages[mask], "Myr")
ds.add_field(("stars", "star_age"), function=_stellar_age,
units="Myr", particle_type=True, force_override=True)
See the documentation for intersect1d to see what I'm doing here to get the
indices of the overlaps:
https://docs.scipy.org/doc/numpy-1.15.0/reference/generated/numpy.intersect1...
On Wed, Feb 6, 2019 at 3:40 AM
Hi again Nathan,
I have modified my script to run on the output_00080 cosmological RAMSES run from http://yt-project.org/data/. The script is uploaded with link: http://use.yt/upload/9d91ea29.
When I run this example I get a similar traceback:
Traceback (most recent call last): File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 308, in _generate_fluid_field finfo.check_available(gen_obj) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/fields/derived_field.py", line 204, in check_available validator(data) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/fields/derived_field.py", line 470, in __call__ raise NeedsGridType(self.ghost_zones,self.fields) yt.fields.field_exceptions.NeedsGridType: (0, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last): File "yt_issue.py", line 58, in <module> center=centre, data_source=box) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/construction_data_containers.py", line 270, in __init__ self.get_data(field) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/construction_data_containers.py", line 344, in get_data self._handle_chunk(chunk, fields, tree) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/construction_data_containers.py", line 450, in _handle_chunk d = chunk[field] * dl File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 255, in __getitem__ self.get_data(f) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1382, in get_data self._generate_fields(fields_to_generate) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1402, in _generate_fields fd = self._generate_field(field) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 292, in _generate_field tr = self._generate_fluid_field(field) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 310, in _generate_fluid_field rv = self._generate_spatial_fluid(field, ngt_exception.ghost_zones) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 330, in _generate_spatial_fluid ind += o.select(self.selector, self[field], rv, ind) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 255, in __getitem__ self.get_data(f) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1382, in get_data self._generate_fields(fields_to_generate) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1402, in _generate_fields fd = self._generate_field(field) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 292, in _generate_field tr = self._generate_fluid_field(field) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 312, in _generate_fluid_field rv = finfo(gen_obj) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/fields/derived_field.py", line 256, in __call__ dd = self._function(self, data) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/fields/particle_fields.py", line 133, in particle_density pos = data[ptype, coord_name].convert_to_units("code_length") File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/octree_subset.py", line 73, in __getitem__ tr = super(OctreeSubset, self).__getitem__(key) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 255, in __getitem__ self.get_data(f) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/data_containers.py", line 1325, in get_data self.get_data(apply_fields[filter_type]) File "/opt/ioa/software/anaconda/anaconda36/envs/20181213_2_py36/lib/python3.6/contextlib.py", line 88, in __exit__ next(self.gen) File "/home/lhw28/.local/lib/python3.6/site-packages/yt/data_objects/particle_filters.py", line 53, in apply raise YTIllDefinedFilter(self, tr.shape, filter.shape) yt.utilities.exceptions.YTIllDefinedFilter: Filter '
' ill-defined. Applied to shape (1175, 3) but is shape (31990,). I realised I never mentioned what version of YT I am using. In case it's important, it's 3.5.0. (And I'm using Python 3.6.3).
Thanks for your help, Lewis _______________________________________________ yt-users mailing list -- yt-users@python.org To unsubscribe send an email to yt-users-leave@python.org