Skip to content

Commit

Permalink
Changing C2 scaling to not clip to 0, and use nodata instead (#48)
Browse files Browse the repository at this point in the history
* changing c2 scaling to not clip to 0, and use nodata instead

* addition of upper valid range

* tidying the valid min and max

* <= and >= for the min and max
  • Loading branch information
eloise-b committed Aug 19, 2021
1 parent cd3eb96 commit 26b07b5
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions wofs/virtualproduct.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
def scale_usgs_collection2(data):
"""These are taken from the Fractional Cover scaling values"""
return data.apply(scale_and_clip_dataarray, keep_attrs=True,
scale_factor=0.275, add_offset=-2000, clip_range=(0, 10000))
scale_factor=0.275, add_offset=-2000,
clip_range=None, valid_range=(0, 10000))


def scale_and_clip_dataarray(dataarray: xr.DataArray, *, scale_factor=1, add_offset=0, clip_range=None,
new_nodata=-999, new_dtype='int16'):
valid_range=None, new_nodata=-999, new_dtype='int16'):
orig_attrs = dataarray.attrs
nodata = dataarray.attrs['nodata']

Expand All @@ -40,6 +41,10 @@ def scale_and_clip_dataarray(dataarray: xr.DataArray, *, scale_factor=1, add_off
dataarray = dataarray.astype(new_dtype)

dataarray.data[mask] = new_nodata
if valid_range is not None:
valid_min, valid_max = valid_range
dataarray = dataarray.where(dataarray>= valid_min, new_nodata)
dataarray = dataarray.where(dataarray<= valid_max, new_nodata)
dataarray.attrs = orig_attrs
dataarray.attrs['nodata'] = new_nodata

Expand Down

0 comments on commit 26b07b5

Please sign in to comment.