Skip to content

Commit

Permalink
rename spectrogram in spectrogram_data
Browse files Browse the repository at this point in the history
  • Loading branch information
Jérémy Neveu committed Jan 23, 2024
1 parent 0974e3d commit e107961
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
10 changes: 5 additions & 5 deletions spectractor/extractor/extractor.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ def __init__(self, spectrum, amplitude_priors_method="noprior", verbose=False, p
# crop data to fit faster
self.lambdas = self.spectrum.lambdas
self.bgd_width = parameters.PIXWIDTH_BACKGROUND + parameters.PIXDIST_BACKGROUND - parameters.PIXWIDTH_SIGNAL
self.data = spectrum.spectrogram[self.bgd_width:-self.bgd_width, :]
self.data = spectrum.spectrogram_data[self.bgd_width:-self.bgd_width, :]
self.err = spectrum.spectrogram_err[self.bgd_width:-self.bgd_width, :]
self.bgd = spectrum.spectrogram_bgd[self.bgd_width:-self.bgd_width, :]
self.bgd_flat = self.bgd.flatten()
Expand Down Expand Up @@ -643,7 +643,7 @@ def plot_spectrogram_comparison_simple(self, ax, title='', extent=None, dispersi

lambdas = self.spectrum.lambdas
sub = np.where((lambdas > parameters.LAMBDA_MIN) & (lambdas < parameters.LAMBDA_MAX))[0]
sub = np.where(sub < self.spectrum.spectrogram.shape[1])[0]
sub = np.where(sub < self.spectrum.spectrogram_data.shape[1])[0]
data = (data + self.bgd_flat).reshape((self.Ny, self.Nx))
err = self.err.reshape((self.Ny, self.Nx))
model = (self.model + self.params["B"] * self.bgd_flat).reshape((self.Ny, self.Nx))
Expand Down Expand Up @@ -1411,7 +1411,7 @@ def bgd_model_func(x, y):
f'\n\tNew target position in spectrogram frame: {target_pixcoords_spectrogram}')

# Save results
spectrum.spectrogram = data
spectrum.spectrogram_data = data
spectrum.spectrogram_err = err
spectrum.spectrogram_x0 = target_pixcoords_spectrogram[0]
spectrum.spectrogram_y0 = target_pixcoords_spectrogram[1]
Expand Down Expand Up @@ -1491,7 +1491,7 @@ def run_spectrogram_deconvolution_psf2d(spectrum, bgd_model_func):
"""
my_logger = set_logger(__name__)
s = spectrum.chromatic_psf
Ny, Nx = spectrum.spectrogram.shape
Ny, Nx = spectrum.spectrogram_data.shape

# build 1D priors
Dx_rot = np.copy(s.table['Dx'])
Expand Down Expand Up @@ -1525,7 +1525,7 @@ def run_spectrogram_deconvolution_psf2d(spectrum, bgd_model_func):
f"\n{s.table[['amplitude', 'x_c', 'y_c', 'Dx', 'Dy', 'Dy_disp_axis']]}")
my_logger.info(f'\n\tStart ChromaticPSF polynomial fit with '
f'mode={mode} and amplitude_priors_method={method}...')
data = spectrum.spectrogram
data = spectrum.spectrogram_data
err = spectrum.spectrogram_err

my_logger.info('\n\t ======================= ChromaticPSF2D polynomial fit =============================')
Expand Down
18 changes: 9 additions & 9 deletions spectractor/extractor/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ class Spectrum:
Outside relative humidity in fraction of one.
throughput: callable
Instrumental throughput of the telescope.
spectrogram: array
spectrogram_data: array
Spectrogram 2D image in image units.
spectrogram_bgd: array
Estimated 2D background fitted below the spectrogram in image units.
Expand Down Expand Up @@ -237,7 +237,7 @@ def __init__(self, file_name="", image=None, order=1, target=None, config="", fa
self.rotation_angle = 0
self.parallactic_angle = None
self.camera_angle = 0
self.spectrogram = None
self.spectrogram_data = None
self.spectrogram_bgd = None
self.spectrogram_bgd_rms = None
self.spectrogram_err = None
Expand Down Expand Up @@ -504,7 +504,7 @@ def plot_spectrogram(self, ax=None, scale="lin", title="", units="Image units",
if ax is None:
plt.figure(figsize=figsize)
ax = plt.gca()
data = np.copy(self.spectrogram)
data = np.copy(self.spectrogram_data)
if plot_stats:
data = np.copy(self.spectrogram_err)
plot_image_simple(ax, data=data, scale=scale, title=title, units=units, cax=cax,
Expand Down Expand Up @@ -587,7 +587,7 @@ def generate_axes(fig):
widthPlot.set_xlabel(r'$\lambda$ [nm]')
widthPlot.grid()

spectrogram = np.copy(self.spectrogram)
spectrogram = np.copy(self.spectrogram_data)
res = self.spectrogram_residuals.reshape((-1, self.spectrogram_Nx))
std = np.std(res)
if spectrogram.shape[0] != res.shape[0]:
Expand Down Expand Up @@ -688,7 +688,7 @@ def save_spectrum(self, output_file_name, overwrite=False):
hdus[extname].header["IM_X0"] = self.target.image_x0
hdus[extname].header["IM_Y0"] = self.target.image_y0
elif extname == "S_DATA":
hdus[extname].data = self.spectrogram
hdus[extname].data = self.spectrogram_data
hdus[extname].header['UNIT1'] = self.units
elif extname == "S_ERR":
hdus[extname].data = self.spectrogram_err
Expand Down Expand Up @@ -784,7 +784,7 @@ def save_spectrogram(self, output_file_name, overwrite=False): # pragma: no cov
hdu6 = fits.ImageHDU()
hdu6.header["EXTNAME"] = "S_RES"
hdu1.header = self.header
hdu1.data = self.spectrogram
hdu1.data = self.spectrogram_data
hdu2.data = self.spectrogram_err
hdu3.data = self.spectrogram_bgd
hdu4.data = self.spectrogram_bgd_rms
Expand Down Expand Up @@ -961,7 +961,7 @@ def load_spectrum_older_24(self, input_file_name, spectrogram_file_name_override
self.target.image_y0 = float(hdu_list["ORDER0"].header["IM_Y0"])
# load spectrogram info
if len(hdu_list) > 4:
self.spectrogram = hdu_list["S_DATA"].data
self.spectrogram_data = hdu_list["S_DATA"].data
self.spectrogram_err = hdu_list["S_ERR"].data
self.spectrogram_bgd = hdu_list["S_BGD"].data
if len(hdu_list) > 7:
Expand Down Expand Up @@ -1074,7 +1074,7 @@ def load_spectrum_latest(self, input_file_name):
self.target.image_x0 = float(hdu_list["ORDER0"].header["IM_X0"])
self.target.image_y0 = float(hdu_list["ORDER0"].header["IM_Y0"])
# load spectrogram info
self.spectrogram = hdu_list["S_DATA"].data
self.spectrogram_data = hdu_list["S_DATA"].data
self.spectrogram_err = hdu_list["S_ERR"].data
self.spectrogram_bgd = hdu_list["S_BGD"].data
self.spectrogram_bgd_rms = hdu_list["S_BGD_ER"].data
Expand All @@ -1100,7 +1100,7 @@ def load_spectrogram(self, input_file_name): # pragma: no cover
if os.path.isfile(input_file_name):
with fits.open(input_file_name) as hdu_list:
header = hdu_list[0].header
self.spectrogram = hdu_list[0].data
self.spectrogram_data = hdu_list[0].data
self.spectrogram_err = hdu_list[1].data
self.spectrogram_bgd = hdu_list[2].data
if len(hdu_list) > 3:
Expand Down
8 changes: 4 additions & 4 deletions spectractor/fit/fit_spectrogram.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,8 @@ def __init__(self, spectrum, atmgrid_file_name="", fit_angstrom_exponent=False,
if self.spectrum.spectrogram_Ny > 2 * parameters.PIXDIST_BACKGROUND:
self.crop_spectrogram()
self.lambdas = self.spectrum.lambdas
self.Ny, self.Nx = self.spectrum.spectrogram.shape
self.data = self.spectrum.spectrogram.flatten()
self.Ny, self.Nx = self.spectrum.spectrogram_data.shape
self.data = self.spectrum.spectrogram_data.flatten()
self.err = self.spectrum.spectrogram_err.flatten()
self.fit_angstrom_exponent = fit_angstrom_exponent

Expand Down Expand Up @@ -164,11 +164,11 @@ def crop_spectrogram(self):
self.spectrum.spectrogram_ymax = self.spectrum.spectrogram_ymax - bgd_width
self.spectrum.spectrogram_ymin += bgd_width
self.spectrum.spectrogram_bgd = self.spectrum.spectrogram_bgd[bgd_width:-bgd_width, :]
self.spectrum.spectrogram = self.spectrum.spectrogram[bgd_width:-bgd_width, :]
self.spectrum.spectrogram_data = self.spectrum.spectrogram_data[bgd_width:-bgd_width, :]
self.spectrum.spectrogram_err = self.spectrum.spectrogram_err[bgd_width:-bgd_width, :]
self.spectrum.spectrogram_y0 -= bgd_width
self.spectrum.chromatic_psf.y0 -= bgd_width
self.spectrum.spectrogram_Ny, self.spectrum.spectrogram_Nx = self.spectrum.spectrogram.shape
self.spectrum.spectrogram_Ny, self.spectrum.spectrogram_Nx = self.spectrum.spectrogram_data.shape
self.spectrum.chromatic_psf.table["y_c"] -= bgd_width
self.my_logger.debug(f'\n\tSize of the spectrogram region after cropping: '
f'({self.spectrum.spectrogram_Nx},{self.spectrum.spectrogram_Ny})')
Expand Down
4 changes: 2 additions & 2 deletions spectractor/simulation/image_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,10 +325,10 @@ def compute(self, star, background, spectrogram, starfield=None):
yy, xx = np.mgrid[0:parameters.CCD_IMSIZE:1, 0:parameters.CCD_IMSIZE:1]
self.data = star.psf.evaluate(np.array([xx, yy])) + background.model()
if spectrogram.full_image:
self.data[spectrogram.spectrogram_ymin:spectrogram.spectrogram_ymax, :] += spectrogram.spectrogram
self.data[spectrogram.spectrogram_ymin:spectrogram.spectrogram_ymax, :] += spectrogram.spectrogram_data
else:
self.data[spectrogram.spectrogram_ymin:spectrogram.spectrogram_ymax,
spectrogram.spectrogram_xmin:spectrogram.spectrogram_xmax] += spectrogram.spectrogram
spectrogram.spectrogram_xmin:spectrogram.spectrogram_xmax] += spectrogram.spectrogram_data
# - spectrogram.spectrogram_bgd)
if starfield is not None:
self.data += starfield.model(xx, yy)
Expand Down

0 comments on commit e107961

Please sign in to comment.