Skip to content

Instantly share code, notes, and snippets.

@robbibt
Created October 21, 2019 05:41
Show Gist options
  • Select an option

  • Save robbibt/891c3f4f579e4bafd89d7c3b1caf77f6 to your computer and use it in GitHub Desktop.

Select an option

Save robbibt/891c3f4f579e4bafd89d7c3b1caf77f6 to your computer and use it in GitHub Desktop.
Compute valid WOfS statistics from WOFLs
# Source: https://bitbucket.org/kirill-ga/wofs-summary/src/0f1e4284085e2a65bd7a0b9fdb00e0f65c36f713/kk/wofs_summary/_wofs_stats.py?utm_term=file&utm_source=bb-slack&utm_medium=referral-external&atlOrigin=eyJpIjoiMWRiZjlmZjhkYmE3NDg0Mzk3NWI3ODZhZjczNGQyODQiLCJwIjoiYmItY2hhdHMtaW50ZWdyYXRpb24ifQ#lines-114:136
def wofs_stats(xx):
attrs = {'crs': xx.crs}
xx_wet = make_mask(xx.water, wet=True).sum(dim='time', dtype='int16')
xx_dry = make_mask(xx.water, dry=True).sum(dim='time', dtype='int16')
xx_clear = xx_wet + xx_dry
xx_freq = xx_wet.astype('float32')/xx_clear
# TODO: actually compute nodata pixels. In this context 0 clear observations
# is not the same as no observations at all. On NCI datacube-stats is
# not computing those either. So this will do for now.
xx_wet.attrs['nodata'] = -1
xx_clear.attrs['nodata'] = -1
out = xr.Dataset({'count_wet': xx_wet,
'count_clear': xx_clear,
'frequency': xx_freq},
attrs=attrs)
for var in out.data_vars.values():
var.attrs.update(**attrs)
return out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment