Skip to content

Commit

Permalink
change float* nodata value to -inf
Browse files Browse the repository at this point in the history
  • Loading branch information
dugalh committed Jul 3, 2024
1 parent 12b2e10 commit ce8df7a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
5 changes: 4 additions & 1 deletion geedim/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@


class BaseImage:
_float_nodata = float('nan')
_float_nodata = float('-inf')
_desc_width = 50
_default_resampling = ResamplingMethod.near
_ee_max_tile_size = 32
Expand Down Expand Up @@ -984,6 +984,9 @@ def download(

def download_tile(tile):
"""Download a tile and write into the destination GeoTIFF."""
# Note: due to an Earth Engine bug (https://issuetracker.google.com/issues/350528377), tile_array is
# float64 for uint32 and int64 exp_image types. The tile_array nodata value is as it should be
# though, so conversion to the exp_image / GeoTIFF type happens ok below.
tile_array = tile.download(session=session, bar=bar)
with out_lock:
out_ds.write(tile_array, window=tile.window)
Expand Down
9 changes: 3 additions & 6 deletions tests/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -466,18 +466,15 @@ def test_prepare_for_download(base_image: str, request: pytest.FixtureRequest):
('int16', -(2**15)),
('uint32', 0),
('int32', -(2**31)),
('float32', float('nan')),
('float64', float('nan')),
('float32', float('-inf')),
('float64', float('-inf')),
],
)
def test_prepare_nodata(user_fix_base_image: BaseImage, region_25ha: Dict, dtype: str, exp_nodata: float):
"""Test BaseImage._prepare_for_download() sets rasterio profile nodata correctly for different dtypes."""
exp_image, exp_profile = user_fix_base_image._prepare_for_download(region=region_25ha, scale=30, dtype=dtype)
assert exp_image.dtype == dtype
if np.isnan(exp_profile['nodata']):
assert np.isnan(exp_nodata)
else:
assert exp_profile['nodata'] == exp_nodata
assert exp_profile['nodata'] == exp_nodata


@pytest.mark.parametrize(
Expand Down

0 comments on commit ce8df7a

Please sign in to comment.