Beispiel #1
0
 def test_coords_unmatched_error(self):
     """Test error is raised if coordinates do not match"""
     x_points = self.rainrate.coord(axis="x").points
     self.rainrate.coord(axis="x").points = x_points + 100.0
     msg = "Rain rate and coverage composites unmatched"
     with self.assertRaisesRegex(ValueError, msg):
         _ = ExtendRadarMask().process(self.rainrate, self.coverage)
Beispiel #2
0
def process(cube: cli.inputcube, coverage: cli.inputcube):
    """ Extend radar mask based on coverage data.

    Extends the mask on radar data based on the radar coverage composite.
    Update the mask on the input cube to reflect where coverage is valid.

    Args:
        cube (iris.cube.Cube):
            Cube containing the radar data to remask.
        coverage (iris.cube.Cube):
            Cube containing the radar coverage data.

    Returns:
        iris.cube.Cube:
            A cube with the remasked radar data.
    """
    from improver.nowcasting.utilities import ExtendRadarMask

    # extend mask
    result = ExtendRadarMask().process(cube, coverage)
    return result
def main(argv=None):
    """Extend radar mask based on coverage data."""
    parser = ArgParser(description="Extend radar mask based on coverage "
                       "data.")
    parser.add_argument("radar_data_filepath",
                        metavar="RADAR_DATA_FILEPATH",
                        type=str,
                        help="Full path to input NetCDF file "
                        "containing the radar variable to remask.")
    parser.add_argument("coverage_filepath",
                        metavar="COVERAGE_FILEPATH",
                        type=str,
                        help="Full path to input NetCDF file "
                        "containing radar coverage data.")
    parser.add_argument("output_filepath",
                        metavar="OUTPUT_FILEPATH",
                        type=str,
                        help="Full path to save remasked radar data "
                        "NetCDF file.")
    parser.add_argument("--fix_float64",
                        action='store_true',
                        default=False,
                        help="Check and fix cube for float64 data. Without "
                        "this option an exception will be raised if "
                        "float64 data is found but no fix applied.")

    args = parser.parse_args(args=argv)

    # load data
    radar_data = load_cube(args.radar_data_filepath)
    coverage = load_cube(args.coverage_filepath)

    # extend mask
    remasked_data = ExtendRadarMask().process(radar_data, coverage)

    # Check and fix for float64 data only option:
    check_cube_not_float64(remasked_data, fix=args.fix_float64)

    # save output file
    save_netcdf(remasked_data, args.output_filepath)
Beispiel #4
0
def process(coverage, radar_data, fix_float64=False):
    """ Extend radar mask based on coverage data.

    Extends the mask on radar data based on the radar coverage composite.
    Update the mask on the input cube to reflect where coverage is valid.

    Args:
        coverage (iris.cube.Cube):
            Cube containing the radar data to remask
        radar_data (iris.cube.Cube):
            Cube containing the radar coverage data.
        fix_float64 (bool):
            Check and fix cube for float64 data. Without this, an exception
            will be raised if float64 data is found but no fix applied.

    Returns:
        iris.cube.Cube:
            A cube with the remasked radar data.
    """
    # extend mask
    result = ExtendRadarMask().process(radar_data, coverage)
    # Check and fix for float64 data only option:
    check_cube_not_float64(result, fix=fix_float64)
    return result
Beispiel #5
0
 def test_basic(self):
     """Test initialisation of class"""
     plugin = ExtendRadarMask()
     self.assertSequenceEqual(plugin.coverage_valid, [1, 2])
Beispiel #6
0
 def test_inputs_unmodified(self):
     """Test the rainrate cube is not modified in place"""
     reference = self.rainrate.copy()
     _ = ExtendRadarMask().process(self.rainrate, self.coverage)
     self.assertEqual(reference, self.rainrate)
Beispiel #7
0
 def test_values(self):
     """Test output cube has expected mask and underlying data is
     unchanged"""
     result = ExtendRadarMask().process(self.rainrate, self.coverage)
     self.assertArrayEqual(result.data.mask, self.expected_mask)
     self.assertArrayEqual(result.data.data, self.rainrate.data.data)
Beispiel #8
0
 def test_basic(self):
     """Test processing outputs a cube of precipitation rates"""
     result = ExtendRadarMask().process(self.rainrate, self.coverage)
     self.assertIsInstance(result, iris.cube.Cube)
     self.assertEqual(result.name(), self.rainrate.name())