コード例 #1
0
ファイル: test_hybrid.py プロジェクト: js297/iris
    def test_invalid_dependencies(self):
        # Must have either delta or orography
        with self.assertRaises(ValueError):
            factory = HybridHeightFactory()
        sigma = self.cube.coord('sigma')
        with self.assertRaises(ValueError):
            factory = HybridHeightFactory(sigma=sigma)

        # Orography must not have bounds
        with warnings.catch_warnings():
            # Cause all warnings to raise Exceptions
            warnings.simplefilter("error")
            with self.assertRaises(UserWarning):
                factory = HybridHeightFactory(orography=sigma)
コード例 #2
0
    def test_hybrid_height_with_non_standard_coords(self):
        # Check the save rules are using the AuxFactory to find the
        # hybrid height coordinates and not relying on their names.
        ny, nx = 30, 40
        sigma_lower, sigma, sigma_upper = 0.75, 0.8, 0.75
        delta_lower, delta, delta_upper = 150, 200, 250

        cube = Cube(np.zeros((ny, nx)), 'air_temperature')
        level_coord = AuxCoord(0, 'model_level_number')
        cube.add_aux_coord(level_coord)
        delta_coord = AuxCoord(delta, bounds=[[delta_lower, delta_upper]],
                               long_name='moog', units='m')
        sigma_coord = AuxCoord(sigma, bounds=[[sigma_lower, sigma_upper]],
                               long_name='mavis')
        surface_altitude_coord = AuxCoord(np.zeros((ny, nx)),
                                          'surface_altitude', units='m')
        cube.add_aux_coord(delta_coord)
        cube.add_aux_coord(sigma_coord)
        cube.add_aux_coord(surface_altitude_coord, (0, 1))
        cube.add_aux_factory(HybridHeightFactory(delta_coord, sigma_coord,
                                                 surface_altitude_coord))

        field = iris.fileformats.pp.PPField3()
        field.lbfc = 0
        field.lbvc = 0
        field.brsvd = [None, None]
        field.lbuser = [None] * 7
        field = verify(cube, field)

        self.assertEqual(field.blev, delta)
        self.assertEqual(field.brlev, delta_lower)
        self.assertEqual(field.bhlev, sigma)
        self.assertEqual(field.bhrlev, sigma_lower)
        self.assertEqual(field.brsvd, [delta_upper, sigma_upper])
コード例 #3
0
def empty_model_level_cube(data, name=None, unit=None, stash=None, **kwargs):
    """
    Create a model_level cube from input data.
    """
    if data is None:
        data = np.empty([1, 3, 8, 6])
    assert data.shape == (3, 8, 6)
    # Make axis=0 for time dim_coord
    new_data = data[np.newaxis, :]
    cube = Cube(new_data)

    # time = AuxCoord([0], 'time', units='hours since epoch')
    time = DimCoord([0], 'time', units='hours since epoch')

    # model = DimCoord([1, 2, 3], 'model_level_number',
    #                  attributes={'positive': 'up'})
    model = DimCoord([1, 2, 3], 'air_pressure',
                     attributes={'positive': 'up'})
    latitude = DimCoord([6.26953125, 6.38671875, 6.50390625, 6.62109375,
                         6.73828125, 6.85546875, 6.97265625, 7.08984375],
                        standard_name='latitude', units='degrees')

    longitude = DimCoord([81.12304688, 81.29882812, 81.47460938,
                          81.65039062, 81.82617188, 82.00195312],
                         standard_name='longitude', units='degrees')

    level_heights = np.array([20., 53.336, 100.])
    level_height = DimCoord(level_heights, long_name='level_height', units='m')
    surface = AuxCoord(topo_aps3.data, 'surface_altitude', units='m')

    sigma = AuxCoord([0.99772321, 0.99393402, 0.98864199], long_name='sigma')

    cube.add_dim_coord(time, 0)
    cube.add_dim_coord(model, 1)
    cube.add_dim_coord(latitude, 2)
    cube.add_dim_coord(longitude, 3)

    cube.add_aux_coord(level_height, 1)
    cube.add_aux_coord(sigma, 1)
    cube.add_aux_coord(surface, (2, 3))

    # Now that we have all of the necessary information, construct a
    # HybridHeight derived "altitude" coordinate.
    cube.add_aux_factory(HybridHeightFactory(level_height, sigma, surface))

    if name:
        cube.long_name = name
    if unit:
        cube.units = unit
    if stash:
        cube.attributes['STASH'] = stash

    return cube
