-
Notifications
You must be signed in to change notification settings - Fork 175
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default floating point bands to nodata=nan when writing COGs. #1602
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #1602 +/- ##
========================================
Coverage 91.78% 91.78%
========================================
Files 132 132
Lines 14637 14640 +3
========================================
+ Hits 13434 13437 +3
Misses 1203 1203 ☔ View full report in Codecov by Sentry. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is working nicely, thanks @SpacemanPaul! If I try and write out a floating point array with no nodata attribute, I now get nodata=nan
in the COG:
import datacube
from datacube.utils.cog import write_cog
dc = datacube.Datacube()
ds = dc.load(
product="ga_ls8c_ard_3",
measurements=["nbart_red"],
time=("2019-01-10", "2019-01-15"),
x=(149.036528545, 149.233835134),
y=(-35.198132594, -35.384897602),
group_by="solar_day",
)
# Convert to float
da_float = ds.nbart_red / 10000
assert "nodata" not in da_float.attrs
# Export to file
write_cog(da_float, "test_missingnodata.tif", overwrite=True)
!gdalinfo test_missingnodata.tif
I also get nodata=nan
in the COG if it is explicitly declared on the Xarray too:
import numpy as np
da_float.attrs["nodata"] = np.nan
# Export to file
write_cog(da_float, "test_nodatanan.tif", overwrite=True)
!gdalinfo test_nodatanan.tif
And custom nodata is still preserved if provided on the Xarray:
da_float.attrs["nodata"] = -999
# Export to file
write_cog(da_float, "test_nodatacustom.tif", overwrite=True)
!gdalinfo test_nodatacustom.tif
* Update test_extra_dimensions to work with numpy 1.x and numpy 2.x * Behaviour of num2numpy function changes between numpy 1.x and numpy 2.x * Pin moto<5 to delay rewriting of tests. * Default float bands to nodata=nan when writing cogs. * Test float bands default to nodata=nan when writing cogs. * Update whats_new.rst * Lintage and incorporate Dependabot's #1600. * Add ESRI to wordlist.txt (roll eyes).
* Update test_extra_dimensions to work with numpy 1.x and numpy 2.x * Behaviour of num2numpy function changes between numpy 1.x and numpy 2.x * Pin moto<5 to delay rewriting of tests. * Default float bands to nodata=nan when writing cogs. * Test float bands default to nodata=nan when writing cogs. * Update whats_new.rst * Lintage and incorporate Dependabot's #1600. * Add ESRI to wordlist.txt (roll eyes).
* Update test_extra_dimensions to work with numpy 1.x and numpy 2.x * Behaviour of num2numpy function changes between numpy 1.x and numpy 2.x * Pin moto<5 to delay rewriting of tests. * Default float bands to nodata=nan when writing cogs. * Test float bands default to nodata=nan when writing cogs. * Update whats_new.rst * Lintage and incorporate Dependabot's #1600. * Add ESRI to wordlist.txt (roll eyes).
Reason for this pull request
Issue #1595
Proposed changes
Always write
nodata=nan
to COGs for all floating point bands (unless another nodata value is explicitly set) and test.Update tests to pass with numpy 2.x and numpy 1.x
Pin
moto<5
(Moto API has changed slightly in v5 and several tests will need to be rewritten to support).Closes Important fix proposal: Implement setting "nan" nodata value for floating point rasters with no nodata attribute #1595
Tests added / passed
Fully documented, including
docs/about/whats_new.rst
for all changes📚 Documentation preview 📚: https://datacube-core--1602.org.readthedocs.build/en/1602/