gplately.write_netcdf_grid

gplately.write_netcdf_grid(filename, grid, extent: tuple | str = 'global', significant_digits=None, fill_value: float | bool | None = None, metadata: dict | None = None, title: str | None = None)[source]

Write geological data contained in a grid to a netCDF4 grid with a specified filename.

Notes

The written netCDF4 grid has the same latitudinal and longitudinal (row and column) dimensions as grid. It has three variables:

  • Latitudes of grid data

  • Longitudes of grid data

  • The data stored in grid

However, the latitudes and longitudes of the grid returned to the user are constrained to those specified in extent. By default, extent assumes a global latitudinal and longitudinal span: extent=[-180,180,-90,90].

Parameters:
  • filename (str) – The full path (including a filename and the “.nc” extension) to save the created netCDF4 grid to.

  • grid (array-like) – An ndarray grid containing data to be written into a netCDF (.nc) file. Note: Rows correspond to the data’s latitudes, while the columns correspond to the data’s longitudes.

  • extent (list, default=[-180,180,-90,90]) – Four elements that specify the [min lon, max lon, min lat, max lat] to constrain the lat and lon variables of the netCDF grid to. If no extents are supplied, full global extent [-180, 180, -90, 90] is assumed.

  • significant_digits (int, optional) – Optionally applies lossy data compression up to a specified number of significant digits. This significantly reduces file size, but make sure the required precision is preserved in the saved netcdf file.

  • fill_value (scalar or False or None, default=None) –

    Value used to fill in missing data.

    If False is specified then no fill value is used, and you must ensure that data was written to all elements of grid. And any NaN elements will be written as the raw bit pattern for NaN (rather than automatically converted to a fill value).

    If None is specified then a default fill value is used, as follows:

    • If significant_digits is NOT specified and the grid data type is floating-point then the default is np.nan. This essentially means that np.nan is only used (as the default) when losslessly compressing floating-point data. This is because lossy compression with a NaN fill value appears to not always mask out NaN regions.

    • In all other cases the default is determined by netCDF based on the grid type. For example, the default for floating-point types is 9.969209968386869e+36 (see netCDF4.default_fillvals) and the default for signed integers is the largest negative value supported by the integer type (for unsigned its largest value). In this case, please ensure the default is outside the range of your valid grid data, otherwise specify a custom fill value.

    …and to query the default value associated with None you can call default_netcdf_fill_value().

  • metadata (dict, default=None) – Optional metadata to store as global netCDF attributes.

  • title (str, default=None) – Title to store as the global title netCDF attribute. If None, defaults to "Grid produced by gplately <version>".

Return type:

A netCDF grid will be saved to the path specified in filename.