[yt-dev] Issue #1261: ProfilePlot should fail more gracefully when used with particle fields (yt_analysis/yt)
Nathan Goldbaum
issues-reply at bitbucket.org
Fri Aug 12 08:39:15 PDT 2016
New issue 1261: ProfilePlot should fail more gracefully when used with particle fields
https://bitbucket.org/yt_analysis/yt/issues/1261/profileplot-should-fail-more-gracefully
Nathan Goldbaum:
Right now ParticlePlot will fail when trying to plot particle fields:
```
import yt
ds = yt.load('output_00080/info_00080.txt')
yt.ProfilePlot(ds.all_data(), 'radius', 'particle_mass')
```
This produces a confusing error:
```
IndexError Traceback (most recent call last)
/Users/goldbaum/Documents/yt-hg/yt/mods.pyc in <module>()
----> 1 yt.ProfilePlot(ds.all_data(), 'radius', 'particle_mass')
/Users/goldbaum/Documents/yt-hg/yt/visualization/profile_plotter.pyc in __init__(self, data_source, x_field, y_fields, weight_field, n_bins, accumulation, fractional, label, plot_spec, x_log, y_log)
228 accumulation=accumulation,
229 fractional=fractional,
--> 230 logs=logs)]
231
232 if plot_spec is None:
/Users/goldbaum/Documents/yt-hg/yt/data_objects/profiles.pyc in create_profile(data_source, bin_fields, fields, n_bins, extrema, logs, units, weight_field, accumulation, fractional, deposition)
1017 setattr(obj, "fractional", fractional)
1018 if fields is not None:
-> 1019 obj.add_fields([field for field in fields])
1020 for field in fields:
1021 if fractional:
/Users/goldbaum/Documents/yt-hg/yt/data_objects/profiles.pyc in add_fields(self, fields)
111 citer = self.data_source.chunks([], "io")
112 for chunk in parallel_objects(citer):
--> 113 self._bin_chunk(chunk, fields, temp_storage)
114 self._finalize_storage(fields, temp_storage)
115
/Users/goldbaum/Documents/yt-hg/yt/data_objects/profiles.pyc in _bin_chunk(self, chunk, fields, storage)
427
428 def _bin_chunk(self, chunk, fields, storage):
--> 429 rv = self._get_data(chunk, fields)
430 if rv is None: return
431 fdata, wdata, (bf_x,) = rv
/Users/goldbaum/Documents/yt-hg/yt/data_objects/profiles.pyc in _get_data(self, chunk, fields)
239 for i, field in enumerate(fields):
240 units = chunk.ds.field_info[field].units
--> 241 arr[:,i] = chunk[field][filter].in_units(units)
242 if self.weight_field is not None:
243 units = chunk.ds.field_info[self.weight_field].units
/Users/goldbaum/Documents/yt-hg/yt/units/yt_array.pyc in __getitem__(self, item)
1159
1160 def __getitem__(self, item):
-> 1161 ret = super(YTArray, self).__getitem__(item)
1162 if ret.shape == ():
1163 return YTQuantity(ret, self.units, bypass_validation=True)
IndexError: index 94462 is out of bounds for axis 1 with size 94462
```
In addition, even if I use particle fields for the bin and binned fields, I still get a similar error:
```
import yt
ds = yt.load('output_00080/info_00080.txt')
yt.ProfilePlot(ds.all_data(), 'particle_radius', 'particle_mass')
```
```
IndexError Traceback (most recent call last)
/Users/goldbaum/Documents/yt-hg/yt/mods.pyc in <module>()
----> 1 yt.ProfilePlot(ds.all_data(), 'particle_radius', 'particle_mass')
/Users/goldbaum/Documents/yt-hg/yt/visualization/profile_plotter.pyc in __init__(self, data_source, x_field, y_fields, weight_field, n_bins, accumulation, fractional, label, plot_spec, x_log, y_log)
228 accumulation=accumulation,
229 fractional=fractional,
--> 230 logs=logs)]
231
232 if plot_spec is None:
/Users/goldbaum/Documents/yt-hg/yt/data_objects/profiles.pyc in create_profile(data_source, bin_fields, fields, n_bins, extrema, logs, units, weight_field, accumulation, fractional, deposition)
1017 setattr(obj, "fractional", fractional)
1018 if fields is not None:
-> 1019 obj.add_fields([field for field in fields])
1020 for field in fields:
1021 if fractional:
/Users/goldbaum/Documents/yt-hg/yt/data_objects/profiles.pyc in add_fields(self, fields)
111 citer = self.data_source.chunks([], "io")
112 for chunk in parallel_objects(citer):
--> 113 self._bin_chunk(chunk, fields, temp_storage)
114 self._finalize_storage(fields, temp_storage)
115
/Users/goldbaum/Documents/yt-hg/yt/data_objects/profiles.pyc in _bin_chunk(self, chunk, fields, storage)
427
428 def _bin_chunk(self, chunk, fields, storage):
--> 429 rv = self._get_data(chunk, fields)
430 if rv is None: return
431 fdata, wdata, (bf_x,) = rv
/Users/goldbaum/Documents/yt-hg/yt/data_objects/profiles.pyc in _get_data(self, chunk, fields)
245 else:
246 weight_data = np.ones(filter.size, dtype="float64")
--> 247 weight_data = weight_data[filter]
248 # So that we can pass these into
249 return arr, weight_data, bin_fields
/Users/goldbaum/Documents/yt-hg/yt/units/yt_array.pyc in __getitem__(self, item)
1159
1160 def __getitem__(self, item):
-> 1161 ret = super(YTArray, self).__getitem__(item)
1162 if ret.shape == ():
1163 return YTQuantity(ret, self.units, bypass_validation=True)
IndexError: index 191131 is out of bounds for axis 1 with size 191131
```
I think the best route here is to fail with a nicer error message, suggesting to use ParticlePlot.
More information about the yt-dev
mailing list