def test_nirspec_nrs1_wcs(self):
        """

        Regression test of creating a WCS object and doing pixel to sky transformation.

        """
        input_file = self.get_data(*self.test_dir,
                                  'jw00023001001_01101_00001_NRS1_ramp_fit.fits')
        ref_file = self.get_data(*self.ref_loc,
                                 'jw00023001001_01101_00001_NRS1_ramp_fit_assign_wcs.fits')

        result = AssignWcsStep.call(input_file, save_results=True, suffix='assign_wcs')
        result.close()

        im = ImageModel(result.meta.filename)
        imref = ImageModel(ref_file)

        for slit in ['S200A1', 'S200A2', 'S400A1', 'S1600A1']:
            w = nirspec.nrs_wcs_set_input(im, slit)
            grid = grid_from_bounding_box(w.bounding_box)
            ra, dec, lam = w(*grid)
            wref = nirspec.nrs_wcs_set_input(imref, slit)
            raref, decref, lamref = wref(*grid)

            assert_allclose(ra, raref, equal_nan=True)
            assert_allclose(dec, decref, equal_nan=True)
            assert_allclose(lam, lamref, equal_nan=True)
Exemple #2
0
def test_nirspec_ifu_wcs(envopt, _jail, test_id, input_file, truth_file):
    """
    Regression test of creating a WCS object and doing pixel to sky transformation.
    """
    del test_id

    input_file = get_bigdata('jwst-pipeline', envopt,
                             'nirspec', 'test_wcs', 'nrs1-ifu', input_file)
    truth_file = get_bigdata('jwst-pipeline', envopt,
                             'nirspec', 'test_wcs', 'nrs1-ifu', 'truth', truth_file)

    result = AssignWcsStep.call(input_file, save_results=True, suffix='assign_wcs')
    result.close()

    im = ImageModel(result.meta.filename)
    imref = ImageModel(truth_file)
    w = nirspec.nrs_wcs_set_input(im, 0)
    grid = grid_from_bounding_box(w.bounding_box)
    ra, dec, lam = w(*grid)
    wref = nirspec.nrs_wcs_set_input(imref, 0)
    raref, decref, lamref = wref(*grid)

    # equal_nan is used here as many of the entries are nan.
    # The domain is defined but it is only a few entries in there that are valid
    # as it is a curved narrow slit.
    assert_allclose(ra, raref, equal_nan=True)
    assert_allclose(dec, decref, equal_nan=True)
    assert_allclose(lam, lamref, equal_nan=True)
def test_master_background_userbg(_jail, user_background):
    """Verify data can run through the step with a user-supplied background"""

    image = datamodels.ImageModel((10, 10))
    image.meta.instrument.name = 'MIRI'
    image.meta.instrument.detector = 'MIRIMAGE'
    image.meta.exposure.type = 'MIR_LRS-FIXEDSLIT'
    image.meta.observation.date = '2018-01-01'
    image.meta.observation.time = '00:00:00'
    image.meta.subarray.xstart = 1
    image.meta.subarray.ystart = 1
    image.meta.wcsinfo.v2_ref = 0
    image.meta.wcsinfo.v3_ref = 0
    image.meta.wcsinfo.roll_ref = 0
    image.meta.wcsinfo.ra_ref = 0
    image.meta.wcsinfo.dec_ref = 0
    image = AssignWcsStep.call(image)

    # Run with a user-supplied background and verify this is recorded in header
    result = MasterBackgroundStep.call(image, user_background=user_background)

    collect_pipeline_cfgs('./config')
    result = MasterBackgroundStep.call(
        image,
        config_file='config/master_background.cfg',
        user_background=user_background,
        )

    # For inputs that are not files, the following should be true
    assert type(image) is type(result)
    assert result is not image
    assert result.meta.cal_step.master_background == 'COMPLETE'
    assert result.meta.background.master_background_file == 'user_background.fits'
    def test_miri_ifu_wcs(self):
        """
        Regression test of creating a WCS object and doing pixel to sky transformation.
        """
        input_file = self.get_data(self.test_dir,
                                   'jw00024001001_01101_00001_MIRIFUSHORT_uncal_MiriSloperPipeline.fits')
        ref_file = self.get_data(os.path.join(*self.ref_loc),
                                 'jw00024001001_01101_00001_MIRIFUSHORT_assign_wcs.fits')


        result = AssignWcsStep.call(input_file)
        output_file = result.meta.filename
        result.save(output_file)
        result.close()

        im = ImageModel(output_file)
        imref = ImageModel(ref_file)

        # Get the region file
        region = RegionsModel(crds_client.get_reference_file(im, 'regions'))

        # inputs
        shape = region.regions.shape
        y, x = np.mgrid[ : shape[0], : shape[1]]

        # Get indices where pixels == 0. These should be NaNs in the output.
        ind_zeros = region.regions == 0

        ra, dec, lam = im.meta.wcs(x, y)
        raref, decref, lamref = imref.meta.wcs(x, y)
        utils.assert_allclose(ra, raref, equal_nan=True)
        utils.assert_allclose(dec, decref, equal_nan=True)
        utils.assert_allclose(lam, lamref, equal_nan=True)

        # Test that we got NaNs at ind_zero
        assert(np.isnan(ra).nonzero()[0] == ind_zeros.nonzero()[0]).all()
        assert(np.isnan(ra).nonzero()[1] == ind_zeros.nonzero()[1]).all()

        # Test the inverse transform
        x1, y1 = im.meta.wcs.backward_transform(ra, dec, lam)
        assert(np.isnan(x1).nonzero()[0] == ind_zeros.nonzero()[0]).all()
        assert (np.isnan(x1).nonzero()[1] == ind_zeros.nonzero()[1]).all()

        # Also run a smoke test with values outside the region.
        dec[100][200] = -80
        ra[100][200] = 7
        lam[100][200] = 15

        x2, y2 = im.meta.wcs.backward_transform(ra, dec, lam)
        assert np.isnan(x2[100][200])
        assert np.isnan(x2[100][200])
    def test_miri_ifu_wcs(self):
        """
        Regression test of creating a WCS object and doing pixel to sky transformation.
        """
        input_file = self.get_data(self.test_dir,
                                   'jw00024001001_01101_00001_MIRIFUSHORT_uncal_MiriSloperPipeline.fits')
        result = AssignWcsStep.call(input_file, save_results=True)

        # Get the region file
        region = RegionsModel(crds_client.get_reference_file(result, 'regions'))

        # inputs
        x, y = grid_from_bounding_box(result.meta.wcs.bounding_box)

        # Get indices where pixels == 0. These should be NaNs in the output.
        ind_zeros = region.regions == 0

        cwd = os.path.abspath('.')
        os.makedirs('truth', exist_ok=True)
        os.chdir('truth')
        truth_file = self.get_data(*self.ref_loc,
                                 'jw00024001001_01101_00001_MIRIFUSHORT_assign_wcs.fits')
        os.chdir(cwd)
        truth = ImageModel(truth_file)

        ra, dec, lam = result.meta.wcs(x, y)
        raref, decref, lamref = truth.meta.wcs(x, y)
        assert_allclose(ra, raref, equal_nan=True)
        assert_allclose(dec, decref, equal_nan=True)
        assert_allclose(lam, lamref, equal_nan=True)

        # Test that we got NaNs at ind_zero
        assert(np.isnan(ra).nonzero()[0] == ind_zeros.nonzero()[0]).all()
        assert(np.isnan(ra).nonzero()[1] == ind_zeros.nonzero()[1]).all()

        # Test the inverse transform
        x1, y1 = result.meta.wcs.backward_transform(ra, dec, lam)
        assert(np.isnan(x1).nonzero()[0] == ind_zeros.nonzero()[0]).all()
        assert (np.isnan(x1).nonzero()[1] == ind_zeros.nonzero()[1]).all()

        # Also run a smoke test with values outside the region.
        dec[100][200] = -80
        ra[100][200] = 7
        lam[100][200] = 15

        x2, y2 = result.meta.wcs.backward_transform(ra, dec, lam)
        assert np.isnan(x2[100][200])
        assert np.isnan(x2[100][200])
    def test_miri_fixed_slit_wcs(self):
        """
        Regression test of creating a WCS object and doing pixel to sky transformation.
        """
        input_file = self.get_data(self.test_dir,
                                   'jw00035001001_01101_00001_mirimage_rate.fits')
        result = AssignWcsStep.call(input_file, save_results=True)

        truth_file = self.get_data(os.path.join(*self.ref_loc),
                                 'jw00035001001_01101_00001_mirimage_assign_wcs.fits')
        truth = ImageModel(truth_file)
        x, y = grid_from_bounding_box(result.meta.wcs.bounding_box)
        ra, dec, lam = result.meta.wcs(x, y)
        raref, decref, lamref = truth.meta.wcs(x, y)
        assert_allclose(ra, raref)
        assert_allclose(dec, decref)
        assert_allclose(lam, lamref)
    def test_miri_slitless_wcs(self):
        """
        Regression test of creating a WCS object and doing pixel to sky transformation.
        """
        input_file = self.get_data(self.test_dir,
                                   "jw80600012001_02101_00003_mirimage_rateints.fits")
        result = AssignWcsStep.call(input_file, save_results=True)

        cwd = os.path.abspath('.')
        os.makedirs('truth', exist_ok=True)
        os.chdir('truth')
        truth_file = self.get_data(*self.ref_loc,
                                 "jw80600012001_02101_00003_mirimage_assignwcsstep.fits")
        os.chdir(cwd)
        truth = CubeModel(truth_file)

        x, y = grid_from_bounding_box(result.meta.wcs.bounding_box)
        ra, dec, lam = result.meta.wcs(x, y)
        raref, decref, lamref = truth.meta.wcs(x, y)
        assert_allclose(ra, raref)
        assert_allclose(dec, decref)
        assert_allclose(lam, lamref)
    def test_miri_image_wcs(self):
        """
        Regression test of creating a WCS object and doing pixel to sky transformation.
        """

        input_file = self.get_data(self.test_dir,
                                    "jw00001001001_01101_00001_MIRIMAGE_ramp_fit.fits")
        result = AssignWcsStep.call(input_file, save_results=True)

        cwd = os.path.abspath('.')
        os.makedirs('truth', exist_ok=True)
        os.chdir('truth')
        truth_file = self.get_data(*self.ref_loc,
                                 "jw00001001001_01101_00001_MIRIMAGE_assign_wcs.fits")
        os.chdir(cwd)
        truth = ImageModel(truth_file)

        x, y = grid_from_bounding_box(result.meta.wcs.bounding_box)
        ra, dec = result.meta.wcs(x, y)
        raref, decref = truth.meta.wcs(x, y)
        assert_allclose(ra, raref)
        assert_allclose(dec, decref)
    def test_miri_image_wcs(self):
        """
        Regression test of creating a WCS object and doing pixel to sky transformation.
        """

        input_file = self.get_data(self.test_dir,
                                    "jw00001001001_01101_00001_MIRIMAGE_ramp_fit.fits")
        ref_file = self.get_data(*self.ref_loc,
                                 "jw00001001001_01101_00001_MIRIMAGE_assign_wcs.fits")

        result = AssignWcsStep.call(input_file)
        output_file = result.meta.filename
        result.save(output_file)
        result.close()

        im = ImageModel(output_file)
        imref = ImageModel(ref_file)
        x, y = np.mgrid[:1031, :1024]
        ra, dec = im.meta.wcs(x, y)
        raref, decref = imref.meta.wcs(x, y)
        utils.assert_allclose(ra, raref)
        utils.assert_allclose(dec, decref)
    def test_miri_fixed_slit_wcs(self):
        """
        Regression test of creating a WCS object and doing pixel to sky transformation.
        """
        input_file = self.get_data(self.test_dir,
                                   'jw00035001001_01101_00001_mirimage_rate.fits')
        ref_file = self.get_data(os.path.join(*self.ref_loc),
                                 'jw00035001001_01101_00001_mirimage_assign_wcs.fits')

        result = AssignWcsStep.call(input_file)
        output_file = result.meta.filename
        result.save(output_file)
        result.close()

        im = ImageModel(output_file)
        imref = ImageModel(ref_file)
        y, x = np.mgrid[:1031, :1024]
        ra, dec, lam = im.meta.wcs(x, y)
        raref, decref, lamref = imref.meta.wcs(x, y)
        utils.assert_allclose(ra, raref)
        utils.assert_allclose(dec, decref)
        utils.assert_allclose(lam, lamref)
    def test_miri_slitless_wcs(self):
        """

        Regression test of creating a WCS object and doing pixel to sky transformation.

        """
        input_file = self.get_data(self.test_dir,
                                   "jw80600012001_02101_00003_mirimage_rateints.fits")
        ref_file = self.get_data(*self.ref_loc,
                                 "jw80600012001_02101_00003_mirimage_assign_wcs.fits")

        result = AssignWcsStep.call(input_file)
        output_file = result.meta.filename
        result.save(output_file)
        result.close()

        im = CubeModel(output_file)
        imref = CubeModel(ref_file)
        x, y = np.mgrid[:1031, :1024]
        ra, dec, lam = im.meta.wcs(x, y)
        raref, decref, lamref = imref.meta.wcs(x, y)
        utils.assert_allclose(ra, raref)
        utils.assert_allclose(dec, decref)
        utils.assert_allclose(lam, lamref)
