Skip to content

Commit

Permalink
JP-3354 Cube build emsm bug (spacetelescope#7847)
Browse files Browse the repository at this point in the history
Co-authored-by: Howard Bushouse <[email protected]>
  • Loading branch information
2 people authored and mairanteodoro committed Sep 20, 2023
1 parent 7ffed92 commit bc3591b
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ cube_build
- Correct slicer scale and orientation in output WCS for IFU cubes built in internal_cal
coordinates, for NIRSpec calibration analysis. [#7811]

- Fix a bug with memory allocation in C extensions when weighting=emsm. [#7847]

datamodels
----------

Expand Down
10 changes: 5 additions & 5 deletions jwst/cube_build/ifu_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __init__(self,
self.roiw = pars_cube.get('roiw')
self.debug_spaxel = pars_cube.get('debug_spaxel')

self.spaxel_x, self.spaxel_y, self.spaxel_z = [int(val) for val in self.debug_spaxel.split()]
self.spaxel_x, self.spaxel_y, self.spaxel_z = [int(val) for val in self.debug_spaxel.split()]
self.spatial_size = None
self.spectral_size = None
self.interpolation = pars_cube.get('interpolation')
Expand Down Expand Up @@ -641,10 +641,10 @@ def build_ifucube(self):
roiw_ave, self.cdelt1, self.cdelt2)

spaxel_flux, spaxel_weight, spaxel_var, spaxel_iflux, spaxel_dq = result
self.spaxel_flux = self.spaxel_flux + np.asarray(result[0], np.float64)
self.spaxel_weight = self.spaxel_weight + np.asarray(result[1], np.float64)
self.spaxel_var = self.spaxel_var + np.asarray(result[2], np.float64)
self.spaxel_iflux = self.spaxel_iflux + np.asarray(result[3], np.float64)
self.spaxel_flux = self.spaxel_flux + np.asarray(spaxel_flux, np.float64)
self.spaxel_weight = self.spaxel_weight + np.asarray(spaxel_weight, np.float64)
self.spaxel_var = self.spaxel_var + np.asarray(spaxel_var, np.float64)
self.spaxel_iflux = self.spaxel_iflux + np.asarray(spaxel_iflux, np.float64)
spaxel_dq.astype(np.uint)
self.spaxel_dq = np.bitwise_or(self.spaxel_dq, spaxel_dq)
result = None
Expand Down
4 changes: 2 additions & 2 deletions jwst/cube_build/src/cube_match_sky_pointcloud.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ extern int dq_miri(int start_region, int end_region, int overlap_partial, int ov
double *xc, double *yc, double *zc,
double *coord1, double *coord2, double *wave,
double *sliceno,
long ncube, int npt,
long ncube, long npt,
int **spaxel_dq);

extern int dq_nirspec(int overlap_partial,
Expand All @@ -117,7 +117,7 @@ extern int dq_nirspec(int overlap_partial,
double *xc, double *yc, double *zc,
double *coord1, double *coord2, double *wave,
double *sliceno,
long ncube, int npt,
long ncube, long npt,
int **spaxel_dq);

extern int set_dqplane_to_zero(int ncube, int **spaxel_dq);
Expand Down
45 changes: 45 additions & 0 deletions jwst/regtest/test_miri_mrs_spec3.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ def run_spec3_ifulong(jail, rtdata_module):
return rtdata


@pytest.fixture(scope='module')
def run_spec3_ifushort_emsm(jail, rtdata_module):
"""Run the Spec3Pipeline (cube_build using weighting emsm) on association with 2 bands on IFUSHORT"""

# Test has bands medium and long for IFUSHORT

rtdata = rtdata_module
rtdata.get_asn('miri/mrs/jw01024_ifushort_mediumlong_spec3_00001_asn.json')

args = [
"calwebb_spec3",
rtdata.input,
'--steps.cube_build.save_results=true',
'--steps.cube_build.weighting=emsm',
'--steps.cube_build.output_file="miri_mrs_emsm"',
'--steps.extract_1d.save_results=true',
]

Step.from_cmdline(args)
return rtdata


@pytest.mark.slow
@pytest.mark.bigdata
@pytest.mark.parametrize(
Expand Down Expand Up @@ -92,3 +114,26 @@ def test_spec3_ifushort(run_spec3_ifushort, fitsdiff_default_kwargs, output):

diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
assert diff.identical, diff.report()


@pytest.mark.slow
@pytest.mark.bigdata
@pytest.mark.parametrize(
'output',
[
'miri_mrs_emsm_ch1-mediumlong_x1d.fits',
'miri_mrs_emsm_ch2-mediumlong_x1d.fits',
'miri_mrs_emsm_ch1-mediumlong_s3d.fits',
'miri_mrs_emsm_ch2-mediumlong_s3d.fits'
],
)
def test_spec3_ifushort_emsm(run_spec3_ifushort_emsm, fitsdiff_default_kwargs, output):
"""Regression test using weighting = 'emsm' """

rtdata = run_spec3_ifushort_emsm
rtdata.output = output

rtdata.get_truth(os.path.join(TRUTH_PATH, rtdata.output))

diff = FITSDiff(rtdata.output, rtdata.truth, **fitsdiff_default_kwargs)
assert diff.identical, diff.report()
39 changes: 38 additions & 1 deletion jwst/regtest/test_nirspec_ifu_spec3.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def run_spec3_multi(jail, rtdata_module):
'step': 'calwebb_spec3',
'args': {
'--steps.master_background.save_results=true',
'--steps.mrs_imatch.save_results=true',
'--steps.outlier_detection.save_results=true',
'--steps.resample_spec.save_results=true',
'--steps.cube_build.save_results=true',
Expand All @@ -31,6 +30,26 @@ def run_spec3_multi(jail, rtdata_module):
return rtdata


@pytest.fixture(scope='module')
def run_spec3_multi_emsm(jail, rtdata_module):
"""Run Spec3Pipeline"""
rtdata = rtdata_module

step_params = {
'input_path': 'nirspec/ifu/jw01249-o005_20230622t074431_spec3_00001_asn.json',
'step': 'calwebb_spec3',
'args': {
'--steps.cube_build.save_results=true',
'--steps.cube_build.weighting=emsm',
'--steps.cube_build.output_file="nirspec_emsm"',
'--steps.extract_1d.save_results=true',
}
}

rtdata = rt.run_step_from_dict(rtdata, **step_params)
return rtdata


@pytest.mark.slow
@pytest.mark.bigdata
@pytest.mark.parametrize(
Expand All @@ -55,3 +74,21 @@ def test_spec3_multi(run_spec3_multi, fitsdiff_default_kwargs, output):
truth_path=TRUTH_PATH,
is_suffix=False
)


@pytest.mark.slow
@pytest.mark.bigdata
@pytest.mark.parametrize(
'output',
[
'nirspec_emsm_g395h-f290lp_s3d.fits',
'nirspec_emsm_g395h-f290lp_x1d.fits',
]
)
def test_spec3_multi_emsm(run_spec3_multi_emsm, fitsdiff_default_kwargs, output):
"""Regression test matching output files"""
rt.is_like_truth(
run_spec3_multi_emsm, fitsdiff_default_kwargs, output,
truth_path=TRUTH_PATH,
is_suffix=False
)

0 comments on commit bc3591b

Please sign in to comment.