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

PresRat correction #215

Open
wants to merge 78 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
78 commits
Select commit Hold shift + click to select a range
d88de6f
Initializing PresRat with reference
castelao Apr 23, 2024
3d6f9ae
feat: ZeroRateMixin()
castelao Apr 23, 2024
8d3fb02
refact: Moving ZeroRateMixin to mixins
castelao May 24, 2024
c8ad983
Adding ipython into dev environment
castelao May 24, 2024
86ac9cf
fix: ZeroRateMixin shouldn't inherit DataRetrievalBase
castelao May 24, 2024
a91dad7
refact: Moving PresRat to qdm sub-module
castelao May 24, 2024
41504a0
fix: Use the given threshold (it was hardcoded before)
castelao May 24, 2024
1686520
PresRat using ZeroRateMixin
castelao May 24, 2024
b92ec3c
doc: Explicit steps for PresRat
castelao May 27, 2024
720848d
Prototype for quantiles on time windows
castelao May 28, 2024
b173b6c
fix: Missing load PresRat at module
castelao May 28, 2024
72ebb5e
Overwritting QDM methods for PresRat requirements
castelao Jun 3, 2024
67a3387
Don't need to overwrite __init__ if defining threshold in the runtime
castelao Jun 3, 2024
d53d8b6
doc: More details on what is PresRat
castelao Jun 3, 2024
cf16c82
Testing apply_zero_precipitation_rate()
castelao Jun 6, 2024
41baa19
test: zero_precipitation_rate()
castelao Jun 11, 2024
a1d484a
test: presrat_zero_rate with multiple thresholds
castelao Jun 12, 2024
d3a7ba4
fix, doc: Typo 'monthly'
castelao Jun 12, 2024
3ea12ee
test: apply_zero_precipitation_rate()
castelao Jun 13, 2024
d3a9d3f
test: Minimalist check for test_presrat_transform()
castelao Jun 13, 2024
5d9a09d
test: parallel results must equal serial
castelao Jun 13, 2024
6a89536
style: Fixing code style
castelao Jun 17, 2024
4461c41
test: test_presrat_transform_nochanges()
castelao Jun 20, 2024
df92e2c
test: Missing to update PresRat standard params for testing
castelao Jun 20, 2024
35931a3
test: Adding back a small noise on future projections
castelao Jun 20, 2024
5f414b3
test: Defining some resources used in the tests
castelao Jun 20, 2024
1074746
clean, test:
castelao Jun 20, 2024
5d172f3
test: test_presrat_zero_rate with multiple thresholds
castelao Jun 20, 2024
6b67870
test, clean: Combining tests
castelao Jun 20, 2024
d5b8647
test: A fixture with fut_cc dataset itself for efficiency
castelao Jun 20, 2024
1353350
test: Standard presrat transform test with dataset from memory
castelao Jun 20, 2024
59d8b2d
test: test_presrat_transform_nozerochanges()
castelao Jun 20, 2024
1fa54db
test: test_presrat_transform_nochanges() working
castelao Jun 20, 2024
5968726
style:
castelao Jun 20, 2024
88ce7c8
test, doc: test_presrat_transform_nochanges()
castelao Jun 20, 2024
68ab5ab
Saving used threshold in metadata
castelao Jun 21, 2024
65f54c9
Entry point for presrat functions
castelao Jun 21, 2024
98c839d
feat: apply_zero_precipitation_rate()
castelao Jun 21, 2024
6a766d7
feat: get_spatial_bc_presrat()
castelao Jun 21, 2024
b0c5beb
fix, test: test_presrat_transform_nochanges()
castelao Jun 21, 2024
bdab03d
feat: Saving requirements to estimate K factor
castelao Jun 21, 2024
f8c88e3
Adding time indices
castelao Jun 21, 2024
7cafe23
fix: zero_precipitation_rate() dealing with NaN
castelao Jun 21, 2024
b17b8d1
refact: Moved apply_zero_precipitation_rate() into bias_tranforms
castelao Jun 21, 2024
9140482
fix: Missing to load xarray
castelao Jun 21, 2024
0a69638
refact: get_spatial_bc_quantiles returing params as dict
castelao Jun 24, 2024
a68fa7a
feat: local_presrat_bc()
castelao Jun 24, 2024
757e0b0
style: Mostly moving to single quote which is the standard used in sup3r
castelao Jun 24, 2024
e0d8c56
test, clean: PresRat tests were already moved into its own module
castelao Jun 24, 2024
dd26ec4
Locking numpy to < 2.0
castelao Jun 24, 2024
ca9123a
doc: Updating one-line description of PresRat
castelao Jun 24, 2024
24e47d8
test: Updating fut_cc_notrend() to match the 'resource'
castelao Jun 24, 2024
3f46c69
test, doc: Better explaing the expected effect of NaNs
castelao Jun 24, 2024
0571a14
feat: PresRat.write_outputs()
castelao Jun 24, 2024
d869c31
fix, doc: Weird string literal issue
castelao Jun 24, 2024
2fae27d
style: Sorting imports
castelao Jun 24, 2024
82a9814
test, doc: More info in PresRat tests
castelao Jun 24, 2024
8b402ea
test: Improving test_presrat_calc()
castelao Jun 24, 2024
9dd55e9
test, refact: Combining tests
castelao Jun 24, 2024
5a439ac
style: Code formating
castelao Jun 24, 2024
7ebbe87
test, refact: Conforming normalizing dataset
castelao Jun 24, 2024
0657edc
style: Missing space
castelao Jun 24, 2024
a98838a
fix, feat: Missing to include presrat_notrend_params()
castelao Jun 24, 2024
de068e5
style: Unused import
castelao Jun 24, 2024
b87c747
test, fix: Missing a few fixtures
castelao Jun 24, 2024
fa32ff8
doc: Missing documentation on testing functions
castelao Jun 24, 2024
c9169c4
test: Global zero rate threshold (ZR_THRESHOLD)
castelao Jun 24, 2024
b5f6d94
clean: Removing ideas for later
castelao Jun 24, 2024
9647c53
Bump Python to 3.11.9
castelao Jun 25, 2024
66376f2
style: Conforming with sup3r style
castelao Jun 26, 2024
bd026d1
style: UP039
castelao Jul 1, 2024
c35f911
fix: Wrong type
castelao Jul 1, 2024
6679323
doc: local_presrat_bc()
castelao Jul 1, 2024
d6ffc84
style: E741 - ambiguous-variable-name
castelao Jul 1, 2024
5822e3a
cfg: Adding UP039 as fixable
castelao Jul 1, 2024
ec26101
style: Fixing notes to conform with numpydoc
castelao Jul 1, 2024
b1ef3b9
doc: Adding TODO label
castelao Jul 1, 2024
8a5d7b7
style: missing-trailing-comma
castelao Jul 1, 2024
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
Prev Previous commit
Next Next commit
refact: Moving PresRat to qdm sub-module
  • Loading branch information
