Tools Module
Computational tools for climate indices and batch processing.
Overview
The climakitae.tools module provides functions for:
- Batch processing — Process multiple locations efficiently
- Climate indices — Calculate heat stress, effective temperature, and other climate metrics
- Derived variables — Compute secondary climate variables from primary ones
Batch Processing
batch_select(approach, selections, points, load_data=False, progress_bar=True)
Conducts batch mode analysis on a series of points for a given metric.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
approach
|
str
|
|
required |
selections
|
DataParameters
|
Selections object that describes the area of interest. The |
required |
points
|
ndarray
|
An array at lat/lon points to gather the specified data at. |
required |
load_data
|
boolean
|
A boolean that tells the function whether or not to load the data into memory. |
False
|
progress_bar
|
boolean
|
A boolean that determines whether progress bar is displayed. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
cells_of_interest |
DataArray
|
Gridcells that the points lie within, aggregated together into one DataArray. It can or cannot be loaded into memory, depending on |
Source code in climakitae/tools/batch.py
Climate Indices
Functions for deriving indices
effective_temp(T)
Compute effective temperature Effective Temp = (1/2)(yesterday's effective temp) + (1/2)(today's actual temp) To make sense of the expansion, today's ET is consist of a portion of the actual temperature of each day up to today--half of today's temp, 1/4 of yesterday's temp, 1/8 of the day before yesterday's temp etc, thus it's "an exponentially smoothed temperature" as stated in the glossary of the reference. This derivation only considers 4 days of temperature data in the computation of EFT: today, yesterday, the day before yesterday, and two days before yesterday. Thus, the first 3 timesteps of the EFT will be NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
DataArray
|
Daily air temperature in any units |
required |
Returns:
| Name | Type | Description |
|---|---|---|
eft |
DataArray
|
Effective temperature |
References
https://www.nationalgas.com/document/132516/download
Source code in climakitae/tools/indices.py
noaa_heat_index(T, RH)
Compute the NOAA Heat Index. Heat Index quantifies the perceived "real feel" of air temperature on the human body, including the impact of humidity. See references for more information on this derived variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
T
|
DataArray
|
Temperature in deg F |
required |
RH
|
DataArray
|
Relative Humidity in percentage (0-100) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
HI |
DataArray
|
Heat index per timestep |
References
NOAA: https://www.wpc.ncep.noaa.gov/html/heatindex_equation.shtml NCAR NCL documentation: https://www.ncl.ucar.edu/Document/Functions/Heat_stress/heat_index_nws.shtml
Source code in climakitae/tools/indices.py
fosberg_fire_index(t2_F, rh_percent, windspeed_mph)
Compute the Fosberg Fire Weather Index. Use hourly weather as inputs. Ensure that the input variables are in the correct units (see below).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t2_F
|
DataArray
|
Air temperature in units of Fahrenheit |
required |
rh_percent
|
DataArray
|
Relative humidity in units of 0-100 (percent) |
required |
windspeed_mph
|
DataArray
|
Windspeed in units of miles per hour |
required |
Returns:
| Name | Type | Description |
|---|---|---|
FFWI |
DataArray
|
Fosberg Fire Weather Index computed for each grid cell |
References
https://a.atmos.washington.edu/wrfrt/descript/definitions/fosbergindex.html https://github.com/sharppy/SHARPpy/blob/main/sharppy/sharptab/fire.py https://www.spc.noaa.gov/exper/firecomp/INFO/fosbinfo.html
Source code in climakitae/tools/indices.py
Derived Variables
Functions for deriving frequently used variables
compute_hdd_cdd(t2, hdd_threshold, cdd_threshold)
Compute heating degree days (HDD) and cooling degree days (CDD)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t2
|
DataArray
|
Air temperature at 2m gridded data |
required |
hdd_threshold
|
int
|
Standard temperature in Fahrenheit. |
required |
cdd_threshold
|
int
|
Standard temperature in Fahrenheit. |
required |
Returns:
| Type | Description |
|---|---|
tuple of xr.DataArray
|
(hdd, cdd) |
Source code in climakitae/tools/derived_variables.py
compute_hdh_cdh(t2, hdh_threshold, cdh_threshold)
Compute heating degree hours (HDH) and cooling degree hours (CDH)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
t2
|
DataArray
|
Air temperature at 2m gridded data |
required |
hdh_threshold
|
int
|
Standard temperature in Fahrenheit. |
required |
cdh_threshold
|
int
|
Standard temperature in Fahrenheit. |
required |
Returns:
| Type | Description |
|---|---|
tuple of xr.DataArray
|
(hdh, cdh) |
Source code in climakitae/tools/derived_variables.py
compute_dewpointtemp(temperature, rel_hum)
Calculate dew point temperature
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
temperature
|
DataArray
|
Temperature in Kelvin (K) |
required |
rel_hum
|
DataArray
|
Relative humidity (0-100 scale) |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dew_point |
DataArray
|
Dew point (K) |
Source code in climakitae/tools/derived_variables.py
compute_specific_humidity(tdps, pressure, name='q2_derived')
Compute specific humidity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tdps
|
DataArray
|
Dew-point temperature, in K |
required |
pressure
|
DataArray
|
Air pressure, in Pascals |
required |
name
|
str
|
Name to assign to output DataArray |
'q2_derived'
|
Returns:
| Name | Type | Description |
|---|---|---|
spec_hum |
DataArray
|
Specific humidity |
Source code in climakitae/tools/derived_variables.py
compute_relative_humidity(pressure, temperature, mixing_ratio, name='rh_derived')
Compute relative humidity. Variable attributes need to be assigned outside of this function because the metpy function removes them
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pressure
|
DataArray
|
Pressure in hPa |
required |
temperature
|
DataArray
|
Temperature in Celsius |
required |
mixing_ratio
|
DataArray
|
Dimensionless mass mixing ratio in g/kg |
required |
name
|
str
|
Name to assign to output DataArray |
'rh_derived'
|
Returns:
| Name | Type | Description |
|---|---|---|
rel_hum |
DataArray
|
Relative humidity |
Source |
https://www.weather.gov/media/epz/wxcalc/mixingRatio.pdf
|
|
Source code in climakitae/tools/derived_variables.py
compute_wind_mag(u10, v10, name='wind_speed_derived')
Compute wind magnitude at 10 meters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u10
|
DataArray
|
Zonal velocity at 10 meters height in m/s |
required |
v10
|
DataArray
|
Meridonal velocity at 10 meters height in m/s |
required |
name
|
str
|
Name to assign to output DataArray |
'wind_speed_derived'
|
Returns:
| Name | Type | Description |
|---|---|---|
wind_mag |
DataArray
|
Wind magnitude |
Source code in climakitae/tools/derived_variables.py
compute_wind_dir(u10, v10, name='wind_direction_derived')
Compute wind direction at 10 meters
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
u10
|
DataArray
|
Zonal velocity at 10 meters height in m/s |
required |
v10
|
DataArray
|
Meridional velocity at 10 meters height in m/s |
required |
name
|
str
|
Name to assign to output DataArray |
'wind_direction_derived'
|
Returns:
| Name | Type | Description |
|---|---|---|
wind_dir |
DataArray
|
Wind direction, in [0, 360] degrees, with 0/360 defined as north, by meteorological convention |
Notes
source: https://sites.google.com/view/raybellwaves/cheat-sheets/xarray
Source code in climakitae/tools/derived_variables.py
compute_sea_level_pressure(psfc, t2, q2, elevation, lapse_rate=0.0065, average_t2=True, name='slp_derived')
Calculate sea level pressure from hourly surface pressure, temperature, and mixing ratio.
This function uses the basic method derived from the hydrostatic balance equation and the equation of state (Hess 1979). The SLP calculation method used here may not produce satisfactory results in locations with high terrain.
By default this method uses a standard lapse rate of 6.5°K/km when calculating the sea level virtual temperature (see Pauley 1998). Users should consider what lapse rate is appropriate for their location.
An option is provided to use a 12-hour average temperature when computing the lapse rate; this option is expected to produce more moderate SLP values that are less influenced by extreme temperatures.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
psfc
|
DataArray
|
Hourly surface pressure in Pascals |
required |
t2
|
DataArray
|
Hourly surface air temperature in Kelvin |
required |
q2
|
DataArray
|
Hourly surface mixing ratio |
required |
elevation
|
DataArray
|
Elevation in meters |
required |
lapse_rate
|
Union[float, DataArray]
|
Lapse rate in K/m. Default is 0.0065 K/m |
0.0065
|
average_t2
|
bool
|
True to use 12-hour mean temperature. Default is True. |
True
|
name
|
str
|
Name to assign to output DataArray |
'slp_derived'
|
Returns:
| Type | Description |
|---|---|
DataArray
|
Sea level pressure in Pascals |
Notes
Virtual temperature is computed in the following way: T_virtual = ((1 + 1.609 q2) / (1 + q2)) * t2 T_virtual_mean = (2 * T_virtual + lapse_rate * elevation) / 2
Sea level pressure is calculated as: slp = psfc * np.exp(elevation / ((Rd * T_virtual_mean)/g)) where Rd is the specific gas constant for dry air and g is the acceleration due to gravity.
References
Hess, S. L., 1979: Introduction to Theoretical Meteorology. Robert E. Krieger Publishing Company, 362 pp. Pauley, P. M., 1998: An Example of Uncertainty in Sea Level Pressure Reduction. Wea. Forecasting, 13, 833–850, https://doi.org/10.1175/1520-0434(1998)013<0833:AEOUIS>2.0.CO;2.
Source code in climakitae/tools/derived_variables.py
337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 | |
compute_geostrophic_wind(geopotential_height, gridlabel='d01')
Calculate the geostrophic wind at a single point on a constant pressure surface.
Currently only implemented for data on the WRF grid. This code follows the MetPy code for calculating the geostrophic wind on an unevenly spaced grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
geopotential_height
|
DataArray
|
Geopotential height in meters on WRF grid. May include multiple pressure levels |
required |
Returns:
| Type | Description |
|---|---|
tuple[DataArray]
|
Earth-relative U and V components of the geostrophic wind. |
References
Hess, S. L., 1979: Introduction to Theoretical Meteorology. Robert E. Krieger Publishing Company, 362 pp. MetPy, 2026: geostrophic_wind. Accessed 10 Feb 2026, https://unidata.github.io/MetPy/latest/api/generated/metpy.calc.geostrophic_wind.html#geostrophic-wind.