Adds livetime correction to get data#192
Conversation
Adds livetime correction to get_data
Adds detector and time masks
samaloney
left a comment
There was a problem hiding this comment.
Looks good - needs docs, change log and test/s
|
|
||
| # fmt: off | ||
| # For the moment copied from idl | ||
| trigger_to_detector = [0, 0, 7, 7, 2, 1, 1, 6, 6, 5, 2, 3, 3, 4, 4, 5, 13, 12, | ||
| 12, 11, 11, 10, 13, 14, 14, 9, 9, 10, 15, 15, 8, 8,] | ||
| # fmt: on | ||
|
|
||
| triggers = self.data["triggers"][:, trigger_to_detector].astype(float)[...] | ||
|
|
||
| _, livefrac, _ = get_livetime_fraction(triggers / self.data["timedel"].to("s").reshape(-1, 1)) |
There was a problem hiding this comment.
So this is now in the instrument configuration namespace
stixpy/stixpy/config/instrument.py
Lines 78 to 92 in fb3004c
Implements corrections and get_spectrum function
get_spectrum and bkg_subtract now work
|
Add properties for |
SRM now functional with wedge grid transmission
SRM fully functional
There was a problem hiding this comment.
Overall this looks great 🚀
Leaving all my comment but I know it still a WIP so some of them I'm sure you'd address anyway.
Few high level things are:
- docstrings
- test
- dockets where it makes sense
- needs a rebase/merge of current main
To me the key aspect is understanding want someone reading the code to know what's happening and why can link to paper / ref where applicable.
IDListis just because it done one way in IDL doesn't mean we have to or even should do the same - we need to support it for comparisons but they only to a point.
Also need to maintain some level of backwards compatibly with old transmission correction etc and also ideally support incremental correction e.g new transmission but no spectral slope correction.
As much of this as possible should be done it get_data we can create return a dictionary, dataclass etc. If we wanted to go hole hog get_data would return Spectrum, SpectrumCollection, or SpectrumSequences objects but that could be a later PR.
Also I think the u, v coords may need to be updated too with the new transmission?
| import astropy.units as u | ||
| import numpy as np | ||
| from astropy.table import Table | ||
| import xraydb |
There was a problem hiding this comment.
So we already use roentgen should either migrate to xraydb or keep using
| ds = 5e-3 | ||
| dh = 5e-2 |
There was a problem hiding this comment.
Magic numbers need at least comment and ideally units
| return subc_transm | ||
|
|
||
|
|
||
| def stx_grid_transmission(pitch, slit, thickness, L): |
|
|
||
| # ;; Transmission for a wedge shape model for grid imperfections | ||
| g0 = slit_rep / pitch_rep + (pitch_rep - slit_rep) / pitch_rep * np.exp( - H_rep / L_rep ) | ||
| ttt = L_rep / dh * ( 1. - np.exp(- dh / L_rep ) ) |
|
|
||
|
|
||
| def get_livetime_fraction(trigger_rate, *, eta=1.10 * u.us, tau=10.1 * u.us): | ||
| def get_livetime_fraction(trigger_rate,*, eta=1.1e-6 *u.s, tau=10.1e-6 * u.s): |
There was a problem hiding this comment.
Just wonder what motivated this change?
| try: | ||
| elut.offset = elut_table["Offset"].reshape(32, 12) | ||
| elut.gain = elut_table["Gain keV/ADC"].reshape(32, 12) | ||
| except KeyError: | ||
| try: | ||
| elut.offset = elut_table["Offset (ADC)"].reshape(32, 12) | ||
| elut.gain = elut_table["Gain (keV/ADC)"].reshape(32, 12) | ||
|
|
||
| except KeyError: | ||
| elut.offset = elut_table["Offset (ADC)"].reshape(32, 12) | ||
| elut.gain = elut_table["Gain (ADC/keV)"].reshape(32, 12) | ||
|
|
||
|
|
There was a problem hiding this comment.
This is already fix on main
Lines 136 to 140 in 4f4e0c7
| return counts_corr, counts_err, times, t_norm, livefrac, energies, elut_cor_fac | ||
|
|
||
|
|
||
| def get_spectrum(self, bkg_prod=None): |
There was a problem hiding this comment.
So ideally this should be handled by get_data e.g.
get_data(detector_indices=[[0,31]], pixel_indices=[[0,8]], elut=True, live=True, ...)
|
|
||
| # NEED TO ADD IN THE DIST AND ANGLE READING AND BKG_SUBTRACT, GETTING THERE THOUGH!!! | ||
|
|
||
| def bkg_subtract(self, bkg_data): |
There was a problem hiding this comment.
I think this might be better as a plain function, e.g. not a method on the object.
|
|
||
| return spec_sub | ||
|
|
||
| def get_masked_srm(self,flare_location): |
There was a problem hiding this comment.
Need to support flat spectral assumption and slope septette the arm sliceing and other stuff
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #192 +/- ##
===========================================
- Coverage 85.29% 50.19% -35.11%
===========================================
Files 50 53 +3
Lines 3175 3676 +501
===========================================
- Hits 2708 1845 -863
- Misses 467 1831 +1364 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Everything has been moved onto get_data()
|
Hi, is there a particular reason why 6-10keV is chosen as the energy range in |
Flare location added from Laura's flarelist and slightly modified, flare angle calculator also added, background subration done for each pixel and detector without collapsing
Adds livetime correction to get data.