Util Module
Supporting utilities for climate data processing, unit conversions, and visualization.
Overview
The climakitae.util module provides:
- General utilities — Helper functions for data manipulation and analysis
- Warming level calculations — Global warming level trajectory computations
- Unit conversions — Climate variable unit transformation
- Colormaps — Custom climate-focused colormaps
- Cluster management — Dask distributed computing setup
- Logging — Logger configuration for climakitae
Core Utilities
downscaling_method_as_list(downscaling_method)
Function to convert string based radio button values to python list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
downscaling_method
|
str
|
one of "Dynamical", "Statistical", or "Dynamical+Statistical" |
required |
Returns:
| Name | Type | Description |
|---|---|---|
method_list |
list
|
one of ["Dynamical"], ["Statistical"], or ["Dynamical","Statistical"] |
Source code in climakitae/util/utils.py
area_average(dset)
Weighted area-average
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dset
|
Dataset
|
one dataset from the catalog |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
sub-setted output data |
Source code in climakitae/util/utils.py
read_csv_file(rel_path, index_col=UNSET, parse_dates=False)
Read CSV file into pandas DataFrame
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rel_path
|
str
|
path to CSV file relative to this util python file |
required |
index_col
|
str
|
CSV column to index DataFrame on |
UNSET
|
parse_dates
|
boolean
|
Whether to have pandas parse the date strings |
False
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
|
Source code in climakitae/util/utils.py
write_csv_file(df, rel_path)
Write CSV file from pandas DataFrame
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
df
|
DataFrame
|
pandas DataFrame to write out |
required |
rel_path
|
str
|
path to CSV file relative to this util python file |
required |
Returns:
| Type | Description |
|---|---|
None
|
|
Source code in climakitae/util/utils.py
f_to_k(f)
Convert temperature from degrees Fahrenheit to Kelvin.
Accepts scalars or array-like inputs (returns numpy array for array-like).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
f
|
float or array - like
|
Degrees Fahrenheit. |
required |
Returns:
| Type | Description |
|---|---|
float or ndarray
|
Temperature in Kelvin. |
Source code in climakitae/util/utils.py
get_closest_gridcell(data, lat, lon, print_coords=True)
From input gridded data, get the closest VALID gridcell to a lat, lon coordinate pair.
This function first transforms the lat,lon coords to the gridded data’s projection. Then, it uses xarray’s built in method .sel to get the nearest gridcell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray | Dataset
|
Gridded data (can be backed by numpy or dask arrays) |
required |
lat
|
float
|
Latitude or y value of coordinate pair |
required |
lon
|
float
|
Longitude or x value of coordinate pair |
required |
print_coords
|
bool
|
Print closest coorindates? Default to True. Set to False for backend use. |
True
|
Returns:
| Type | Description |
|---|---|
Dataset | DataArray | None
|
Grid cell closest to input lat,lon coordinate pair, returns same type as input. The result preserves lazy evaluation if the input was lazy. |
See also
xr.DataArray.isel
Source code in climakitae/util/utils.py
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 | |
get_closest_gridcells(data, lats, lons, print_coords=True, bbox_buffer=5)
Find the nearest grid cell(s) for given latitude and longitude coordinates.
This function uses vectorized operations to efficiently find closest gridcells for multiple coordinate pairs at once. For a single point, it delegates to get_closest_gridcell.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray | Dataset
|
Gridded dataset with (x, y) or (lat, lon) dimensions. |
required |
lats
|
float | Iterable[float]
|
Latitude coordinate(s). |
required |
lons
|
float | Iterable[float]
|
Longitude coordinate(s). |
required |
print_coords
|
bool
|
Print closest coordinates for each point. Default is True. Note: For large numbers of points, printing is automatically suppressed. |
True
|
bbox_buffer
|
int
|
Number of grid cells to add as buffer around the bounding box when pre-clipping large datasets. Default is 5. |
5
|
Returns:
| Type | Description |
|---|---|
Dataset | DataArray | None
|
Nearest grid cell(s) or None if no valid match is found. If multiple coordinates are provided, results are concatenated along 'points' dimension. |
See Also
get_closest_gridcell
Notes
For large datasets with many target points, this function first clips the data to a bounding box around the target points. This dramatically reduces the Dask task graph complexity and improves performance for downstream operations.
Source code in climakitae/util/utils.py
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 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 | |
julianDay_to_date(julday, year=None, return_type='str', str_format='%b-%d')
Convert julian day of year to a date object or formatted string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
julday
|
int
|
Julian day (day of year) |
required |
year
|
int
|
Year to use. If None, uses current year or a leap year (2024) based on needs. Default is None. |
None
|
return_type
|
str
|
Type of return value: - "str": formatted string (default) - "datetime": datetime object - "date": date object |
'str'
|
str_format
|
str
|
String format of output date when return_type is "str". Default is "%b-%d" which outputs format like "Jan-01". |
'%b-%d'
|
Returns:
| Name | Type | Description |
|---|---|---|
date |
str, datetime.datetime, or datetime.date
|
Julian day converted to specified format or object |
Examples:
>>> julianDay_to_date(1)
'Jan-01'
>>> julianDay_to_date(32, year=2023, return_type="date")
datetime.date(2023, 2, 1)
>>> julianDay_to_date(60, year=2024, str_format="%Y-%m-%d")
'2024-02-29'
Source code in climakitae/util/utils.py
readable_bytes(b)
Return the given bytes as a human friendly KB, MB, GB, or TB string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
b
|
int
|
Size in bytes. |
required |
Returns:
| Type | Description |
|---|---|
str
|
|
Code from stackoverflow: https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb
|
|
Source code in climakitae/util/utils.py
reproject_data(xr_da, proj='EPSG:4326', fill_value=np.nan)
Reproject xr.DataArray using rioxarray.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xr_da
|
DataArray
|
2-or-3-dimensional DataArray, with 2 spatial dimensions |
required |
proj
|
str
|
proj to use for reprojection (default to "EPSG:4326"-- lat/lon coords) |
'EPSG:4326'
|
fill_value
|
float
|
fill value (default to np.nan) |
nan
|
Returns:
| Name | Type | Description |
|---|---|---|
data_reprojected |
DataArray
|
2-or-3-dimensional reprojected DataArray |
Raises:
| Type | Description |
|---|---|
ValueError
|
if input data does not have spatial coords x,y |
ValueError
|
if input data has more than 5 dimensions |
Source code in climakitae/util/utils.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 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 | |
compute_annual_aggreggate(data, name, num_grid_cells)
Calculates the annual sum of HDD and CDD
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
|
required |
name
|
str
|
|
required |
num_grid_cells
|
int
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
annual_ag |
DataArray
|
|
Source code in climakitae/util/utils.py
compute_multimodel_stats(data)
Calculates model mean, min, max, median across simulations
Used in heat_index.ipynb and degree_days.ipynb
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
stats_concat |
DataArray
|
|
Source code in climakitae/util/utils.py
trendline(data, kind='mean')
Calculates treadline of the multi-model mean or median.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dataarray
|
|
required |
kind
|
str
|
Options are 'mean' and 'median' |
'mean'
|
Returns:
| Name | Type | Description |
|---|---|---|
trendline |
DataArray
|
|
Note
- Development note: If an additional option to trendline 'kind' is required, compute_multimodel_stats must be modified to update optionality.
Source code in climakitae/util/utils.py
combine_hdd_cdd(data)
Drops specific unneeded coords from HDD/CDD data, independent of station or gridded data source
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
data |
DataArray
|
|
Source code in climakitae/util/utils.py
summary_table(data)
Helper function to organize dataset object into a pandas dataframe for ease.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dataset
|
|
required |
Returns:
| Name | Type | Description |
|---|---|---|
df |
DataFrame
|
df is organized so that the simulations are stacked in individual columns by year/time |
Source code in climakitae/util/utils.py
convert_to_local_time(data, lon=UNSET, lat=UNSET)
Convert time dimension from UTC to local time for the grid or station.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataArray or Dataset
|
Input data. |
required |
lon
|
float
|
Mean longitude of dataset if no lat/lon coordinates |
UNSET
|
lat
|
float
|
Mean latitude of dataset if no lat/lon coordinates |
UNSET
|
Returns:
| Type | Description |
|---|---|
DataArray or Dataset
|
Data with converted time coordinate. |
Source code in climakitae/util/utils.py
1383 1384 1385 1386 1387 1388 1389 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 | |
add_dummy_time_to_wl(wl_da, freq_name='daily')
Replace the [hours/days/months]_from_center or time_delta dimension in a DataArray returned from WarmingLevels with a dummy time index for calculations with tools that require a time dimension.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
wl_da
|
DataArray
|
The input Warming Levels DataArray. It is expected to have a time-based dimension which typically includes "from_center" in its name or time_delta indicating the time dimension in relation to the year that the given warming level is reached per simulation. |
required |
freq_name
|
str
|
The frequency name to use when time_delta is the time dimension. Options are "hourly", "daily", or "monthly". Default is "daily". |
'daily'
|
Returns:
| Type | Description |
|---|---|
DataArray
|
A modified version of the input DataArray with the original time dimension replaced by a dummy time series. The new dimension will be named "time". |
Notes
- The function looks for the dimension name containing "from_center" to identify the time-based dimension.
- It supports creating dummy time series with frequencies of hours, days, or months, based on the prefix of the dimension name.
- The dummy time series starts from "2000-01-01".
Source code in climakitae/util/utils.py
1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 | |
downscaling_method_to_activity_id(downscaling_method, reverse=False)
Convert downscaling method to activity id to match catalog names
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
downscaling_method
|
str
|
Downscaling method |
required |
reverse
|
boolean
|
Set reverse=True to get downscaling method from input activity_id Default to False |
False
|
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in climakitae/util/utils.py
resolution_to_gridlabel(resolution, reverse=False)
Convert resolution format to grid_label format matching catalog names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str
|
resolution |
required |
reverse
|
boolean
|
Set reverse=True to get resolution format from input grid_label. Default to False |
False
|
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in climakitae/util/utils.py
timescale_to_table_id(timescale, reverse=False)
Convert resolution format to table_id format matching catalog names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timescale
|
str
|
|
required |
reverse
|
boolean
|
Set reverse=True to get resolution format from input table_id. Default to False |
False
|
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in climakitae/util/utils.py
scenario_to_experiment_id(scenario, reverse=False)
Convert scenario format to experiment_id format matching catalog names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scenario
|
str
|
|
required |
reverse
|
boolean
|
Set reverse=True to get scenario format from input experiement_id. Default to False |
False
|
Returns:
| Type | Description |
|---|---|
str
|
|
Source code in climakitae/util/utils.py
clip_to_shapefile(data, shapefile_path, feature=(), name='user-defined', **kwargs)
Use a shapefile to select an area subset of AE data.
By default, this function will clip the data to the area covered by all features in the shapefile. To clip to specific features, use the feature keyword.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Dataset | DataArray
|
Data to be clipped. |
required |
shapefile_path
|
str
|
Filepath to shapefile. Shapefile must include valid CRS. |
required |
feature
|
tuple(str, str | int | float | list)
|
Tuple containing attribute name and value(s) for target feature(s) (optional). |
()
|
name
|
str
|
Location name to record in data attributes if 'feature' parameter is not set (optional). |
'user-defined'
|
**kwargs
|
Additional arguments to pass to the rioxarray clip function |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
clipped |
Dataset | DataArray
|
Returns same type as 'data', but grid is clipped to shapefile feature(s). |
Source code in climakitae/util/utils.py
1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 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 | |
clip_gpd_to_shapefile(gdf, shapefile)
Use a shapefile to select an area subset of a geodataframe. Used to subset stationlist to shapefile area.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gdf
|
GeoDataFrame
|
Data to be clipped. |
required |
shapefile
|
GeoDataFrame
|
Shapefile must include valid CRS. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
clipped |
GeoDataFrame
|
Subsetted geodataframe within shapefile area of interest. |
Source code in climakitae/util/utils.py
Warming Level Utilities
Helper functions related to applying a warming levels approach to a data object
calculate_warming_level(warming_data, gwl_times, level, months, window)
Perform warming level computation for a single warming level.
Assumes the data has already been stacked by simulation and scenario to create a MultiIndex dimension "all_sims" and that the invalid simulations have been removed such that the gwl_times table can be adequately parsed.
Internal function only; see the function _apply_warming_levels_approach for more documentation on how this function is applied internally. Appropriate attributes for new dimensions are applied by the retrieval function (not here).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
warming_data
|
DataArray
|
Data object returned by _get_data_one_var, stacked by simulation/scenario, and then with invalid simulations removed. |
required |
gwl_times
|
DataFrame
|
Global warming levels table indicating when each unique model/run/scenario (simulation) reaches each warming level. |
required |
level
|
float
|
Warming level. Must be a valid column in gwl_times table. |
required |
months
|
list of int
|
Months of the year (in integers) to compute function for.
For example, for a full year: |
required |
window
|
int
|
Years around Global Warming Level (+/-). For example, 15 means a 30-year window. |
required |
Returns:
| Type | Description |
|---|---|
DataArray
|
The warming level subset data. |
Source code in climakitae/util/warming_levels.py
drop_invalid_sims(ds, selections)
As part of the warming levels calculation, the data is stacked by simulation and scenario, creating some empty values for that coordinate. Here, we remove those empty coordinate values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ds
|
Dataset
|
The dataset must have a
dimension |
required |
selections
|
DataParameters
|
Warming level data selections |
required |
Returns:
| Type | Description |
|---|---|
Dataset
|
The dataset with only valid simulations retained. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If the dataset does not have an |
Source code in climakitae/util/warming_levels.py
read_warming_level_csvs()
Reads two CSV files containing global warming level (GWL) data.
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame]
|
df : pd.DataFrame Time-indexed DataFrame (time as index, simulations as columns). other_df : pd.DataFrame DataFrame with warming levels per simulation (no datetime index). |
Source code in climakitae/util/warming_levels.py
get_wl_timestamp(series, degree)
Finds the first timestamp when the series crosses the specified warming level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
series
|
Series
|
A time-indexed warming level series. |
required |
degree
|
float
|
Target warming level. |
required |
Returns:
| Type | Description |
|---|---|
str | float
|
Timestamp as string if crossed, else np.nan. |
Source code in climakitae/util/warming_levels.py
create_new_warming_level_table(warming_level)
Returns a table of timestamps when each simulation reaches the given warming level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
warming_level
|
float
|
New WL to retrieve WL timing for. |
required |
Returns:
| Type | Description |
|---|---|
pd.DataFrame
|
Same DataFrame as |
Source code in climakitae/util/warming_levels.py
filter_warming_trajectories_to_ae(simulations_df, warming_trajectories, downscaling_method)
Filters all simulations in warming_trajectories to only the ones we have on AE (simulations_df).
Does this filtering by downscaling_method as well.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulations_df
|
DataFrame
|
Complete simulation dataframe of all simulations in GWL tables. |
required |
warming_trajectories
|
DataFrame
|
Full warming trajectory DataFrame, computed from |
required |
downscaling_method
|
str
|
Downscaling method to filter DataFrame by ('LOCA' or 'WRF'). |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Filtered |
Source code in climakitae/util/warming_levels.py
create_ae_warming_trajectories(resolution)
Creates warming trajectories for all AE simulations based on a given resolution. This resolution is an important parameter because not all resolutions have the same number of WRF simulations (i.e. 3km has 8 but 9km has 10).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
resolution
|
str
|
Grid resolution (e.g., "6km", "12km"). |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataFrame, DataFrame]
|
LOCA2 warming trajectories (pd.DataFrame) WRF warming trajectories (pd.DataFrame) |
Source code in climakitae/util/warming_levels.py
generate_ssp_dict()
Loads historical and SSP scenario CSVs into one dictionary.
Returns:
| Type | Description |
|---|---|
Dict[str, pd.DataFrame] : A dictionary mapping scenario names to their
|
pandas DataFrames, indexed by year. |
Source code in climakitae/util/warming_levels.py
get_gwl_at_year(year, ssp='all')
Retrieve estimated Global Warming Level (GWL) statistics for a given year.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
year
|
int
|
The year for which to retrieve GWL estimates. |
required |
ssp
|
str
|
The SSP scenario to use. Use 'all' to retrieve results for all SSPs. |
'all'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame with SSPs as rows and '5%', 'Mean', and '95%' as columns, containing the warming level estimates for the specified year. |
Source code in climakitae/util/warming_levels.py
get_year_at_gwl(gwl, ssp='all')
Retrieve the year when a given Global Warming Level (GWL) is reached for each SSP scenario.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
gwl
|
nan | int
|
The Global Warming Level to check (e.g., 1.5, 2.0). |
required |
ssp
|
str
|
The SSP scenario to evaluate. Use 'all' to check across all SSPs and the Historical period. |
'all'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
A DataFrame with SSPs as rows and columns ['5%', 'Mean', '95%'] indicating the years when each warming level threshold is crossed for the respective uncertainty bounds. NaN indicates the level was not reached by 2100. |
Source code in climakitae/util/warming_levels.py
Unit Conversions
Calculates alternative units for variables with multiple commonly used units, following NWS conversions for pressure and wind speed.
get_unit_conversion_options()
Get dictionary of unit conversion options offered for each unit
Source code in climakitae/util/unit_conversions.py
convert_units(da, selected_units)
Converts units for any variable
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
da
|
DataArray
|
data |
required |
selected_units
|
str
|
selected units of data, from selections.units |
required |
Returns:
| Name | Type | Description |
|---|---|---|
da |
DataArray
|
data with converted units and updated units attribute |
References
Wind speed: https://www.weather.gov/media/epz/wxcalc/windConversion.pdf Pressure: https://www.weather.gov/media/epz/wxcalc/pressureConversion.pdf
Source code in climakitae/util/unit_conversions.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 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 | |
Colormaps
read_ae_colormap(cmap='ae_orange', cmap_hex=False)
Read in AE colormap by name
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cmap
|
str
|
one of ["ae_orange", "ae_diverging", "ae_blue", "ae_diverging_r", "categorical_cb"] |
'ae_orange'
|
cmap_hex
|
boolean
|
return RGB or hex colors? |
False
|
Returns:
| Name | Type | Description |
|---|---|---|
one of either
|
|
|
cmap_data |
LinearSegmentedColormap
|
used for matplotlib (if cmap_hex == False) |
cmap_data |
list
|
used for hvplot maps (if cmap_hex == True) |
Source code in climakitae/util/colormap.py
Cluster Management
Cluster
Bases: GatewayCluster
A dask-gateway cluster allowing one cluster per user. Instead of always creating new clusters, connect to a previously running user cluster, and attempt to limit users to a single cluster.
Methods:
| Name | Description |
|---|---|
get_client |
Get a dask client connected to the cluster. |
Examples:
>>> from climakitae.util.cluster import Cluster
>>> cluster = Cluster() # Create cluster
>>> cluster.adapt(minimum=0, maximum=8) # Specify the number of workers to use
>>> client = cluster.get_client()
>>> cluster # Output cluster information
get_client(set_as_default=True)
Get client
Returns:
| Type | Description |
|---|---|
Client
|
|