Ejemplo n.º 1
0
 def test_addVAR(self):
     ad = astrodata.open(os.path.join(TESTDATAPATH, 'NIRI',
                             'N20070819S0104_ADUToElectrons.fits'))
     p = NIRIImage([ad])
     ad = p.addVAR(read_noise=True, poisson_noise=True)[0]
     assert ad_compare(ad, os.path.join(TESTDATAPATH, 'NIRI',
                             'N20070819S0104_varAdded.fits'))
Ejemplo n.º 2
0
 def test_prepare(self):
     ad = astrodata.open(os.path.join(TESTDATAPATH, 'NIRI',
                             'N20070819S0104.fits'))
     p = NIRIImage([ad])
     ad = p.prepare()[0]
     assert ad_compare(ad, os.path.join(TESTDATAPATH, 'NIRI',
                             'N20070819S0104_prepared.fits'))
Ejemplo n.º 3
0
 def test_nonlinearityCorrect(self):
     ad = astrodata.open(os.path.join(TESTDATAPATH, 'NIRI',
                             'N20070819S0104_varAdded.fits'))
     p = NIRIImage([ad])
     ad = p.nonlinearityCorrect()[0]
     assert ad_compare(ad, os.path.join(TESTDATAPATH, 'NIRI',
                             'N20070819S0104_nonlinearityCorrected.fits'))
Ejemplo n.º 4
0
 def test_writeOutputs(self):
     filenames = ['N20070819S{:04d}_flatCorrected.fits'.format(i)
                  for i in range(104, 106)]
     adinputs = [astrodata.open(os.path.join(TESTDATAPATH, 'NIRI', f))
                 for f in filenames]
     p = NIRIImage(adinputs)
     p.writeOutputs(prefix='test', suffix='_blah', strip=True)
     # Check renamed files are on disk and the filenames have been
     # changed for the adinputs
     for f, ad in zip(filenames, p.streams['main']):
         newfilename = 'test'+f.replace('flatCorrected', 'blah')
         assert os.path.exists(newfilename)
         os.remove(newfilename)
         assert newfilename == ad.filename
Ejemplo n.º 5
0
 def test_addToList(self):
     filenames = ['N20070819S{:04d}_flatCorrected.fits'.format(i)
                  for i in range(104, 109)]
     adinputs = [astrodata.open(os.path.join(TESTDATAPATH, 'NIRI', f))
                 for f in filenames]
     # Add one image twice, just for laughs; it should appear only once
     adinputs.append(adinputs[0])
     p = NIRIImage(adinputs)
     p.stacks = {}
     p.addToList(purpose='forTest')
     for f in filenames:
         newfilename = f.replace('flatCorrected', 'forTest')
         assert os.path.exists(newfilename)
         os.remove(newfilename)
     # Check there's one stack of length 5
     assert len(p.stacks) == 1
     assert len(p.stacks[p.stacks.keys()[0]]) == 5
Ejemplo n.º 6
0
def niri_images():
    """Create two NIRI images, one all 1s, the other all 2s"""
    try:
        import AstroFaker
    except ImportError:
        pytest.skip("AstroFaker not installed")

    adinputs = []
    for i in (1, 2):
        ad = AstroFaker.create('NIRI', 'IMAGE')
        ad.init_default_extensions()
        ad[0].data += i

    adinputs.append(ad)

    return NIRIImage(adinputs)
Ejemplo n.º 7
0
def niri_image():

    try:
        import AstroFaker
    except ImportError:
        pytest.skip("AstroFaker is not installed")

    ad = AstroFaker.create('NIRI', 'IMAGE')
    ad.init_default_extensions()

    # SExtractor struggles if the background is noiseless
    ad.add_read_noise()

    for x, y in STAR_POSITIONS:
        ad[0].add_star(amplitude=500, x=x, y=y)

    return NIRIImage([ad])
Ejemplo n.º 8
0
def test_associateSky():
    filenames = [
        'N20070819S{:04d}_flatCorrected.fits'.format(i)
        for i in range(104, 109)
    ]

    adinputs = [
        astrodata.open(os.path.join(TESTDATAPATH, 'NIRI', f))
        for f in filenames
    ]

    p = NIRIImage(adinputs)
    p.separateSky()  # Difficult to construct this by hand
    p.associateSky()
    filename_set = {ad.phu['ORIGNAME'] for ad in adinputs}

    # Test here is that each science frame has all other frames as skies
    for k, v in p.sky_dict.items():
        v = [ad.phu['ORIGNAME'] for ad in v]
        assert len(v) == len(filenames) - 1
        assert set([k] + v) == filename_set
