示例#1
0
def test_read_memmap():
    data, _ = _fits.read(TEST_AIA_IMAGE, memmap=True)[0]
    assert data.base is not None
    assert isinstance(data.base, mmap.mmap)

    data, _ = _fits.read(TEST_AIA_IMAGE, memmap=False)[0]
    assert data.base is None
示例#2
0
def test_simple_write_compressed(tmpdir):
    data, header = _fits.read(TEST_AIA_IMAGE)[0]
    outfile = tmpdir / "test.fits"
    _fits.write(str(outfile), data, header, hdu_type=fits.CompImageHDU)
    assert outfile.exists()
    with fits.open(str(outfile)) as hdul:
        assert len(hdul) == 2
        assert isinstance(hdul[1], fits.CompImageHDU)
示例#3
0
def test_simple_write_compressed_difftypeinst(tmpdir):
    # `hdu_type=fits.CompImageHDU` and `hdu_type=fits.CompImageHDU()`
    # should produce identical FITS files
    data, header = _fits.read(TEST_AIA_IMAGE)[0]
    outfile_type = str(tmpdir / "test_type.fits")
    outfile_inst = str(tmpdir / "test_inst.fits")
    _fits.write(outfile_type, data, header, hdu_type=fits.CompImageHDU)
    _fits.write(outfile_inst, data, header, hdu_type=fits.CompImageHDU())
    assert fits.FITSDiff(outfile_type, outfile_inst, ignore_comments=['PCOUNT']).identical
示例#4
0
def test_simple_write(tmpdir):
    data, header = _fits.read(TEST_AIA_IMAGE)[0]
    outfile = tmpdir / "test.jp2"
    jp2.write(str(outfile), data, header)
    assert outfile.exists()

    # Sanity check that reading back the jp2 returns coherent data
    jp2_readback = jp2.read(outfile)
    assert header['DATE'] == jp2_readback[0].header['DATE']
示例#5
0
def test_simple_write_compressed_instance(tmpdir, kwargs, should_fail):
    data, header = _fits.read(TEST_AIA_IMAGE)[0]
    outfile = tmpdir / "test.fits"

    # Ensure HDU instance is used correctly
    hdu = fits.CompImageHDU(data=np.array([0.]), **kwargs)
    hdu.header['HELLO'] = 'world'  # should be in the written file
    hdu.header['TELESCOP'] = 'other'  # should be replaced with 'SDO/AIA'
    hdu.header['NAXIS'] = 5  # should be replaced with 2
    _fits.write(str(outfile), data, header, hdu_type=hdu)
    assert outfile.exists()
    with fits.open(str(outfile)) as hdul:
        assert len(hdul) == 2
        assert isinstance(hdul[1], fits.CompImageHDU)
        assert hdul[1].header['HELLO'] == 'world'
        assert hdul[1].header['TELESCOP'] == 'SDO/AIA'
        assert hdul[1].header['NAXIS'] == 2
        data_preserved = hdul[1].data == pytest.approx(data, abs=10)
        print(np.abs(hdul[1].data - data).max())
        print(kwargs)
        if should_fail:  # high compression setting preserved
            assert not data_preserved
        else:
            assert data_preserved
示例#6
0
def test_extra_comment_write(tmpdir):
    data, header = _fits.read(TEST_AIA_IMAGE)[0]
    header["KEYCOMMENTS"]["TEST"] = "Hello world"
    outfile = tmpdir / "test.fits"
    _fits.write(str(outfile), data, header)
    assert outfile.exists()
示例#7
0
def test_simple_write(tmpdir):
    data, header = _fits.read(TEST_AIA_IMAGE)[0]
    outfile = tmpdir / "test.fits"
    _fits.write(str(outfile), data, header)
    assert outfile.exists()
示例#8
0
def test_read_hdus(fname, hdus, length):
    pairs = _fits.read(fname, hdus=hdus)
    assert len(pairs) == length