mule.validators

This module provides a set of common validation functions. Generally the different file classes don’t have the exact same requirements, but since a lot of the validation logic is very similar it is contained here.

exception mule.validators.ValidateError(filename, message)[source]

Bases: ValueError

Exception class to raise when validation does not pass.

__init__(filename, message)[source]
add_note()

Exception.add_note(note) – add a note to the exception

with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

mule.validators.validate_umf(umf, filename=None, warn=False, GridArakawaA=False)[source]

Main validation method, ensures that certain quantities are the expected sizes and different header quantities are self-consistent.

Kwargs:
  • filename:

    If provided, this filename will be included in any validation error messages raised by this method.

  • warn:

    If True, issue a warning rather than a failure in the event that the object fails to validate.

  • GridArakawaA:

    If True, switch validation to use grid staggering allowed in GRIB files - namely Arakawa A grids

mule.validators.validate_dataset_type(umf, dt_valid)[source]

Check that a UMFile object has an accepted dataset_type.

Args:
  • umf:

    A UMFile subclass instance.

  • dt_valid:

    A tuple containing valid values of the dataset type to be checked against.

mule.validators.validate_grid_staggering(umf, gs_valid)[source]

Check that a UMFile object has an accepted grid staggering.

Args:
  • umf:

    A UMFile subclass instance.

  • gs_valid:

    A tuple containing valid values of the grid staggering to be checked against.

mule.validators.validate_integer_constants(umf, ic_valid)[source]

Check that integer constants associated with a UMFile object are present and the expected size.

Args:
  • umf:

    A UMFile subclass instance.

  • ic_valid:

    The expected number of integer constants to be checked against.

mule.validators.validate_real_constants(umf, rc_valid)[source]

Check that real constants associated with a UMFile object are present and the expected size.

Args:
  • umf:

    A UMFile subclass instance.

  • rc_valid:

    The expected number of real constants to be checked against.

mule.validators.validate_level_dependent_constants(umf, ldc_valid)[source]

Check that level dependent constants associated with a UMFile object are present and the expected size.

Args:
  • umf:

    A UMFile subclass instance.

  • ldc_valid:

    Tuple containing the size of the two expected dimensions of the level dependent constants to be checked against.

mule.validators.validate_row_dependent_constants(umf, rdc_valid)[source]

Check that the row dependent constants associated with a UMFile object are the expected size.

Note

This does not confirm that the constants are present, since these constants are optional; the caller must check this separately.

Args:
  • umf:

    A UMFile subclass instance.

  • rdc_valid:

    Tuple containing the size of the two expected dimensions of the row dependent constants to be checked against.

mule.validators.validate_column_dependent_constants(umf, cdc_valid)[source]

Check that the column dependent constants associated with a UMFile object are the expected size.

Note

This does not confirm that the constants are present, since these constants are optional; the caller must check this separately.

Args:
  • umf:

    A UMFile subclass instance.

  • cdc_valid:

    Tuple containing the size of the two expected dimensions of the column dependent constants to be checked against.

mule.validators.validate_field_grid_type(umf, field)[source]

Check that the type of grid in the field agrees with the type of grid specified by the file.

Args:
  • umf:

    A UMFile subclass instance.

  • field:

    A Field subclass instance.

mule.validators.validate_variable_resolution_field(umf, field)[source]

Check the grid-specific lookup headers from a field in a variable resolution file. These must agree with the row + column dependent constants, and the fixed grid lookup headers must be set to RMDI.

Args:
  • umf:

    A UMFile subclass instance.

  • field:

    A Field subclass instance.

mule.validators.validate_regular_field(umf, field)[source]

Check the grid-specific lookup headers from a field in a fixed resolution file. This assumes that the field object has a reference to a STASHmaster entry; if it does not, or if it is of a type which isn’t handled explicitly below it will defer to the non-stash version of this routine.

Args:
  • umf:

    A UMFile subclass instance.

  • field:

    A Field subclass instance.

mule.validators.validate_regular_field_nostash(umf, field)[source]

Check the grid-specific lookup headers from a field in a fixed resolution file. The file defines the model domain and it is expected that the field should cover the same area - which is a reasonable way to test should the STASHmaster entry not be available.

Args:
  • umf:

    A UMFile subclass instance.

  • field:

    A Field subclass instance.