Ejemplo n.º 1
0
def _order_cell_methods(cube: Cube) -> None:
    """
    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.

    Args:
        cube:
            The cube on which the cell methods are to be sorted.
    """
    cell_methods = tuple(sorted(cube.cell_methods))
    cube.cell_methods = cell_methods
Ejemplo n.º 2
0
    def _discard_redundant_cell_methods(cube: Cube) -> None:
        """
        Removes cell method "point": "time" from cube if present.
        """
        if not cube.cell_methods:
            return
        removable_cms = [
            CellMethod(method="point", coords="time"),
        ]
        updated_cms = []
        for cm in cube.cell_methods:
            if cm in removable_cms:
                continue
            updated_cms.append(cm)

        cube.cell_methods = updated_cms
Ejemplo n.º 3
0
def format_cell_methods_for_diagnostic(cube: Cube) -> None:
    """Remove reference to threshold-type coordinate from cell method comments that
    were previously on a probability cube.  Modifies cube in place.

    Args:
        cube:
            Cube to update
    """
    cell_methods = []
    for cell_method in cube.cell_methods:
        new_cell_method = iris.coords.CellMethod(
            cell_method.method,
            coords=cell_method.coord_names,
            intervals=cell_method.intervals,
        )
        cell_methods.append(new_cell_method)
    cube.cell_methods = cell_methods
Ejemplo n.º 4
0
def format_cell_methods_for_probability(cube: Cube, threshold_name: str) -> None:
    """Update cell methods on a diagnostic cube to reflect the fact that the
    data to which they now refer is on a coordinate.  Modifies cube in place.

    Args:
        cube:
            Cube to update
        threshold_name:
            Name of the threshold-type coordinate to which the cell
            method now refers
    """
    cell_methods = []
    for cell_method in cube.cell_methods:
        new_cell_method = iris.coords.CellMethod(
            cell_method.method,
            coords=cell_method.coord_names,
            intervals=cell_method.intervals,
            comments=f"of {threshold_name}",
        )
        cell_methods.append(new_cell_method)
    cube.cell_methods = cell_methods