Ejemplo n.º 1
0
def test_weight_type(nircam_rate, _jail):
    """Check that weight_type of exptime and ivm work"""
    im1 = AssignWcsStep.call(nircam_rate, sip_approx=False)
    im1.var_rnoise[:] = 0
    im2 = im1.copy()
    im3 = im1.copy()
    im1.data += 10
    im2.data += 5
    im3.data += 5
    im1.var_rnoise += (1 / 10)
    im2.var_rnoise += (1 / 5)
    im3.var_rnoise += (1 / 5)
    im2.meta.observation.sequence_id = "2"
    im3.meta.observation.sequence_id = "3"

    c = ModelContainer([im1, im2, im3])
    assert len(c.group_names) == 3

    result1 = ResampleStep.call(c, weight_type="ivm", blendheaders=False, save_results=True)

    # assert_allclose(result1.data, result2.data)
    # assert_allclose(result1.wht, result2.wht)
    assert_allclose(result1.data[100:105, 100:105], 7.5, rtol=1e-2)
    assert_allclose(result1.wht[100:105, 100:105], 20, rtol=1e-2)

    result2 = ResampleStep.call(c, weight_type="exptime", blendheaders=False)

    assert_allclose(result2.data[100:105, 100:105], 7.5, rtol=1e-2)
    assert_allclose(result2.wht[100:105, 100:105], 20, rtol=1e-2)
Ejemplo n.º 2
0
def test_resample_undefined_variance(nircam_rate, shape):
    """Test that resampled variance and error arrays are computed properly"""
    im = AssignWcsStep.call(nircam_rate)
    im.var_rnoise = np.ones(shape, dtype=im.var_rnoise.dtype.type)
    im.var_poisson = np.ones(shape, dtype=im.var_poisson.dtype.type)
    im.var_flat = np.ones(shape, dtype=im.var_flat.dtype.type)
    im.meta.filename = "foo.fits"

    c = ModelContainer([im])
    ResampleStep.call(c, blendheaders=False)
Ejemplo n.º 3
0
def test_pixel_scale_ratio_imaging(nircam_rate, ratio):
    im = AssignWcsStep.call(nircam_rate, sip_approx=False)
    im.data += 5
    result1 = ResampleStep.call(im)
    result2 = ResampleStep.call(im, pixel_scale_ratio=ratio)

    assert_allclose(np.array(result1.data.shape), np.array(result2.data.shape) * ratio, rtol=1, atol=1)

    # Avoid edge effects; make sure data values are identical for surface brightness data
    assert np.mean(result1.data[10:-10, 10:-10]) == np.mean(result2.data[10:-10, 10:-10])

    # Make sure the photometry keywords describing the solid angle of a pixel
    # are updated
    area1 = result1.meta.photometry.pixelarea_steradians
    area2 = result2.meta.photometry.pixelarea_steradians
    assert_allclose(area1 * ratio**2, area2, rtol=1e-6)
Ejemplo n.º 4
0
def test_custom_wcs_resample_imaging(nircam_rate, ratio, rotation, crpix,
                                     crval, shape):
    im = AssignWcsStep.call(nircam_rate, sip_approx=False)
    im.data += 5
    result = ResampleStep.call(im,
                               output_shape=shape,
                               crpix=crpix,
                               crval=crval,
                               rotation=rotation,
                               pixel_scale_ratio=ratio)

    t = result.meta.wcs.forward_transform

    # test rotation
    pc = t['pc_rotation_matrix'].matrix.value
    orientation = np.rad2deg(np.arctan2(pc[0, 1], pc[1, 1]))
    assert np.allclose(rotation, orientation)

    # test CRPIX
    assert np.allclose((-t['crpix1'].offset.value, -t['crpix2'].offset.value),
                       crpix)

    # test CRVAL
    assert np.allclose(t(*crpix), crval)

    # test output image shape
    assert result.data.shape == shape[::-1]
