Skip to content
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

Changing C2 scaling to not clip to 0, and use nodata instead #48

Merged
merged 4 commits into from
Aug 19, 2021
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
alexgleith marked this conversation as resolved.
Show resolved Hide resolved
dataarray = dataarray.where(dataarray< valid_max, new_nodata)
dataarray.attrs = orig_attrs
dataarray.attrs['nodata'] = new_nodata

Expand Down