pycif.plugins.domains.gridded_NetCDF — API reference

pycif.plugins.domains.gridded_NetCDF — API reference#

Configuration reference: gridded_NetCDF plugin

pycif.plugins.domains.gridded_NetCDF.create_domain.create_domain(*args, **kwargs)[source]#
pycif.plugins.domains.gridded_NetCDF.read_domain.read_vcoord(domain)[source]#

Read vertical coordinate information from a NetCDF file into the domain.

Behaviour depends on whether domain.vertical_coord is set:

  • Not set — creates a single surface level (sigma_b = [1], sigma_a = [0], nlev = 1).

  • Set to ``’mids’`` — reads level mid-point values for sigma_a / sigma_b (sigma pressure) or heights (metres).

  • Set to ``’bounds’`` — reads level boundary values and derives nlev = len(sigma_b) - 1.

The vertical coordinate file is {dir}/{file} by default, or {dir_vcoord}/{file_vcoord} if the latter is explicitly provided.

Levels are automatically reordered so that pressure decreases upward (surface at index 0). Units are validated against 'Pa', 'hPa', or 'm'.

Sets on domain: nlev, pressure_unit, and one of sigma_a_mid / sigma_b_mid, sigma_a / sigma_b, heights_mid, or heights depending on vertical_coord and vertical_dim_type.

Parameters:

domain – gridded_NetCDF domain plugin instance with dir, file, and optional vertical_coord, vertical_dim_type, file_vcoord, dir_vcoord, pressure_unit set.

Raises:
  • ValueError – for unrecognised pressure units, non-monotone level ordering, or unexpected vertical_coord values.

  • Exception – for unrecognised vertical_dim_type.

pycif.plugins.domains.gridded_NetCDF.read_domain.read_grid(domain, **kwargs)[source]#

Read horizontal and vertical grid coordinates from a NetCDF file.

Locates latitude and longitude variables by their standard_name / long_name attributes (or by latitude_varname / longitude_varname overrides), then derives cell corners either from a bounds attribute or from the coordinate spacing.

Handles:

  • Automatically flipping non-increasing coordinate arrays.

  • Fixed-spacing corners via delta_lat / delta_lon.

  • Corner-as-centre mode (use_corners = True) with optional extension by one cell.

  • Force-centred cell midpoints via force_centered_lat / force_centered_lon.

  • Cyclic zonal unwrapping when lon_cyclic is detected.

Delegates vertical coordinate reading to read_vcoord().

Sets on domain: nlon, nlat, zlon, zlat, zlonc, zlatc, lon_cyclic, and all vertical attributes from read_vcoord().

Parameters:
  • domain – gridded_NetCDF domain plugin instance with dir, file, and all grid / vcoord arguments set.

  • **kwargs – unused.

Raises:
  • IOError – if the NetCDF file cannot be opened with xarray.

  • AssertionError – if coordinates are not strictly increasing after optional flipping.

pycif.plugins.domains.gridded_NetCDF.utils.get_bounds(ds: Dataset, coord_name: str, flip_coord: bool, min_bound: float, max_bound: float, regular_extent: bool) ndarray[source]#

Get the bounds of a given coordinates.

pycif.plugins.domains.gridded_NetCDF.utils.get_centers(coord: ndarray, flip_coord: bool) ndarray[source]#
pycif.plugins.domains.gridded_NetCDF.utils.find_coord(ds: Dataset | DataArray, name: str, coord_name: str = None) str[source]#

Find a variable or coordinate name in a dataset based on its ‘long_name’ or ‘standard_name’ attribute.