Exemple #12
0
def test_spatial_transform_miri():
    wcsinfo = {
        'dec_ref': 40,
        'ra_ref': 100,
        'roll_ref': 0.0,
        'v2_ref': -453.5134,
        'v3_ref': -373.4826,
        'v3yangle': 0.0,
        'vparity': -1
    }

    instrument = {'detector': 'MIRIMAGE', 'filter': 'P750L', 'name': 'MIRI'}

    observation = {'date': '2019-01-01', 'time': '17:00:00'}

    subarray = {
        'fastaxis': 1,
        'name': 'SLITLESSPRISM',
        'slowaxis': 2,
        'xsize': 72,
        'xstart': 1,
        'ysize': 416,
        'ystart': 529
    }

    exposure = {
        'duration': 11.805952,
        'end_time': 58119.85416,
        'exposure_time': 11.776,
        'frame_time': 0.11776,
        'group_time': 0.11776,
        'groupgap': 0,
        'integration_time': 11.776,
        'nframes': 1,
        'ngroups': 100,
        'nints': 1,
        'nresets_between_ints': 0,
        'nsamples': 1,
        'readpatt': 'FAST',
        'sample_time': 10.0,
        'start_time': 58119.8333,
        'type': 'MIR_LRS-SLITLESS',
        'zero_frame': False
    }

    im = ImageModel((416, 72))

    im.meta.wcsinfo = wcsinfo
    im.meta.instrument = instrument
    im.meta.observation = observation
    im.meta.exposure = exposure
    im.meta.subarray = subarray

    im = AssignWcsStep.call(im)
    im = ResampleSpecStep.call(im)

    x, y = grid_from_bounding_box(im.meta.wcs.bounding_box)
    ra, dec, lam = im.meta.wcs(x, y)
    xp, yp = im.meta.wcs.invert(ra, dec, lam)
    assert_allclose(x, xp, atol=1e-8)
    assert_allclose(y, yp, atol=1e-8)
