Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: accessing data in re-loaded sphere object errors #4795

Open
chrishavlin opened this issue Jan 30, 2024 · 1 comment
Open

BUG: accessing data in re-loaded sphere object errors #4795

chrishavlin opened this issue Jan 30, 2024 · 1 comment

Comments

@chrishavlin
Copy link
Contributor

Bug report

Only took a quick look based on a question on slack, but I'm pretty sure this is a bug:

from yt.testing import fake_amr_ds
import yt
ds = fake_amr_ds()
sp = ds.sphere(ds.domain_center, ds.quan(0.5,'code_length'))
fi = 'tmpfile.h5'
sp.save_as_dataset(fi)
ds_in = yt.load(fi)
ds_in.all_data()

Actual outcome

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [16], in <cell line: 8>()
      6 sp.save_as_dataset(fi)
      7 ds_in = yt.load(fi)
----> 8 ds_in.all_data()

File ~/src/yt_general/yt/yt/data_objects/static_output.py:1194, in Dataset.all_data(self, find_max, **kwargs)
   1189 def all_data(self, find_max=False, **kwargs):
   1190     """
   1191     all_data is a wrapper to the Region object for creating a region
   1192     which covers the entire simulation domain.
   1193     """
-> 1194     self.index
   1195     if find_max:
   1196         c = self.find_max("density")[1]

File ~/src/yt_general/yt/yt/data_objects/static_output.py:606, in Dataset.index(self)
    603 @property
    604 def index(self):
    605     if self._instantiated_index is None:
--> 606         self._instantiated_index = self._index_class(
    607             self, dataset_type=self.dataset_type
    608         )
    609         # Now we do things that we need an instantiated index for
    610         # ...first off, we create our field_info now.
    611         oldsettings = np.geterr()

File ~/src/yt_general/yt/yt/geometry/particle_geometry_handler.py:72, in ParticleIndex.__init__(self, ds, dataset_type)
     70 self.dataset = weakref.proxy(ds)
     71 self.float_type = np.float64
---> 72 super().__init__(ds, dataset_type)
     73 self._initialize_index()

File ~/src/yt_general/yt/yt/geometry/geometry_handler.py:47, in Index.__init__(self, ds, dataset_type)
     44 # Note that this falls under the "geometry" object since it's
     45 # potentially quite expensive, and should be done with the indexing.
     46 mylog.debug("Detecting fields.")
---> 47 self._detect_output_fields()

File ~/src/yt_general/yt/yt/geometry/particle_geometry_handler.py:360, in ParticleIndex._detect_output_fields(self)
    358 dsl = []
    359 units = {}
--> 360 pcounts = self._get_particle_type_counts()
    361 field_cache = {}
    362 for dom in self.data_files:

File ~/src/yt_general/yt/yt/geometry/particle_geometry_handler.py:86, in ParticleIndex._get_particle_type_counts(self)
     84 def _get_particle_type_counts(self):
     85     result = collections.defaultdict(lambda: 0)
---> 86     for df in self.data_files:
     87         for k in df.total_particles.keys():
     88             result[k] += df.total_particles[k]

File ~/src/yt_general/yt/yt/geometry/particle_geometry_handler.py:106, in ParticleIndex.data_files(self)
    103 if self._data_files is not None:
    104     return self._data_files
--> 106 self._setup_filenames()
    107 return self._data_files

File ~/src/yt_general/yt/yt/geometry/particle_geometry_handler.py:140, in ParticleIndex._setup_filenames(self)
    138 try:
    139     _filename = template % {"num": i}
--> 140     df = cls(self.dataset, self.io, _filename, fi, (start, end))
    141 except FileNotFoundError:
    142     mylog.warning(
    143         "Failed to load '%s' (missing file or directory)", _filename
    144     )

File ~/src/yt_general/yt/yt/frontends/ytdata/data_structures.py:233, in YTDataHDF5File.__init__(self, ds, io, filename, file_id, range)
    230 with h5py.File(filename, mode="r") as f:
    231     self.header = {field: parse_h5_attr(f, field) for field in f.attrs.keys()}
--> 233 super().__init__(ds, io, filename, file_id, range)

File ~/src/yt_general/yt/yt/data_objects/static_output.py:2081, in ParticleFile.__init__(self, ds, io, filename, file_id, range)
   2079 if self.start is None:
   2080     self.start = 0
-> 2081 self.end = max(self.total_particles.values()) + self.start

ValueError: max() arg is an empty sequence

Expected outcome

get all the data!

Version Information
yt '4.4.dev0'

@chrishavlin
Copy link
Contributor Author

Note, providing the fields arguments seems to avoid the problem:

from yt.testing import fake_amr_ds
import yt
ds = fake_amr_ds()
sp = ds.sphere(ds.domain_center, ds.quan(0.5,'code_length'))
fi = 'tmpfile.h5'
sp.save_as_dataset(fi, fields=ds.field_list)
ds_in = yt.load(fi)
ad = ds_in.all_data()
ad[('grid', 'Density')]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant