Skip to content

Commit

Permalink
set tiling and compression options for water mask geotiff
Browse files Browse the repository at this point in the history
  • Loading branch information
asjohnston-asf committed Jul 13, 2023
1 parent e4a184b commit 87918f6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/hyp3_isce2/water_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ def create_water_mask(input_tif: str, output_tif: str):

src_ds = gdal.Open(input_tif)

dst_ds = gdal.GetDriverByName('GTiff').Create(output_tif, src_ds.RasterXSize, src_ds.RasterYSize, 1, gdal.GDT_Byte)
dst_ds = gdal.GetDriverByName('GTiff').Create(output_tif, src_ds.RasterXSize, src_ds.RasterYSize, 1, gdal.GDT_Byte,
['COMPRESS=LZW', 'TILED=YES', 'NUM_THREADS=ALL_CPUS'])
dst_ds.SetGeoTransform(src_ds.GetGeoTransform())
dst_ds.SetProjection(src_ds.GetProjection())
dst_ds.SetMetadataItem('AREA_OR_POINT', src_ds.GetMetadataItem('AREA_OR_POINT'))
Expand Down
4 changes: 4 additions & 0 deletions tests/test_water_mask.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,9 @@ def test_create_water_mask_with_no_water(tmp_path, test_data_dir):
assert info['bands'][0]['type'] == 'Byte'
assert info['bands'][0]['minimum'] == 1
assert info['bands'][0]['maximum'] == 1
assert info['bands'][0]['block'] == [256, 256]
assert info['metadata']['']['AREA_OR_POINT'] == 'Area'
assert info['metadata']['IMAGE_STRUCTURE']['COMPRESSION'] == 'LZW'


def test_create_water_mask_with_water_and_land(tmp_path, test_data_dir):
Expand All @@ -74,7 +76,9 @@ def test_create_water_mask_with_water_and_land(tmp_path, test_data_dir):
info = gdal.Info(output_tif, format='json')
assert info['geoTransform'] == [200360.0, 80.0, 0.0, 1756920.0, 0.0, -80.0]
assert info['bands'][0]['type'] == 'Byte'
assert info['bands'][0]['block'] == [256, 256]
assert info['metadata']['']['AREA_OR_POINT'] == 'Point'
assert info['metadata']['IMAGE_STRUCTURE']['COMPRESSION'] == 'LZW'

ds = gdal.Open(str(output_tif))
data = ds.GetRasterBand(1).ReadAsArray()
Expand Down

0 comments on commit 87918f6

Please sign in to comment.