improver.utilities.mathematical_operations module¶
Module to contain mathematical operations.
-
class
improver.utilities.mathematical_operations.Integration(coord_name_to_integrate, start_point=None, end_point=None, direction_of_integration='negative')[source]¶ Bases:
improver.BasePluginPerform integration along a chosen coordinate. This class currently supports the integration of positive values only, in order to support its usage as part of computing the wet-bulb temperature integral. Generalisation of this class to support standard numerical integration can be undertaken, if required.
-
__init__(coord_name_to_integrate, start_point=None, end_point=None, direction_of_integration='negative')[source]¶ Initialise class.
- Parameters
coord_name_to_integrate (str) – Name of the coordinate to be integrated.
start_point (float or None) – Point at which to start the integration. Default is None. If start_point is None, integration starts from the first available point.
end_point (float or None) – Point at which to end the integration. Default is None. If end_point is None, integration will continue until the last available point.
direction_of_integration (str) – Description of the direction in which to integrate. Options are ‘positive’ or ‘negative’. ‘positive’ corresponds to the values within the array increasing as the array index increases. ‘negative’ corresponds to the values within the array decreasing as the array index increases.
-
_abc_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache= <_weakrefset.WeakSet object>¶
-
_abc_negative_cache_version= 213¶
-
_abc_registry= <_weakrefset.WeakSet object>¶
-
_create_output_cube(template, data, points, bounds)[source]¶ Populates a template cube with data from the integration
- Parameters
template (iris.cube.Cube) – Copy of upper or lower bounds cube, based on direction of integration
data (list or numpy.ndarray) – Integrated data
points (list or numpy.ndarray) – Points values for the integrated coordinate. These will not match the template cube if any slices were skipped in the integration, and therefore are used to slice the template cube to match the data array.
bounds (list or numpy.ndarray) – Bounds values for the integrated coordinate
- Returns
iris.cube.Cube
-
_generate_output_name_and_units()[source]¶ Gets suitable output name and units from input cube metadata
-
ensure_monotonic_increase_in_chosen_direction(cube)[source]¶ Ensure that the chosen coordinate is monotonically increasing in the specified direction.
- Parameters
cube (iris.cube.Cube) – The cube containing the coordinate to check. Note that the input cube will be modified by this method.
- Returns
The cube containing a coordinate that is monotonically increasing in the desired direction.
- Return type
-
perform_integration(upper_bounds_cube, lower_bounds_cube)[source]¶ Perform the integration.
Integration is performed by firstly defining the stride as the difference between the upper and lower bound. The contribution from the uppermost half of the stride is calculated by multiplying the upper bound value by 0.5 * stride, and the contribution from the lowermost half of the stride is calculated by multiplying the lower bound value by 0.5 * stride. The contribution from the uppermost half of the stride and the bottom half of the stride is summed.
Integration is performed ONLY over positive values.
- Parameters
upper_bounds_cube (iris.cube.Cube) – Cube containing the upper bounds to be used during the integration.
lower_bounds_cube (iris.cube.Cube) – Cube containing the lower bounds to be used during the integration.
- Returns
Cube containing the output from the integration.
- Return type
-
prepare_for_integration()[source]¶ Prepare for integration by creating the cubes needed for the integration. These are separate cubes for representing the upper and lower limits of the integration.
- Returns
- tuple containing:
- upper_bounds_cube (iris.cube.Cube):
Cube containing the upper bounds to be used during the integration.
- lower_bounds_cube (iris.cube.Cube):
Cube containing the lower bounds to be used during the integration.
- Return type
(tuple)
-
process(cube)[source]¶ Integrate data along a specified coordinate. Only positive values are integrated; zero and negative values are not included in the sum or as levels on the integrated cube.
- Parameters
cube (iris.cube.Cube) – Cube containing the data to be integrated.
- Returns
The cube containing the result of the integration. This will have the same name and units as the input cube (TODO same name and units are incorrect - fix this).
- Return type
-