예제 #1
0
 def test_landband_data(self):
     """test correct mask is produced for land bands > 0m"""
     result = GenOrogMasks().gen_orography_masks(self.orography,
                                                 self.landmask,
                                                 self.land_key,
                                                 self.land_threshold)
     self.assertArrayAlmostEqual(result.data.data, self.exp_landmask)
 def test_nonzero_landband_data(self):
     """test that correct data is produced when neither landband
     bound is zero."""
     result = GenOrogMasks().gen_orography_masks(
         self.orography, self.landmask, self.nonzero_land_threshold
     )
     self.assertArrayAlmostEqual(result.data, self.exp_nonzero_landmask)
예제 #3
0
 def test_high_landband_data(self):
     """test that a correct mask is produced when the land band is
     higher than any land in the test cube."""
     result = GenOrogMasks().gen_orography_masks(self.orography,
                                                 self.landmask,
                                                 self.high_land_threshold)
     self.assertArrayAlmostEqual(result.data, self.exp_high_landmask)
예제 #4
0
 def test_nonsensekey(self):
     """test the correct exception is raised for unknown keys"""
     exception_dict = {'nonsense': [[0, 10]]}
     with self.assertRaisesRegexp(KeyError, 'Unknown threshold_dict key'):
         GenOrogMasks().gen_orography_masks(self.orography, self.landmask,
                                            "nonsense",
                                            exception_dict["nonsense"])
예제 #5
0
 def test_nothreshold(self):
     """test the correct exception is raised for key without threshold"""
     key = 'land'
     threshold = []
     with self.assertRaises(ValueError):
         GenOrogMasks().gen_orography_masks(self.orography, self.landmask,
                                            key, threshold)
 def test_nonzero_landband_cube(self):
     """test that a correct cube is produced when neither landband
     bound is zero."""
     result = GenOrogMasks().gen_orography_masks(
         self.orography, self.landmask, self.nonzero_land_threshold)
     self.assertEqual(
         result.coord('topographic_zone').points,
         np.mean(self.nonzero_land_threshold))
예제 #7
0
 def test_high_landband_cube(self):
     """test that a correct cube is produced when the land band is
     higher than any land in the test cube."""
     result = GenOrogMasks().gen_orography_masks(self.orography,
                                                 self.landmask,
                                                 self.high_land_threshold)
     self.assertEqual(
         result.coord("topographic_zone").points,
         np.mean(self.high_land_threshold))
 def test_unit_conversion_for_landband_data(self):
     """test correct mask is produced for land bands > 0m"""
     land_threshold = [0, 0.05]
     threshold_units = "km"
     result = GenOrogMasks().gen_orography_masks(
         self.orography, self.landmask, land_threshold, units=threshold_units
     )
     self.assertArrayAlmostEqual(result.data, self.exp_landmask)
     self.assertEqual(result.coord("topographic_zone").units, Unit("m"))
 def test_all_land_points(self):
     """Test that a correct mask is produced when the landsea mask only has
        land points in it."""
     land_mask_cube = self.landmask.copy()
     land_mask_cube.data = np.ones((3, 3))
     result = GenOrogMasks().gen_orography_masks(
         self.orography, land_mask_cube, self.valley_threshold
     )
     expected_data = np.array([[[1.0, 1.0, 1.0], [0.0, 0.0, 0.0], [0.0, 0.0, 0.0]]])
     self.assertArrayAlmostEqual(result.data, expected_data)
 def test_basic_sea_fill_value(self):
     """Test that the expected data is returned when the landmask specifies
     a mix of land and sea points and a fill value is given."""
     expected_data = np.array([[10., 0, 0], [20., 0, 0], [-10, 100., 40]])
     result = GenOrogMasks().sea_mask(self.landmask.data,
                                      self.orography.data,
                                      sea_fill_value=0)
     self.assertIsInstance(result, np.ndarray)
     self.assertArrayAlmostEqual(result, expected_data)
     self.assertEqual(np.ma.is_masked(result), False)
예제 #11
0
 def test_all_land_points(self):
     """Test that the expected data is returned when the landmask specifies
     only land points."""
     expected = np.array([[10.0, 0.0, 0.0], [20.0, 100.0, 15.0],
                          [-10.0, 100.0, 40.0]])
     landmask_data = np.array([[1, 1, 1], [1, 1, 1], [1, 1, 1]])
     landmask = set_up_landmask_cube(landmask_data=landmask_data)
     result = GenOrogMasks().sea_mask(landmask.data, self.orography.data)
     self.assertIsInstance(result, np.ndarray)
     self.assertArrayAlmostEqual(result, expected)
