Example #1
0
 def test_hybrid_height_cubes(self):
     hh1 = stock.simple_4d_with_hybrid_height()
     hh1.attributes["cube"] = "hh1"
     hh2 = stock.simple_4d_with_hybrid_height()
     hh2.attributes["cube"] = "hh2"
     sa = hh2.coord("surface_altitude")
     sa.points = sa.points * 10
     with self.temp_filename(".nc") as fname:
         iris.save([hh1, hh2], fname)
         cubes = iris.load(fname, "air_temperature")
         cubes = sorted(cubes, key=lambda cube: cube.attributes["cube"])
         self.assertCML(cubes)
Example #2
0
 def test_hybrid_height_cubes(self):
     hh1 = stock.simple_4d_with_hybrid_height()
     hh1.attributes['cube'] = 'hh1'
     hh2 = stock.simple_4d_with_hybrid_height()
     hh2.attributes['cube'] = 'hh2'
     sa = hh2.coord('surface_altitude')
     sa.points = sa.points * 10
     with self.temp_filename('.nc') as fname:
         iris.save([hh1, hh2], fname)
         cubes = iris.load(fname)
         cubes = sorted(cubes, key=lambda cube: cube.attributes['cube'])
         self.assertCML(cubes)
Example #3
0
 def test_hybrid_height_cubes(self):
     hh1 = stock.simple_4d_with_hybrid_height()
     hh1.attributes['cube'] = 'hh1'
     hh2 = stock.simple_4d_with_hybrid_height()
     hh2.attributes['cube'] = 'hh2'
     sa = hh2.coord('surface_altitude')
     sa.points = sa.points * 10
     with self.temp_filename('.nc') as fname:
         iris.save([hh1, hh2], fname)
         cubes = iris.load(fname)
         cubes = sorted(cubes, key=lambda cube: cube.attributes['cube'])
         self.assertCML(cubes)
Example #4
0
    def test_cube__anon_dim(self):
        cube = simple_4d_with_hybrid_height()
        cube.remove_coord('model_level_number')  # Make cube dim 1 anonymous.
        waypoints = [{
            'grid_latitude': 21,
            'grid_longitude': 31
        }, {
            'grid_latitude': 23,
            'grid_longitude': 33
        }]
        sample_count = 4
        new_coord_name = 'index'
        trajectory = Trajectory(waypoints, sample_count=sample_count)
        result = trajectory.interpolate(cube)

        dim_names, named_dims, anon_dims = self._result_cube_metadata(result)
        new_coord = result.coord(new_coord_name)
        exp_named_dims = [0, 2]
        exp_anon_dims = [1]

        self.assertEqual(result.ndim, cube.ndim - 1)
        self.assertIn(new_coord_name, dim_names)
        self.assertEqual(named_dims, exp_named_dims)
        self.assertEqual(anon_dims, exp_anon_dims)
        self.assertEqual(len(new_coord.points), sample_count)
    def test_hybrid_height(self):
        cube = istk.simple_4d_with_hybrid_height()
        # Put a biggus array on the cube so we can test deferred loading.
        cube.lazy_data(biggus.NumpyArrayAdapter(cube.data))

        traj = (('grid_latitude', [20.5, 21.5, 22.5, 23.5]),
                ('grid_longitude', [31, 32, 33, 34]))
        xsec = traj_interpolate(cube, traj, method='nearest')

        # Check that creating the trajectory hasn't led to the original
        # data being loaded.
        self.assertTrue(cube.has_lazy_data())
        self.assertCML([cube, xsec], ('trajectory', 'hybrid_height.cml'))
Example #6
0
    def test_hybrid_height(self):
        cube = istk.simple_4d_with_hybrid_height()
        # Put a lazy array into the cube so we can test deferred loading.
        cube.data = as_lazy_data(cube.data)

        traj = (
            ("grid_latitude", [20.5, 21.5, 22.5, 23.5]),
            ("grid_longitude", [31, 32, 33, 34]),
        )
        xsec = traj_interpolate(cube, traj, method="nearest")

        # Check that creating the trajectory hasn't led to the original
        # data being loaded.
        self.assertTrue(cube.has_lazy_data())
        self.assertCML([cube, xsec], ("trajectory", "hybrid_height.cml"))
Example #7
0
    def test_hybrid_height(self):
        cube = istk.simple_4d_with_hybrid_height()
        # Put a lazy array into the cube so we can test deferred loading.
        cube.data = as_lazy_data(cube.data)

        # Use opionated grid-latitudes to avoid the issue of platform
        # specific behaviour within SciPy cKDTree choosing a different
        # equi-distant nearest neighbour point when there are multiple
        # valid candidates.
        traj = (
            ("grid_latitude", [20.4, 21.6, 22.6, 23.6]),
            ("grid_longitude", [31, 32, 33, 34]),
        )
        xsec = traj_interpolate(cube, traj, method="nearest")

        # Check that creating the trajectory hasn't led to the original
        # data being loaded.
        self.assertTrue(cube.has_lazy_data())
        self.assertCML([cube, xsec], ("trajectory", "hybrid_height.cml"))
Example #8
0
def forecast():
    """Creates a set of files with different lead times
    """
    cube = stock.simple_4d_with_hybrid_height()
    times = grid.get_datetime(cube)

    mapping = {}
    for n, time in enumerate(times):
        filename = 'forecast_' + str(n) + '.nc'
        iris.save(cube[n], filename)
        mapping[datetime.datetime(
            time.year,
            time.month,
            time.day,
            time.hour,
            time.minute,
        )] = filename

    yield Forecast(sorted(mapping.keys())[0], mapping)
Example #9
0
    def test_cube__anon_dim(self):
        cube = simple_4d_with_hybrid_height()
        cube.remove_coord('model_level_number')  # Make cube dim 1 anonymous.
        waypoints = [{'grid_latitude': 21, 'grid_longitude': 31},
                     {'grid_latitude': 23, 'grid_longitude': 33}]
        sample_count = 4
        new_coord_name = 'index'
        trajectory = Trajectory(waypoints, sample_count=sample_count)
        result = trajectory.interpolate(cube)

        dim_names, named_dims, anon_dims = self._result_cube_metadata(result)
        new_coord = result.coord(new_coord_name)
        exp_named_dims = [0, 2]
        exp_anon_dims = [1]

        self.assertEqual(result.ndim, cube.ndim - 1)
        self.assertIn(new_coord_name, dim_names)
        self.assertEqual(named_dims, exp_named_dims)
        self.assertEqual(anon_dims, exp_anon_dims)
        self.assertEqual(len(new_coord.points), sample_count)
 def setUp(self):
     self.cube = stock.simple_4d_with_hybrid_height()
     mask = np.isnan(self.cube.data)
     mask[::3, ::3] = True
     self.cube.data = np.ma.masked_array(self.cube.data, mask=mask)
Example #11
0
 def setUp(self):
     self.cube = stock.simple_4d_with_hybrid_height()
     mask = np.isnan(self.cube.data)
     mask[::3, ::3] = True
     self.cube.data = np.ma.masked_array(self.cube.data,
                                         mask=mask)