示例#1
0
def miri_full_coverage():
    """ Generate a IFU images SHORT, LONG for all three bands """

    input_model1 = datamodels.IFUImageModel()
    input_model1.meta.wcsinfo._instance.update(wcsinfo)
    input_model1.meta.instrument._instance.update(mirifushort_short)
    input_model1.meta.observation._instance.update(observation)
    input_model1.meta.subarray._instance.update(subarray)
    input_model1.meta.cal_step.assign_wcs = 'COMPLETE'

    input_model2 = datamodels.IFUImageModel()
    input_model2.meta.wcsinfo._instance.update(wcsinfo)
    input_model2.meta.instrument._instance.update(mirifushort_medium)
    input_model2.meta.observation._instance.update(observation)
    input_model2.meta.subarray._instance.update(subarray)
    input_model2.meta.cal_step.assign_wcs = 'COMPLETE'

    input_model3 = datamodels.IFUImageModel()
    input_model3.meta.wcsinfo._instance.update(wcsinfo)
    input_model3.meta.instrument._instance.update(mirifushort_long)
    input_model3.meta.observation._instance.update(observation)
    input_model3.meta.subarray._instance.update(subarray)
    input_model3.meta.cal_step.assign_wcs = 'COMPLETE'

    input_model4 = datamodels.IFUImageModel()
    input_model4.meta.wcsinfo._instance.update(wcsinfo)
    input_model4.meta.instrument._instance.update(mirifulong_short)
    input_model4.meta.observation._instance.update(observation)
    input_model4.meta.subarray._instance.update(subarray)
    input_model4.meta.cal_step.assign_wcs = 'COMPLETE'

    input_model5 = datamodels.IFUImageModel()
    input_model5.meta.wcsinfo._instance.update(wcsinfo)
    input_model5.meta.instrument._instance.update(mirifulong_medium)
    input_model5.meta.observation._instance.update(observation)
    input_model5.meta.subarray._instance.update(subarray)
    input_model5.meta.cal_step.assign_wcs = 'COMPLETE'

    input_model6 = datamodels.IFUImageModel()
    input_model6.meta.wcsinfo._instance.update(wcsinfo)
    input_model6.meta.instrument._instance.update(mirifulong_long)
    input_model6.meta.observation._instance.update(observation)
    input_model6.meta.subarray._instance.update(subarray)
    input_model6.meta.cal_step.assign_wcs = 'COMPLETE'

    # full range and 2 dithers (12 files, 2 dithers of each band)
    input_models = []
    input_models.append(input_model1)
    input_models.append(input_model1)
    input_models.append(input_model2)
    input_models.append(input_model2)
    input_models.append(input_model3)
    input_models.append(input_model3)
    input_models.append(input_model4)
    input_models.append(input_model4)
    input_models.append(input_model5)
    input_models.append(input_model5)
    input_models.append(input_model6)
    input_models.append(input_model6)
    return input_models
def test_ifu_correction():
    """Test application of IFU corrections"""

    data = np.ones((5, 5))
    pl_ps = 2 * data
    pl_un = data / 2
    input = datamodels.IFUImageModel(data=data,
                                     pathloss_point=pl_ps,
                                     pathloss_uniform=pl_un)

    corrected = input.data * pl_ps / pl_un
    result = correct_nrs_ifu_bkg(input)

    assert np.allclose(corrected, result.data, rtol=1.e-10)
示例#3
0
    def test_cubebuild_miri(self):
        """
        Regression test of cube_build performed on MIRI MRS data.
        """
        input_file = self.get_data(
            self.test_dir, 'jw10001001001_01101_00001_mirifushort_cal.fits')

        input_model = datamodels.IFUImageModel(input_file)
        CubeBuildStep.call(input_model, output_type='multi', save_results=True)

        outputs = [('jw10001001001_01101_00001_mirifushort_s3d.fits',
                    'jw10001001001_01101_00001_mirifushort_s3d_ref.fits',
                    ['primary', 'sci', 'err', 'dq', 'wmap'])]
        self.compare_outputs(outputs)
示例#4
0
def nirspec_medium_coverage():
    """ Generate a IFU images NIRSpec G140M, G235M """

    input_model1 = datamodels.IFUImageModel()
    input_model1.meta.wcsinfo._instance.update(wcsinfo)
    input_model1.meta.instrument._instance.update(nirspec_G140M)
    input_model1.meta.observation._instance.update(observation)
    input_model1.meta.subarray._instance.update(subarray_nirspec)
    input_model1.meta.cal_step.assign_wcs = 'COMPLETE'

    input_model2 = datamodels.IFUImageModel()
    input_model2.meta.wcsinfo._instance.update(wcsinfo)
    input_model2.meta.instrument._instance.update(nirspec_G235M)
    input_model2.meta.observation._instance.update(observation)
    input_model2.meta.subarray._instance.update(subarray_nirspec)
    input_model2.meta.cal_step.assign_wcs = 'COMPLETE'

    input_models = []
    input_models.append(input_model1)
    input_models.append(input_model1)
    input_models.append(input_model2)
    input_models.append(input_model2)
    return input_models
示例#5
0
def test_cubebuild_miri(_bigdata):
    """
    Regression test of cube_build performed on MIRI MRS data.
    """
    input_model = datamodels.IFUImageModel(_bigdata+'/miri/test_cube_build/jw10001001001_01101_00001_mirifushort_cal.fits')
    CubeBuildStep.call(input_model, output_type='multi', save_results=True)

    h = fits.open('jw10001001001_01101_00001_mirifushort_s3d.fits')
    href = fits.open(_bigdata+'/miri/test_cube_build/jw10001001001_01101_00001_mirifushort_s3d_ref.fits')
    newh = fits.HDUList([h['primary'],h['sci'],h['err'],h['dq'],h['wmap']])
    newhref = fits.HDUList([href['primary'],href['sci'],href['err'],href['dq'],href['wmap']])
    result = fits.diff.FITSDiff(newh,
                              newhref,
                              ignore_keywords = ['DATE','CAL_VER','CAL_VCS','CRDS_VER','CRDS_CTX'],
                              rtol = 0.000001
    )
    assert result.identical, result.report()
示例#6
0
def science_image():
    """Generate science image"""

    image = datamodels.IFUImageModel((10, 10))
    image.data[:, :] = 100
    image.meta.instrument.name = 'NIRSPEC'
    image.meta.instrument.detector = 'NRS1'
    image.meta.instrument.filter = 'CLEAR'
    image.meta.instrument.grating = 'PRISM'
    image.meta.exposure.type = 'NRS_IFU'
    image.meta.observation.date = '2019-02-27'
    image.meta.observation.time = '13:37:18.548'
    image.meta.date = '2019-02-27T13:37:18.548'
    image.meta.subarray.xstart = 1
    image.meta.subarray.ystart = 1

    image.meta.instrument.gwa_xtilt = 0.0001
    image.meta.instrument.gwa_ytilt = 0.0001
    image.meta.instrument.gwa_tilt = 37.0610

    return image
示例#7
0
def test_get_2d_pixgrid():
    """ Test if x,y grid for channel is formed correctly  """

    # test if channel 1 then left side of detector
    # test shape of x (1/2 detector) and min,max (0,511) + 4 reference pixels
    input_model12 = datamodels.IFUImageModel((20, 20))
    input_model12.meta.instrument._instance.update(mirifushort_short)
    x, y = _get_2d_pixgrid(input_model12, '1')

    xsize0 = x.shape[0]
    xsize1 = x.shape[1]
    assert xsize0 == 1024
    assert xsize1 == 512
    xmin = np.amin(x)
    xmax = np.amax(x)
    assert xmin == 4
    assert xmax == 515

    # test if channel 2 then right side of detector
    # test shape of x (1/2 detector) and min,max 516, 1027 (no reference pixels)
    input_model12 = datamodels.IFUImageModel((20, 20))
    input_model12.meta.instrument._instance.update(mirifushort_short)
    x, y = _get_2d_pixgrid(input_model12, '2')

    xsize0 = x.shape[0]
    xsize1 = x.shape[1]
    assert xsize0 == 1024
    assert xsize1 == 512
    xmin = np.amin(x)
    xmax = np.amax(x)
    assert xmin == 516
    assert xmax == 1027

    # test if channel 3 then right side of detector
    # test shape of x (1/2 detector) and min,max 516, 1027 (no reference pixels)
    input_model34 = datamodels.IFUImageModel((20, 20))
    input_model34.meta.instrument._instance.update(mirifulong_long)
    x, y = _get_2d_pixgrid(input_model34, '3')

    xsize0 = x.shape[0]
    xsize1 = x.shape[1]
    assert xsize0 == 1024
    assert xsize1 == 512
    xmin = np.amin(x)
    xmax = np.amax(x)
    assert xmin == 516
    assert xmax == 1027

    # test if channel 4 then left side of detector
    # test shape of x (1/2 detector) and min,max 4, 515 (includes reference pixels)
    input_model34 = datamodels.IFUImageModel((20, 20))
    input_model34.meta.instrument._instance.update(mirifulong_long)
    x, y = _get_2d_pixgrid(input_model34, '4')

    xsize0 = x.shape[0]
    xsize1 = x.shape[1]
    assert xsize0 == 1024
    assert xsize1 == 512
    xmin = np.amin(x)
    xmax = np.amax(x)
    assert xmin == 4
    assert xmax == 515
示例#8
0
def test_find_channel_index(_jail, miri_dither_ch12):
    """ Test if correct channel index is returned """

    # channel 1 - model only has 1 bckground polynomial
    input_model12 = datamodels.IFUImageModel((20, 20))
    input_model12.meta.instrument._instance.update(mirifushort_short)
    degree = (
        1,
        1,
        1,
    )
    center = (
        5,
        5,
        5,
    )
    poly = np.ndarray(9)
    poly[:] = 1.3
    channel = '1'
    input_model12.meta.background.polynomial_info.append({
        'degree':
        degree,
        'refpoint':
        center,
        'coefficients':
        poly.ravel().tolist(),
        'channel':
        channel
    })

    index = _find_channel_bkg_index(input_model12, '1')
    assert index == 0

    # channel 2  background only has 1 background polynomial
    input_model12 = datamodels.IFUImageModel((20, 20))
    input_model12.meta.instrument._instance.update(mirifushort_short)
    degree = (
        1,
        1,
        1,
    )
    center = (
        5,
        5,
        5,
    )
    poly = np.ndarray(9)
    poly[:] = 1.3
    channel = '2'
    input_model12.meta.background.polynomial_info.append({
        'degree':
        degree,
        'refpoint':
        center,
        'coefficients':
        poly.ravel().tolist(),
        'channel':
        channel
    })

    index = _find_channel_bkg_index(input_model12, '2')
    assert index == 0

    # add background polynomial for channel 1 and test index
    degree = (
        1,
        1,
        1,
    )
    center = (
        5,
        5,
        5,
    )
    poly = np.ndarray(9)
    poly[:] = 1.3
    channel = '1'
    input_model12.meta.background.polynomial_info.append({
        'degree':
        degree,
        'refpoint':
        center,
        'coefficients':
        poly.ravel().tolist(),
        'channel':
        channel
    })

    index = _find_channel_bkg_index(input_model12, '1')
    assert index == 1

    # set up a new models only channel 3
    # channel 3
    input_model34 = datamodels.IFUImageModel((20, 20))
    input_model34.meta.instrument._instance.update(mirifulong_long)
    degree = (
        1,
        1,
        1,
    )
    center = (
        5,
        5,
        5,
    )
    poly = np.ndarray(9)
    poly[:] = 1.3
    channel = '3'
    input_model34.meta.background.polynomial_info.append({
        'degree':
        degree,
        'refpoint':
        center,
        'coefficients':
        poly.ravel().tolist(),
        'channel':
        channel
    })

    index = _find_channel_bkg_index(input_model34, '3')
    assert index == 0

    # set up a new model only have channe 4
    # channel 4
    input_model34 = datamodels.IFUImageModel((20, 20))
    input_model34.meta.instrument._instance.update(mirifulong_long)
    degree = (
        1,
        1,
        1,
    )
    center = (
        5,
        5,
        5,
    )
    poly = np.ndarray(9)
    poly[:] = 1.3
    channel = '4'
    input_model34.meta.background.polynomial_info.append({
        'degree':
        degree,
        'refpoint':
        center,
        'coefficients':
        poly.ravel().tolist(),
        'channel':
        channel
    })

    index = _find_channel_bkg_index(input_model34, '4')
    assert index == 0

    # set up a new model with both channel 3 and 4 background polynomials
    # channel 3 & 4
    input_model34 = datamodels.IFUImageModel((20, 20))
    input_model34.meta.instrument._instance.update(mirifulong_long)
    degree = (
        1,
        1,
        1,
    )
    center = (
        5,
        5,
        5,
    )
    poly = np.ndarray(9)
    poly[:] = 1.3
    channel = '4'
    input_model34.meta.background.polynomial_info.append({
        'degree':
        degree,
        'refpoint':
        center,
        'coefficients':
        poly.ravel().tolist(),
        'channel':
        channel
    })

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

    index = _find_channel_bkg_index(input_model34, '4')
    assert index == 0

    index = _find_channel_bkg_index(input_model34, '3')
    assert index == 1
