def test_nrs_msa_spec2(self): """ Regression test of calwebb_spec2 pipeline performed on NIRSpec MSA data. """ input = 'f170lp-g235m_mos_observation-6-c0e0_001_dn_nrs1_mod.fits' input_file = self.get_data(self.test_dir, input) self.get_data(self.test_dir, 'jw95065006001_0_short_msa.fits') # define step for use in test step = Spec2Pipeline() step.save_results = True step.save_bsub = False step.output_use_model = True step.resample_spec.save_results = True step.extract_1d.save_results = True step.extract_1d.smoothing_length = 0 step.extract_1d.bkg_order = 0 step.run(input_file) outputs = [ ('f170lp-g235m_mos_observation-6-c0e0_001_dn_nrs1_mod_cal.fits', 'f170lp-g235m_mos_observation-6-c0e0_001_dn_nrs1_mod_cal_ref.fits' ), ('f170lp-g235m_mos_observation-6-c0e0_001_dn_nrs1_mod_s2d.fits', 'f170lp-g235m_mos_observation-6-c0e0_001_dn_nrs1_mod_s2d_ref.fits' ), ('f170lp-g235m_mos_observation-6-c0e0_001_dn_nrs1_mod_x1d.fits', 'f170lp-g235m_mos_observation-6-c0e0_001_dn_nrs1_mod_x1d_ref.fits' ) ] self.compare_outputs(outputs)
def test_mrs_spec2(self): """ Regression test of calwebb_spec2 pipeline performed on MIRI MRS data. """ self.rtol = 0.000001 input_file = self.get_data(self.test_dir, 'jw10001001001_01101_00001_mirifushort_rate.fits') step = Spec2Pipeline() step.save_bsub=True, step.save_results=True step.resample_spec.save_results = True step.cube_build.save_results = True step.extract_1d.save_results = True step.run(input_file) outputs = [('jw10001001001_01101_00001_mirifushort_cal.fits', 'jw10001001001_01101_00001_mirifushort_cal_ref.fits', ['primary','sci','err','dq','relsens2d']), ('jw10001001001_01101_00001_mirifushort_s3d.fits', 'jw10001001001_01101_00001_mirifushort_s3d_ref.fits', ['primary','sci','err','dq','wmap']), ('jw10001001001_01101_00001_mirifushort_x1d.fits', 'jw10001001001_01101_00001_mirifushort_x1d_ref.fits', ['primary','extract1d']) ] self.compare_outputs(outputs)
def test_miri_lrs_slit_1(self): """ Regression test of calwebb_spec2 pipeline performed on a single MIRI LRS fixed-slit exposure. """ input_file = self.get_data(self.test_dir, 'jw00035001001_01101_00001_MIRIMAGE_rate.fits') step = Spec2Pipeline() step.save_bsub=True, step.save_results=True step.resample_spec.save_results = True step.cube_build.save_results = True step.extract_1d.save_results = True step.run(input_file) outputs = [('jw00035001001_01101_00001_MIRIMAGE_cal.fits', 'jw00035001001_01101_00001_MIRIMAGE_cal_ref.fits', ['primary','sci','err','dq','relsens']), ('jw00035001001_01101_00001_MIRIMAGE_x1d.fits', 'jw00035001001_01101_00001_MIRIMAGE_x1d_ref.fits', ['primary','extract1d']) ] self.compare_outputs(outputs)
def test_mrs2pipeline1(self): """ Regression test of calwebb_spec2 pipeline performed on MIRI MRS data. """ test_dir = 'test_mrs2pipeline' self.ref_loc = ['test_mrs2pipeline', 'truth'] input_file = self.get_data(test_dir, 'jw80500018001_02101_00002_MIRIFUSHORT_rate.fits') step = Spec2Pipeline() step.save_bsub=True, step.save_results=True step.resample_spec.save_results = True step.cube_build.save_results = True step.extract_1d.save_results = True step.run(input_file) outputs = [('jw80500018001_02101_00002_MIRIFUSHORT_cal.fits', 'jw80500018001_02101_00002_MIRIFUSHORT_cal_ref.fits', ['primary','sci','err','dq']), ('jw80500018001_02101_00002_MIRIFUSHORT_s3d.fits', 'jw80500018001_02101_00002_MIRIFUSHORT_s3d_ref.fits', ['primary','sci','err','dq','wmap']), ('jw80500018001_02101_00002_MIRIFUSHORT_x1d.fits', 'jw80500018001_02101_00002_MIRIFUSHORT_x1d_ref.fits', ['primary','extract1d']) ] self.compare_outputs(outputs)
def test_nrs2_nodata_api(envopt, _jail): """ Regression test of handling NRS2 detector that has no data.\ """ # Only need to ensure that assing_wcs is run. # This still will fail and should cause the pipeline to halt. step = Spec2Pipeline() step.assign_wcs.skip = False with pytest.raises(NoDataOnDetectorError): step.run( get_bigdata('jwst-pipeline', envopt, 'nirspec', 'test_assignwcs', 'jw84700006001_02101_00001_nrs2_rate.fits'))
def test_nrs_fs_multi_spec2(self, input, outputs): """ Regression test of calwebb_spec2 pipeline performed on NIRSpec data. """ input_file = self.get_data(self.test_dir, input) step = Spec2Pipeline() step.save_bsub = True step.save_results = True step.resample_spec.save_results = True step.cube_build.save_results = True step.extract_1d.save_results = True step.run(input_file) self.compare_outputs(outputs)
def test_nirspec_nrs2_nodata_api(_jail, rtdata, fitsdiff_default_kwargs): """ Test of calwebb_spec2 pipeline performed on NIRSpec IFU exposure that has a filter/grating combination that produces no data on the NRS2 detector. Pipeline should raise an exception. """ # Get the input file rtdata.get_data('nirspec/ifu/jw84700006001_02101_00001_nrs2_rate.fits') # Call the Spec2Pipeline step = Spec2Pipeline() step.assign_wcs.skip = False with pytest.raises(NoDataOnDetectorError): step.run(rtdata.input)
def test_nrs_fs_single_spec2(self): """ Regression test of calwebb_spec2 pipeline performed on NIRSpec fixed-slit data that uses a single-slit subarray (S200B1). """ input_file = self.get_data(self.test_dir, 'jw84600002001_02101_00001_nrs2_rate.fits') step = Spec2Pipeline() step.save_bsub = True step.save_results = True step.resample_spec.save_results = True step.cube_build.save_results = True step.extract_1d.save_results = True step.run(input_file) outputs = [('jw84600002001_02101_00001_nrs2_cal.fits', 'jw84600002001_02101_00001_nrs2_cal_ref.fits'), ('jw84600002001_02101_00001_nrs2_s2d.fits', 'jw84600002001_02101_00001_nrs2_s2d_ref.fits'), ('jw84600002001_02101_00001_nrs2_x1d.fits', 'jw84600002001_02101_00001_nrs2_x1d_ref.fits')] self.compare_outputs(outputs)
def test_miri_lrs_bkgnod(self): """ Regression test of calwebb_spec2 pipeline performed on an association of nodded MIRI LRS fixed-slit exposures. """ asn_file = self.get_data(self.test_dir, 'lrs_bkgnod_asn.json') for file in raw_from_asn(asn_file): self.get_data(self.test_dir, file) step = Spec2Pipeline() step.save_bsub=True, step.save_results=True step.resample_spec.save_results = True step.cube_build.save_results = True step.extract_1d.save_results = True step.run(asn_file) outputs = [('test_lrs1_bsub.fits', 'test_lrs1_bsub_ref.fits', ['primary','sci','err','dq']), ('test_lrs2_bsub.fits','test_lrs2_bsub_ref.fits', ['primary','sci','err','dq']), ('test_lrs3_bsub.fits','test_lrs3_bsub_ref.fits', ['primary','sci','err','dq']), ('test_lrs4_bsub.fits','test_lrs4_bsub_ref.fits', ['primary','sci','err','dq']), ('test_lrs1_cal.fits', 'test_lrs1_cal_ref.fits', ['primary','sci','err','dq','relsens']), ('test_lrs2_cal.fits', 'test_lrs2_cal_ref.fits', ['primary','sci','err','dq','relsens']), ('test_lrs3_cal.fits', 'test_lrs3_cal_ref.fits', ['primary','sci','err','dq','relsens']), ('test_lrs4_cal.fits', 'test_lrs4_cal_ref.fits', ['primary','sci','err','dq','relsens']) ] self.compare_outputs(outputs)
def test_miri_lrs_slit_1b(self): """ Regression test of calwebb_spec2 pipeline performed on a single MIRI LRS fixed-slit exposure with multiple integrations. Compare _calints. """ input_file = self.get_data(self.test_dir, 'jw00035001001_01101_00001_MIRIMAGE_rateints.fits') step = Spec2Pipeline() step.save_bsub=True, step.save_results=True step.extract_1d.save_results = True step.run(input_file) outputs = [('jw00035001001_01101_00001_MIRIMAGE_calints.fits', 'jw00035001001_01101_00001_MIRIMAGE_calints_ref.fits', ['primary','sci','err','dq','relsens']), ('jw00035001001_01101_00001_MIRIMAGE_x1dints.fits', 'jw00035001001_01101_00001_MIRIMAGE_x1dints_ref.fits', ['primary', ('extract1d', 1), ('extract1d', 2), ('extract1d', 3), ('extract1d', 4)] ) ] self.compare_outputs(outputs)
def test_nrs_msa_spec2b(self): """ Regression test of calwebb_spec2 pipeline performed on NIRSpec MSA data, including barshadow correction. """ input = 'jw95065_nrs_msaspec_barshadow.fits' input_file = self.get_data(self.test_dir, input) self.get_data(self.test_dir, 'jwst_nirspec_shutters_barshadow.fits') step = Spec2Pipeline() step.output_file = 'jw95065_nrs_msaspec_barshadow_cal.fits' step.save_bsub = False step.save_results = True step.resample_spec.save_results = True step.extract_1d.save_results = True step.run(input_file) outputs = [('jw95065_nrs_msaspec_barshadow_cal.fits', 'jw95065_nrs_msaspec_barshadow_cal_ref.fits'), ('jw95065_nrs_msaspec_barshadow_s2d.fits', 'jw95065_nrs_msaspec_barshadow_s2d_ref.fits'), ('jw95065_nrs_msaspec_barshadow_x1d.fits', 'jw95065_nrs_msaspec_barshadow_x1d_ref.fits')] self.compare_outputs(outputs)
def calibrate(self, configdir=None, outdir=None, **kwargs): """ Pipeline process the file Parameters ---------- configdir: str The directory containing the configuration files outdir: str The directory to put the calibrated files into """ # Get config directory if configdir is None: configdir = resource_filename('specialsoss', 'files') # Get output directory if outdir is None: outdir = os.path.dirname(self.file) # Get basename basename = os.path.basename(self.file) file = os.path.join(outdir, basename) # Dict for new files new_files = {} if self.ext == 'uncal': # Create Detector1Pipeline instance cfg1_file = os.path.join(configdir, 'calwebb_tso1.cfg') from jwst.pipeline import Detector1Pipeline tso1 = Detector1Pipeline.call(self.file, save_results=True, config_file=cfg1_file, output_dir=outdir) # Calibrated files new_files['ramp'] = os.path.join( outdir, file.replace('_uncal.fits', '_ramp.fits')) new_files['rate'] = os.path.join( outdir, file.replace('_uncal.fits', '_rate.fits')) new_files['rateints'] = os.path.join( outdir, file.replace('_uncal.fits', '_rateints.fits')) if self.ext in ['rate', 'rateints']: # SPEC2 Pipeline cfg2_file = os.path.join(configdir, 'calwebb_tso-spec2.cfg') from jwst.pipeline import Spec2Pipeline tso2 = Spec2Pipeline(save_results=True, config_file=cfg2_file, output_dir=outdir) # Configure steps tso2.cube_build.skip = True tso2.extract_2d.skip = True tso2.bkg_subtract.skip = True tso2.msa_flagging.skip = True tso2.barshadow.skip = True tso2.extract_1d.save_results = True # Run the pipeline tso2.run(self.file) # Calibrated files new_files['calints'] = os.path.join( outdir, file.replace('_rateints.fits', '_calints.fits')) new_files['x1dints'] = os.path.join( outdir, file.replace('_rateints.fits', '_x1dints.fits')) else: print("Not sure how to calibrate a '{}' file right now.".format( self.ext)) return new_files