Exemple #13
0
def test_spatial_transform_miri():
    wcsinfo = {
        'dec_ref': -0.00601415671349804,
        'ra_ref': -0.02073605215697509,
        'roll_ref': -0.0,
        'v2_ref': -453.5134,
        'v3_ref': -373.4826,
        'v3yangle': 0.0,
        'vparity': -1
    }

    instrument = {'detector': 'MIRIMAGE', 'filter': 'P750L', 'name': 'MIRI'}

    observation = {'date': '2019-01-01', 'time': '17:00:00'}

    subarray = {
        'fastaxis': 1,
        'name': 'SLITLESSPRISM',
        'slowaxis': 2,
        'xsize': 72,
        'xstart': 1,
        'ysize': 416,
        'ystart': 529
    }

    exposure = {
        'duration': 11.805952,
        'end_time': 58119.85416,
        'exposure_time': 11.776,
        'frame_time': 0.11776,
        'group_time': 0.11776,
        'groupgap': 0,
        'integration_time': 11.776,
        'nframes': 1,
        'ngroups': 100,
        'nints': 1,
        'nresets_between_ints': 0,
        'nsamples': 1,
        'readpatt': 'FAST',
        'sample_time': 10.0,
        'start_time': 58119.8333,
        'type': 'MIR_LRS-SLITLESS',
        'zero_frame': False
    }

    im = ImageModel()
    im.data = np.random.rand(416, 72)
    im.error = np.random.rand(416, 72)
    im.dq = np.random.rand(416, 72)

    im.meta.wcsinfo._instance.update(wcsinfo)
    im.meta.instrument._instance.update(instrument)
    im.meta.observation._instance.update(observation)
    im.meta.exposure._instance.update(exposure)
    im.meta.subarray._instance.update(subarray)

    out = AssignWcsStep.call(im)
    out = ResampleSpecStep.call(out)
    x, y = grid_from_bounding_box(out.meta.wcs.bounding_box)
    ra, dec, lam = out.meta.wcs(x, y)
    ra1 = np.where(ra < 0, 360 + ra, ra)
    assert_allclose(out.meta.wcs.invert(ra, dec, lam),
                    out.meta.wcs.invert(ra1, dec, lam))