示例#9
0
def test_ifu_bbox():
    bbox = {
        0: ((122.0908542999878, 1586.2584665188083), (773.5411133037417,
                                                      825.1150258966278)),
        1: ((140.3793485788431, 1606.8904629423566), (1190.353197027459,
                                                      1243.0853605832503)),
        2: ((120.0139534379125, 1583.9271768905855), (724.3249534782219,
                                                      775.8104288584977)),
        3: ((142.50252648927454, 1609.3106221382388), (1239.4122720740888,
                                                       1292.288713688988)),
        4: ((117.88884113088403, 1581.5517394150106), (674.9787657901347,
                                                       726.3752061973377)),
        5: ((144.57465414462143, 1611.688447569682), (1288.4808318659427,
                                                      1341.5035313084197)),
        6: ((115.8602297714846, 1579.27471654949), (625.7982466386104,
                                                    677.1147840452901)),
        7: ((146.7944728147906, 1614.2161842198498), (1337.531525654835,
                                                      1390.7050687363856)),
        8: ((113.86384530944383, 1577.0293086386203), (576.5344359685643,
                                                       627.777022204828)),
        9: ((149.0259581360621, 1616.7687282225652), (1386.5118806905086,
                                                      1439.843598490326)),
        10: ((111.91564190274217, 1574.8351095461135), (527.229828693075,
                                                        578.402894851317)),
        11: ((151.3053466801954, 1619.3720722471498), (1435.423685040875,
                                                       1488.917203728964)),
        12: ((109.8957204607345, 1572.570246400894), (477.9699083444277,
                                                      529.0782087498488)),
        13: ((153.5023503173659, 1621.9005029476564), (1484.38405923062,
                                                       1538.0443479389924)),
        14: ((107.98320121613297, 1570.411787034636), (428.6704834494425,
                                                       479.7217241891257)),
        15: ((155.77991404913857, 1624.5184927460925), (1533.169633314481,
                                                        1586.9984359105376)),
        16: ((106.10212081215678, 1568.286103827344), (379.3860245240618,
                                                       430.3780648366697)),
        17: ((158.23149941845386, 1627.305849064835), (1582.0496119714928,
                                                       1636.0513450787032)),
        18: ((104.09366374413436, 1566.030231370944), (330.0822744105267,
                                                       381.01974582564395)),
        19: ((160.4511021152353, 1629.888830991371), (1630.7797743277185,
                                                      1684.9592727079018)),
        20: ((102.25220592881234, 1563.9475099032868), (280.7233309522168,
                                                        331.6093009077988)),
        21: ((162.72784286205734, 1632.5257403739463), (1679.6815760587567,
                                                        1734.03692957156)),
        22: ((100.40115742738622, 1561.8476640376036), (231.35443588323855,
                                                        282.19575854747006)),
        23: ((165.05939163941662, 1635.2270773628682), (1728.511467615387,
                                                        1783.0485841263735)),
        24: ((98.45723949658425, 1559.6499479349648), (182.0417295679079,
                                                       232.83530870639865)),
        25: ((167.44628840053574, 1637.9923229870349), (1777.2512197664128,
                                                        1831.971115503598)),
        26: ((96.56508092457855, 1557.5079027818058), (132.5285162704088,
                                                       183.27350269292484)),
        27: ((169.8529496136358, 1640.778485168005), (1826.028691168028,
                                                      1880.9336718824313)),
        28: ((94.71390837793813, 1555.4048050512263), (82.94691422559131,
                                                       133.63901517357235)),
        29: ((172.3681094850081, 1643.685604697228), (1874.8184744639657,
                                                      1929.9072657798927))
    }

    hdul = create_nirspec_ifu_file("F290LP", "G140M")
    im = datamodels.IFUImageModel(hdul)
    im.meta.filename = "test_ifu.fits"
    refs = create_reference_files(im)

    pipe = nirspec.create_pipeline(im, refs, slit_y_range=[-.5, .5])
    w = wcs.WCS(pipe)
    im.meta.wcs = w

    _, wrange = nirspec.spectral_order_wrange_from_model(im)
    pipe = im.meta.wcs.pipeline

    g2s = pipe[2].transform
    transforms = [pipe[0].transform]
    transforms.append(pipe[1].transform[1:])
    transforms.append(astmodels.Identity(1))
    transforms.append(astmodels.Identity(1))
    transforms.extend([step.transform for step in pipe[4:-1]])

    for sl in range(30):
        transforms[2] = g2s.get_model(sl)
        m = functools.reduce(lambda x, y: x | y,
                             [tr.inverse for tr in transforms[:3][::-1]])
        bbox_sl = nirspec.compute_bounding_box(m, wrange)
        assert_allclose(bbox[sl], bbox_sl)