예제 #12
0
 def test_any_surface_type_mask(self):
     """Test that the correct mask is produced when no landsea mask is
        provided. This is equivalent to the all_land_points test above."""
     result = GenOrogMasks().gen_orography_masks(self.orography, None,
                                                 self.valley_threshold)
     expected_data = np.array([[[1.0, 1.0, 1.0], [0.0, 0.0, 0.0],
                                [0.0, 0.0, 0.0]]])
     self.assertArrayAlmostEqual(result.data, expected_data)
     self.assertEqual(
         result.attributes["topographic_zones_include_seapoints"], "True")
예제 #13
0
 def test_basic(self):
     """Test that the expected data is returned when the landmask specifies
     a mix of land and sea points."""
     expected_data = np.array([[10.0, 1e20, 1e20], [20.0, 1e20, 1e20],
                               [-10, 100.0, 40]])
     expected_mask = np.array([[False, True, True], [False, True, True],
                               [False, False, False]])
     result = GenOrogMasks().sea_mask(self.landmask.data,
                                      self.orography.data)
     self.assertIsInstance(result, np.ndarray)
     self.assertArrayAlmostEqual(result.data, expected_data)
     self.assertArrayAlmostEqual(result.mask, expected_mask)
예제 #14
0
 def test_valleyband_cube(self):
     """test correct cube data is produced for land bands < 0m"""
     result = GenOrogMasks().gen_orography_masks(self.orography,
                                                 self.landmask,
                                                 self.valley_key,
                                                 self.valley_threshold)[0]
     self.assertEqual(result.attributes['Topographical Type'], 'Land')
     self.assertEqual(
         result.coord('topographic_bound_lower').points,
         self.valley_threshold[0])
     self.assertEqual(
         result.coord('topographic_bound_upper').points,
         self.valley_threshold[1])
예제 #15
0
 def test_maxband_cube(self):
     """test correct cube data is produced for land bands > max"""
     result = GenOrogMasks().gen_orography_masks(self.orography,
                                                 self.landmask,
                                                 self.max_key,
                                                 self.max_threshold)[0]
     self.assertEqual(result.attributes['Topographical Type'],
                      'Max_Land_Threshold')
     self.assertEqual(
         result.coord('topographic_bound_lower').points,
         self.max_threshold[0])
     msg = 'Expected to find exactly 1  coordinate, but found none.'
     with self.assertRaisesRegexp(CoordinateNotFoundError, msg):
         result.coord('topographic_bound_upper')
예제 #16
0
 def test_landband_cube(self):
     """test correct cube data is produced for land bands > 0m"""
     result = GenOrogMasks().gen_orography_masks(self.orography,
                                                 self.landmask,
                                                 self.land_key,
                                                 self.land_threshold)
     self.assertEqual(result.attributes['Topographical Type'], 'Land')
     self.assertEqual(
         result.coord('topographic_zone').points,
         np.mean(self.land_threshold))
     self.assertEqual(
         result.coord('topographic_zone').bounds[0][0],
         self.land_threshold[0])
     self.assertEqual(
         result.coord('topographic_zone').bounds[0][1],
         self.land_threshold[1])
예제 #17
0
 def test_landband_cube(self):
     """test correct cube data is produced for land bands > 0m"""
     result = GenOrogMasks().gen_orography_masks(self.orography,
                                                 self.landmask,
                                                 self.land_threshold)
     self.assertEqual(
         result.attributes["topographic_zones_include_seapoints"], "False")
     self.assertEqual(
         result.coord("topographic_zone").points,
         np.mean(self.land_threshold))
     self.assertEqual(
         result.coord("topographic_zone").bounds[0][0],
         self.land_threshold[0])
     self.assertEqual(
         result.coord("topographic_zone").bounds[0][1],
         self.land_threshold[1])
예제 #18
0
 def test_thresholdset(self):
     """test the plugin produces correct number of cubes"""
     result = GenOrogMasks().process(self.orography,
                                     self.threshold_dict,
                                     landmask=self.landmask)
     self.assertEqual(len(result), 2)