Exemplo n.º 1
0
def call_with_assorted_user_inputs(catalogs, crs, dates, backgrounds,
                                   roll_angles):
    """Test various user-inputs to yaml_generator, including dates, backgrounds,
    roll angles, cosmic rays, and catalogs
    """
    # Make an instance of the SimInput class
    input_xml = os.path.join(
        __location__,
        'test_data/misc/54321/54321_niriss_wfss_prime_nircam_imaging_parallel_mult_targets.xml'
    )
    pointing_file = os.path.join(
        __location__,
        'test_data/misc/54321/54321_niriss_wfss_prime_nircam_imaging_parallel_mult_targets.pointing'
    )
    temp_output_dir = os.path.join(__location__, "temp")

    yam = SimInput(input_xml,
                   pointing_file,
                   verbose=True,
                   catalogs=catalogs,
                   offline=True,
                   output_dir=temp_output_dir,
                   simdata_output_dir=temp_output_dir,
                   datatype='raw',
                   reffile_defaults='crds',
                   cosmic_rays=crs,
                   dates=dates,
                   background=backgrounds,
                   roll_angle=roll_angles)
    yam.use_linearized_darks = True
    yam.create_inputs()
    return yam.info
Exemplo n.º 2
0
def test_reffile_crds():
    """Make this a copy of test_reffile_crds_full_name (including reffile_overrides)
    but use 'crds'
    """
    catalogs = None

    # Make an instance of the SimInput class
    input_xml = os.path.join(__location__, 'test_data/misc/12345/12345_nircam_imaging_prime_niriss_wfss_parallel.xml')
    pointing_file = os.path.join(__location__, 'test_data/misc/12345/12345_nircam_imaging_prime_niriss_wfss_parallel.pointing')
    temp_output_dir = os.path.join(__location__, "temp")

    yam = SimInput(input_xml, pointing_file, verbose=True, catalogs=catalogs,
                   offline=True, output_dir=temp_output_dir,
                   simdata_output_dir=temp_output_dir,
                   datatype='raw', reffile_defaults='crds')
    yam.use_linearized_darks = True
    yam.create_inputs()

    # Check that all reference files are simply the string 'crds'
    expected_value = 'crds'
    assert np.all(np.array(yam.info['superbias']) == expected_value)
    assert np.all(np.array(yam.info['linearity']) == expected_value)
    assert np.all(np.array(yam.info['saturation']) == expected_value)
    assert np.all(np.array(yam.info['gain']) == expected_value)
    assert np.all(np.array(yam.info['astrometric']) == expected_value)
    assert np.all(np.array(yam.info['pixelAreaMap']) == expected_value)
    assert np.all(np.array(yam.info['badpixmask']) == expected_value)
    assert np.all(np.array(yam.info['ipc']) == expected_value)

# Clean up
    os.system('rm -r {}'.format(temp_output_dir))
def call_yaml_generator(xml_file):
    """Call the yaml generator. Assume the pointing file is in the same directory
    and has the same name as the xml file
    """
    temp_output_dir = os.path.join(__location__, "temp")
    pointing_file = xml_file.replace('.xml', '.pointing')

    yam = SimInput(xml_file,
                   pointing_file,
                   verbose=True,
                   offline=True,
                   output_dir=temp_output_dir,
                   simdata_output_dir=temp_output_dir,
                   datatype='raw',
                   reffile_defaults='crds')
    yam.use_linearized_darks = True
    yam.create_inputs()
    return yam
