climakitae.util package#
Submodules#
climakitae.util.cluster module#
Wrapper for creating a Dask Gateway Cluster
- class climakitae.util.cluster.Cluster(address=None, proxy_address=None, public_address=None, auth=None, cluster_options=None, shutdown_on_close=True, asynchronous=False, loop=None, **kwargs)#
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.
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
- extra_packages = ['git+https://github.com/cal-adapt/climakitae.git']#
- get_client(set_as_default=True)#
Get client
- Returns:
climakitae.util.generate_gwl_tables module#
Util for generating warming level reference data in ../data/ ###
To run, type: <<python generate_gwl_tables.py>> in the command line and wait for printed model outputs showing progress. Generation takes ~1.5 hours for generating all 4 csv’s.
- climakitae.util.generate_gwl_tables.get_sims_on_aws(df)#
Make a table of all of the relevant CMIP6 simulations on AWS.
- climakitae.util.generate_gwl_tables.main()#
Call everything needed to write the global warming level reference files for all of the available GCMs.
climakitae.util.unit_conversions module#
Calculates alternative units for variables with multiple commonly used units, following NWS conversions for pressure and wind speed.
- climakitae.util.unit_conversions.convert_units(da, selected_units)#
Converts units for any variable
- Parameters:
- Returns:
da (
DataArray
) – data with converted units and updated units attributeReferences
-------
Wind speed (
https://www.weather.gov/media/epz/wxcalc/windConversion.pdf
)Pressure (
https://www.weather.gov/media/epz/wxcalc/pressureConversion.pdf
)
- climakitae.util.unit_conversions.get_unit_conversion_options()#
Get dictionary of unit conversion options offered for each unit
climakitae.util.utils module#
Miscellaneous utility functions.
- climakitae.util.utils.area_average(dset)#
Weighted area-average
- climakitae.util.utils.combine_hdd_cdd(data)#
Drops specific unneeded coords from HDD/CDD data, independent of station or gridded data source
- climakitae.util.utils.compute_annual_aggreggate(data, name, num_grid_cells)#
Calculates the annual sum of HDD and CDD
- climakitae.util.utils.compute_multimodel_stats(data)#
Calculates model mean, min, max, median across simulations
- climakitae.util.utils.convert_to_local_time(data, selections)#
Converts the inputted data to the local time of the selection.
- climakitae.util.utils.downscaling_method_as_list(downscaling_method)#
Function to convert string based radio button values to python list.
- climakitae.util.utils.get_closest_gridcell(data, lat, lon, print_coords=True)#
From input gridded data, get the closest 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:
- Returns:
DataArray
– Grid cell closest to input lat,lon coordinate pair
See also
- climakitae.util.utils.hdd_cdd_lineplot(annual_data, trendline, title='title')#
Plots annual CDD/HDD with trendline provided
- climakitae.util.utils.hdh_cdh_lineplot(data)#
Plots HDH/CDH
- climakitae.util.utils.julianDay_to_str_date(julday, leap_year=True, str_format='%b-%d')#
Convert julian day of year to string format i.e. if str_format = “%b-%d”, the output will be Mon-Day (“Jan-01”)
- climakitae.util.utils.read_ae_colormap(cmap='ae_orange', cmap_hex=False)#
Read in AE colormap by name
- Parameters:
- Returns:
one
ofeither
cmap_data (
matplotlib.colors.LinearSegmentedColormap
) – used for matplotlib (if cmap_hex == False)cmap_data (
list
) – used for hvplot maps (if cmap_hex == True)
- climakitae.util.utils.read_csv_file(rel_path, index_col=None, parse_dates=False)#
- climakitae.util.utils.readable_bytes(B)#
Return the given bytes as a human friendly KB, MB, GB, or TB string. Code from stackoverflow: https://stackoverflow.com/questions/12523586/python-format-size-application-converting-b-to-kb-mb-gb-tb
- climakitae.util.utils.reproject_data(xr_da, proj='EPSG:4326', fill_value=nan)#
Reproject xr.DataArray using rioxarray.
- Parameters:
- Returns:
data_reprojected (
DataArray
) – 2-or-3-dimensional reprojected DataArray- Raises:
ValueError – if input data does not have spatial coords x,y
ValueError – if input data has more than 5 dimensions
- climakitae.util.utils.scenario_to_experiment_id(scenario, reverse=False)#
Convert scenario format to experiment_id format matching catalog names. Set reverse=True to get scenario format from input experiement_id.
- climakitae.util.utils.summary_table(data)#
Helper function to organize dataset object into a pandas dataframe for ease.
- climakitae.util.utils.trendline(data, kind='mean')#
Calculates treadline of the multi-model mean or median.
- Parameters:
data (
Dataset
)kind (
str (optional)
) – Options are ‘mean’ and ‘median’
- Returns:
trendline (
Dataset
)
Note
1. Development note: If an additional option to trendline ‘kind’ is required, compute_multimodel_stats must be modified to update optionality.
- climakitae.util.utils.write_csv_file(df, rel_path)#