Skip to content

Commit b5ae616

Browse files
authored
Merge pull request #158 from dgergel/update_wdf_correction
Update wdf correction
2 parents 0621b92 + 0b35fba commit b5ae616

File tree

3 files changed

+20
-17
lines changed

3 files changed

+20
-17
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
66

77
## [Unreleased]
88
### Changed
9+
- Update wet day frequency correction to include small negative values in correction and to limit the correction range to the threshold * 10 ^ -2. (PR #158, @dgergel)
910
- Update package setup, README, HISTORY/CHANGELOG to new system. (PR #154, @brews)
1011

1112
## [0.13.0] - 2021-12-17

dodola/core.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -535,9 +535,13 @@ def apply_wet_day_frequency_correction(ds, process):
535535
28, Issue 7, pp. 6938-6959.
536536
"""
537537
threshold = 0.05 # mm/day
538-
low = 1e-16
538+
# adjusted "low" value from the original epsilon in Cannon et al 2015 to
539+
# avoid having some values get extremely large
540+
low = threshold * pow(10, -2)
541+
539542
if process == "pre":
540-
ds_corrected = ds.where(ds != 0.0, np.random.uniform(low=low, high=threshold))
543+
# includes very small values that are negative in CMIP6 output
544+
ds_corrected = ds.where(ds > 0.0, np.random.uniform(low=low, high=threshold))
541545
elif process == "post":
542546
ds_corrected = ds.where(ds >= threshold, 0.0)
543547
else:
@@ -761,14 +765,19 @@ def _test_negative_values(ds, var):
761765
Tests for presence of negative values
762766
"""
763767
# this is not set to 0 to deal with floating point error
764-
assert ds[var].where(ds[var] < -0.001).count() == 0, "there are negative values!"
768+
neg_values = ds[var].where(ds[var] < -0.001).count()
769+
assert neg_values == 0, "there are {} negative values!".format(neg_values)
765770

766771

767772
def _test_maximum_precip(ds, var):
768773
"""
769774
Tests that max precip is reasonable
770775
"""
771776
threshold = 2000 # in mm, max observed is 1.825m --> maximum occurs between 0.5-0.8
777+
max_precip = ds[var].max()
778+
num_precip_values_over_threshold = ds[var].where(ds[var] > threshold).count()
772779
assert (
773-
ds[var].where(ds[var] > threshold).count() == 0
774-
), "maximum precip exceeds 2000mm"
780+
num_precip_values_over_threshold == 0
781+
), "maximum precip is {} mm and there are {} values over 2000mm".format(
782+
max_precip, num_precip_values_over_threshold
783+
)

dodola/tests/test_services.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -747,19 +747,12 @@ def test_correct_wet_day_frequency(process):
747747
ds_precip_corrected = repository.read(out_url)
748748

749749
if process == "pre":
750-
# all 0 values should have been set to a random uniform value below 0.05
751-
assert (
752-
ds_precip_corrected["fakevariable"].where(
753-
ds_precip["fakevariable"] == 0, drop=True
754-
)
755-
!= 0.0
756-
)
757-
assert (
758-
ds_precip_corrected["fakevariable"].where(
759-
ds_precip["fakevariable"] == 0, drop=True
760-
)
761-
< threshold
750+
# all 0s and very small negative values should have been set to a random uniform value below 0.05
751+
corrected_values = ds_precip_corrected["fakevariable"].where(
752+
ds_precip["fakevariable"] <= 0, drop=True
762753
)
754+
assert corrected_values > 0.0
755+
assert corrected_values < threshold
763756
elif process == "post":
764757
# all values below 0.05 should be reset to 0
765758
assert (

0 commit comments

Comments
 (0)