Exemple #14
0
def test_spatial_transform_nirspec():
    wcsinfo = {
        'dec_ref': -0.00601415671349804,
        'ra_ref': -0.02073605215697509,
        'roll_ref': -0.0,
        'v2_ref': -453.5134,
        'v3_ref': -373.4826,
        'v3yangle': 0.0,
        'vparity': -1
    }

    instrument = {
        'detector': 'NRS1',
        'filter': 'CLEAR',
        'grating': 'PRISM',
        'name': 'NIRSPEC',
        'gwa_tilt': 37.0610,
        'gwa_xtilt': 0.0001,
        'gwa_ytilt': 0.0001
    }

    subarray = {
        'fastaxis': 1,
        'name': 'SUBS200A1',
        'slowaxis': 2,
        'xsize': 72,
        'xstart': 1,
        'ysize': 416,
        'ystart': 529
    }

    observation = {'date': '2016-09-05', 'time': '8:59:37'}

    exposure = {
        'duration': 11.805952,
        'end_time': 58119.85416,
        'exposure_time': 11.776,
        'frame_time': 0.11776,
        'group_time': 0.11776,
        'groupgap': 0,
        'integration_time': 11.776,
        'nframes': 1,
        'ngroups': 100,
        'nints': 1,
        'nresets_between_ints': 0,
        'nsamples': 1,
        'readpatt': 'NRSRAPID',
        'sample_time': 10.0,
        'start_time': 58119.8333,
        'type': 'NRS_FIXEDSLIT',
        'zero_frame': False
    }

    im = ImageModel()
    im.data = np.random.rand(2048, 2048)
    im.error = np.random.rand(2048, 2048)
    im.dq = np.random.rand(2048, 2048)

    im.meta.wcsinfo._instance.update(wcsinfo)
    im.meta.instrument._instance.update(instrument)
    im.meta.observation._instance.update(observation)
    im.meta.exposure._instance.update(exposure)
    im.meta.subarray._instance.update(subarray)
    im = AssignWcsStep.call(im)

    im = Extract2dStep.call(im)

    im = ResampleSpecStep.call(im)

    for slit in im.products:
        x, y = grid_from_bounding_box(slit.meta.wcs.bounding_box)
        ra, dec, lam = slit.meta.wcs(x, y)

        ra1 = np.where(ra < 0, 360 + ra, ra)
        assert_allclose(slit.meta.wcs.invert(ra, dec, lam),
                        slit.meta.wcs.invert(ra1, dec, lam))
