Skip to content

Commit

Permalink
Add tests for output filename for cube build
Browse files Browse the repository at this point in the history
  • Loading branch information
melanieclarke committed Dec 18, 2024
1 parent 36c4c25 commit 7bb1036
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 5 deletions.
3 changes: 1 addition & 2 deletions jwst/cube_build/ifu_cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,9 @@ def define_cubename(self):
# that the remaining suffixes created below form the entire
# list of optical elements in the final output name.
suffix = self.output_name_base[self.output_name_base.rfind('_') + 1:]

if suffix in ['clear']:
self.output_name_base = self.output_name_base[:self.output_name_base.rfind('_')]

# Now compose the appropriate list of optical element suffix names
# based on MRS channel and sub-channel
channels = []
Expand Down
38 changes: 35 additions & 3 deletions jwst/cube_build/tests/test_cube_build_step.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"""

import numpy as np
import os
import pytest
from astropy.io import fits

Expand All @@ -13,6 +14,7 @@
from jwst.cube_build import CubeBuildStep
from jwst.cube_build.file_table import ErrorNoAssignWCS
from jwst.cube_build.cube_build import ErrorNoChannels
from jwst.datamodels import ModelContainer


@pytest.fixture(scope='module')
Expand Down Expand Up @@ -158,7 +160,7 @@ def nirspec_data():
image.meta.instrument.name = 'NIRSPEC'
image.meta.instrument.detector = 'NRS1'
image.meta.exposure.type = 'NRS_IFU'
image.meta.filename = 'test_nirspec.fits'
image.meta.filename = 'test_nirspec_cal.fits'
image.meta.observation.date = '2023-10-06'
image.meta.observation.time = '00:00:00.000'
# below values taken from regtest using file
Expand All @@ -182,12 +184,42 @@ def nirspec_data():
@pytest.mark.parametrize("as_filename", [True, False])
def test_call_cube_build_nirspec(tmp_cwd, nirspec_data, tmp_path, as_filename):
if as_filename:
fn = tmp_path / 'test_nirspec.fits'
fn = tmp_path / 'test_nirspec_cal.fits'
nirspec_data.save(fn)
step_input = fn
else:
step_input = nirspec_data
step = CubeBuildStep()
step.channel = '1'
step.coord_system = 'internal_cal'
step.run(step_input)
step.save_results = True
result = step.run(step_input)

assert isinstance(result, ModelContainer)
assert len(result) == 1
model = result[0]
assert model.meta.cal_step.cube_build == 'COMPLETE'
assert model.meta.filename == 'test_nirspec_g395h-f290lp_internal_s3d.fits'
assert os.path.isfile(model.meta.filename)


@pytest.mark.parametrize("as_filename", [True, False])
def test_call_cube_build_nirspec_multi(tmp_cwd, nirspec_data, tmp_path, as_filename):
if as_filename:
fn = tmp_path / 'test_nirspec_cal.fits'
nirspec_data.save(fn)
step_input = fn
else:
step_input = nirspec_data
step = CubeBuildStep()
step.channel = '1'
step.coord_system = 'internal_cal'
step.save_results = True
step.output_type = 'multi'
result = step.run(step_input)

assert isinstance(result, ModelContainer)
assert len(result) == 1
model = result[0]
assert model.meta.cal_step.cube_build == 'COMPLETE'
assert model.meta.filename == 'test_nirspec_s3d.fits'

0 comments on commit 7bb1036

Please sign in to comment.