opendatacube / odc-geo

GeoBox and geometry utilities extracted from datacube-core
https://odc-geo.readthedocs.io/en/latest/
Apache License 2.0
83 stars 15 forks source link

account for `src_nodata` kwarg in `xr_reproject` #60

Closed valpesendorfer closed 2 years ago

valpesendorfer commented 2 years ago

Passing in src_nodata as kwarg in odc.reproject raises a TypeError.

Example:

import xarray as xr
from numpy.random import uniform
from odc.geo.data import country_geom
from odc.geo.xr import rasterize

# Make some sample images
def gen_sample(iso3, crs="epsg:3857", res=60_000, vmin=0, vmax=1000):
    xx = rasterize(country_geom(iso3, crs), res)
    return xr.where(xx, uniform(vmin, vmax, size=xx.shape), float("nan")).astype("float32")

aus = gen_sample("AUS")
aus.odc.reproject(aus.odc.geobox.zoom_out(1), src_nodata=0)

Result:


TypeError: rio_reproject() got multiple values for keyword argument 'src_nodata'

The changes in this PR account for the kwarg, and give it precedence with the assumption the user wants to manually override it.

codecov[bot] commented 2 years ago

Codecov Report

Merging #60 (8c9073e) into develop (d5f1819) will increase coverage by 0.00%. The diff coverage is 100.00%.

@@           Coverage Diff            @@
##           develop      #60   +/-   ##
========================================
  Coverage    97.48%   97.48%           
========================================
  Files           22       22           
  Lines         3144     3146    +2     
========================================
+ Hits          3065     3067    +2     
  Misses          79       79           
Impacted Files Coverage Δ
odc/geo/_xr_interop.py 99.35% <100.00%> (+<0.01%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update d5f1819...8c9073e. Read the comment docs.

Kirill888 commented 2 years ago

it's meant to come from nodata attribute of the source array, but sure, having an override can be useful sometimes.

valpesendorfer commented 2 years ago

it's meant to come from nodata attribute of the source array, but sure, having an override can be useful sometimes.

Like when source is missing nodata attribute, or has an incorrect one. Happens ...