예제 #1
0
def test_slit_projection_on_detector():
    step = assign_wcs_step.AssignWcsStep()

    hdul = create_nirspec_fs_file(grating="G395M",
                                  filter="OPAQUE",
                                  lamp="ARGON")
    hdul[0].header['DETECTOR'] = 'NRS2'
    im = datamodels.ImageModel(hdul)

    refs = {}
    for reftype in step.reference_file_types:
        refs[reftype] = step.get_reference_file(im, reftype)

    open_slits = nirspec.get_open_slits(im, refs)
    assert len(open_slits) == 1
    assert open_slits[0].name == "S200B1"

    hdul[0].header['DETECTOR'] = 'NRS1'
    im = datamodels.ImageModel(hdul)

    open_slits = nirspec.get_open_slits(im, refs)
    assert len(open_slits) == 4
    names = [s.name for s in open_slits]
    assert "S200A1" in names
    assert "S200A2" in names
    assert "S400A1" in names
    assert "S1600A1" in names
예제 #2
0
def test_open_slits():
    """ Test that get_open_slits works with MSA data.

    Issue #2321
    """
    image = create_nirspec_mos_file()
    model = datamodels.ImageModel(image)
    msaconfl = get_file_path('msa_configuration.fits')

    model.meta.instrument.msa_metadata_file = msaconfl
    model.meta.instrument.msa_metadata_id = 12

    slits = nirspec.get_open_slits(model)
    assert len(slits) == 1
예제 #3
0
def test_nirspec_mos_wcs(rtdata):
    """Test NIRSpec MOS wcs"""
    input_file = 'msa_patt_num.fits'
    # Get MSA meta file
    rtdata.get_data('nirspec/mos/V9621500100101_short_msa.fits')
    rtdata.get_data(f"nirspec/mos/{input_file}")
    AssignWcsStep.call(input_file, save_results=True, suffix='assign_wcs')

    output = input_file.replace('.fits', '_assign_wcs.fits')
    rtdata.output = output

    rtdata.get_truth(f"truth/test_nirspec_wcs/{output}")

    with datamodels.open(rtdata.output) as im, datamodels.open(
            rtdata.truth) as im_truth:
        names = [slit.name for slit in nirspec.get_open_slits(im)]
        for name in names:
            wcs = nirspec.nrs_wcs_set_input(im, name)
            wcs_truth = nirspec.nrs_wcs_set_input(im_truth, name)

            assert_wcs_grid_allclose(wcs, wcs_truth)
예제 #4
0
파일: extract_2d.py 프로젝트: rij/jwst
def extract2d(input_model, which_subarray=None):
    exp_type = input_model.meta.exposure.type.upper()
    log.info('EXP_TYPE is {0}'.format(exp_type))
    if exp_type in ['NRS_FIXEDSLIT', 'NRS_MSASPEC']:
        if which_subarray is None:
            open_slits = nirspec.get_open_slits(input_model)
        else:
            open_slits = [nirspec.slit_name2id[which_subarray]]
    else:
        # Set the step status to COMPLETE
        output_model.meta.cal_step.extract_2d = 'SKIPPED'
        return input_model

    log.info('open slits {0}'.format(open_slits))

    output_model = models.MultiSlitModel()
    output_model.update(input_model)

    _, wrange = nirspec.spectral_order_wrange_from_model(input_model)

    if exp_type == 'NRS_FIXEDSLIT':
        slit_names = [nirspec.slit_id2name[tuple(slit)] for slit in open_slits]
    else:
        slit_names = [str(slit) for slit in open_slits]
    for slit, slit_name in zip(open_slits, slit_names):
        slit_wcs = nirspec.nrs_wcs_set_input(input_model.meta.wcs, slit[0],
                                             slit[1], wrange)
        if (input_model.meta.subarray.ystart is not None):
            xlo, xhi, ylo, yhi = _adjust_subarray(input_model, slit_wcs)
        else:
            log.info('Subarray ystart metadata value not found')
            xlo, xhi = slit_wcs.domain[0]['lower'], slit_wcs.domain[0]['upper']
            ylo, yhi = slit_wcs.domain[1]['lower'], slit_wcs.domain[1]['upper']

        log.info('Name of subarray extracted: %s', slit_name)
        log.info('Subarray x-extents are: %s %s', xlo, xhi)
        log.info('Subarray y-extents are: %s %s', ylo, yhi)

        ext_data = input_model.data[ylo:yhi + 1, xlo:xhi + 1].copy()
        ext_err = input_model.err[ylo:yhi + 1, xlo:xhi + 1].copy()
        ext_dq = input_model.dq[ylo:yhi + 1, xlo:xhi + 1].copy()
        new_model = models.ImageModel(data=ext_data, err=ext_err, dq=ext_dq)
        shape = ext_data.shape
        domain = [{
            'lower': -0.5,
            'upper': shape[1] + 0.5,
            'includes_lower': True,
            'includes_upper': False
        }, {
            'lower': -0.5,
            'upper': shape[0] + 0.5,
            'includes_lower': True,
            'includes_upper': False
        }]
        slit_wcs.domain = domain
        new_model.meta.wcs = slit_wcs
        output_model.slits.append(new_model)
        # set x/ystart values relative to full detector space, so need
        # to account for x/ystart values of input if it's a subarray
        nslit = len(output_model.slits) - 1
        output_model.slits[nslit].name = slit_name
        output_model.slits[
            nslit].xstart = input_model.meta.subarray.xstart + xlo
        output_model.slits[nslit].xsize = xhi - xlo + 1
        output_model.slits[
            nslit].ystart = input_model.meta.subarray.ystart + ylo
        output_model.slits[nslit].ysize = yhi - ylo + 1
    del input_model
    #del output_model.meta.wcs
    # Set the step status to COMPLETE
    output_model.meta.cal_step.extract_2d = 'COMPLETE'
    return output_model