def test_photom_nircam(_bigdata): """ Regression test of photom step performed on NIRCam imaging data. """ suffix = 'photom' output_file_base, output_file = add_suffix('photom1_output.fits', suffix) PhotomStep.call( _bigdata + '/nircam/test_photom/jw00017001001_01101_00001_NRCA1_emission.fits', output_file=output_file_base, suffix=suffix) h = fits.open(output_file) href = fits.open( _bigdata + '/nircam/test_photom/jw00017001001_01101_00001_NRCA1_photom.fits') newh = fits.HDUList( [h['primary'], h['sci'], h['err'], h['dq'], h['relsens'], h['area']]) newhref = fits.HDUList([ href['primary'], href['sci'], href['err'], href['dq'], href['relsens'], href['area'] ]) result = fits.diff.FITSDiff( newh, newhref, ignore_keywords=['DATE', 'CAL_VER', 'CAL_VCS', 'CRDS_VER', 'CRDS_CTX'], rtol=0.00001) assert result.identical, result.report()
def test_photom_niriss(_bigdata): """ Regression test of photom step performed on NIRISS imaging data. """ suffix = 'photom' output_file_base, output_file = add_suffix('photom1_output.fits', suffix) override_photom = _bigdata + '/niriss/test_photom/jwst_niriss_photom_b7a.fits' PhotomStep.call( _bigdata + '/niriss/test_photom/jw00034001001_01101_00001_NIRISS_flat_field.fits', output_file=output_file_base, suffix=suffix, override_photom=override_photom) h = pf.open(output_file) href = pf.open( _bigdata + '/niriss/test_photom/jw00034001001_01101_00001_NIRISS_photom.fits') newh = pf.HDUList( [h['primary'], h['sci'], h['err'], h['dq'], h['relsens']]) newhref = pf.HDUList([ href['primary'], href['sci'], href['err'], href['dq'], href['relsens'] ]) result = pf.diff.FITSDiff( newh, newhref, ignore_keywords=['DATE', 'CAL_VER', 'CAL_VCS', 'CRDS_VER', 'CRDS_CTX'], rtol=0.00001) assert result.identical, result.report()
def test_photom_miri2(_bigdata): """ Regression test of photom step performed on MIRI LRS slitless data. """ suffix = 'photom' output_file_base, output_file = add_suffix('photom2_output.fits', suffix) try: os.remove(output_file) except: pass PhotomStep.call( _bigdata + '/miri/test_photom/jw80600012001_02101_00003_mirimage_srctype.fits', output_file=output_file_base, suffix=suffix) h = pf.open(output_file) href = pf.open( _bigdata + '/miri/test_photom/jw80600012001_02101_00003_mirimage_photom.fits') newh = pf.HDUList( [h['primary'], h['sci'], h['err'], h['dq'], h['relsens']]) newhref = pf.HDUList([ href['primary'], href['sci'], href['err'], href['dq'], href['relsens'] ]) result = pf.diff.FITSDiff( newh, newhref, ignore_keywords=['DATE', 'CAL_VER', 'CAL_VCS', 'CRDS_VER', 'CRDS_CTX'], rtol=0.00001) assert result.identical, result.report()
def test_photom_nirspec(_bigdata): """ Regression test of photom step performed on NIRSpec fixed slit data. """ output_file_base, output_file = add_suffix('photom1_output.fits', 'photom') try: os.remove(output_file) except: pass PhotomStep.call( _bigdata + '/nirspec/test_photom/jw00023001001_01101_00001_NRS1_flat_field.fits', output_file=output_file_base, name='photom') h = pf.open(output_file) href = pf.open( _bigdata + '/nirspec/test_photom/jw00023001001_01101_00001_NRS1_photom.fits') newh = pf.HDUList([ h['primary'], h['sci', 1], h['err', 1], h['dq', 1], h['relsens', 1], h['sci', 2], h['err', 2], h['dq', 2], h['relsens', 2], h['sci', 3], h['err', 3], h['dq', 3], h['relsens', 3], h['sci', 4], h['err', 4], h['dq', 4], h['relsens', 4] ]) newhref = pf.HDUList([ href['primary'], href['sci', 1], href['err', 1], href['dq', 1], href['relsens', 1], href['sci', 2], href['err', 2], href['dq', 2], href['relsens', 2], href['sci', 3], href['err', 3], href['dq', 3], href['relsens', 3], href['sci', 4], href['err', 4], href['dq', 4], href['relsens', 4] ]) result = pf.diff.FITSDiff( newh, newhref, ignore_keywords=['DATE', 'CAL_VER', 'CAL_VCS', 'CRDS_VER', 'CRDS_CTX'], rtol=0.00001) assert result.identical, result.report()
def output_hdul(set_inandout_filenames, config): set_inandout_filenames_info = core_utils.read_info4outputhdul( config, set_inandout_filenames) step, txt_name, step_input_file, step_output_file, run_calwebb_spec2, outstep_file_suffix = set_inandout_filenames_info run_pipe_step = config.getboolean("run_pipe_steps", step) # determine which tests are to be run photom_completion_tests = config.getboolean( "run_pytest", "_".join((step, "completion", "tests"))) #photom_reffile_tests = config.getboolean("run_pytest", "_".join((step, "reffile", "tests"))) #photom_validation_tests = config.getboolean("run_pytest", "_".join((step, "validation", "tests"))) run_pytests = [photom_completion_tests ] #, photom_reffile_tests, photom_validation_tests] # if run_calwebb_spec2 is True calwebb_spec2 will be called, else individual steps will be ran step_completed = False end_time = '0.0' output_directory = config.get("calwebb_spec2_input_file", "output_directory") initial_input_file = config.get("calwebb_spec2_input_file", "input_file") initial_input_file = os.path.join(output_directory, initial_input_file) detector = fits.getval(initial_input_file, "DETECTOR", 0) if not os.path.isfile(initial_input_file): pytest.skip( "Skipping " + step + " because the initial input file given in PTT_config.cfg does not exist." ) # check if the filter is to be changed change_filter_opaque = config.getboolean("calwebb_spec2_input_file", "change_filter_opaque") if change_filter_opaque: is_filter_opaque, step_input_filename = change_filter_opaque2science.change_filter_opaque( step_input_file, step=step) if is_filter_opaque: filter_opaque_msg = "With FILTER=OPAQUE, the calwebb_spec2 will run up to the extract_2d step. Photometry pytest now set to Skip." print(filter_opaque_msg) core_utils.add_completed_steps(txt_name, step, outstep_file_suffix, step_completed, end_time) pytest.skip("Skipping " + step + " because FILTER=OPAQUE.") if run_calwebb_spec2: hdul = core_utils.read_hdrfits(step_output_file, info=False, show_hdr=False) return hdul, step_output_file, run_pytests else: if run_pipe_step: # Create the logfile for PTT, but erase the previous one if it exists PTTcalspec2_log = os.path.join( output_directory, 'PTT_calspec2_' + detector + '_' + step + '.log') if os.path.isfile(PTTcalspec2_log): os.remove(PTTcalspec2_log) print( "Information outputed to screen from PTT will be logged in file: ", PTTcalspec2_log) for handler in logging.root.handlers[:]: logging.root.removeHandler(handler) logging.basicConfig(filename=PTTcalspec2_log, level=logging.INFO) # print pipeline version import jwst pipeline_version = "\n *** Using jwst pipeline version: " + jwst.__version__ + " *** \n" print(pipeline_version) logging.info(pipeline_version) if change_filter_opaque: logging.info(filter_opaque_msg) if os.path.isfile(step_input_file): msg = " *** Step " + step + " set to True" print(msg) logging.info(msg) stp = PhotomStep() # check that previous pipeline steps were run up to this point core_utils.check_completed_steps(step, step_input_file) # get the right configuration files to run the step local_pipe_cfg_path = config.get("calwebb_spec2_input_file", "local_pipe_cfg_path") # start the timer to compute the step running time start_time = time.time() if local_pipe_cfg_path == "pipe_source_tree_code": result = stp.call(step_input_file) else: result = stp.call(step_input_file, config_file=local_pipe_cfg_path + '/photom.cfg') result.save(step_output_file) # end the timer to compute the step running time end_time = repr(time.time() - start_time) # this is in seconds msg = "Step " + step + " took " + end_time + " seconds to finish" print(msg) logging.info(msg) step_completed = True hdul = core_utils.read_hdrfits(step_output_file, info=False, show_hdr=False) # rename and move the pipeline log file try: calspec2_pilelog = "calspec2_pipeline_" + step + "_" + detector + ".log" pytest_workdir = TESTSDIR logfile = glob(pytest_workdir + "/pipeline.log")[0] os.rename(logfile, os.path.join(output_directory, calspec2_pilelog)) except: IndexError # add the running time for this step core_utils.add_completed_steps(txt_name, step, outstep_file_suffix, step_completed, end_time) return hdul, step_output_file, run_pytests else: msg = "Skipping running pipeline step " + step print(msg) logging.info(msg) end_time = core_utils.get_stp_run_time_from_screenfile( step, detector, output_directory) if os.path.isfile(step_output_file): hdul = core_utils.read_hdrfits(step_output_file, info=False, show_hdr=False) step_completed = True # add the running time for this step core_utils.add_completed_steps(txt_name, step, outstep_file_suffix, step_completed, end_time) return hdul, step_output_file, run_pytests else: step_completed = False # add the running time for this step core_utils.add_completed_steps(txt_name, step, outstep_file_suffix, step_completed, end_time) pytest.skip("Test skipped because input file " + step_output_file + " does not exist.") else: msg = " The input file does not exist. Skipping step." print(msg) logging.info(msg) core_utils.add_completed_steps(txt_name, step, outstep_file_suffix, step_completed, end_time) pytest.skip("Skipping " + step + " because the input file does not exist.")
def output_hdul(set_inandout_filenames, config): set_inandout_filenames_info = core_utils.read_info4outputhdul( config, set_inandout_filenames) step, txt_name, step_input_file, step_output_file, run_calwebb_spec2, outstep_file_suffix = set_inandout_filenames_info skip_runing_pipe_step = config.getboolean("tests_only", "_".join( (step, "tests"))) stp = PhotomStep() # if run_calwebb_spec2 is True calwebb_spec2 will be called, else individual steps will be ran step_completed = False end_time = '0.0' if run_calwebb_spec2: # read the assign wcs fits file local_step_output_file = core_utils.read_completion_to_full_run_map( "full_run_map.txt", step) hdul = core_utils.read_hdrfits(local_step_output_file, info=False, show_hdr=False) # move the output file into the working directory working_directory = config.get("calwebb_spec2_input_file", "working_directory") step_output_file = os.path.join(working_directory, local_step_output_file) print("Step product was saved as: ", step_output_file) subprocess.run(["mv", local_step_output_file, step_output_file]) return hdul else: if config.getboolean("steps", step): print("*** Step " + step + " set to True") if os.path.isfile(step_input_file): if not skip_runing_pipe_step: # get the right configuration files to run the step local_pipe_cfg_path = config.get( "calwebb_spec2_input_file", "local_pipe_cfg_path") # start the timer to compute the step running time start_time = time.time() if local_pipe_cfg_path == "pipe_source_tree_code": result = stp.call(step_input_file) else: result = stp.call(step_input_file, config_file=local_pipe_cfg_path + '/photom.cfg') result.save(step_output_file) # end the timer to compute the step running time end_time = repr(time.time() - start_time) # this is in seconds print("Step " + step + " took " + end_time + " seconds to finish") step_completed = True core_utils.add_completed_steps(txt_name, step, outstep_file_suffix, step_completed, end_time) hdul = core_utils.read_hdrfits(step_output_file, info=False, show_hdr=False) return hdul else: core_utils.add_completed_steps(txt_name, step, outstep_file_suffix, step_completed, end_time) pytest.skip("Skipping " + step + " because the input file does not exist.") else: core_utils.add_completed_steps(txt_name, step, outstep_file_suffix, step_completed, end_time) pytest.skip("Skipping " + step + ". Step set to False in configuration file.")