cgeniepy.array#
Classes#
Module Contents#
- class cgeniepy.array.GriddedData(array=np.nan, attrs={})#
- modify_in_place = False#
- keep_attrs = True#
GriddedData is a class to store and compute GENIE netcdf data.
It stores data in xarray.DataArray format, and provides optimalised methods for GENIE model output to compute statistics.
- data#
- attrs#
- __repr__()#
- __getitem__(item)#
make GriddedData subscriptable like xarray.DataArray
- __array__()#
return the numpy array of the data
- interpolate(*args, **kwargs)#
Interpolate the GriddedData to a finer grid, mostly useful for GENIE plotting
- Returns:
a GriddedData object with interpolated data
Example#
>>> model = GenieModel(path) >>> var = model.get_var(target_var) >>> var.interpolate(method='r-linear') ## regular linear interpolation
- sel(*args, **kwargs)#
select grid points based on the given coordinates a wrapper to xarray sel method
- Returns:
a GriddedData object with selected data
Examples:#
>>> model = GenieModel(path) >>> var = model.get_var(target_var) >>> var.search_grid(lon=XX, lat=XX, zt=XX, method='nearest')
- isel(*args, **kwargs)#
select grid points based on the given index a wrapper to xarray isel method
Examples:#
>>> model = GenieModel(path) >>> var = model.get_var(target_var) >>> var.isel(lon=XX, lat=XX, zt=XX)
- normalise_longitude(method='g2n', *args, **kwargs)#
Normalise GENIE’s longitude (eastern degree) to normal longitude (-180, 180)
- Parameters:
method – normalise method, default is ‘g2n’ (GENIE to normal). A full list of methods are: - ‘g2n’: GENIE to normal - ‘n2g’: normal to GENIE - ‘e2n’: eastern to normal - ‘n2e’: normal to eastern
Example#
>>> Model = GenieModel("a path") >>> Model.get_var('abc').normalise_longitude()
- __add__(other)#
Allow GriddedData to be added by a number or another GriddedData
- __radd__(other)#
Allow a number or another GriddedData to be added to this GriddedData
- __sub__(other)#
Allow GriddedData to be subtracted by a number or another GriddedData
- __rsub__(other)#
Allow a number or another GriddedData to be subtracted from this GriddedData
- __truediv__(other)#
Allow GriddedData to be divided by a number or another GriddedData
NA/NA -> NA
- __rtruediv__(other)#
Allow a number or another GriddedData to be divided by this GriddedData
- __mul__(other)#
Allow GriddedData to be multiplied by a number or another GriddedData
- __rmul__(other)#
Allow a number or another GriddedData to be multiplied by this GriddedData
- __pow__(other)#
Allow GriddedData to be raised to a power
- __lt__(other)#
- __le__(other)#
- __gt__(other)#
- __ge__(other)#
- __eq__(other)#
- __ne__(other)#
- max(*args, **kwargs)#
compute the maximum value of the array
- min(*args, **kwargs)#
compute the minimal value of the array
- sum(*args, **kwargs)#
compute the sum of the array
- mean(*args, **kwargs)#
compute the mean of the array. Note this is not weighted mean, for weighted mean, use weighted_mean method
- median(*args, **kwargs)#
compute the median of the array
- std(*args, **kwargs)#
Compute the standard deviation using xarray’s API so named dimensions can be selected.
- sd(*args, **kwargs)#
Backward-compatible alias for std.
- variance(*args, **kwargs)#
compute the variance of the array
- se(*args, **kwargs)#
compute the standard error of the mean
- weighted(weights, *args, **kwargs)#
assign weights to the data
- sel_modern_basin(basin, norm_lon_method='g2n')#
select modern basin from regionmask.defined_regions.ar6.ocean
The 58 defines marine regions from the sixth IPCC assessment report (AR6), Iturbide et al., (2020) ESSD
https://regionmask.readthedocs.io/en/stable/_images/plotting_ar6_all.png
- Parameters:
basin – the basin index (int) or basin abbrev name (str), or a list of basin index or basin name
norm_lon_method – normalise longitude method, default is ‘g2n’
49: South Pacific
50: North Atlantic Ocean 51: Equatorial Atlantic Ocean 52: Southern Atlantic Ocean
53: North Indian Ocean 55: Equatorial Indian Ocean 56: South Indian Ocean
57: Southern Ocean 46: Arctic Ocean ——————————–
Example:#
>>> gd.sel_modern_basin(47) ## North Pacific
- mask_basin(base, basin, subbasin)#
use pre-defined grid mask to select_basin, mostly used for cGENIE model
- Parameters:
base – the base configuration name, e.g., worjh2, worlg4
basin – the basin name, e.g., Atlantic, Pacific, Indian
subbasin – N/S/ALL, ALL means Southern Ocean section included
Example#
>>> gd.mask_basin('worjh2', 'Atlantic'').mean()
- save_ocn_data()#
- search_point(point, ignore_na=False, to_genielon=False, **kwargs)#
search the nearest grid point to the given coordinates
- Parameters:
point – a list/tuple of coordinate values in the same order to the data dimension (self.data.dims)
ignore_na – whether only check ocean data (which ignore the NA grids)
to_genielon – whether convert the input longitude to genie longitude, input point must be list if True
Example#
>>> lat, lon, depth = 10, 20, 30 >>> data.search_point((lat, lon, depth))
- to_GriddedDataVis()#
convert GriddedData to GriddedDataVis
- plot(*args, **kwargs)#
plot the data using GriddedDataVis
- to_dataframe()#
convert GriddedData to pandas.DataFrame
- to_ScatterData()#
convert GriddedData to ScatterData
- fill_poles()#
Fill the poles with a given value, default is NaN