コード例 #4
0
def uk_cube():
    data = np.arange(12, dtype=np.float32).reshape(3, 4)
    uk = Cube(data)
    cs = OSGB()
    y_coord = DimCoord(np.arange(3), 'projection_y_coordinate', units='m',
                       coord_system=cs)
    x_coord = DimCoord(np.arange(4), 'projection_x_coordinate', units='m',
                       coord_system=cs)
    uk.add_dim_coord(y_coord, 0)
    uk.add_dim_coord(x_coord, 1)
    surface = AuxCoord(data * 10, 'surface_altitude', units='m')
    uk.add_aux_coord(surface, (0, 1))
    uk.add_aux_factory(HybridHeightFactory(orography=surface))
    return uk
コード例 #5
0
ファイル: test_hybrid.py プロジェクト: js297/iris
    def test_no_orography(self):
        # Get rid of the normal hybrid-height factory.
        cube = self.cube
        factory = cube.aux_factory(name='altitude')
        cube.remove_aux_factory(factory)

        # Add a new one which only references level_height & sigma.
        delta = cube.coord('level_height')
        sigma = cube.coord('sigma')
        factory = HybridHeightFactory(delta, sigma)
        cube.add_aux_factory(factory)

        self.assertEqual(len(cube.aux_factories), 1)
        self.assertEqual(len(cube.derived_coords), 1)
        self.assertString(str(cube), ('derived', 'no_orog.__str__.txt'))
        self.assertCML(cube, ('derived', 'no_orog.cml'))
コード例 #6
0
    def setUp(self):
        src = global_pp()[::10, ::10]
        level_height = AuxCoord(0, long_name='level_height', units='m',
                                attributes={'positive': 'up'})
        sigma = AuxCoord(1, long_name='sigma')
        surface_altitude = AuxCoord((src.data - src.data.min()) * 50,
                                    'surface_altitude', units='m')
        src.add_aux_coord(level_height)
        src.add_aux_coord(sigma)
        src.add_aux_coord(surface_altitude, [0, 1])
        hybrid_height = HybridHeightFactory(level_height, sigma,
                                            surface_altitude)
        src.add_aux_factory(hybrid_height)
        self.src = src

        grid = global_pp()[:4, :4]
        grid.coord('longitude').points = grid.coord('longitude').points - 5
        self.grid = grid
コード例 #7
0
def mock_hybrid_height_cube():
    """Return mocked cube with hybrid height coordinate."""
    cube = unittest.mock.create_autospec(Cube, spec_set=True, instance=True)
    lev_coord = AuxCoord([1.0], bounds=[[0.0, 2.0]], var_name='lev', units='m')
    b_coord = AuxCoord([0.0], bounds=[[-0.5, 1.5]], var_name='b')
    orog_coord = AuxCoord([[[100000]]], var_name='orog', units='m')
    cube.coord.side_effect = [lev_coord, b_coord, orog_coord,
                              lev_coord, b_coord, orog_coord]
    cube.coords.return_value = [
        lev_coord,
        b_coord,
        orog_coord,
        AuxCoord(0.0, standard_name='atmosphere_hybrid_height_coordinate'),
    ]
    aux_factory = HybridHeightFactory(
        delta=lev_coord,
        sigma=b_coord,
        orography=orog_coord,
    )
    cube.aux_factories = ['dummy', aux_factory]
    return cube