Skip to content

Commit

Permalink
FITS driver improved: new functions for Scale Offset and FITS World C…
Browse files Browse the repository at this point in the history
…oordinate System read and write (#1298)
  • Loading branch information
cmarmo authored and rouault committed Mar 20, 2019
1 parent ab4def2 commit 322e1b1
Show file tree
Hide file tree
Showing 4 changed files with 1,007 additions and 45 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@
.cproject
.idea
.vscode

Binary file added autotest/gdrivers/data/offscale_byte.tif
Binary file not shown.
38 changes: 35 additions & 3 deletions autotest/gdrivers/fits.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

@pytest.mark.parametrize(
'filename',
['byte', 'int16', 'int32', 'float32', 'float64']
['byte', 'int16', 'uint16', 'int32', 'uint32', 'float32', 'float64']
)
def test_fits(filename):
driver = gdal.GetDriverByName('FITS')
Expand All @@ -54,8 +54,7 @@ def test_fits(filename):
ds2 = None
driver.Delete('tmp/' + filename + '.fits')


def fits_metadata():
def test_fits_metadata():
driver = gdal.GetDriverByName('FITS')

ds = gdal.Open('../gcore/data/byte.tif')
Expand All @@ -82,3 +81,36 @@ def fits_metadata():
ds2 = None

assert md['TEST2'] == 'test_value2'

def test_fits_nodata():
driver = gdal.GetDriverByName('FITS')

ds = gdal.Open('../gcore/data/nodata_byte.tif')
ds2 = driver.CreateCopy('tmp/nodata_byte.fits', ds)
ds2 = None
gdal.Unlink('tmp/nodata_byte.fits.aux.xml')

ds2 = gdal.Open('tmp/nodata_byte.fits')
nd = ds2.GetRasterBand(1).GetNoDataValue()
ds2 = None
driver.Delete('tmp/nodata_byte.fits')

assert nd == 0

def test_fits_offscale():
driver = gdal.GetDriverByName('FITS')

ds = gdal.Open('../gdrivers/data/offscale_byte.tif')
ds2 = driver.CreateCopy('tmp/offscale_byte.fits', ds)
ds2 = None
gdal.Unlink('tmp/offscale_byte.fits.aux.xml')

ds2 = gdal.Open('tmp/offscale_byte.fits')
offset = ds2.GetRasterBand(1).GetOffset()
scale = ds2.GetRasterBand(1).GetScale()
ds2 = None
driver.Delete('tmp/offscale_byte.fits')

assert offset == -0.0039525691699605
assert scale == 1.00395256917

Loading

0 comments on commit 322e1b1

Please sign in to comment.