Skip to content

Adds livetime correction to get data#192

Open
jajmitchell wants to merge 23 commits into
TCDSolar:mainfrom
jajmitchell:adds_livetime_correction_to_get_data
Open

Adds livetime correction to get data#192
jajmitchell wants to merge 23 commits into
TCDSolar:mainfrom
jajmitchell:adds_livetime_correction_to_get_data

Conversation

@jajmitchell

Copy link
Copy Markdown

Adds livetime correction to get data.

@samaloney samaloney left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - needs docs, change log and test/s

Comment thread stixpy/product/sources/science.py Outdated
Comment on lines +900 to +909

# 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))

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is now in the instrument configuration namespace

STIX_INSTRUMENT = SimpleNamespace(
__doc__="""This namespace contains the instrument name, visibility information, sub-collimator ADC mapping, sub-collimator parameters, and pixel configuration.
The visibility information is obtained from the _get_uv_points_data function,
the sub-collimator ADC mapping is read from the detector ADC mapping file,
the sub-collimator parameters are read from the sub-collimator parameters file,
and the pixel configuration is read from the pixel parameters file.
The namespace is used to encapsulate all the configuration data related to the STIX instrument.
This allows for easy access and management of the instrument's configuration data.""",
name="STIX",
vis_info=_get_uv_points_data(),
subcol_adc_mapping=np.array(read_det_adc_mapping()["Adc #"]),
subcol_params=_SUBCOL_PARAMS,
pixel_config=read_pixel_params(),
)

Implements corrections and get_spectrum function
get_spectrum and bkg_subtract now work
@samaloney samaloney added this to the v0.4.0 milestone Nov 25, 2025
@samaloney

Copy link
Copy Markdown
Member

Add properties for livetime and livefrac or deadfrac

@samaloney samaloney modified the milestones: v0.4.0, v0.3.0 Nov 25, 2025

@samaloney samaloney left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we already use roentgen should either migrate to xraydb or keep using

Comment on lines +133 to +134
ds = 5e-3
dh = 5e-2

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Magic numbers need at least comment and ideally units

return subc_transm


def stx_grid_transmission(pitch, slit, thickness, L):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Needs a docstring and test

Comment thread stixpy/calibration/grid.py Outdated

# ;; 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 ) )

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ask paolo

Comment thread stixpy/calibration/livetime.py Outdated


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):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just wonder what motivated this change?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change back

Comment thread stixpy/io/readers.py Outdated
Comment on lines +137 to +149
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)


Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already fix on main

stixpy/stixpy/io/readers.py

Lines 136 to 140 in 4f4e0c7

elut = type("ELUT", (object,), dict())
elut.file = elut_file.name
offset_col = [col for col in elut_table.colnames if "offset" in col.casefold()][0]
gain_col = [col for col in elut_table.colnames if "gain" in col.casefold()][0]
elut.offset = elut_table[offset_col].reshape(32, 12)

Comment thread stixpy/product/sources/science.py Outdated
return counts_corr, counts_err, times, t_norm, livefrac, energies, elut_cor_fac


def get_spectrum(self, bkg_prod=None):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, ...)

Comment thread stixpy/product/sources/science.py Outdated

# NEED TO ADD IN THE DIST AND ANGLE READING AND BKG_SUBTRACT, GETTING THERE THOUGH!!!

def bkg_subtract(self, bkg_data):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might be better as a plain function, e.g. not a method on the object.

Comment thread stixpy/product/sources/science.py Outdated

return spec_sub

def get_masked_srm(self,flare_location):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to support flat spectral assumption and slope septette the arm sliceing and other stuff

@codecov

codecov Bot commented Apr 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 3.58423% with 538 lines in your changes missing coverage. Please review.
✅ Project coverage is 50.19%. Comparing base (9778770) to head (adda454).

Files with missing lines Patch % Lines
stixpy/product/sources/science.py 0.55% 358 Missing ⚠️
stixpy/coordinates/flare_location.py 2.46% 79 Missing ⚠️
stixpy/calibration/grid.py 2.08% 47 Missing ⚠️
stixpy/calibration/elut.py 15.90% 37 Missing ⚠️
stixpy/coordinates/flare_angle.py 33.33% 16 Missing ⚠️
stixpy/calibration/detector.py 0.00% 1 Missing ⚠️

❗ There is a different number of reports uploaded between BASE (9778770) and HEAD (adda454). Click for more details.

HEAD has 19 uploads less than BASE
Flag BASE (9778770) HEAD (adda454)
20 1
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Everything has been moved onto get_data()
@rh2082

rh2082 commented May 12, 2026

Copy link
Copy Markdown
Contributor

Hi, is there a particular reason why 6-10keV is chosen as the energy range in estimate_flare_location?

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants