Skip to content

Commit

Permalink
functional version new v2 re re fw
Browse files Browse the repository at this point in the history
  • Loading branch information
tapastro committed Sep 9, 2024
1 parent c233382 commit 31f44bd
Showing 1 changed file with 34 additions and 13 deletions.
47 changes: 34 additions & 13 deletions jwst/extract_1d/soss_extract/soss_extract.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

import numpy as np
from scipy.interpolate import UnivariateSpline
from scipy.interpolate import UnivariateSpline, CubicSpline

from stdatamodels.jwst import datamodels
from stdatamodels.jwst.datamodels import dqflags, SossWaveGridModel
Expand Down Expand Up @@ -105,7 +105,6 @@ def get_ref_file_args(ref_files):
idx_invalid = ~np.isfinite(wv_cent)
wv_cent[idx_invalid] = 0.0
centroid[order] = wv_cent

# Get kernels
kernels_o1 = WebbKernel(speckernel_ref.wavelengths, speckernel_ref.kernels, centroid[1], ovs, n_pix)
kernels_o2 = WebbKernel(speckernel_ref.wavelengths, speckernel_ref.kernels, centroid[2], ovs, n_pix)
Expand Down Expand Up @@ -138,15 +137,38 @@ def get_trace_1d(ref_files, order):
"""

pastasoss_ref = ref_files['pastasoss']
if order in [1, 2]:
_, xtrace, ytrace, wavetrace = \
get_soss_traces(pastasoss_ref, pwcpos=ref_files['pwcpos'], order=str(order), subarray=ref_files['subarray'])
if hasattr(pastasoss_ref.traces[0], "padding"):
pad = pastasoss_ref.traces[0].padding

Check warning on line 141 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L139-L141

Added lines #L139 - L141 were not covered by tests
else:
errmsg = f"Pastasoss does not currently support order {order}."
pad = 0
padding = False
if pad > 0:
padding = True
(wavemap_o1, wavemap_o2), (spectrace_o1, spectrace_o2) = \

Check warning on line 147 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L143-L147

Added lines #L143 - L147 were not covered by tests
get_soss_wavemaps(pastasoss_ref, pwcpos=ref_files['pwcpos'], subarray=ref_files['subarray'],
padding=padding, padsize=pad, spectraces=True)
if order == 1:
wavemap = wavemap_o1
spectrace = spectrace_o1

Check warning on line 152 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L150-L152

Added lines #L150 - L152 were not covered by tests
xtrace = np.arange(2048)
elif order == 2:
wavemap = wavemap_o2
spectrace = spectrace_o2
xtrace = np.arange(1783)

Check warning on line 157 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L154-L157

Added lines #L154 - L157 were not covered by tests
else:
errmsg = f"Order {order} is not covered by Pastasoss reference file!"
log.error(errmsg)
raise ValueError(errmsg)

Check warning on line 161 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L159-L161

Added lines #L159 - L161 were not covered by tests

return xtrace.astype(int), ytrace, wavetrace
# CubicSpline requires monotonically increasing x arr
if spectrace[0][0] - spectrace[0][1] > 0:
spectrace = np.flip(spectrace, axis=1)

Check warning on line 165 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L164-L165

Added lines #L164 - L165 were not covered by tests

trace_interp_y = CubicSpline(spectrace[0], spectrace[1])
trace_interp_wave = CubicSpline(spectrace[0], spectrace[2])
ytrace = trace_interp_y(xtrace)
wavetrace = trace_interp_wave(xtrace)

Check warning on line 170 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L167-L170

Added lines #L167 - L170 were not covered by tests
return xtrace, ytrace, wavetrace


def estim_flux_first_order(scidata_bkg, scierr, scimask, ref_file_args, mask_trace_profile, threshold=1e-4):
Expand Down Expand Up @@ -1205,19 +1227,18 @@ def run_extract1d(input_model, pastasoss_ref_name,
if i == 0:
all_box_weights[order] = []
all_box_weights[order].append(box_weights[order])

# Copy spectral data for each order into the output model.
for order in fluxes.keys():

table_size = len(wavelengths[order])

out_table = np.zeros(table_size, dtype=datamodels.SpecModel().spec_table.dtype)
out_table['WAVELENGTH'] = wavelengths[order]
out_table['FLUX'] = fluxes[order]
out_table['FLUX_ERROR'] = fluxerrs[order]
out_table['WAVELENGTH'] = wavelengths[order][:table_size]
out_table['FLUX'] = fluxes[order][:table_size]
out_table['FLUX_ERROR'] = fluxerrs[order][:table_size]

Check warning on line 1238 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L1236-L1238

Added lines #L1236 - L1238 were not covered by tests
out_table['DQ'] = np.zeros(table_size)
out_table['BACKGROUND'] = col_bkg
out_table['NPIXELS'] = npixels[order]
out_table['BACKGROUND'] = col_bkg[:table_size]
out_table['NPIXELS'] = npixels[order][:table_size]

Check warning on line 1241 in jwst/extract_1d/soss_extract/soss_extract.py

View check run for this annotation

Codecov / codecov/patch

jwst/extract_1d/soss_extract/soss_extract.py#L1240-L1241

Added lines #L1240 - L1241 were not covered by tests

spec = datamodels.SpecModel(spec_table=out_table)

Expand Down

0 comments on commit 31f44bd

Please sign in to comment.