improver.utilities.cube_extraction module¶
Utilities to parse a list of constraints and extract matching subcube
-
improver.utilities.cube_extraction.apply_extraction(cube, constraint, units=None)[source]¶ Using a set of constraints, extract a subcube from the provided cube if it is available.
Parameters: - cube (iris.cube.Cube) – The cube from which a subcube is to be extracted.
- constraint (iris.Constraint or iris.ConstraintCombination) – The constraint or ConstraintCombination that will be used to extract a subcube from the input cube.
- Kwargs:
- units (dictionary):
- A dictionary of units for the constraints. Supplied if any coordinate constraints are provided in different units from those of the input cube (eg precip in mm/h for cube threshold in m/s).
Returns: A single cube matching the input constraints, or None if no subcube is found within cube that matches the constraints. Return type: output_cube (iris.cube.Cube)
-
improver.utilities.cube_extraction.create_range_constraint(coord_name, value)[source]¶ Create a constraint that is representative of a range.
Parameters: - coord_name (string) – Name of the coordinate for which the constraint will be created.
- value (string) – A string containing the range information. It is assumed that the input value is of the form: “[2:10]”.
Returns: The constraint that has been created to represent the range.
Return type: constr (iris.Constraint)
-
improver.utilities.cube_extraction.extract_subcube(cube, constraints, units=None)[source]¶ Using a set of constraints, extract a subcube from the provided cube if it is available.
Parameters: - cube (iris.cube.Cube) – The cube from which a subcube is to be extracted.
- constraints (list) – List of string constraints with keys and values split by “=”: e.g: [“kw1=val1”, “kw2 = val2”, “kw3=val3”].
- Kwargs:
- units (list):
- List of units (as strings) corresponding to each coordinate in the list of constraints. One or more “units” may be None, and units may only be associated with coordinate constraints.
Returns: A single cube matching the input constraints, or None if no subcube is found within cube that matches the constraints. Return type: output_cube (iris.cube.Cube or None)
-
improver.utilities.cube_extraction.is_complex_parsing_required(value)[source]¶ Determine if the string being parsed requires complex parsing. Currently, this is solely determined by the presence of a colon (:).
Parameters: value (string) – A string that will be parsed. Returns: Flag value to indicate whether the string requires complex parsing. Return type: complex_constraint (bool)
-
improver.utilities.cube_extraction.parse_constraint_list(constraints, units=None)[source]¶ For simple constraints of a key=value format, these are passed in as a list of strings and converted to key-value pairs prior to creating the constraints. For more complex constraints, the list of strings given as input are evaluated by parsing for specific identifiers and then the constraints are created as required. The simple key-value pairs and other constraints are merged into a single constraint.
Parameters: constraints (list) – List of string constraints with keys and values split by “=”: e.g: [“kw1=val1”, “kw2 = val2”, “kw3=val3”]. - Kwargs:
- units (list):
- List of units (as strings) corresponding to each coordinate in the list of constraints. One or more “units” may be None, and units may only be associated with coordinate constraints.
Returns: - tuple containing
- constraints (iris.Constraint or iris._constraints.ConstraintCombination):
- A combination of all the constraints that were supplied.
- units_dict (dictionary or None):
- A dictionary of unit keys and values
Return type: (tuple)