示例#1
0
def create_slit(model, x0, y0, order):
    """ Create a SlitModel representing a grism slit."""
    ymin = 0
    xmin = 0
    # ymax = 58
    # xmax = 1323
    model = Mapping((0, 1, 0, 0, 0)) | (Shift(xmin) & Shift(ymin) & Const1D(x0)
                                        & Const1D(y0) & Const1D(order)) | model
    wcsobj = wcs.WCS([('det', model), ('world', None)])
    wcsobj.bounding_box = ((20, 25), (800, 805))
    slit = SlitModel()
    slit.meta.wcs = wcsobj
    slit.source_xpos = x0
    slit.source_ypos = y0
    return slit
示例#2
0
def test_interpolate_response():

    wavelength = np.array([0.5, 5., 7., 18., 26.], dtype=np.float32)
    wl1 = np.arange(1, 21, dtype=np.float64)
    wl2 = np.arange(1, 21, dtype=np.float64)[::-1]  # decreasing order
    response = np.arange(20, dtype=np.float64) * 2. + 5.

    slit = SlitModel()  # this is only used for the dtype of relsens
    tbl1 = np.array(list(zip(wl1, response)), dtype=slit.relsens.dtype)
    tbl2 = np.array(list(zip(wl2, response)), dtype=slit.relsens.dtype)

    reciprocal_r1 = extract.interpolate_response(wavelength,
                                                 tbl1,
                                                 verbose=False)
    assert len(reciprocal_r1) == len(wavelength)
    assert math.isclose(1. / reciprocal_r1[1], 13.0, rel_tol=1.e-6)
    assert reciprocal_r1[0] == 0.  # because wavelength is out of range
    assert reciprocal_r1[4] == 0.

    reciprocal_r2 = extract.interpolate_response(wavelength,
                                                 tbl2,
                                                 verbose=False)
    assert len(reciprocal_r2) == len(wavelength)
    assert math.isclose(1. / reciprocal_r2[1], 35.0, rel_tol=1.e-6)
    assert reciprocal_r2[0] == 0.  # because wavelength is out of range
    assert reciprocal_r2[4] == 0.
示例#3
0
def test_find_dispersion_axis():
    """
    Test the find_dispersion_axis() function
    """
    dm = SlitModel()

    dm.meta.wcsinfo.dispersion_direction = 1  # horizontal
    assert find_dispersion_axis(dm) == 0  # X axis for wcs functions

    dm.meta.wcsinfo.dispersion_direction = 2  # vertical
    assert find_dispersion_axis(dm) == 1  # Y axis for wcs functions
示例#4
0
def test_interpolate_response():

    wavelength = np.array([0.5, 5., 7., 18., 26.], dtype=np.float32)
    wl1 = np.arange(1, 21, dtype=np.float64)
    wl2 = np.arange(1, 21, dtype=np.float64)[::-1]  # decreasing order
    response = np.arange(20, dtype=np.float64) * 2. + 5.

    slit = SlitModel()  # this is only used for the dtype of relsens
    tbl1 = np.array(list(zip(wl1, response)), dtype=slit.relsens.dtype)
    tbl2 = np.array(list(zip(wl2, response)), dtype=slit.relsens.dtype)

    r1 = extract.interpolate_response(wavelength, tbl1, verbose=False)
    assert len(r1) == len(wavelength)
    assert r1[1] == 13.0

    r2 = extract.interpolate_response(wavelength, tbl2, verbose=False)
    assert len(r2) == len(wavelength)
    assert r2[1] == 35.0
def s2d_single(generate_wcs_transform):
    pytest.importorskip("jwst")
    from jwst.datamodels import MultiSlitModel, SlitModel
    from jwst.assign_wcs.util import wcs_bbox_from_shape

    shape = (10, 100)
    dispaxis = 1

    model = MultiSlitModel()
    sm = SlitModel(shape)
    sm.data
    model.slits.append(sm)
    for slit in model.slits:
        slit.meta.wcs = generate_wcs_transform(dispaxis)
        slit.meta.wcs.bounding_box = wcs_bbox_from_shape(shape)
        slit.meta.wcsinfo.dispersion_direction = dispaxis

    model.meta.telescope = "JWST"

    return model
示例#6
0
def test_slit_from_image():
    data = np.arange(24, dtype=np.float32).reshape((6, 4))
    im = ImageModel(data=data, err=data / 2, dq=data)
    im.meta.instrument.name = "MIRI"
    slit_dm = SlitDataModel(im)
    assert_allclose(im.data, slit_dm.data)
    assert hasattr(slit_dm, 'wavelength')
    # this should be enabled after gwcs starts using non-coordinate inputs
    # assert not hasattr(slit_dm, 'meta')

    slit = SlitModel(im)
    assert_allclose(im.data, slit.data)
    assert_allclose(im.err, slit.err)
    assert hasattr(slit, 'wavelength')
    assert slit.meta.instrument.name == "MIRI"

    im = ImageModel(slit)
    assert type(im) == ImageModel

    im = ImageModel(slit_dm)
    assert type(im) == ImageModel
def s2d_multi(generate_wcs_transform, request):
    pytest.importorskip("jwst")
    from jwst.datamodels import SlitModel, MultiSlitModel
    from jwst.assign_wcs.util import wcs_bbox_from_shape

    shape = request.param
    if shape[0] < shape[1]:
        dispaxis = 1
    else:
        dispaxis = 2

    model = MultiSlitModel()
    sm = SlitModel(shape)
    sm.data
    model.slits.append(sm)
    model.slits.append(sm)
    for slit in model.slits:
        slit.meta.wcs = generate_wcs_transform(dispaxis)
        slit.meta.wcs.bounding_box = wcs_bbox_from_shape(shape)
        slit.meta.wcsinfo.dispersion_direction = dispaxis
        slit.meta.bunit_data = "Jy"
        slit.meta.bunit_err = "Jy"

    return model