Ejemplo n.º 1
0
    def __new__(cls, *args, **kwargs):
        # Input array is an already formed ndarray instance

        longName = kwargs.pop('longName', None)
        units = kwargs.pop('units', None)
        missingValue = kwargs.pop('missingValue', -9999.)

        obj = MaskedArray.__new__(cls, *args, **kwargs)

        # Add the new attributes to the created instance

        obj.longName = longName
        obj.units = units
        obj.missingValue = missingValue

        # Finally, we must return the newly created object:
        return obj
Ejemplo n.º 2
0
 def __array_finalize__(self, obj):
     np.matrix.__array_finalize__(self, obj)
     MaskedArray.__array_finalize__(self, obj)
     return
Ejemplo n.º 3
0
 def __new__(cls, data, mask=nomask):
     mat = np.matrix(data)
     _data = MaskedArray.__new__(cls, data=mat, mask=mask)
     return _data
Ejemplo n.º 4
0
 def __new__(cls, data, info={}, mask=nomask):
     subarr = SubArray(data, info)
     _data = MaskedArray.__new__(cls, data=subarr, mask=mask)
     _data.info = subarr.info
     return _data
Ejemplo n.º 5
0
 def __array_finalize__(self, obj):
     np.matrix.__array_finalize__(self, obj)
     MaskedArray.__array_finalize__(self, obj)
     return
Ejemplo n.º 6
0
 def __new__(cls, data, mask=nomask):
     mat = np.matrix(data)
     _data = MaskedArray.__new__(cls, data=mat, mask=mask)
     return _data
Ejemplo n.º 7
0
 def __new__(cls, data, info={}, mask=nomask):
     subarr = SubArray(data, info)
     _data = MaskedArray.__new__(cls, data=subarr, mask=mask)
     _data.info = subarr.info
     return _data
Ejemplo n.º 8
0
def _make_mask_cube(
    mask_data: MaskedArray,
    coords: List,
    topographic_bounds: List[float],
    topographic_units: str,
    sea_points_included: bool = False,
) -> Cube:
    """
    Makes cube from numpy masked array generated from orography fields.

    Args:
        mask_data:
            The numpy array to make a cube from.
        coords:
            Dictionary of coordinate on the model ancillary file.
        topographic_bounds:
            List containing the lower and upper thresholds defining the mask
        topographic_units:
            Name of the units of the topographic zone coordinate of the output
            cube.
        sea_points_included:
            Default is False. Value for the output cube attribute
            'topographic_zones_include_seapoints', signifying whether sea
            points have been included when the ancillary is generated.

    Returns:
        Cube containing the mask_data array, with appropriate coordinate
        and attribute information.
    """
    mask_data = mask_data.astype(np.int32)
    mask_cube = iris.cube.Cube(mask_data, long_name="topography_mask")
    if any(item is None for item in topographic_bounds):
        msg = ("The topographic bounds variable should have both an "
               "upper and lower limit: "
               "Your topographic_bounds are {}")
        raise TypeError(msg.format(topographic_bounds))

    if len(topographic_bounds) != 2:
        msg = ("The topographic bounds variable should have only an "
               "upper and lower limit: "
               "Your topographic_bounds variable has length {}")
        raise TypeError(msg.format(len(topographic_bounds)))

    coord_name = "topographic_zone"
    central_point = np.mean(topographic_bounds)
    threshold_coord = iris.coords.AuxCoord(
        central_point,
        bounds=topographic_bounds,
        long_name=coord_name,
        units=Unit(topographic_units),
    )
    mask_cube.add_aux_coord(threshold_coord)
    # We can't save attributes with boolean values so convert to string.
    mask_cube.attributes.update(
        {"topographic_zones_include_seapoints": str(sea_points_included)})
    for coord in coords:
        if coord.name() in ["projection_y_coordinate", "latitude"]:
            mask_cube.add_dim_coord(coord, 0)
        elif coord.name() in ["projection_x_coordinate", "longitude"]:
            mask_cube.add_dim_coord(coord, 1)
        else:
            mask_cube.add_aux_coord(coord)
    mask_cube = iris.util.new_axis(mask_cube, scalar_coord=coord_name)
    return mask_cube