Exemple #15
0
def test_apply_background_2d(_jail, miri_dither_ch12):
    """ Test if  background polynomial is set it is subtracted correctly"""

    all_models = datamodels.ModelContainer(miri_dither_ch12)

    # test if given a background polynomial - apply_background_2d gives the correct answer
    # Polynomial information was created by running a faked full array data set to determine
    # what the polynomial values should be
    new_container = []
    degree = (1, 1, 1,)
    center = (9.99999408089876, -4.668612949274985e-06, 4.889999912818894)
    poly = np.ndarray(9)

    # run AssignWcsStep on first file and set wcs of other files to this

    channel = '1'
    for im, m in enumerate(all_models):
        if im == 0:
            m = AssignWcsStep.call(m)
            wcs1 = m.meta.wcs
            poly = [-2.50000000e+00, -6.66518331e-15,  5.67845589e-12, -1.23549218e-11,
                    3.26209108e-12, -5.43180357e-12, -2.54903452e-09,  6.21614553e-09]
        elif im == 1:
            m.meta.wcs = wcs1
            poly = [-2.50000000e+00, -9.29031986e-15,  1.74437380e-12, -3.94894956e-12,
                     4.71729481e-13,  5.42031845e-13, -9.96151554e-10,  2.78281950e-09]
        elif im == 2:
            m.meta.wcs = wcs1
            poly = [7.50000000e+00,  2.22921836e-14, -6.97131279e-12,  1.58336906e-11,
                     -5.43704212e-12,  6.79109678e-12,  2.63515372e-09, -8.00226976e-09]
        else:
            m.meta.wcs = wcs1
            poly = [-2.50000000e+00, -6.33668043e-15, -4.51516905e-13,  4.70180795e-13,
                     1.70322157e-12, -1.90132506e-12,  9.10032350e-10, -9.96695272e-10]

        poly = np.asarray(poly)
        m.meta.background.polynomial_info.append(
            {
                'degree': degree,
                'refpoint': center,
                'coefficients': poly.ravel().tolist(),
                'channel': channel
                }
            )

        # input 10 output 12.5 for all images
        apply_background_2d(m, channel, subtract=True)
        new_container.append(m)

    # all the data should now be the same for the science pixels
    # the edge pixels are located in non-science region and no
    # background subtraction is done on these pixels

    data1 = new_container[0].data[:, 16:]
    data2 = new_container[1].data[:, 16:]
    data3 = new_container[2].data[:, 16:]
    data4 = new_container[3].data[:, 16:]

    assert(np.allclose(data1, data2, rtol=1e-6))
    assert(np.allclose(data2, data3, rtol=1e-6))
    assert(np.allclose(data3, data4, rtol=1e-6))
    assert(np.allclose(data1, data4, rtol=1e-6))
