Explore Module
High-level analysis and visualization tools for climate data exploration.
Overview
The climakitae.explore module provides user-friendly classes and functions for climate data analysis, including:
- Warming level analysis — Analyze data by global warming thresholds
- Time series visualization — Plot multi-model ensemble trends
- Uncertainty quantification — CMIP6 ensemble analysis
- Threshold analysis — Climate threshold and exceedance analysis
- Typical meteorological year — TMY analysis for engineering applications
- Vulnerability assessment — Climate vulnerability analysis tools
Warming Levels
High-level container for the warming levels analysis workflow.
Orchestrates data retrieval, GWL-window slicing, optional anomaly computation, and optional in-memory loading for all available warming levels.
Attributes:
| Name | Type | Description |
|---|---|---|
wl_params |
WarmingLevelChoose
|
Parameter panel that controls variable, resolution, window size, and other query options. |
warming_levels |
list of float
|
Warming level thresholds derived from the GWL lookup table. |
gwl_times |
DataFrame or None
|
Lookup table mapping each simulation/scenario combination to the
calendar year it crosses each warming level. Populated by
:py:meth: |
catalog_data |
DataArray or None
|
Raw stacked data retrieved from the catalog. Populated by
:py:meth: |
sliced_data |
dict of {str: xarray.DataArray}
|
Mapping from warming level string (e.g. |
gwl_snapshots |
DataArray
|
Time-mean snapshots for every warming level, concatenated along a
|
Examples:
>>> wl = WarmingLevels()
>>> wl.wl_params.variable = "Maximum air temperature at 2m"
>>> wl.calculate() # blocks until all levels are computed
>>> snapshot_2deg = wl.gwl_snapshots.sel(warming_level="2.0")
Source code in climakitae/explore/warming.py
find_warming_slice(level, gwl_times)
Slice catalog data to the window around a single warming level.
Groups catalog_data by all_sims, calls :py:func:get_sliced_data
for every simulation, then cleans and relabels the result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
level
|
str
|
Warming level threshold to slice around, e.g. |
required |
gwl_times
|
DataFrame
|
GWL lookup table produced by :py:meth: |
required |
Returns:
| Type | Description |
|---|---|
DataArray
|
DataArray with an expanded |
Source code in climakitae/explore/warming.py
calculate()
Run the full warming levels pipeline and populate instance attributes.
Retrieves catalog data using wl_params, stacks simulations and
scenarios, removes invalid combinations, then iterates over every
warming level to produce time-windowed slices and time-mean snapshots.
Results are stored in-place:
catalog_data— raw stacked DataArraysliced_data— dict mapping level → windowed DataArraygwl_snapshots— concatenated time-mean DataArray
Notes
Progress is reported via a :py:class:tqdm progress bar, one tick per
warming level. If wl_params.load_data is True, each slice is
loaded into memory before moving to the next level.
Source code in climakitae/explore/warming.py
Time Series Visualization
Holds the instance of TimeSeriesParameters that is used for the following purposes: 1) to display a panel that previews various time-series transforms (explore), and 2) to save the transform represented by the current state of that preview into a new variable (output_current).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
Time series array with no spatial coordinates. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
choices |
TimeSeriesParameters
|
Param object containing time series data and analysis parameters. |
Source code in climakitae/explore/timeseries.py
output_current()
Output the current attributes of the class to a DataArray object. Allows the data to be easily accessed by the user after modifying the attributes directly in the explore panel, for example.
Returns:
| Type | Description |
|---|---|
DataArray
|
|
Source code in climakitae/explore/timeseries.py
Uncertainty Analysis (CMIP Ensemble Optimization)
A class for holding relevant data options for cmip preprocessing
Attributes:
| Name | Type | Description |
|---|---|---|
variable |
str
|
variable name, cf-compliant (or cmip6 variable name) |
area_subset |
str
|
geographic boundary name (states/counties) |
location |
str
|
geographic area name (name of county/state) |
timescale |
str
|
frequency of data |
area_average |
bool
|
average computed across domain |
Methods:
| Name | Description |
|---|---|
_cmip_clip |
CMIP6-specific subsetting |
Source code in climakitae/explore/uncertainty.py
Typical Meteorological Year
Encapsulate the code needed to generate Typical Meteorological Year (TMY) files.
Uses WRF hourly data to produce TMYs. User provides the start and end years along with location to generate file.
How to set location: The location can either be provided as latitude and
longitude coordinates or as the name of a HadISD station in California. Do not set
latitude and longitude if using a HadISD station. If latitude and longitude
are set along with a custom value for station_name (NOT a HadISD station), the
custom station name will be used in file headers where appropriate.
How to set time period: The time period can either be set with a time approach using
start_year and end_year or with a warming level approach using warming_level.
If the warming level approach is used, a 30-year period is obtained centered around
the given warming level and the start and end years are taken for that warming level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_year
|
str
|
Initial year of TMY period (time approach) |
UNSET
|
end_year
|
str
|
Final year of TMY period (time approach) |
UNSET
|
warming_level
|
float | int
|
Desired warming level (warming level approach) |
UNSET
|
station_name
|
str
|
Long name of desired station |
UNSET
|
latitude
|
float | int(optional)
|
Latitude for TMY data if station_name not set |
UNSET
|
longitude
|
float | int(optional)
|
Longitude for TMY data if station_name not set |
UNSET
|
reanalysis
|
bool
|
True to use ERA5 reanalysis instead of models |
False
|
verbose
|
bool
|
True to increase verbosity |
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
start_year |
str
|
Initial year of TMY period |
end_year |
str
|
Final year of TMY period |
warming_level |
float | int
|
Warming level value |
lat_range |
tuple
|
Pair of latitudes that bracket |
lon_range |
tuple
|
Pair of longitudes that bracket |
reanalysis |
bool
|
True to use ERA5 reanalysis instead of models |
simulations |
list[str]
|
List of included simulations |
scenario |
list[str]
|
List of scenarios |
vars_and_units |
dict[str, str]
|
Dictionary of all required variables and units |
verbose |
bool
|
True to increase verbosity |
cdf_climatology |
Dataset
|
CDF climatology data |
cdf_monthly |
Dataset
|
CDF monthly data by model |
weighted_fs_sum |
Dataset
|
Weighted F-S statistic results |
top_months |
DataFrame
|
Table of top months by model |
all_vars |
Dataset
|
All loaded variables for TMY |
tmy_data_to_export |
dict[Dataframe]
|
Dictionary of TMY results by simulation |
_skip_last |
bool
|
Internal flag to track last year for warming level approach |
Source code in climakitae/explore/typical_meteorological_year.py
512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 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 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 | |
load_all_variables()
Load hourly TMY variables and derive daily statistics for CDF/F-S.
Fetches hourly raw variables via ClimateData for the 8760 profile assembly, then derives ALL daily statistics from the hourly data in local time. This matches the original TMY code's approach and avoids two problems with fetching daily catalog variables directly:
- UTC vs local time: Catalog daily variables are pre-aggregated over UTC day boundaries, which differ from local-time days by the station's UTC offset (e.g., 8 hours for California).
- Non-determinism: With a Dask distributed client active, lazy
reductions (
.resample().sum()) can produce slightly different floating-point results on each run due to non-deterministic task ordering. Computing hourly data eagerly to numpy before resampling guarantees deterministic daily statistics.
Source code in climakitae/explore/typical_meteorological_year.py
957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 | |
set_cdf_climatology()
Calculate the long-term climatology for each index for each month so we can establish the baseline pattern.
Source code in climakitae/explore/typical_meteorological_year.py
set_cdf_monthly()
Get CDF for each month and variable.
Source code in climakitae/explore/typical_meteorological_year.py
set_weighted_statistic()
Calculate the weighted F-S statistic.
Source code in climakitae/explore/typical_meteorological_year.py
set_top_months()
Calculate top months dataframe.
Source code in climakitae/explore/typical_meteorological_year.py
show_tmy_data_to_export(simulation)
Show line plots of TMY data for single model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
str
|
Simulation to display. |
required |
Source code in climakitae/explore/typical_meteorological_year.py
run_tmy_analysis()
Generate typical meteorological year data.
Output will be a list of dataframes per simulation. Print statements throughout the function indicate progress.
Notes
Results are saved to the class variable tmy_data_to_export.
Source code in climakitae/explore/typical_meteorological_year.py
1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 | |
export_tmy_data(extension='epw')
Write TMY data to EPW file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extension
|
str
|
Desired file extension ('tmy','epw', or 'csv') |
'epw'
|
Source code in climakitae/explore/typical_meteorological_year.py
get_candidate_months()
Run CDF functions to get top candidates.
This function can be used to view the candidate months without running the entire TMY workflow.
Source code in climakitae/explore/typical_meteorological_year.py
generate_tmy()
Run the whole TMY workflow.
Source code in climakitae/explore/typical_meteorological_year.py
Extreme Meteorological Year
Functions for Shock and Persistence Extreme Meteorological Year creation.
shock_XMY(extreme=UNSET, start_year=UNSET, end_year=UNSET, warming_level=UNSET, station_name=UNSET, latitude=UNSET, longitude=UNSET, reanalysis=False, verbose=True)
Encapsulate the code needed to generate Typical Meteorological Year (shock XMY) files.
Uses WRF hourly data to produce shock XMYs. User provides the start and end years along with location to generate file.
How to set location: The location can either be provided as latitude and
longitude coordinates or as the name of a HadISD station in California. Do not set
latitude and longitude if using a HadISD station. If latitude and longitude
are set along with a custom value for station_name (NOT a HadISD station), the
custom station name will be used in file headers where appropriate.
How to set time period: The time period can either be set with a time approach using
start_year and end_year or with a warming level approach using warming_level.
If the warming level approach is used, a 30-year period is obtained centered around
the given warming level and the start and end years are taken for that warming level.
How to set extreme: The extreme can either be set as 'hot' or 'cold'. The 'hot' extreme corresponds to extreme events like heat waves, while the 'cold' extreme corresponds to extreme evens like cold snaps.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extreme
|
str
|
Type of shock extreme |
UNSET
|
start_year
|
str
|
Initial year of XMY period (time approach) |
UNSET
|
end_year
|
str
|
Final year of XMY period (time approach) |
UNSET
|
warming_level
|
float | int
|
Desired warming level (warming level approach) |
UNSET
|
station_name
|
str
|
Long name of desired station |
UNSET
|
latitude
|
float | int(optional)
|
Latitude for shock XMY data if station_name not set |
UNSET
|
longitude
|
float | int(optional)
|
Longitude for shock XMY data if station_name not set |
UNSET
|
reanalysis
|
bool
|
True to use ERA5 reanalysis instead of models |
False
|
verbose
|
bool
|
True to increase verbosity |
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
extreme |
str
|
extreme type, either "hot" or "cold" |
start_year |
str
|
Initial year of shock XMY period |
end_year |
str
|
Final year of shock XMY period |
warming_level |
float | int
|
Warming level value |
lat_range |
tuple
|
Pair of latitudes that bracket |
lon_range |
tuple
|
Pair of longitudes that bracket |
reanalysis |
bool
|
True to use ERA5 reanalysis instead of models |
simulations |
list[str]
|
List of included simulations |
scenario |
list[str]
|
List of scenarios |
vars_and_units |
dict[str, str]
|
Dictionary of all required variables and units |
verbose |
bool
|
True to increase verbosity |
cdf_climatology |
Dataset
|
CDF climatology data |
cdf_monthly |
Dataset
|
CDF monthly data by model |
top_months |
DataFrame
|
Table of top months by model |
all_vars |
Dataset
|
All loaded variables for shock XMY |
air_temp_vars |
Dataset
|
Air temperature variables, for use in finding candidate months |
xmy_data_to_export |
dict[Dataframe]
|
Dictionary of shock XMY results by simulation |
_skip_last |
bool
|
Internal flag to track last year for warming level approach |
Source code in climakitae/explore/extreme_meteorological_year.py
264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 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 326 327 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 | |
load_all_variables()
Load hourly shock XMY variables and derive daily statistics.
Fetches hourly raw variables via ClimateData for the 8760 profile assembly, then derives ALL daily statistics from the hourly data in local time. This approach avoids two problems with fetching daily catalog variables directly:
- UTC vs local time: Catalog daily variables are pre-aggregated over UTC day boundaries, which differ from local-time days by the station's UTC offset (e.g., 8 hours for California).
- Non-determinism: With a Dask distributed client active, lazy
reductions (
.resample().sum()) can produce slightly different floating-point results on each run due to non-deterministic task ordering. Computing hourly data eagerly to numpy before resampling guarantees deterministic daily statistics.
Source code in climakitae/explore/extreme_meteorological_year.py
719 720 721 722 723 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 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 | |
set_cdf_climatology()
Calculate the long-term climatology for each index for each month so we can establish the baseline pattern.
Source code in climakitae/explore/extreme_meteorological_year.py
set_cdf_monthly()
Get CDF for each month and variable.
Source code in climakitae/explore/extreme_meteorological_year.py
set_top_months()
Calculate top months dataframe.
Source code in climakitae/explore/extreme_meteorological_year.py
show_xmy_data_to_export(simulation)
Show line plots of shock XMY data for single model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
str
|
Simulation to display. |
required |
Source code in climakitae/explore/extreme_meteorological_year.py
run_xmy_analysis()
Generate shock extreme meteorological year data.
Output will be a list of dataframes per simulation. Print statements throughout the function indicate progress.
Notes
Results are saved to the class variable xmy_data_to_export.
Source code in climakitae/explore/extreme_meteorological_year.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 | |
export_xmy_data(extension='epw')
Write XMY data to EPW file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extension
|
str
|
Desired file extension ('tmy','epw', or 'csv') |
'epw'
|
Source code in climakitae/explore/extreme_meteorological_year.py
get_candidate_months()
Run CDF functions to get top candidates.
This function can be used to view the candidate months without running the entire shock XMY workflow.
Source code in climakitae/explore/extreme_meteorological_year.py
generate_xmy()
Run the whole XMY workflow.
Source code in climakitae/explore/extreme_meteorological_year.py
persistence_XMY(q=UNSET, start_year=UNSET, end_year=UNSET, warming_level=UNSET, station_name=UNSET, latitude=UNSET, longitude=UNSET, reanalysis=False, verbose=True)
Encapsulate the code needed to generate Persistence Extreme Meteorological Year (persistence XMY) files.
Uses WRF hourly data to produce persistence XMYs. User provides the start and end years along with location to generate file.
How to set location: The location can either be provided as latitude and
longitude coordinates or as the name of a HadISD station in California. Do not set
latitude and longitude if using a HadISD station. If latitude and longitude
are set along with a custom value for station_name (NOT a HadISD station), the
custom station name will be used in file headers where appropriate.
How to set time period: The time period can either be set with a time approach using
start_year and end_year or with a warming level approach using warming_level.
If the warming level approach is used, a 30-year period is obtained centered around
the given warming level and the start and end years are taken for that warming level.
How to set extreme: The extreme is defined by the quantile value, q, and can be a value betwee 0 and 1. For example, q=0.10 will produce a cold extreme, while a q=0.90 will produce a hot extreme.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
q
|
float
|
Extreme quantile |
UNSET
|
start_year
|
str
|
Initial year of XMY period (time approach) |
UNSET
|
end_year
|
str
|
Final year of XMY period (time approach) |
UNSET
|
warming_level
|
float | int
|
Desired warming level (warming level approach) |
UNSET
|
station_name
|
str
|
Long name of desired station |
UNSET
|
latitude
|
float | int(optional)
|
Latitude for persistence XMY data if station_name not set |
UNSET
|
longitude
|
float | int(optional)
|
Longitude for persistence XMY data if station_name not set |
UNSET
|
verbose
|
bool
|
True to increase verbosity |
True
|
Attributes:
| Name | Type | Description |
|---|---|---|
q |
float
|
extreme quantile, ranging from 0 to 1 |
start_year |
str
|
Initial year of persistence XMY period |
end_year |
str
|
Final year of persistence XMY period |
warming_level |
float | int
|
Warming level value |
lat_range |
tuple
|
Pair of latitudes that bracket |
lon_range |
tuple
|
Pair of longitudes that bracket |
reanalysis |
bool
|
True to use ERA5 reanalysis |
simulations |
list[str]
|
List of included simulations |
scenario |
list[str]
|
List of scenarios |
vars_and_units |
dict[str, str]
|
Dictionary of all required variables and units |
verbose |
bool
|
True to increase verbosity |
top_hours |
DataFrame
|
Table of top months by model |
all_vars |
Dataset
|
All loaded variables for persistence XMY |
air_temp |
Dataset
|
Air temperature, for use in finding candidate hours |
xmy_data_to_export |
dict[Dataframe]
|
Dictionary of persistence XMY results by simulation |
_skip_last |
bool
|
Internal flag to track last year for warming level approach |
Source code in climakitae/explore/extreme_meteorological_year.py
1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 | |
load_all_variables()
Load hourly persistence XMY variables and derive daily statistics.
Fetches hourly raw variables via ClimateData for the 8760 profile assembly, then derives ALL daily statistics from the hourly data in local time. This approach avoids two problems with fetching daily catalog variables directly:
- UTC vs local time: Catalog daily variables are pre-aggregated over UTC day boundaries, which differ from local-time days by the station's UTC offset (e.g., 8 hours for California).
- Non-determinism: With a Dask distributed client active, lazy
reductions (
.resample().sum()) can produce slightly different floating-point results on each run due to non-deterministic task ordering. Computing hourly data eagerly to numpy before resampling guarantees deterministic daily statistics.
Source code in climakitae/explore/extreme_meteorological_year.py
1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 | |
set_top_hours()
Calculate top months dataframe.
Source code in climakitae/explore/extreme_meteorological_year.py
show_xmy_data_to_export(simulation)
Show line plots of persistence XMY data for single model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation
|
str
|
Simulation to display. Use simulation names as defined in self.simuations |
required |
Source code in climakitae/explore/extreme_meteorological_year.py
run_xmy_analysis()
Generate persistence extreme meteorological year data.
Output will be a list of dataframes per simulation. Print statements throughout the function indicate progress.
Notes
Results are saved to the class variable xmy_data_to_export.
Source code in climakitae/explore/extreme_meteorological_year.py
2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 | |
export_xmy_data(extension='epw')
Write XMY data to EPW file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
extension
|
str
|
Desired file extension ('tmy','epw', or 'csv') |
'epw'
|
Source code in climakitae/explore/extreme_meteorological_year.py
get_candidate_hours()
Get top candidate hours.
This function can be used to view the candidate hours without running the entire persistence XMY workflow.
Source code in climakitae/explore/extreme_meteorological_year.py
generate_xmy()
Run the whole XMY workflow.
Source code in climakitae/explore/extreme_meteorological_year.py
find_hot_cold_extreme_from_median(sub_month, sub_clim, target=0.5, extreme='cold')
Identifies hottest or coldest year based on deviation from the median (CDF=0.5) temperature value across years.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sub_month
|
DataArray
|
dims: (year, data, bin_number) |
required |
sub_clim
|
DataArray
|
climatology with same structure |
required |
target
|
float
|
CDF level (default 0.5) |
0.5
|
extreme
|
str
|
"cold" -> pick minimum deviation "hot" -> pick maximum deviation |
'cold'
|
Returns:
| Name | Type | Description |
|---|---|---|
results |
list
|
median values per year |
worst_year |
scalar
|
identified extreme year |
Source code in climakitae/explore/extreme_meteorological_year.py
generate_candidate_months(cdf_monthly, cdf_climatology, extreme='cold', skip_last=False)
Run find_hot_cold_extreme_from_median() over entire input dataset. Generate a dataframe of selected years per month and simulation for input to XMY generation function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cdf_monthly
|
DataArray
|
Monthly CDF to compare against climatological CDF |
required |
cdf_climatology
|
DataArray
|
CDF representing climatology |
required |
extreme
|
str
|
The type of shock XMY. "cold" -> pick minimum deviation "hot" -> pick maximum deviation |
'cold'
|
skip_last
|
bool
|
True to exclude the final month, e.g. if data missing after time conversion |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
top_df |
dataframe of selected years per simulation and month
|
|
Source code in climakitae/explore/extreme_meteorological_year.py
persistence_get_top_hours(data, q=0.5, skip_last=False)
Selects a representative year for each hour using the Cal-Adapt Standard Year methodology, using hourly air temperature.
Computes the specified quantile for each hour of the year across all years, then selects the actual data value closest to that quantile (not interpolated), and returns the year that value was taken from for each of the 8760 hours (one year), for each simulation.
Constructs a table of years or per hour per simulation for use in persistence XMY generation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
Hourly air temperature with time and simulation dimensions. |
required |
q
|
float
|
Quantile value for selecting representative values (0.0 to 1.0). Default is 0.5 (median). |
0.5
|
skip_last
|
bool
|
True to exclude the final month, e.g. if data missing after time conversion |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standard year table for each warming level and simulation, with days of year as the index and hour of day as the columns. Multi-index columns include Hour, Warming_Level, and Simulation dimensions. |
Source code in climakitae/explore/extreme_meteorological_year.py
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 | |
Standard Year Profile
Calculates the Standard Year Climate Profiles using a warming level approach and designated quantiles. The historical baseline for relative profile computation is a warming level of 1.2 C. User specified warming level will be calculated relative to this baseline unless the "no_delta" option is set to True, in which case the raw profile(s) for the requested warming level(s) will be returned.
export_profile_to_csv(profile, **kwargs)
Export profile to csv file with a descriptive file name.
Each warming level is saved in a separate file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
DataFrame
|
Standard year profile with MultiIndex columns |
required |
**kwargs
|
dict
|
Keyword arguments for data selection. Allowed keys: variable : str Name of variable used in profile q : float Percentile used in profile global_warming_levels : list[float] List of global warming levels in profile warming_level_winow: int in range (5,25), optional Years around Global Warming Level (+/-) (e.g. 15 means a 30yr window) location : str, tuple(float | int), list[str | float | int] Station name, cached_area, or coordinates cached_area : str, optional Name of cached area used in profile no_delta : bool, default False, optional True if no_delta=True when generating profile approach (Optional) : str, "Warming Level" or "Time" The climate profile approach to use, either - "Time" (which is actually a warming level approach, but centered on an input) or - "Warming Level" (default) centered_year (Optional) : int in range [1980,2099] For approach="Time", the year for which to find a corresponding warming level time_profile_scenario (Optional) : str, default "SSP 3-7.0" SSP scenario from ["SSP 3-7.0", "SSP 2-4.5","SSP 5-8.5"] bias_adjusted_models (optional) : bool, default False, if True only return bias-adjusted WRF models |
{}
|
Source code in climakitae/explore/standard_year_profile.py
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 326 327 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 | |
retrieve_profile_data(**kwargs)
Backend function for retrieving data needed for computing climate profiles.
Reads in the full hourly data for the 8760 analysis, including all warming levels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
dict
|
Keyword arguments for data selection. Allowed keys: - variable (Optional) : str, default "Air Temperature at 2m" - resolution (Optional) : str, default "3 km" - approach (Optional) : str, "Warming Level" or "Time" - centered (Optional) : int - warming_levels (Optional) : List[float], default [1.2] - warming_level_window (Optional): int in range [5,25] - cached_area (Optional) : str or List[str] - latitude (Optional) : float or tuple - longitude (Optional) : float or tuple - stations (Optional) : list[str], default None - units (Optional) : str, default "degF" - no_delta (optional) : bool, default False, if True, do not retrieve historical data, return raw future profile - bias_adjusted_models (optional) : bool, default False, if True only return bias-adjusted WRF models |
{}
|
Returns:
| Type | Description |
|---|---|
Tuple[Dataset, Dataset]
|
(historic_data, future_data, get_data_params) - Historical data at 1.2°C warming, and future data at specified warming levels. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If invalid parameter keys are provided. |
Example
historic_data, future_data = retrieve_profile_data( ... variable="Air Temperature at 2m", ... resolution="45 km", ... time_profile_scenario="SSP 2-4.5", ... warming_level=[1.5, 2.0, 3.0], ... units="degF" ... )
historic_data, future_data = retrieve_profile_data( ... warming_level=[2.0] ... )
Notes
Historical data is always retrieved for warming level = 1.2°C. Future data uses user-specified warming levels or defaults.
The function prioritizes location parameters in the following order: 1. cached_area 2. latitude/longitude 3. stations Each parameter will override the lower-priority ones if provided. So if cached_area is given, lat/lon and stations are ignored. If lat/lon are given, stations are ignored. If stations are given, they are used only if neither cached_area nor lat/lon are provided.
If no location parameters are provided, a warning is issued about retrieving the entire CA dataset.
Source code in climakitae/explore/standard_year_profile.py
689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 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 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 | |
get_climate_profile(**kwargs)
High-level function to compute standard year climate profiles using warming level data.
This function retrieves climate data and computes standard year profiles using the 8760 analysis approach. It combines data retrieval and profile computation in a single call.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**kwargs
|
dict
|
Keyword arguments for data selection. Allowed keys: - variable (Optional) : str, default "Air Temperature at 2m" - resolution (Optional) : str, default "3 km" - approach (Optional) : str, "Warming Level" or "Time", default "Warming Level" - centered_year (Optional) : int - time_profile_scenario (Optional) : str, default "SSP 3-7.0" - warming_level (Required) : List[float], default [1.2] - warming_level_window (Optional): int in range [5,25], default 15 - location (Optional) : str, List[str|float|int], or Tuple[str|float|int] - units (Optional) : str, default "degF" - q (Optional) : float | list[float], default 0.5, quantile for profile calculation - no_delta (optional) : bool, default False, if True, do not apply baseline subtraction, return raw future profile - bias_adjusted_models (optional) : bool, default False, if True only return bias-adjusted WRF models |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standard year table for each warming level, with days of year as the index and hour of day as the columns. If multiple warming levels exist, they will be included as additional column levels. Units and metadata are preserved in the DataFrame's attrs dictionary. |
Examples:
>>> profile = get_climate_profile(
... variable="Air Temperature at 2m",
... warming_level=[1.5, 2.0, 3.0],
... units="degF"
... )
Source code in climakitae/explore/standard_year_profile.py
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 | |
compute_profile(data, q=0.5)
Calculates the standard year climate profile for warming level data using 8760 analysis.
This function handles global warming levels approach using time_delta coordinate. Processes all 30 years of warming level data centered around the year a warming level is reached, computes the specified quantile for each hour of the year across all years, then selects the actual data value closest to that quantile (not interpolated), and returns a characteristic profile of 8760 hours (one year) for each warming level and simulation combination.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
Hourly base-line subtracted data for one variable with warming_level, time_delta, and simulation dimensions. Expected to contain ~30 years (262,800 hours) of data for each warming level and simulation. |
required |
q
|
float
|
Quantile value for selecting representative values (0.0 to 1.0). Default is 0.5 (median). |
0.5
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Standard year table for each warming level and simulation, with days of year as the index and hour of day as the columns. Multi-index columns include Hour, Warming_Level, and Simulation dimensions. |
Source code in climakitae/explore/standard_year_profile.py
1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 | |
get_profile_units(profile_df)
Extract units information from a climate profile DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile_df
|
DataFrame
|
Climate profile DataFrame with units stored in attrs |
required |
Returns:
| Type | Description |
|---|---|
str
|
Units string, or 'Unknown' if not found |
Examples:
>>> profile = get_climate_profile(variable="Air Temperature at 2m", warming_level=[2.0])
>>> units = get_profile_units(profile)
>>> print(f"Temperature units: {units}")
Source code in climakitae/explore/standard_year_profile.py
get_profile_metadata(profile_df)
Extract all metadata from a climate profile DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile_df
|
DataFrame
|
Climate profile DataFrame with metadata stored in attrs |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing all available metadata |
Examples:
>>> profile = get_climate_profile(variable="Air Temperature at 2m", warming_level=[2.0])
>>> metadata = get_profile_metadata(profile)
>>> print(f"Variable: {metadata.get('variable_name')}")
>>> print(f"Units: {metadata.get('units')}")
>>> print(f"Method: {metadata.get('method')}")
Source code in climakitae/explore/standard_year_profile.py
set_profile_metadata(profile_df, metadata)
Set or update metadata in a climate profile DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile_df
|
DataFrame
|
Climate profile DataFrame to update |
required |
metadata
|
dict
|
Dictionary containing metadata key-value pairs to set |
required |
Returns:
| Type | Description |
|---|---|
None
|
The function modifies the DataFrame in place |
Examples:
>>> profile = get_climate_profile(variable="Air Temperature at 2m", warming_level=[2.0])
>>> new_metadata = {
... "source": "Custom Dataset",
... "author": "Jane Doe",
... "notes": "This profile was generated for testing purposes."
... }
>>> set_profile_metadata(profile, new_metadata)
>>> print(profile.attrs)
Source code in climakitae/explore/standard_year_profile.py
Climate Vulnerability Assessment
Bases: Parameterized
Climate Analysis and Vulnerability Assessment Parameters Class.
This class defines and validates parameters for climate vulnerability analysis, supporting various climate variables, metrics, and analysis approaches.
Attributes:
| Name | Type | Description |
|---|---|---|
input_locations |
DataFrame
|
Input coordinates that must have 'lat' and 'lon' columns with numeric data. |
time_start_year |
int, default=1981
|
Start year for the analysis period. Must be between 1900 and 2100. |
time_end_year |
int, default=2010
|
End year for the analysis period. Must be between 1900 and 2100. |
units |
str, default="Celsius"
|
Units for temperature measurement. |
variable |
str, default="Air Temperature at 2m"
|
Climate variable to analyze. Options include "Air Temperature at 2m", "Precipitation (total)", "NOAA Heat Index", "Effective Temperature". |
metric_calc |
str, default="max"
|
Statistical metric calculation method. Options: "min", "max", "mean", "median". |
percentile |
float or None, default=None
|
Percentile value for calculation. Must be between 0 and 100 if specified. |
heat_idx_threshold |
float or None, default=None
|
Threshold value for heat index calculations. |
one_in_x |
int, float, list or None, default=None
|
Return period(s) for extreme event analysis (e.g., 1-in-100 year event). Can be a single value or list of values. |
season |
str, default="all"
|
Season to analyze. Options: "summer", "winter", "all". |
downscaling_method |
str, default="Dynamical"
|
Climate model downscaling method. Options: "Dynamical", "Statistical". |
approach |
str, default="Time"
|
Analysis approach. Options: "Time" (time period), "Warming Level" (temperature target). |
warming_level |
float, default=1.0
|
Global warming level in degrees Celsius. Must be between 0 and 7. |
wrf_bias_adjust |
bool, default=True
|
Whether to apply bias adjustment to WRF model data. |
historical_data |
str, default="Historical Climate"
|
Type of historical data. Options: "Historical Climate", "Historical Reconstruction". |
ssp_data |
list, default=["SSP 3-7.0"]
|
Shared Socioeconomic Pathway scenarios to use. Options: "SSP 2-4.5", "SSP 3-7.0", "SSP 5-8.5". |
export_method |
str, default="both"
|
Data export method. Options: "raw", "calculate", "both", "None". |
separate_files |
bool, default=False
|
Whether to save climate variables in separate files. |
file_format |
str, default="NetCDF"
|
Output file format. |
batch_mode |
bool, default=False
|
Whether to run in batch processing mode. |
distr |
str, default="gev"
|
Statistical distribution for extreme value analysis. Options: "gev" (Generalized Extreme Value), "genpareto" (Generalized Pareto), "gamma". |
duration |
tuple, default=UNSET
|
Length of extreme event, specified as (4, 'hour'). Only implemented for hourly data. |
groupby |
tuple, default=(1, "day")
|
Group over which to look for max occurrence, specified as (1, 'day'). Only 'day' groupings supported. |
grouped_duration |
tuple, default=UNSET
|
Length of event after grouping, specified as (5, 'day'). Requires groupby to be set. |
file_name |
str
|
Base name for output files, no extension (e.g., "output", not "output.nc"). |
Methods:
| Name | Description |
|---|---|
validate_params |
Validate all parameters for consistency and compatibility. |
get_names |
Generate standardized names and metadata for data processing. If parameter validation fails. Common validation errors include: - Missing or non-numeric lat/lon columns in input_locations - Invalid time range (start year > end year) - Incompatible parameter combinations (e.g., multiple threshold parameters) - Unsupported variable-downscaling method combinations - Invalid approach-data type combinations |
Notes
The class enforces several validation rules: - Only one threshold parameter (heat_idx_threshold, percentile, or one_in_x) can be specified - Historical Reconstruction data requires time-based approach and end year <= 2022 - NOAA Heat Index and Effective Temperature cannot use Statistical downscaling - Dynamical downscaling with time-based approach only supports SSP 3-7.0 - duration only supports "hour" units; groupby and grouped_duration only support "day" units
Examples:
>>> import pandas as pd
>>> locations = pd.DataFrame({'lat': [34.05, 36.17], 'lon': [-118.25, -115.14]})
>>> params = CavaParams(
... input_locations=locations,
... time_start_year=2020,
... time_end_year=2050,
... variable="Air Temperature at 2m",
... percentile=95,
... metric_calc="max"
... )
Source code in climakitae/explore/vulnerability.py
validate_params()
Validate the parameters for vulnerability analysis.
Returns:
| Type | Description |
|---|---|
None
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any validation check fails. The error message lists all validation failures found during the validation process. |
Notes
The method validates the following conditions: - Input locations DataFrame contains required 'lat' and 'lon' columns with numeric data types (float64 or int64) - Time range validity (start year must be <= end year) - Historical reconstruction data constraints: - End year must be <= 2022 - Only time-based approach is supported - Mutual exclusivity of threshold parameters (only one of heat_idx_threshold, percentile, or one_in_x can be specified) - At least one threshold parameter must be specified - Metric calculation ('min' or 'max') compatibility with percentile calculations - Variable and downscaling method compatibility (NOAA Heat Index and Effective Temperature cannot use Statistical downscaling) - SSP data constraints for WRF/Dynamical downscaling (only SSP 3-7.0 allowed for time-based approach)
Side Effects
Converts self.one_in_x to a list if it's not None and not already a list.
Source code in climakitae/explore/vulnerability.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 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
get_names()
Generate names and metadata for climate data processing.
Returns:
| Type | Description |
|---|---|
dict
|
A dictionary containing the following keys: ssp_selected : str or list The SSP (Shared Socioeconomic Pathway) data selected for analysis. variable : str The climate variable being analyzed, potentially adjusted based on downscaling method and metric calculation. variable_type : str Type of variable, either "Variable" for raw climate variables or "Derived Index" for calculated indices. var_name : str Human-readable description of the calculation being performed, including variable, metric, time period/warming level, and season. raw_name : str Standardized name for raw data storage. calc_name : str Standardized name for calculated data storage. |
Notes
The function handles three main calculation types based on instance attributes: - Percentile calculations (when self.percentile is not None) - Heat index threshold calculations (when self.heat_idx_threshold is not None) - Return period calculations (when self.one_in_x is not None) For LOCA2 statistical downscaling with air temperature, the variable name is adjusted based on whether maximum or minimum metric calculation is selected. The approach can be either "Time" (using start/end years) or "Warming Level" (using a specific warming level in degrees Celsius).
Raises:
| Type | Description |
|---|---|
ValueError
|
If metric_calc is not "max" or "min" for LOCA2 air temperature data. |
ValueError
|
If approach is not "Time" or "Warming Level". |
ValueError
|
If an unsupported variable is used for 1-in-X calculations. |
Source code in climakitae/explore/vulnerability.py
885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 | |
Threshold Tools
Helper functions for performing analyses related to thresholds
calculate_ess(data, nlags=UNSET)
Function for calculating the effective sample size (ESS) of the provided data using the autocorrelation of the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
Input array is assumed to be timeseries data with potential autocorrelation. |
required |
nlags
|
int
|
Number of lags to use in the autocorrelation function, defaults to the length of the timeseries. |
UNSET
|
Returns:
| Type | Description |
|---|---|
DataArray
|
Effective sample size. Returned as a DataArray object so it can be utilized by xr.groupby and xr.resample. |
References
Zwiers, F. W., and H. von Storch, 1995: Taking Serial Correlation into Account in Tests of the Mean. J. Climate, 8, 336–351, https://doi.org/10.1175/1520-0442(1995)008<0336:TSCIAI>2.0.CO;2.
Source code in climakitae/explore/threshold_tools.py
get_block_maxima(da_series, extremes_type='max', duration=UNSET, groupby=UNSET, grouped_duration=UNSET, check_ess=True, block_size=1, rolling_agg='sustained')
Convert a timeseries into block extrema (maxima or minima), defaulting to annual block size.
Resamples the input array by taking the most extreme value in each block.
Optional arguments duration, groupby, and grouped_duration define the
type of compound event to extract extrema from, corresponding to the event types
used in get_exceedance_count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
da_series
|
DataArray
|
Input timeseries from which block extrema are extracted. |
required |
extremes_type
|
(max, min)
|
Whether to extract block maxima or minima. Default is |
"max"
|
duration
|
tuple[int, str]
|
Length of the extreme event, specified as |
UNSET
|
groupby
|
tuple[int, str]
|
Temporal grouping applied before computing block extrema, specified as
|
UNSET
|
grouped_duration
|
tuple[int, str]
|
Rolling window applied after |
UNSET
|
check_ess
|
bool
|
If |
True
|
block_size
|
int
|
Block size in years over which to take the extremum. Default is |
1
|
rolling_agg
|
(sustained, cumulative, average)
|
Aggregation method applied during rolling windows ( |
"sustained"
|
Returns:
| Type | Description |
|---|---|
DataArray
|
Block extrema series with the same non-time dimensions as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If |
ValueError
|
If all block values are NaN (i.e. the input contains no valid observations for this variable). |
Source code in climakitae/explore/threshold_tools.py
48 49 50 51 52 53 54 55 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 122 123 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 181 182 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 233 234 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 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 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 | |
get_ks_stat(bms, distr='gev', multiple_points=True)
Function to perform kstest on input DataArray
Creates a dataset of ks test d-statistics and p-values from an inputed maximum series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bms
|
DataArray
|
Block maximum series, can be output from the function get_block_maxima() |
required |
distr
|
str
|
name of distribution to use |
'gev'
|
multiple_points
|
boolean
|
Whether or not the data contains multiple points (has x, y dimensions) |
True
|
Returns:
| Type | Description |
|---|---|
Dataset
|
|
Source code in climakitae/explore/threshold_tools.py
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 527 528 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 571 572 573 574 575 576 577 578 579 580 581 582 | |
get_return_value(bms, return_period=10, distr='gev', bootstrap_runs=100, conf_int_lower_bound=2.5, conf_int_upper_bound=97.5, multiple_points=True, extremes_type='max', dropna_time=False, dim_to_fit='time')
Creates xarray Dataset with return values and confidence intervals from maximum series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bms
|
DataArray
|
Block maximum series, can be output from the function get_block_maxima() |
required |
return_period
|
float
|
The recurrence interval (in years) for which to calculate the return value |
10
|
distr
|
str
|
The type of extreme value distribution to fit |
'gev'
|
bootstrap_runs
|
int
|
Number of bootstrap samples |
100
|
conf_int_lower_bound
|
float
|
Confidence interval lower bound |
2.5
|
conf_int_upper_bound
|
float
|
Confidence interval upper bound |
97.5
|
multiple_points
|
boolean
|
Whether or not the data contains multiple points (has x, y dimensions) |
True
|
extremes_type
|
str
|
Whether to compute max ('max') or min ('min') extremes, by default 'max'. |
'max'
|
dropna_time
|
bool
|
Whether to drop NaNs along the time axis |
False
|
dim_to_fit
|
str
|
Name of the dimension that the distribution is going to be fit on. |
'time'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with return values and confidence intervals |
Notes
This function calls _get_return_variable, which will attempt to use the block_size attribute from the BMS to get the block size. If the block_size attribute is not found, an default of 1 will be used. The block size is used to get the annual probability of the desired event when the block size is > 1 year.
Source code in climakitae/explore/threshold_tools.py
991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 | |
get_return_prob(bms, threshold, distr='gev', bootstrap_runs=100, conf_int_lower_bound=2.5, conf_int_upper_bound=97.5, multiple_points=True, extremes_type='max', dropna_time=False, dim_to_fit='time')
Creates xarray Dataset with return probabilities and confidence intervals from maximum series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bms
|
DataArray
|
Block maximum series, can be output from the function get_block_maxima() |
required |
threshold
|
float
|
The threshold value for which to calculate the probability of exceedance |
required |
distr
|
str
|
The type of extreme value distribution to fit |
'gev'
|
bootstrap_runs
|
int
|
Number of bootstrap samples |
100
|
conf_int_lower_bound
|
float
|
Confidence interval lower bound |
2.5
|
conf_int_upper_bound
|
float
|
Confidence interval upper bound |
97.5
|
multiple_points
|
boolean
|
Whether or not the data contains multiple points (has x, y dimensions) |
True
|
extremes_type
|
str
|
Whether to compute max ('max') or min ('min') extremes, by default 'max'. |
'max'
|
dropna_time
|
bool
|
Whether to drop NaNs along the time axis |
False
|
dim_to_fit
|
str
|
Name of the dimension that the distribution is going to be fit on. |
'time'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with return probabilities and confidence intervals |
Notes
This function calls _get_return_variable, which will attempt to use the block_size attribute from the BMS to get the block size. If the block_size attribute is not found, an default of 1 will be used. The block size is used to get the annual probability of the desired event when the block size is > 1 year.
Source code in climakitae/explore/threshold_tools.py
1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
get_return_period(bms, return_value, distr='gev', bootstrap_runs=100, conf_int_lower_bound=2.5, conf_int_upper_bound=97.5, multiple_points=True, extremes_type='max', dropna_time=False, dim_to_fit='time')
Creates xarray Dataset with return periods and confidence intervals from maximum series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
bms
|
DataArray
|
Block maximum series, can be output from the function get_block_maxima() |
required |
return_value
|
float
|
The threshold value for which to calculate the return period of occurance |
required |
distr
|
str
|
The type of extreme value distribution to fit |
'gev'
|
bootstrap_runs
|
int
|
Number of bootstrap samples |
100
|
conf_int_lower_bound
|
float
|
Confidence interval lower bound |
2.5
|
conf_int_upper_bound
|
float
|
Confidence interval upper bound |
97.5
|
multiple_points
|
boolean
|
Whether or not the data contains multiple points (has x, y dimensions) |
True
|
extremes_type
|
str
|
Whether to compute max ('max') or min ('min') extremes, by default 'max'. |
'max'
|
dropna_time
|
bool
|
Whether to drop NaNs along the time axis |
False
|
dim_to_fit
|
str
|
Name of the dimension that the distribution is going to be fit on. |
'time'
|
Returns:
| Type | Description |
|---|---|
Dataset
|
Dataset with return periods and confidence intervals |
Notes
This function calls _get_return_variable, which will attempt to use the block_size attribute from the BMS to get the block size. If the block_size attribute is not found, an default of 1 will be used. The block size is used to get the annual probability of the desired event when the block size is > 1 year.
Source code in climakitae/explore/threshold_tools.py
1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 | |
get_exceedance_count(da, threshold_value, duration1=UNSET, period=(1, 'year'), threshold_direction='above', duration2=UNSET, groupby=UNSET, smoothing=UNSET)
Calculate the number of occurances of exceeding the specified threshold within each period.
Returns an xarray.DataArray with the same coordinates as the input data except for the time dimension, which will be collapsed to one value per period (equal to the number of event occurances in each period).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
da
|
DataArray
|
array of some climate variable. Can have multiple scenarios, simulations, or x and y coordinates. |
required |
threshold_value
|
float
|
value against which to test exceedance |
required |
duration1
|
tuple[int, str]
|
length of exceedance in order to qualify as an event (before grouping) |
UNSET
|
period
|
tuple[int, str]
|
amount of time across which to sum the number of occurances, default is (1, "year"). Specified as a tuple: (x, time) where x is an integer, and time is one of: ["day", "month", "year"] |
(1, 'year')
|
threshold_direction
|
str
|
either "above" or "below", default is above. |
'above'
|
duration2
|
tuple[int, str]
|
length of exceedance in order to qualify as an event (after grouping) |
UNSET
|
groupby
|
tuple[int, str]
|
see examples for explanation. Typical grouping could be (1, "day") |
UNSET
|
smoothing
|
int
|
option to average the result across multiple periods with a rolling average; value is either UNSET or the number of timesteps to use as the window size |
UNSET
|
Returns:
| Type | Description |
|---|---|
DataArray
|
|
Source code in climakitae/explore/threshold_tools.py
1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 | |
exceedance_plot_title(exceedance_count)
Function to build title for exceedance plots
Helper function for making the title for exceedance plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exceedance_count
|
DataArray
|
|
required |
Returns:
| Type | Description |
|---|---|
string
|
|
Examples:
'Air Temperatue at 2m: events above 35C'
'Preciptation (total): events below 10mm'
Source code in climakitae/explore/threshold_tools.py
exceedance_plot_subtitle(exceedance_count)
Function of build exceedance plot subtitle
Helper function for making the subtile for exceedance plots.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exceedance_count
|
DataArray
|
|
required |
Returns:
| Type | Description |
|---|---|
string
|
|
Examples:
'Number of hours per year'
'Number of 4-hour events per 3-months'
'Number of days per year with conditions lasting at least 4-hours'
Source code in climakitae/explore/threshold_tools.py
Thresholds
get_threshold_data(selections)
This function pulls data from the catalog and reads it into memory
Arguments
selections : DataParameters object holding user's selections
Returns:
| Name | Type | Description |
|---|---|---|
data |
DataArray
|
data to use for creating postage stamp data |
Source code in climakitae/explore/thresholds.py
Vulnerability Tables
create_vul_table(example_loc, percentile, heat_idx_threshold, one_in_x)
Creates a vulnerability assessment table and exports the table to CSV.