spaemis.utils

General utility functions

area_grid

area_grid(lat, lon)[source]

Calculate the area of each grid cell

Area is in square meters

Parameters:
Returns:

xarray.core.dataarray.DataArrayarea (grid-cell area in square-meters with dimensions, [lat,lon])

Notes

Based on the function in https://github.com/chadagreene/CDT/blob/master/cdt/cdtarea.m

earth_radius

earth_radius(lat)[source]

Calculate radius of Earth assuming oblate spheroid

Defined by WGS84

Parameters:

lat (vector or latitudes in degrees) –

Returns:

numpy.ndarray[typing.Any, numpy.dtype[numpy.float64]] – Vector of radius in meters

Notes

WGS84: https://earth-info.nga.mil/GandG/publications/tr8350.2/tr8350.2-a/Chapter%203.pdf

clip_region

clip_region(da, boundary)[source]

Clip a region out of a larger DS

Parameters:
Returns:

typing.TypeVar(T, xarray.core.dataarray.DataArray, xarray.core.dataset.Dataset) – Dataset which only includes the selected area

weighted_annual_mean

weighted_annual_mean(ds, variable)[source]

Calculate a weighted temporal annual mean

This method takes into account the different number of days in each month

Parameters:
Returns:

xarray.core.dataarray.DataArrayWeighted annual mean of the target variable

chdir

chdir(current_directory)[source]

Context manager to temporarily change the current working directory

Should not be used in async or parallel methods as it changes the global state

Parameters:

current_directory (str) –

Return type:

collections.abc.Generator[None, None, None]

load_australia_boundary

load_australia_boundary()[source]

Load Australia boundary shapefile

Returns:

geopandas.geodataframe.GeoDataFrame – GeoDataFrame containing borders for each state

covers

covers(dataarray, dim, value)[source]

Check if a dimension of a DataArray can be interpolated for a given value

If this check fails an extrapolation will be required :type dataarray: xarray.core.dataarray.DataArray :param dataarray: DataArray to check :type dim: str :param dim: Dimension of interest :type value: float :param value: Value to check

Returns:

bool – True if value could be interpolated in DataArray’s dimension dim