Fix indexing of reweighted injections and event samples
The notebook is failing when reading in reweighted injections and reweighted event samples. In the notebook, seeing a failure in Retrieving Data Products
-> Reweighted Event Samples
# get reweighted samples for only GW150914
GW150914_event_samples = result.get_reweighted_event_samples(events='GW150914')
Here's the traceback:
Click to expand
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[20], line 2
1 # get reweighted samples for only GW150914
----> 2 GW150914_event_samples = result.get_reweighted_event_samples(events='GW150914')
4 # get reweighted first 100 event samples for first hyperparameter
5 truncated_first_hyperparam_event_samples = result.get_reweighted_event_samples(draw_idx=slice(0,100),
6 hyper_sample_idx=0)
File ~/projects/O4/RatesPop/popsummary/popsummary/popresult.py:151, in PopulationResult.get_reweighted_event_samples(self, events, draw_idx, hyper_sample_idx, group)
148 else:
149 mask_hyper_sample = hyper_sample_idx
--> 151 return f[group]['reweighted_event_samples'][mask_event, mask_draw, mask_hyper_sample, :]
File h5py/_objects.pyx:54, in h5py._objects.with_phil.wrapper()
File h5py/_objects.pyx:55, in h5py._objects.with_phil.wrapper()
File ~/.local/lib/python3.9/site-packages/h5py/_hl/dataset.py:783, in Dataset.__getitem__(self, args, new_dtype)
778 return arr
780 # === Everything else ===================
781
782 # Perform the dataspace selection.
--> 783 selection = sel.select(self.shape, args, dataset=self)
785 if selection.nselect == 0:
786 return numpy.ndarray(selection.array_shape, dtype=new_dtype)
File ~/.local/lib/python3.9/site-packages/h5py/_hl/selections.py:82, in select(shape, args, dataset)
79 space = h5s.create_simple(shape)
80 selector = _selector.Selector(space)
---> 82 return selector.make_selection(args)
File h5py/_selector.pyx:272, in h5py._selector.Selector.make_selection()
File h5py/_selector.pyx:183, in h5py._selector.Selector.apply_args()
TypeError: Indexing arrays must have integer dtypes
I also see an error in the following subsection:
# retrieve injections for first hyper sample for events GW150914 and GW151012
first_sample_GW150914_GW151012_injections = result.get_reweighted_injections(events=['GW150914', 'GW151012'],
hyper_sample_idx=0)
# retrieve first 2 catalogs
first_ten_catalog_injections = result.get_reweighted_injections(catalog_idx=slice(0,2))
And the traceback:
Click to expand
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
Cell In[24], line 2
1 # retrieve injections for first hyper sample for events GW150914 and GW151012
----> 2 first_sample_GW150914_GW151012_injections = result.get_reweighted_injections(events=['GW150914', 'GW151012'],
3 hyper_sample_idx=0)
5 # retrieve first 2 catalogs
6 first_ten_catalog_injections = result.get_reweighted_injections(catalog_idx=slice(0,2))
File ~/projects/O4/RatesPop/popsummary/popsummary/popresult.py:209, in PopulationResult.get_reweighted_injections(self, events, catalog_idx, hyper_sample_idx, group)
206 else:
207 mask_hyper_sample = hyper_sample_idx
--> 209 return f[group]['reweighted_injections'][mask_event, mask_catalog, mask_hyper_sample, :]
File h5py/_objects.pyx:54, in h5py._objects.with_phil.wrapper()
File h5py/_objects.pyx:55, in h5py._objects.with_phil.wrapper()
File ~/.local/lib/python3.9/site-packages/h5py/_hl/dataset.py:783, in Dataset.__getitem__(self, args, new_dtype)
778 return arr
780 # === Everything else ===================
781
782 # Perform the dataspace selection.
--> 783 selection = sel.select(self.shape, args, dataset=self)
785 if selection.nselect == 0:
786 return numpy.ndarray(selection.array_shape, dtype=new_dtype)
File ~/.local/lib/python3.9/site-packages/h5py/_hl/selections.py:82, in select(shape, args, dataset)
79 space = h5s.create_simple(shape)
80 selector = _selector.Selector(space)
---> 82 return selector.make_selection(args)
File h5py/_selector.pyx:272, in h5py._selector.Selector.make_selection()
File h5py/_selector.pyx:183, in h5py._selector.Selector.apply_args()
TypeError: Indexing arrays must have integer dtypes
It should also be noted that reweighted injections have a number of events in each "catalog" of simulated detections, but those events are not real and therefore one should not be able to select them based on event name but rather by index.
So, three things to fix:
-
Deal with TypeError: Indexing arrays must have integer dtypes
error for reweighted event samples -
Deal with TypeError: Indexing arrays must have integer dtypes
error for reweighted injections -
Fix reweighted injections getter function so that it indexes events by index number rather than event name since there are no event names for injections. Ask @zoheyr-doctor if this is unclear
Edited by Zoheyr Doctor