castelao committed Jul 1, 2024
commit a91dad7cd1e7c5c80167ee2c529bf50316c13b9f
16 changes: 0 additions & 16 deletions sup3r/bias/bias_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -1092,22 +1092,6 @@ def get_linear_correction(bias_data, base_data, bias_feature, base_dset):
return out


class PresRat(DataRetrievalBase):
"""PresRat bias correction method (precipitation)

The PresRat correction is defined as the combination of using the
model-predicted change ratio, the treatment of zero-precipitation days,
and the final correction factor (K) [Pierce2015]_.

References
----------
.. [Pierce2015] Pierce, D. W., Cayan, D. R., Maurer, E. P., Abatzoglou, J.
T., & Hegewisch, K. C. (2015). Improved bias correction techniques for
hydrological simulations of climate change. Journal of Hydrometeorology,
16(6), 2421-2442.
"""


class SkillAssessment(MonthlyLinearCorrection):
"""Calculate historical skill of one dataset compared to another."""

Expand Down
45 changes: 45 additions & 0 deletions sup3r/bias/qdm.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,3 +495,48 @@ def run(self,
self.write_outputs(fp_out, self.out)

return copy.deepcopy(self.out)


class PresRat(QuantileDeltaMappingCorrection):
"""PresRat bias correction method (precipitation)

The PresRat correction is defined as the combination of using the
model-predicted change ratio, the treatment of zero-precipitation days,
and the final correction factor (K) [Pierce2015]_.

References
----------
.. [Pierce2015] Pierce, D. W., Cayan, D. R., Maurer, E. P., Abatzoglou, J.
T., & Hegewisch, K. C. (2015). Improved bias correction techniques for
hydrological simulations of climate change. Journal of Hydrometeorology,
16(6), 2421-2442.
# Todo:
# - Identify Z_gf. (0.01 mm) Also have to save on output params
# - Estimate K = <x> / <hat{x}>
"""

def correction_factor():
"""Preserve the mean precipitation change (K factor)

When bias correcting, the mean can fall in a different quantile, thus
modifying the corrected mean if the shape of the distribution changes.
That effect is more pronounced in skewed distributions, such as
precipitation.
"""
pass
self.bias_dh.bias_ti

def dev():
# Estimate means per month. Later will split this into resolution (n
# of chunks and window width such as 30 days) and end up with one
# value per month to be used later as the K numberator.
t = self.base_dh.time_index
t.month

base_data, base_ti = cls.get_base_data(base_fps,
base_dset,
base_gid,
base_handler,
daily_reduction=daily_reduction,
decimals=decimals,
base_dh_inst=base_dh_inst)