def test_wavecorr_fs():
    hdul = create_nirspec_fs_file(grating="PRISM", filter="CLEAR")
    im = datamodels.ImageModel(hdul)
    dither = {'x_offset': -0.0264, 'y_offset': 1.089798712}

    im.meta.dither = dither
    im.meta.instrument.fixed_slit = 'S200A1'
    im.meta.instrument.lamp_state = 'NONE'
    im.meta.instrument.lamp_mode = 'FIXEDSLIT'
    im.meta.instrument.gwa_tilt = 698.1256999999999
    im.meta.instrument.gwa_xtilt = 0.334691644
    im.meta.instrument.gwa_ytilt = 0.0349255353
    im.meta.exposure.type = 'NRS_FIXEDSLIT'
    im.meta.wcsinfo = {
        'dec_ref': -70.77497509320972,
        'dispersion_direction': 1,
        'ra_ref': 90.75414044948525,
        'roll_ref': 38.2179067606001,
        'specsys': 'BARYCENT',
        'spectral_order': 0,
        'v2_ref': 332.136078,
        'v3_ref': -479.224213,
        'v3yangle': 138.7605896,
        'velosys': -1398.2,
        'vparity': -1,
        'waverange_end': 5.3e-06,
        'waverange_start': 6e-07
    }

    result = AssignWcsStep.call(im)
    result = Extract2dStep.call(result)
    bbox = ((-.5, 428.5), (-.5, 38.5))
    result.slits[0].meta.wcs.bounding_box = bbox
    x, y = wcstools.grid_from_bounding_box(bbox)
    ra, dec, lam_before = result.slits[0].meta.wcs(x, y)
    result.slits[0].wavelength = lam_before
    src_result = SourceTypeStep.call(result)
    result = WavecorrStep.call(src_result)

    assert_allclose(result.slits[0].source_xpos, 0.127111, atol=1e-6)

    slit = result.slits[0]
    source_xpos = wavecorr.get_source_xpos(slit, slit.meta.wcs, lam=2)
    assert_allclose(result.slits[0].source_xpos, source_xpos, atol=1e-6)

    mean_correction = np.abs(src_result.slits[0].wavelength -
                             result.slits[0].wavelength)
    assert_allclose(np.nanmean(mean_correction), 0.003, atol=.001)

    dispersion = wavecorr.compute_dispersion(slit.meta.wcs, x, y)
    assert_allclose(dispersion[~np.isnan(dispersion)], 1e-8, atol=1.04e-8)

    # test on both sides of the slit center
    source_xpos1 = -.2
    source_xpos2 = .2

    ref_name = result.meta.ref_file.wavecorr.name
    freference = datamodels.WaveCorrModel(
        WavecorrStep.reference_uri_to_cache_path(ref_name,
                                                 im.crds_observatory))
    zero_point1 = wavecorr.compute_zero_point_correction(
        lam_before, freference, source_xpos1, 'S200A1', dispersion)
    zero_point2 = wavecorr.compute_zero_point_correction(
        lam_before, freference, source_xpos2, 'S200A1', dispersion)
    diff_correction = np.abs(zero_point1[1] - zero_point2[1])
    assert_allclose(np.nanmean(diff_correction), 0.45, atol=0.01)
Exemple #17
0
def test_spatial_transform_nirspec():
    wcsinfo = {
        'dec_ref': 40,
        'ra_ref': 100,
        'roll_ref': 0,
        'v2_ref': -453.5134,
        'v3_ref': -373.4826,
        'v3yangle': 0.0,
        'vparity': -1
    }

    instrument = {
        'detector': 'NRS1',
        'filter': 'CLEAR',
        'grating': 'PRISM',
        'name': 'NIRSPEC',
        'gwa_tilt': 37.0610,
        'gwa_xtilt': 0.0001,
        'gwa_ytilt': 0.0001
    }

    subarray = {
        'fastaxis': 1,
        'name': 'SUBS200A1',
        'slowaxis': 2,
        'xsize': 72,
        'xstart': 1,
        'ysize': 416,
        'ystart': 529
    }

    observation = {'date': '2016-09-05', 'time': '8:59:37'}

    exposure = {
        'duration': 11.805952,
        'end_time': 58119.85416,
        'exposure_time': 11.776,
        'frame_time': 0.11776,
        'group_time': 0.11776,
        'groupgap': 0,
        'integration_time': 11.776,
        'nframes': 1,
        'ngroups': 100,
        'nints': 1,
        'nresets_between_ints': 0,
        'nsamples': 1,
        'readpatt': 'NRSRAPID',
        'sample_time': 10.0,
        'start_time': 58119.8333,
        'type': 'NRS_FIXEDSLIT',
        'zero_frame': False
    }

    im = ImageModel((2048, 2048))

    im.meta.wcsinfo = wcsinfo
    im.meta.instrument = instrument
    im.meta.observation = observation
    im.meta.exposure = exposure
    im.meta.subarray = subarray

    im = AssignWcsStep.call(im)
    im = Extract2dStep.call(im)
    im = ResampleSpecStep.call(im)

    for slit in im.slits:
        x, y = grid_from_bounding_box(slit.meta.wcs.bounding_box)
        ra, dec, lam = slit.meta.wcs(x, y)
        xp, yp = slit.meta.wcs.invert(ra, dec, lam)

        assert_allclose(x, xp, atol=1e-8)
        assert_allclose(y, yp, atol=1e-8)