AtomDB / pyatomdb

AtomDB project (www.atomdb.org)
Docs: atomdb.readthedocs.io
Other
32 stars 12 forks source link

s.spectra is not reseted when spectrum bins are updated. #14

Closed jagophile closed 6 years ago

jagophile commented 6 years ago

Hi Adam,

I found a (possible) problem of pyatomdb.spectrum.Session(). When spectrum bins are updated using the set_specbins() method, spectrum is NOT recalculated with the new bins.

For example, see below code snippet.

s = pyatomdb.spectrum.Session()

bins = np.arange(0.3, 1.0, 0.001) # original bins s.set_specbins(bins, specunits='keV') spectra = s.return_spectra(0.2, teunit='keV')

new_bins = bins * (1 + 0.1) # I want to apply a redshift of 0.1 s.set_specbins(new_bins, specunits='keV') new_spectra = s.return_spectra(0.2, teunit='keV') # actually, spectrum is NOT recalculated

spectra == new_spectra # this returns True

From Shinya Nakashima:

The cause of the problem is that s.spectra is not reseted when spectrum bins are updated. I have a workaround as below.

s = pyatomdb.spectrum.Session()

bins = np.arange(0.3, 1.0, 0.001) # original bins s.set_specbins(bins, specunits='keV') spectra = s.return_spectra(0.2, teunit='keV')

s.spectra = {} # reset spectra new_bins = bins * (1 + 0.1) # I want to apply a redshift of 0.1 s.set_specbins(new_bins, specunits='keV') new_spectra = s.return_spectra(0.2, teunit='keV')

spectra == new_spectra # this returns False

My suggestion is that the line of "s.spectra = {}" should be added in the end of the set_specbins() method. How do you think that? I would be happy if you could update pyatomdb.

jagophile commented 6 years ago

This is a bug. Fixed as suggested (almost). Released as version 0.5.4