Exemplo n.º 4
0
def test_reffile_crds_full_name():
    """Test that the correct values for reference files are found
    """
    reffile_overrides = {'nircam': {'superbias': {'nrcb5': {'bright1': 'my_reffiles/my_superbias_for_b5.fits',
                                                            'shallow4': 'my_reffiles/my_superbias_for_b5.fits'
                                                            },
                                                  'nrcb4': {'shallow2': 'my_reffiles/my_superbias_for_b4.fits'}
                                                  },
                                    'linearity': {'nrcb5': 'my_reffiles/my_linearity_for_b5.fits',
                                                  'nrcb4': 'my_reffiles/my_linearity_for_b4.fits'},
                                    'saturation': {'nrcb5': 'my_reffiles/my_saturation_for_b5.fits',
                                                   'nrcb4': 'my_reffiles/my_saturation_for_b4.fits'},
                                    'gain': {'nrcb5': 'my_reffiles/my_gain_for_b5.fits',
                                             'nrcb4': 'my_reffiles/my_gain_for_b4.fits'},
                                    'distortion': {'nrcb5': {'f322w2': {'NRC_IMAGE': 'my_reffiles/my_distortion_for_b5.asdf'}},
                                                   'nrcb4': {'f150w': {'NRC_IMAGE': 'my_reffiles/my_distortion_for_b4.asdf'}}},
                                    'area': {'nrcb5': {'f322w2': {'clear': {'nrc_image': 'my_reffiles/my_pam_for_b5.fits'}}},
                                             'nrcb4': {'f150w': {'clear': {'nrc_image': 'my_reffiles/my_pam_for_b4.fits'}}}},
                                    'transmission': {'nrcb5': {'f322w2': {'clear': 'my_reffiles/my_transmission_for_b5.fits'},
                                                               'f444w': {'clear': 'my_reffiles/my_transmission_for_b5.fits'},
                                                               'f335m': {'clear': 'my_reffiles/my_transmission_for_b5.fits'},
                                                               'f300m': {'clear': 'my_reffiles/my_transmission_for_b5.fits'}},
                                                     'nrcb1': {'f150w': {'clear': 'my_reffiles/my_transmission_for_b1.fits'},
                                                               'f070w': {'clear': 'my_reffiles/my_transmission_for_b1.fits'},
                                                               'f150w2': {'clear': 'my_reffiles/my_transmission_for_b1.fits'},
                                                               'f187n': {'clear': 'my_reffiles/my_transmission_for_b1.fits'}},
                                                     'nrcb2': {'f150w': {'clear': 'my_reffiles/my_transmission_for_b2.fits'},
                                                               'f070w': {'clear': 'my_reffiles/my_transmission_for_b2.fits'},
                                                               'f150w2': {'clear': 'my_reffiles/my_transmission_for_b2.fits'},
                                                               'f187n': {'clear': 'my_reffiles/my_transmission_for_b2.fits'}},
                                                     'nrcb3': {'f150w': {'clear': 'my_reffiles/my_transmission_for_b3.fits'},
                                                               'f070w': {'clear': 'my_reffiles/my_transmission_for_b3.fits'},
                                                               'f150w2': {'clear': 'my_reffiles/my_transmission_for_b3.fits'},
                                                               'f187n': {'clear': 'my_reffiles/my_transmission_for_b3.fits'}},
                                                     'nrcb4': {'f150w': {'clear': 'my_reffiles/my_transmission_for_b4.fits'},
                                                               'f070w': {'clear': 'my_reffiles/my_transmission_for_b4.fits'},
                                                               'f150w2': {'clear': 'my_reffiles/my_transmission_for_b4.fits'},
                                                               'f187n': {'clear': 'my_reffiles/my_transmission_for_b4.fits'}},
                                                    },
                                    'badpixmask': {'nrcb5': 'my_reffiles/my_bpm_for_b5.fits',
                                                   'nrcb4': 'my_reffiles/my_bpm_for_b4.fits'},
                                    'pixelflat': {'nrcb5': {'f322w2': {'clear': 'my_reffiles/my_flatfield_for_b5.fits'}}}
                                    },
                         'niriss': {'superbias': {'nisrapid': 'my_niriss_supebias.fits'},
                                    'linearity': 'my_niriss_linearity,fits',
                                    'saturation': 'my_niriss_saturation.fits',
                                    'gain': 'my_niriss_gain.fits',
                                    'distortion': {'F115W': {'nis_image': 'my_niriss_disotrtion.asdf'}},
                                    'area': {'clear': {'f115w': {'nis_image': 'my_niriss_area.fits'}}},
                                    'transmission': {'clear': {'f115w': 'my_niriss_transmission.fits'},
                                                     'gr150c': {'f115w': 'my_niriss_gr_transmission.fits'}
                                                     },
                                    'badpixmask': 'my_niriss_badpixmask.fits',
                                    'pixelflat': {'clear': {'f115w': 'my_niriss_flatfield.fits'}}
                                    }
                         }

    catalogs = None

    # Make an instance of the SimInput class
    input_xml = os.path.join(__location__, 'test_data/misc/12345/12345_nircam_imaging_prime_niriss_wfss_parallel.xml')
    pointing_file = os.path.join(__location__, 'test_data/misc/12345/12345_nircam_imaging_prime_niriss_wfss_parallel.pointing')
    temp_output_dir = os.path.join(__location__, "temp")

    yam = SimInput(input_xml, pointing_file, verbose=True, catalogs=catalogs,
                   offline=True, output_dir=temp_output_dir,
                   simdata_output_dir=temp_output_dir,
                   datatype='raw', reffile_defaults='crds_full_name',
                   reffile_overrides=reffile_overrides)
    yam.use_linearized_darks = True
    yam.create_inputs()

    # Make into numpy arrays for easier matching
    sw_filternames = np.array(yam.info['ShortFilter'])
    lw_filternames = np.array(yam.info['LongFilter'])
    sw_pupilnames = np.array(yam.info['ShortPupil'])
    lw_pupilnames = np.array(yam.info['LongPupil'])
    filternames = np.array(yam.info['FilterWheel'])
    pupilnames = np.array(yam.info['PupilWheel'])
    detectors = np.array(yam.info['detector'])
    instruments = np.array(yam.info['Instrument'])
    read_patterns = np.array(yam.info['ReadoutPattern'])

    match_nrc_sw_superbias = np.where((read_patterns == 'SHALLOW2') & (detectors == 'B4'))[0]
    match_nrc_lw_superbias = np.where((read_patterns == 'BRIGHT1') & (detectors == 'B5'))[0]
    match_nrc_sw_common = np.where(detectors == 'B4')[0]
    match_nrc_lw_common = np.where(detectors == 'B5')[0]
    match_nrc_sw_distortion_area = np.where((sw_filternames == 'F150W') & (detectors == 'B4') & (sw_pupilnames == 'CLEAR'))[0]
    match_nrc_lw_distortion_area = np.where((lw_filternames == 'F322W2') & (detectors == 'B5') & (lw_pupilnames == 'CLEAR'))[0]
    match_nrc_lw_flat = np.where((lw_filternames == 'F322W2') & (detectors == 'B5') & (lw_pupilnames == 'CLEAR'))[0]

    match_nis_superbias = np.where(read_patterns == 'NISRAPID')[0]
    match_nis_common = np.where(instruments == 'NIRISS')[0]
    match_nis_distortion_area = np.where((pupilnames == 'F115W') & (instruments == 'NIRISS') & (filternames == 'CLEAR'))[0]
    match_nis_flat = np.where((pupilnames == 'F115W') & (instruments == 'NIRISS') & (filternames == 'CLEAR'))[0]

    # Check that reference files that are covered by reffile_overrides
    # are equal to the override values.
    for index in match_nrc_sw_superbias:
        assert yam.info['superbias'][index] == 'my_reffiles/my_superbias_for_b4.fits'
    for index in match_nrc_lw_superbias:
        assert yam.info['superbias'][index] == 'my_reffiles/my_superbias_for_b5.fits'
    for index in match_nrc_sw_common:
        assert yam.info['linearity'][index] == 'my_reffiles/my_linearity_for_b4.fits'
        assert yam.info['saturation'][index] == 'my_reffiles/my_saturation_for_b4.fits'
        assert yam.info['gain'][index] == 'my_reffiles/my_gain_for_b4.fits'
        assert yam.info['badpixmask'][index] == 'my_reffiles/my_bpm_for_b4.fits'
    for index in match_nrc_lw_common:
        assert yam.info['linearity'][index] == 'my_reffiles/my_linearity_for_b5.fits'
        assert yam.info['saturation'][index] == 'my_reffiles/my_saturation_for_b5.fits'
        assert yam.info['gain'][index] == 'my_reffiles/my_gain_for_b5.fits'
        assert yam.info['badpixmask'][index] == 'my_reffiles/my_bpm_for_b5.fits'
    for index in match_nrc_sw_distortion_area:
        assert yam.info['astrometric'][index] == 'my_reffiles/my_distortion_for_b4.asdf'
        assert yam.info['pixelAreaMap'][index] == 'my_reffiles/my_pam_for_b4.fits'
        assert yam.info['transmission'][index] == 'my_reffiles/my_transmission_for_b4.fits'
    for index in match_nrc_lw_distortion_area:
        assert yam.info['astrometric'][index] == 'my_reffiles/my_distortion_for_b5.asdf'
        assert yam.info['pixelAreaMap'][index] == 'my_reffiles/my_pam_for_b5.fits'
        assert yam.info['transmission'][index] == 'my_reffiles/my_transmission_for_b5.fits'
    for index in match_nrc_lw_flat:
        assert yam.info['pixelflat'][index] == 'my_reffiles/my_flatfield_for_b5.fits'

    for index in match_nis_superbias:
        assert yam.info['superbias'][index] == 'my_niriss_supebias.fits'
    for index in match_nis_common:
        assert yam.info['linearity'][index] == 'my_niriss_linearity,fits'
        assert yam.info['saturation'][index] == 'my_niriss_saturation.fits'
        assert yam.info['gain'][index] == 'my_niriss_gain.fits'
        assert yam.info['badpixmask'][index] == 'my_niriss_badpixmask.fits'
    for info in match_nis_distortion_area:
        assert yam.info['astrometric'][index] == 'my_niriss_disotrtion.asdf'
        assert yam.info['pixelAreaMap'][index] == 'my_niriss_area.fits'
        assert yam.info['transmission'][index] == 'my_niriss_transmission.fits'
    for info in match_nis_flat:
        assert yam.info['pixelflat'][index] == 'my_niriss_flatfield.fits'

    # Check that reference files covered by reffile_overrides contain
    # the CRDS_PATH, which here has been set to the temp directory
    match_nrc_sw_defaults = np.where((instruments == 'NIRCAM') & (sw_filternames == 'F070W') & (detectors != 'B5'))[0]
    match_nrc_lw_defaults = np.where((instruments == 'NIRCAM') & (lw_filternames == 'F335M') & (detectors == 'B5'))[0]

    for index in list(match_nrc_sw_defaults) + list(match_nrc_lw_defaults):
        assert temp_output_dir in yam.info['superbias'][index]
        assert temp_output_dir in yam.info['astrometric'][index]
        assert temp_output_dir in yam.info['pixelAreaMap'][index]
        assert temp_output_dir in yam.info['ipc'][index]

    # Clean up
    os.system('rm -r {}'.format(temp_output_dir))