improver.utilities.save module

Module for saving netcdf cubes with desired attribute types.

_check_metadata(cube)[source]

Checks cube metadata that needs to be correct to guarantee data integrity

Parameters:

cube (Cube) – Cube to be checked

Raises:
  • ValueError – if time coordinates do not have the required datatypes and units; needed because values may be wrong

  • ValueError – if numerical datatypes are other than 32-bit (except where specified); needed because values may be wrong

  • ValueError – if cube dataset has unknown units; because this may cause misinterpretation on “load”

Return type:

None

_order_cell_methods(cube)[source]

Sorts the cell methods on a cube such that if there are multiple methods they are always written in a consistent order in the output cube. The input cube is modified.

Parameters:

cube (Cube) – The cube on which the cell methods are to be sorted.

Return type:

None

save_netcdf(cubelist, filename, compression_level=1, least_significant_digit=None)[source]

Save the input Cube or CubeList as a NetCDF file and check metadata where required for integrity.

Uses the functionality provided by iris.fileformats.netcdf.save with local_keys to record non-global attributes as data attributes rather than global attributes.

Parameters:
  • cubelist (Union[Cube, CubeList]) – Cube or list of cubes to be saved

  • filename (str) – Filename to save input cube(s)

  • compression_level (int) – 1-9 to specify compression level, or 0 to not compress (default compress with complevel 1)

  • least_significant_digit (Optional[int]) – If specified will truncate the data to a precision given by 10**(-least_significant_digit), e.g. if least_significant_digit=2, then the data will be quantized to a precision of 0.01 (10**(-2)). See http://www.esrl.noaa.gov/psd/data/gridded/conventions/cdc_netcdf_standard.shtml for details. When used with compression level, this will result in lossy compression.

Raises:

warning if cubelist contains cubes of varying dimensions.

Return type:

None