cgeniepy.array ============== .. py:module:: cgeniepy.array Classes ------- .. autoapisummary:: cgeniepy.array.GriddedData Module Contents --------------- .. py:class:: GriddedData(array=np.nan, attrs={}) .. py:attribute:: modify_in_place :value: False .. py:attribute:: keep_attrs :value: 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. .. py:attribute:: data .. py:attribute:: attrs .. py:method:: __repr__() .. py:method:: __getitem__(item) make GriddedData subscriptable like xarray.DataArray .. py:method:: __array__() return the numpy array of the data .. py:method:: 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 .. py:method:: 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') .. py:method:: 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) .. py:method:: normalise_longitude(method='g2n', *args, **kwargs) Normalise GENIE's longitude (eastern degree) to normal longitude (-180, 180) :param 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() .. py:method:: __add__(other) Allow GriddedData to be added by a number or another GriddedData .. py:method:: __radd__(other) Allow a number or another GriddedData to be added to this GriddedData .. py:method:: __sub__(other) Allow GriddedData to be subtracted by a number or another GriddedData .. py:method:: __rsub__(other) Allow a number or another GriddedData to be subtracted from this GriddedData .. py:method:: __truediv__(other) Allow GriddedData to be divided by a number or another GriddedData NA/NA -> NA .. py:method:: __rtruediv__(other) Allow a number or another GriddedData to be divided by this GriddedData .. py:method:: __mul__(other) Allow GriddedData to be multiplied by a number or another GriddedData .. py:method:: __rmul__(other) Allow a number or another GriddedData to be multiplied by this GriddedData .. py:method:: __pow__(other) Allow GriddedData to be raised to a power .. py:method:: __lt__(other) .. py:method:: __le__(other) .. py:method:: __gt__(other) .. py:method:: __ge__(other) .. py:method:: __eq__(other) .. py:method:: __ne__(other) .. py:method:: max(*args, **kwargs) compute the maximum value of the array .. py:method:: min(*args, **kwargs) compute the minimal value of the array .. py:method:: sum(*args, **kwargs) compute the sum of the array .. py:method:: mean(*args, **kwargs) compute the mean of the array. Note this is not weighted mean, for weighted mean, use `weighted_mean` method .. py:method:: median(*args, **kwargs) compute the median of the array .. py:method:: std(*args, **kwargs) Compute the standard deviation using xarray's API so named dimensions can be selected. .. py:method:: sd(*args, **kwargs) Backward-compatible alias for std. .. py:method:: variance(*args, **kwargs) compute the variance of the array .. py:method:: se(*args, **kwargs) compute the standard error of the mean .. py:method:: weighted(weights, *args, **kwargs) assign weights to the data .. py:method:: 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 :param basin: the basin index (int) or basin abbrev name (str), or a list of basin index or basin name :param norm_lon_method: normalise longitude method, default is 'g2n' -------------------------------- 47: North Pacific 48: Equatorial Pacific 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 .. py:method:: mask_basin(base, basin, subbasin) use pre-defined grid mask to select_basin, mostly used for cGENIE model :param base: the base configuration name, e.g., worjh2, worlg4 :param basin: the basin name, e.g., Atlantic, Pacific, Indian :param subbasin: N/S/ALL, ALL means Southern Ocean section included Example --------- >>> gd.mask_basin('worjh2', 'Atlantic'').mean() .. py:method:: save_ocn_data() .. py:method:: search_point(point, ignore_na=False, to_genielon=False, **kwargs) search the nearest grid point to the given coordinates :param point: a list/tuple of coordinate values in the same order to the data dimension (self.data.dims) :param ignore_na: whether only check ocean data (which ignore the NA grids) :param 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)) .. py:method:: to_GriddedDataVis() convert GriddedData to GriddedDataVis .. py:method:: plot(*args, **kwargs) plot the data using GriddedDataVis .. py:method:: to_dataframe() convert GriddedData to pandas.DataFrame .. py:method:: to_ScatterData() convert GriddedData to ScatterData .. py:method:: fill_poles() Fill the poles with a given value, default is NaN