Skip to content

Commit

Permalink
Always record wet and dry pixel numbers and areas
Browse files Browse the repository at this point in the history
  • Loading branch information
Fang Yuan committed Oct 15, 2023
1 parent a96f0ed commit 13ecbf5
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions deafrica_conflux/plugins/waterbodies_timeseries.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,20 @@ def summarise(inputs: xr.Dataset, resolution: tuple) -> xr.Dataset:
pc_invalid = (px_invalid / px_total) * 100.0
ar_invalid = px_invalid * px_area

# Set wet and dry values to nan, which will be used if insufficient pixels are observed
px_wet = float("nan")
# Calculate wet and dry pixel numbers and areas
px_wet = inputs.water.sum()
ar_wet = px_wet * px_area
px_dry = px_total - px_invalid - px_wet
ar_dry = px_dry * px_area

# Set pc_wet and pc_dry values to nan, which will be used if insufficient pixels are observed
pc_wet = float("nan")
ar_wet = float("nan")
px_dry = float("nan")
pc_dry = float("nan")
ar_dry = float("nan")

# If the proportion of the waterbody missing is less than 10%, calculate values for wet and dry
# If the proportion of the waterbody missing is less than 10%, calculate values for pc_wet and pc_dry
if pc_invalid <= 10.0:
px_wet = inputs.water.sum()
pc_wet = (px_wet / px_total) * 100.0
ar_wet = px_wet * px_area

px_dry = px_total - px_invalid - px_wet
pc_dry = 100.0 - pc_invalid - pc_wet
ar_dry = px_dry * px_area

# Return all calculated values
return xr.Dataset(
Expand Down

0 comments on commit 13ecbf5

Please sign in to comment.