-
Notifications
You must be signed in to change notification settings - Fork 3
CAL spectra : daily energy calibration #427
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 16 commits
a178fdc
3a06055
3848748
067651d
d4b0ea5
641354d
9ec1392
8f876ad
c45320f
941b581
b1a7447
a23eb33
958b970
8f0b116
4355806
4e7dd47
1fb8bdf
f924fa8
7e966a5
7c59ac0
2e3480b
d35d950
eeb3479
c10c49d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
nicHoch marked this conversation as resolved.
Show resolved
Hide resolved
|
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,229 @@ | ||||||
| """ | ||||||
| Author: O. Limousin, CEA | ||||||
| Date: Oct 23, 2024 | ||||||
| This script to: | ||||||
|
|
||||||
| #%%%%%%%%%%%%%% FOR fit of ECC_ULTRA_FINE %%%%%%%%%%%%%% | ||||||
| ../00_CALIBRATION_MONITORING_ULTRA_FINE/02_MONITOR_ECC_SPECTRA ==> XX_erg.fits | ||||||
|
|
||||||
| ../00_CALIBRATION_MONITORING_ULTRA_FINE/01_MONITOR_ECC_PARA/ ==> ECC_para_XXXX.fits | ||||||
|
|
||||||
| + read the log (.xlsx file) | ||||||
| + open the ECC calibrated spectra XX_erg.fits | ||||||
| + fit 31 and 81 keV lines (Fit_Ba_robust) (fit right hand side, and baseline) | ||||||
| + register the results in a Pandas Dataframe | ||||||
| + date, Run Number, Fit Goodness flags,DET, PIX, | ||||||
| P31, err_P31, dE31, err_dE31, H31 | ||||||
| P81, err_P81, dE81, err_dE81, H81 | ||||||
| + compute gain/offset corrections | ||||||
| + fill the dataframe with new values | ||||||
| + include errors | ||||||
| + include a Flag (Flag31 and Flag81) which is True if fit was OK | ||||||
| if was not OK, the ECC value in NOT corrected | ||||||
| + store the results in pkl | ||||||
| + generate update ECC_para files to recalibrate uncalibrated files | ||||||
|
|
||||||
| """ | ||||||
|
|
||||||
| import numpy as np | ||||||
| import pandas as pd | ||||||
| from lmfit import Model | ||||||
|
|
||||||
| from astropy.io import fits | ||||||
|
|
||||||
| from stixcore.util.logging import get_logger | ||||||
|
|
||||||
| logger = get_logger(__name__) | ||||||
|
|
||||||
|
|
||||||
| def open_fits_tables(fits_path): | ||||||
| # Get the data from .fits | ||||||
| data = [] | ||||||
| with fits.open(fits_path, memmap=False) as hdul: | ||||||
| header = [hdul[0].header] | ||||||
| for i in range(1, len(hdul)): | ||||||
| header.append(hdul[i].header) | ||||||
| data.append(hdul[i].data) | ||||||
|
|
||||||
| # Get the fields of each data table and sort the data in lists | ||||||
| data_names = [data_i.columns.names for data_i in data] | ||||||
| data_format = [data_i.columns.formats for data_i in data] | ||||||
| data_unit = [data_i.columns.units for data_i in data] | ||||||
| data_list = [[list(data[i][data_names[i][j]]) for j in range(len(data_names[i]))] for i in range(len(data))] | ||||||
| return header, data, data_list, data_names, data_format, data_unit | ||||||
|
|
||||||
|
|
||||||
| def Read_fits_STIX_One_Pixel(data, PIX=0, DETECTOR_ID=1, Nbin=2024, NRebin=1, NSigma=1): | ||||||
| data = data[0] | ||||||
| Pix = PIX | ||||||
| Pix = Pix + (DETECTOR_ID - 1) * 12 | ||||||
| obs = [0] * Nbin | ||||||
samaloney marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
nicHoch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| erg_c = data.ERG_center # data.field(0) | ||||||
| obs = data.field(3 + Pix) | ||||||
| nbin = Nbin | ||||||
| Nbin = [Nbin / NRebin] | ||||||
nicHoch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| # TODO: check if we really need to rebin with congrid here | ||||||
| # erg_c = congrid(erg_c[:nbin], Nbin) | ||||||
| # obs = congrid(obs[:nbin], Nbin) | ||||||
samaloney marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| erg_c = erg_c[:nbin] | ||||||
| obs = obs[:nbin] | ||||||
|
|
||||||
| yerr = NSigma * np.sqrt(obs) | ||||||
| return erg_c, obs, yerr | ||||||
|
|
||||||
|
|
||||||
| def line(x, slope, intercept): | ||||||
| """a line""" | ||||||
| return slope * x + intercept | ||||||
|
|
||||||
|
|
||||||
| def poly(x, degree, slope, intercept): | ||||||
| """a line""" | ||||||
nicHoch marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| return degree * x * x + slope * x + intercept | ||||||
|
|
||||||
|
|
||||||
| def gaussian(x, amp, cen, wid): | ||||||
| # """1-d gaussian: gaussian(x, amp, cen, wid)""" | ||||||
|
||||||
| # """1-d gaussian: gaussian(x, amp, cen, wid)""" | |
| """1-d gaussian: gaussian(x, amp, cen, wid)""" |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo in comment: "QUIET" should be "QUITE".
| # THE FOLLOWING SECTION IS QUIET ROBUST BUT MIGHT OVERESTIMATE THE ENERGY RESOLUTION AT 32 keV | |
| # THE FOLLOWING SECTION IS QUITE ROBUST BUT MIGHT OVERESTIMATE THE ENERGY RESOLUTION AT 32 keV |
samaloney marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
nicHoch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
nicHoch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
nicHoch marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
nicHoch marked this conversation as resolved.
Show resolved
Hide resolved
nicHoch marked this conversation as resolved.
Show resolved
Hide resolved
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shadowing the built-in dict with a variable name will cause issues if the built-in is needed elsewhere in the function. While it works here, it's a Python anti-pattern. Rename this variable to something like pixel_data or result_dict.
Uh oh!
There was an error while loading. Please reload this page.