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:
lat (
typing.Union[numpy._typing._array_like._SupportsArray[numpy.dtype[typing.Any]],numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[typing.Any]]],bool,int,float,complex,str,bytes,numpy._typing._nested_sequence._NestedSequence[typing.Union[bool,int,float,complex,str,bytes]]]) – Vector of latitude in degreeslon (
typing.Union[numpy._typing._array_like._SupportsArray[numpy.dtype[typing.Any]],numpy._typing._nested_sequence._NestedSequence[numpy._typing._array_like._SupportsArray[numpy.dtype[typing.Any]]],bool,int,float,complex,str,bytes,numpy._typing._nested_sequence._NestedSequence[typing.Union[bool,int,float,complex,str,bytes]]]) – Vector of longitude in degrees
- Returns:
xarray.core.dataarray.DataArray– area (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:
da (
typing.TypeVar(T,xarray.core.dataarray.DataArray,xarray.core.dataset.Dataset)) –boundary (
geopandas.geodataframe.GeoDataFrame) –Boundary to cut out
GeoJSON is expected so it must have a geometry array
- 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:
ds (
xarray.core.dataset.Dataset) –variable (
str) – Variable to calculate the weighted mean of
- Returns:
xarray.core.dataarray.DataArray– Weighted annual mean of the target variable
chdir
load_australia_boundary
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