dodola.core
Core logic for bias adjustment and downscaling
Math stuff and business logic goes here. This is the "business logic".
Functions:
Name | Description |
---|---|
adjust_analogdownscaling |
Apply QPLAD to downscale bias corrected output. |
adjust_quantiledeltamapping |
Apply QDM to adjust a range of years within a simulation. |
adjust_quantiledeltamapping_year |
Apply QDM to adjust a year within a simulation. |
apply_precip_ceiling |
Converts all precip values above a threshold to the threshold value, uniformly across space and time. |
apply_wet_day_frequency_correction |
Parameters |
dtr_floor |
Converts all diurnal temperature range (DTR) values strictly below a floor |
non_polar_dtr_ceiling |
Converts all non-polar (regions between the 60th south and north parallel) diurnal temperature range (DTR) values strictly above a ceiling |
standardize_gcm |
360 calendar conversion requires that there are no chunks in |
test_dtr_range |
Ensure DTR values are in a valid range |
test_for_nans |
Tests for presence of NaNs |
test_maximum_precip |
Tests that max precip is reasonable |
test_negative_values |
Tests for presence of negative values |
test_temp_range |
Ensure temperature values are in a valid range |
test_timesteps |
Tests that Dataset contains the correct number of timesteps (number of days on a noleap calendar) |
test_variable_names |
Test that the correct variable name exists in the file |
train_analogdownscaling |
Train Quantile-Preserving, Localized Analogs Downscaling (QPLAD) |
train_quantiledeltamapping |
Train quantile delta mapping |
xclim_convert_360day_calendar_interpolate |
Parameters |
xclim_remove_leapdays |
Parameters |
xclim_units_any2pint |
Parameters |
xclim_units_pint2cf |
Parameters |
xesmf_regrid |
Regrid a Dataset. |
dodola.core.adjust_analogdownscaling
adjust_analogdownscaling(simulation, qplad, variable)
Apply QPLAD to downscale bias corrected output.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation
|
Dataset
|
Daily bias corrected data to be downscaled. Target variable must have a units attribute. |
required |
qplad
|
Dataset or QuantilePreservingAnalogDownscaling
|
Trained |
required |
variable
|
str
|
Target variable in |
required |
Returns:
Name | Type | Description |
---|---|---|
out |
Dataset
|
QPLAD-downscaled values from |
Source code in dodola/core.py
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 |
|
dodola.core.adjust_quantiledeltamapping
adjust_quantiledeltamapping(simulation, variable, qdm, years, astype=None, quantile_variable='sim_q', **kwargs)
Apply QDM to adjust a range of years within a simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation
|
Dataset
|
Daily simulation data to be adjusted. Must have sufficient observations
around |
required |
variable
|
str
|
Target variable in |
required |
qdm
|
Dataset or QuantileDeltaMapping
|
Trained |
required |
years
|
sequence of ints
|
Years of simulation to adjust, with rolling years and day grouping. |
required |
astype
|
str, numpy.dtype, or None
|
Typecode or data-type to which the regridded output is cast. |
None
|
quantile_variable
|
str or None
|
Name of quantile coordinate to reset to data variable. Not reset
if |
'sim_q'
|
kwargs
|
Keyword arguments passed to
|
{}
|
Returns:
Name | Type | Description |
---|---|---|
out |
Dataset
|
QDM-adjusted values from |
Source code in dodola/core.py
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 |
|
dodola.core.adjust_quantiledeltamapping_year
adjust_quantiledeltamapping_year(simulation, qdm, year, variable, halfyearwindow_n=10, include_quantiles=False)
Apply QDM to adjust a year within a simulation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
simulation
|
Dataset
|
Daily simulation data to be adjusted. Must have sufficient observations
around |
required |
qdm
|
Dataset or QuantileDeltaMapping
|
Trained |
required |
year
|
int
|
Target year to adjust, with rolling years and day grouping. |
required |
variable
|
str
|
Target variable in |
required |
halfyearwindow_n
|
int
|
Half-length of the annual rolling window to extract along either
side of |
10
|
include_quantiles
|
bool
|
Whether or not to output quantiles (sim_q) as a coordinate on the bias corrected data variable in output. |
False
|
Returns:
Name | Type | Description |
---|---|---|
out |
Dataset
|
QDM-adjusted values from |
Source code in dodola/core.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
|
dodola.core.apply_precip_ceiling
apply_precip_ceiling(ds, ceiling)
Converts all precip values above a threshold to the threshold value, uniformly across space and time.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
ceiling
|
int or float
|
|
required |
Returns:
Type | Description |
---|---|
Dataset
|
|
Source code in dodola/core.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 |
|
dodola.core.apply_wet_day_frequency_correction
apply_wet_day_frequency_correction(ds, process, variable='pr')
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
process
|
(pre, post)
|
|
"pre"
|
variable
|
|
'pr'
|
Returns:
Type | Description |
---|---|
Dataset
|
|
Notes
[1] A.J. Cannon, S.R. Sobie, and T.Q. Murdock (2015), "Bias correction of GCM precipitation by quantile mapping: How well do methods preserve changes in quantiles and extremes?", Journal of Climate, vol. 28, Issue 7, pp. 6938-6959. [2] S. Hempel, K. Frieler, L. Warszawski, J. Schewe, and F. Piotek (2013), "A trend-preserving bias correction - The ISI-MIP approach", Earth Syst. Dynam. vol. 4, pp. 219-236.
Source code in dodola/core.py
529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 |
|
dodola.core.dtr_floor
dtr_floor(ds, floor)
Converts all diurnal temperature range (DTR) values strictly below a floor to that floor.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
floor
|
int or float
|
|
required |
Returns:
Type | Description |
---|---|
Dataset
|
|
Source code in dodola/core.py
573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 |
|
dodola.core.non_polar_dtr_ceiling
non_polar_dtr_ceiling(ds, ceiling)
Converts all non-polar (regions between the 60th south and north parallel) diurnal temperature range (DTR) values strictly above a ceiling to that ceiling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
ceiling
|
int or float
|
|
required |
Returns:
Type | Description |
---|---|
Dataset
|
|
Source code in dodola/core.py
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
|
dodola.core.standardize_gcm
standardize_gcm(ds, leapday_removal=True)
360 calendar conversion requires that there are no chunks in
the 'time' dimension of ds
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
leapday_removal
|
bool
|
|
True
|
Returns:
Type | Description |
---|---|
Dataset
|
|
Source code in dodola/core.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 |
|
dodola.core.test_dtr_range
test_dtr_range(ds, var, data_type)
Ensure DTR values are in a valid range Test polar values separately since some polar values can be much higher post bias adjustment.
Source code in dodola/core.py
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 |
|
dodola.core.test_for_nans
test_for_nans(ds, var)
Tests for presence of NaNs
Source code in dodola/core.py
637 638 639 640 641 |
|
dodola.core.test_maximum_precip
test_maximum_precip(ds, var)
Tests that max precip is reasonable
Source code in dodola/core.py
782 783 784 785 786 787 788 789 790 791 792 793 794 795 |
|
dodola.core.test_negative_values
test_negative_values(ds, var)
Tests for presence of negative values
Source code in dodola/core.py
773 774 775 776 777 778 779 |
|
dodola.core.test_temp_range
test_temp_range(ds, var)
Ensure temperature values are in a valid range
Source code in dodola/core.py
713 714 715 716 717 718 719 720 721 |
|
dodola.core.test_timesteps
test_timesteps(ds, data_type, time_period)
Tests that Dataset contains the correct number of timesteps (number of days on a noleap calendar) for the data_type/time_period combination.
Source code in dodola/core.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 |
|
dodola.core.test_variable_names
test_variable_names(ds, var)
Test that the correct variable name exists in the file
Source code in dodola/core.py
706 707 708 709 710 |
|
dodola.core.train_analogdownscaling
train_analogdownscaling(coarse_reference, fine_reference, variable, kind, quantiles_n=620, window_n=31)
Train Quantile-Preserving, Localized Analogs Downscaling (QPLAD)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
coarse_reference
|
Dataset
|
Dataset to use as resampled (to fine resolution) coarse reference.Target variable must have a units attribute. |
required |
fine_reference
|
Dataset
|
Dataset to use as fine-resolution reference. Target variable must have a units attribute. |
required |
variable
|
str
|
Name of target variable to extract from |
required |
kind
|
('+', '*')
|
Kind of variable. Used for creating QPLAD adjustment factors. |
"+"
|
quantiles_n
|
int
|
Number of quantiles for QPLAD. |
620
|
window_n
|
int
|
Centered window size for day-of-year grouping. |
31
|
Returns:
Type | Description |
---|---|
QuantilePreservingAnalogDownscaling
|
|
Source code in dodola/core.py
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 |
|
dodola.core.train_quantiledeltamapping
train_quantiledeltamapping(reference, historical, variable, kind, quantiles_n=100, window_n=31)
Train quantile delta mapping
Parameters:
Name | Type | Description | Default |
---|---|---|---|
reference
|
Dataset
|
Dataset to use as model reference. Target variable must have a units attribute. |
required |
historical
|
Dataset
|
Dataset to use as historical simulation. Target variable must have a units attribute. |
required |
variable
|
str
|
Name of target variable to extract from |
required |
kind
|
('+', '*')
|
Kind of variable. Used for QDM scaling. |
"+"
|
quantiles_n
|
int
|
Number of quantiles for QDM. |
100
|
window_n
|
int
|
Centered window size for day-of-year grouping. |
31
|
Returns:
Type | Description |
---|---|
QuantileDeltaMapping
|
|
Source code in dodola/core.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|
dodola.core.xclim_convert_360day_calendar_interpolate
xclim_convert_360day_calendar_interpolate(ds, target='noleap', align_on='random', interpolation='linear', return_indices=False, ignore_nans=True)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
target
|
str
|
see xclim.core.calendar.convert_calendar |
'noleap'
|
align_on
|
str
|
this determines which days in the calendar will have missing values or will be the product of interpolation, if there is. It could be every year the same calendar days, or the days could randomly change. see xclim.core.calendar.convert_calendar |
'random'
|
interpolation
|
None or str
|
passed to xr.Dataset.interpolate_na if not None |
'linear'
|
return_indices
|
bool
|
on top of the converted dataset, return a list of the array indices identifying values that were inserted. This assumes there were no NaNs before conversion. |
False
|
ignore_nans
|
bool
|
if False and there are any NaNs in |
True
|
Returns:
Type | Description |
---|---|
tuple(xr.Dataset, xr.Dataset) if return_indices is True, xr.Dataset otherwise.
|
|
Notes
The default values of target
, align_on
and interpolation
mean that our default approach is equivalent to that of the LOCA
calendar conversion [1] for conversion from 360 days calendars to noleap calendars. In that approach, 5 calendar days are added (noleap
calendars always have 365 days) to each year. But those calendar days are not necessarily those that will have their value be the product
of interpolation. The days for which we interpolate are selected randomly every block of 72 days, so that they change every year.
[1] http://loca.ucsd.edu/loca-calendar/
Source code in dodola/core.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 |
|
dodola.core.xclim_remove_leapdays
xclim_remove_leapdays(ds)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
Returns:
Type | Description |
---|---|
Dataset
|
|
Source code in dodola/core.py
450 451 452 453 454 455 456 457 458 459 460 461 462 |
|
dodola.core.xclim_units_any2pint
xclim_units_any2pint(ds, var)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
var
|
str
|
|
required |
Returns:
Type | Description |
---|---|
xr.Dataset with `var` units str attribute converted to xclim's pint registry format
|
|
Source code in dodola/core.py
415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 |
|
dodola.core.xclim_units_pint2cf
xclim_units_pint2cf(ds, var)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ds
|
Dataset
|
|
required |
var
|
str
|
|
required |
Returns:
Type | Description |
---|---|
xr.Dataset with `var` units str attribute converted to CF format
|
|
Source code in dodola/core.py
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 |
|
dodola.core.xesmf_regrid
xesmf_regrid(x, domain, method, weights_path=None, astype=None, add_cyclic=None, keep_attrs=True)
Regrid a Dataset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x
|
Dataset
|
|
required |
domain
|
Dataset
|
Domain to regrid to. |
required |
method
|
str
|
Method of regridding. Passed to |
required |
weights_path
|
str
|
Local path to netCDF file of pre-calculated XESMF regridding weights. |
None
|
astype
|
str, numpy.dtype, or None
|
Typecode or data-type to which the regridded output is cast. |
None
|
add_cyclic
|
str, or None
|
Add cyclic point (aka wrap-around pixel) to given dimension before regridding. Useful for avoiding dateline artifacts along longitude in global datasets. |
None
|
keep_attrs
|
bool
|
Whether to pass attrs from input to regridded output. |
True
|
Returns:
Type | Description |
---|---|
Dataset
|
|
Source code in dodola/core.py
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|