Ejemplo n.º 9
0
def test_adjust_wcs_to_reference(astrofaker, no_wcs, rotate, scale):
    scale = False
    mods = [models.Identity(2)]
    for params in MODEL_PARMS:
        m = models.Shift(params[0]) & models.Shift(params[1])
        if rotate:
            m |= models.Rotation2D(params[2])
        if scale:
            m |= models.Scale(params[3]) & models.Scale(params[3])
        mods.append(m)
    adinputs = make_images(astrofaker, mods=mods)
    if no_wcs:
        for ad in adinputs:
            del ad[0].hdr['CD*']
            ad[0].wcs = None
    p = NIRIImage(adinputs)
    p.detectSources()
    p.adjustWCSToReference(first_pass=45 if no_wcs else 5,
                           rotate=rotate,
                           scale=scale)

    # We're going to confirm that a grid of input points are transformed
    # correctly, rather than comparing the components of the registration
    # model with the original model
    yin, xin = np.mgrid[:1000:100, :1000:100]
    for i, (ad, m) in enumerate(zip(p.streams['main'], mods)):
        if i == 0:  # the Identity model: nothing to check
            continue
        m_regist = ad[0].wcs.forward_transform[:m.n_submodels]
        print(m_regist)

        xref, yref = m(xin, yin)
        xout, yout = m_regist(xin, yin)
        np.testing.assert_allclose(xref, xout, atol=0.1)
        np.testing.assert_allclose(yref, yout, atol=0.1)
        rms = np.sqrt(((xref - xout)**2 + (yref - yout)**2).mean())
        assert rms < 0.05
Ejemplo n.º 10
0
def niriprim():
    file_path = download_from_archive("N20190120S0287.fits")
    ad = astrodata.open(file_path)
    p = NIRIImage([ad])
    p.addDQ()
    return p
Ejemplo n.º 11
0
def test_associateSky():

    filenames = [
        'N20070819S{:04d}_flatCorrected.fits'.format(i)
        for i in range(104, 109)
    ]

    adinputs = [
        astrodata.open(os.path.join(TESTDATAPATH, 'NIRI', f))
        for f in filenames
    ]

    p = NIRIImage(adinputs)
    p.separateSky()  # Difficult to construct this by hand
    p.associateSky()
    filename_set = set([ad.phu['ORIGNAME'] for ad in adinputs])

    # Test here is that each science frame has all other frames as skies
    for k, v in p.sky_dict.items():
        v = [ad.phu['ORIGNAME'] for ad in v]
        assert len(v) == len(filenames) - 1
        assert set([k] + v) == filename_set


# def test_correctBackgroundToReference(self):
#     pass

# def test_darkCorrect(self):
#     ad = astrodata.open(os.path.join(TESTDATAPATH, 'NIRI',
#                             'N20070819S0104_nonlinearityCorrected.fits'))
#     p = NIRIImage([ad])
#     ad = p.darkCorrect()[0]
#     assert ad_compare(ad, os.path.join(TESTDATAPATH, 'NIRI',
#                             'N20070819S0104_darkCorrected.fits'))

# def test_darkCorrect_with_af(self):
#     science = AstroFaker.create('NIRI', 'IMAGE')
#     dark = AstroFaker.create('NIRI', 'IMAGE')
#     p = NIRIImage([science])
#     p.darkCorrect([science], dark=dark)
#     science.subtract(dark)
#     assert ad_compare(science, dark)

# af.init_default_extensions()
# af[0].mask = np.zeros_like(af[0].data, dtype=np.uint16)
# def test_flatCorrect(self):
#     ad = astrodata.open(os.path.join(TESTDATAPATH, 'NIRI',
#                             'N20070819S0104_darkCorrected.fits'))
#     p = NIRIImage([ad])
#     ad = p.flatCorrect()[0]
#     assert ad_compare(ad, os.path.join(TESTDATAPATH, 'NIRI',
#                             'N20070819S0104_flatCorrected.fits'))
#
# def test_makeSky(self):
#     pass
#
# def test_nonlinearityCorrect(self):
#     # Don't use NIRI data; NIRI has its own primitive
#     pass
#
# def test_normalizeFlat(self):
#     flat_file = os.path.join(TESTDATAPATH, 'NIRI',
#                             'N20070913S0220_flat.fits')
#     ad = astrodata.open(flat_file)
#     ad.multiply(10.0)
#     del ad.phu['NORMLIZE']  # Delete timestamp of previous processing
#     p = NIRIImage([ad])
#     ad = p.normalizeFlat(suffix='_flat', strip=True)[0]
#     assert ad_compare(ad, flat_file)
#
# def test_separateSky(self):
#     pass
#
# def test_skyCorrect(self):
#     pass
#
# def test_subtractSky(self):
#     pass
#
# def test_subtractSkyBackground(self):
#     ad = astrodata.open(os.path.join(TESTDATAPATH, 'NIRI',
#                             'N20070819S0104_flatCorrected.fits'))
#     ad.hdr['SKYLEVEL'] = 1000.0
#     orig_data = ad[0].data.copy()
#     p = NIRIImage([ad])
#     ad = p.subtractSkyBackground()[0]
#     assert (orig_data - ad[0].data).min() > 999.99
#     assert (orig_data - ad[0].data).max() < 1000.01
#
# def test_thresholdFlatfield(self):
#     ad = astrodata.open(os.path.join(TESTDATAPATH, 'NIRI',
#                                      'N20070913S0220_flat.fits'))
#     del ad.phu['TRHFLAT']  # Delete timestamp of previous processing
#     ad[0].data[100, 100] = 20.0
#     p = NIRIImage([ad])
#     ad = p.thresholdFlatfield()[0]
#     assert ad[0].mask[100, 100] == 64
Ejemplo n.º 12
0
def test_not_prepared(adinputs):
    p = NIRIImage(adinputs)
    with pytest.raises(IOError):
        p.stackFrames()