Ejemplo n.º 5
0
def test_resample_variance(nircam_rate, n_images):
    """Test that resampled variance and error arrays are computed properly"""
    err = 0.02429
    var_rnoise = 0.00034
    var_poisson = 0.00025
    im = AssignWcsStep.call(nircam_rate)
    im.var_rnoise += var_rnoise
    im.var_poisson += var_poisson
    im.err += err
    im.meta.filename = "foo.fits"

    c = ModelContainer()
    for n in range(n_images):
        c.append(im.copy())

    result = ResampleStep.call(c, blendheaders=False)

    # Verify that the combined uncertainty goes as 1 / sqrt(N)
    assert_allclose(result.err[5:-5, 5:-5].mean(),
                    err / np.sqrt(n_images),
                    atol=1e-5)
    assert_allclose(result.var_rnoise[5:-5, 5:-5].mean(),
                    var_rnoise / n_images,
                    atol=1e-7)
    assert_allclose(result.var_poisson[5:-5, 5:-5].mean(),
                    var_poisson / n_images,
                    atol=1e-7)
Ejemplo n.º 6
0
def test_image(asnfile):
    '''Test to single FITS input.'''

    with open(asnfile) as json_data:
        d = json.load(json_data)
    members = d['products'][0]['members'][0]['expname']

    wcs = AssignWcsStep.call(members)
    resample = ResampleStep.call(wcs)
    resample.save(asnfile[:5] + '_singleimage_resample.fits')
Ejemplo n.º 7
0
def test_kernel(asnfile, kernel):
    '''Test to check kernel.'''

    calib = ResampleStep.call(asnfile,
                              kernel=kernel,
                              output_file=asnfile[:5] + '_kernel' +
                              str(kernel) + '_resample.fits')
    img3 = calwebb_image3.Image3Pipeline(config_file='calwebb_image2.cfg')
    img3.tweakreg.skip = True
    img3.resample.kernel = kernel
    img3.output_file = asnfile[:5] + '_kernel' + str(kernel) + '_resample.fits'
    img3.run(asnfile)
Ejemplo n.º 8
0
def test_wcs_keywords(nircam_rate):
    # make sure certain wcs keywords are removed after resample

    im = AssignWcsStep.call(nircam_rate)
    result = ResampleStep.call(im)

    assert result.meta.wcsinfo.v2_ref is None
    assert result.meta.wcsinfo.v3_ref is None
    assert result.meta.wcsinfo.ra_ref is None
    assert result.meta.wcsinfo.dec_ref is None
    assert result.meta.wcsinfo.roll_ref is None
    assert result.meta.wcsinfo.v3yangle is None
    assert result.meta.wcsinfo.vparity is None
Ejemplo n.º 9
0
def test_custom_wcs_pscale_resample_imaging(nircam_rate, ratio):
    im = AssignWcsStep.call(nircam_rate, sip_approx=False)
    im.data += 5

    fiducial = compute_fiducial([im.meta.wcs])
    input_scale = compute_scale(wcs=im.meta.wcs, fiducial=fiducial)
    result = ResampleStep.call(im,
                               pixel_scale_ratio=ratio,
                               pixel_scale=3600 * input_scale * 0.75)
    output_scale = compute_scale(wcs=result.meta.wcs, fiducial=fiducial)

    # test scales are close
    assert np.allclose(output_scale, input_scale * 0.75)
Ejemplo n.º 10
0
def test_sip_coeffs_do_not_propagate(nircam_rate):
    im = AssignWcsStep.call(nircam_rate, sip_degree=2)

    # Check some SIP keywords produced above
    assert im.meta.wcsinfo.cd1_1 is not None
    assert im.meta.wcsinfo.ctype1 == "RA---TAN-SIP"

    # Make sure no PC matrix stuff is there
    assert im.meta.wcsinfo.pc1_1 is None

    result = ResampleStep.call(im)

    # Verify that SIP-related keywords do not propagate to resampled output
    assert result.meta.wcsinfo.cd1_1 is None
    assert result.meta.wcsinfo.ctype1 == "RA---TAN"

    # Make sure we have a PC matrix
    assert result.meta.wcsinfo.pc1_1 is not None