Open DavidT3 opened 1 week ago
Should help this error I get when trying to set up a Spectrum instance with a grouped chandra source spectrum and a non-grouped background spectrum:
IndexError Traceback (most recent call last) Cell In[102], line 4 1 sp = Spectrum("testoo_grp.pi", "testoo.rmf", "testoo.arf", "testoo_bkg.pi", rel_src.ra_dec, Quantity(0, 'deg'), cur_r500_deg, oi, 'ACIS', 2 True, min_counts, None, None, None, '', '', '') 3 sp.src_name = rel_src.name ----> 4 sp.view(back_sub=False, grouped=False)
File ~/software/anaconda3/envs/chandra_daxa_dev/lib/python3.11/site-packages/xga/products/spec.py:1587, in Spectrum.view(self, figsize, lo_lim, hi_lim, back_sub, energy, src_colour, bck_colour, grouped, xscale, yscale, fontsize, show_model_fits, save_path) 1585 if not grouped: 1586 sct = self.count_rates.copy() -> 1587 bct = self.back_count_rates.copy() 1588 if energy: 1589 x_dat = self.conv_channel_energy(self.channels.copy()).value
File ~/software/anaconda3/envs/chandra_daxa_dev/lib/python3.11/site-packages/xga/products/spec.py:612, in Spectrum.back_count_rates(self) 601 @property 602 def back_count_rates(self) -> Quantity: 603 """ 604 The array of counts/second associated with each channel of the background spectrum. This takes the 605 back_counts property and divides it by the EXPOSURE entry in the background spectrum header. A second column (...) 609 :return: The counts/second quantity in units of 'ct/s'. 610 """ --> 612 return self.back_counts / self.back_exposure
File ~/software/anaconda3/envs/chandra_daxa_dev/lib/python3.11/site-packages/xga/products/spec.py:584, in Spectrum.back_counts(self) 580 # Checks whether the initial value of the background spec counts attribute has been overwritten, if not 581 # then I run the read on demand method to grab the information from the file. 582 if self._back_counts is None: 583 # Passing false means it won't read the source spectrum, but instead the background spectrum --> 584 self._read_on_demand(False) 586 return Quantity([self._back_counts, np.sqrt(self._back_counts)], 'ct').T
File ~/software/anaconda3/envs/chandra_daxa_dev/lib/python3.11/site-packages/xga/products/spec.py:300, in Spectrum._read_on_demand(self, src_spec) 298 rel_path = self.background 299 all_dat = read(rel_path) --> 300 self._back_counts = all_dat['COUNTS'] 301 self._back_channels = all_dat['CHANNEL'] 303 # Background spectra do not necessarily have these entries
IndexError: only integers, slices (:
), ellipsis (...
), numpy.newaxis (None
) and integer or boolean arrays are valid indices
This, for now at least, is mostly something that would make plotting the spectra work in that situation.
Pretty sure that XSPEC actually already does apply the source grouping to background.
This is motivated by the fact that there doesn't seem to be a way to apply the spectrum binning to the background when using specextract - even though part of the docs suggests that there is, I think that is a mistake.