예제 #1
0
    def test_identical(self):
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        return_sio = six.StringIO()
        iris.util.describe_diff(test_cube_a, test_cube_b, output_file=return_sio)
        return_str = return_sio.getvalue()

        self.assertString(return_str, 'compatible_cubes.str.txt')
예제 #2
0
파일: test_util.py 프로젝트: hjoliver/iris
    def test_identical(self):
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        return_str_IO = StringIO.StringIO()
        iris.util.describe_diff(test_cube_a, test_cube_b, output_file=return_str_IO)
        return_str = return_str_IO.getvalue()

        self.assertString(return_str, 'compatible_cubes.str.txt')
예제 #3
0
    def test_scalar_cube(self):
        cube = stock.realistic_4d()[0, 0, 0, 0]

        with self.temp_filename(suffix='.nc') as filename:
            iris.save(cube, filename, netcdf_format='NETCDF3_CLASSIC')
            self.assertCDL(filename,
                           ('netcdf', 'netcdf_save_realistic_0d.cdl'))
 def test_nop(self):
     # The destination grid points are exactly the same as the
     # src grid points.
     src = realistic_4d()[:5, :2, ::40, ::30]
     grid = src.copy()
     result = regrid(src, grid)
     self.assertEqual(result, src)
 def test_nop(self):
     # The destination grid points are exactly the same as the
     # src grid points.
     src = realistic_4d()[:5, :2, ::40, ::30]
     grid = src.copy()
     result = regrid(src, grid)
     self.assertEqual(result, src)
예제 #6
0
    def test_scalar_cube(self):
        cube = stock.realistic_4d()[0, 0, 0, 0]

        with self.temp_filename(suffix=".nc") as filename:
            iris.save(cube, filename, netcdf_format="NETCDF3_CLASSIC")
            self.assertCDL(filename,
                           ("netcdf", "netcdf_save_realistic_0d.cdl"))
예제 #7
0
파일: test_netcdf.py 프로젝트: cpelley/iris
    def test_scalar_cube(self):
        cube = stock.realistic_4d()[0, 0, 0, 0]

        with self.temp_filename(suffix='.nc') as filename:
            iris.save(cube, filename, netcdf_format='NETCDF3_CLASSIC')
            self.assertCDL(filename, ('netcdf',
                                      'netcdf_save_realistic_0d.cdl'))
예제 #8
0
파일: test_util.py 프로젝트: pelson/iris
    def test_output_file(self):
        # test incompatible attributes
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d().collapsed("model_level_number", iris.analysis.MEAN)

        test_cube_a.attributes["Conventions"] = "CF-1.5"
        test_cube_b.attributes["Conventions"] = "CF-1.6"
        test_cube_a.standard_name = "relative_humidity"
        test_cube_a.units = iris.unit.Unit("m")

        with self.temp_filename() as filename:
            with open(filename, "w") as f:
                iris.util.describe_diff(test_cube_a, test_cube_b, output_file=f)
                f.close()

            self.assertFilesEqual(filename, "incompatible_cubes.str.txt")
예제 #9
0
    def test_different(self):
        # test incompatible attributes
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        test_cube_a.attributes["Conventions"] = "CF-1.5"
        test_cube_b.attributes["Conventions"] = "CF-1.6"

        return_sio = StringIO()
        iris.util.describe_diff(
            test_cube_a, test_cube_b, output_file=return_sio
        )
        return_str = return_sio.getvalue()

        self.assertString(return_str, "incompatible_attr.str.txt")

        # test incompatible names
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        test_cube_a.standard_name = "relative_humidity"

        return_sio = StringIO()
        iris.util.describe_diff(
            test_cube_a, test_cube_b, output_file=return_sio
        )
        return_str = return_sio.getvalue()

        self.assertString(return_str, "incompatible_name.str.txt")

        # test incompatible unit
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        test_cube_a.units = cf_units.Unit("m")

        return_sio = StringIO()
        iris.util.describe_diff(
            test_cube_a, test_cube_b, output_file=return_sio
        )
        return_str = return_sio.getvalue()

        self.assertString(return_str, "incompatible_unit.str.txt")

        # test incompatible methods
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d().collapsed(
            "model_level_number", iris.analysis.MEAN
        )

        return_sio = StringIO()
        iris.util.describe_diff(
            test_cube_a, test_cube_b, output_file=return_sio
        )
        return_str = return_sio.getvalue()

        self.assertString(return_str, "incompatible_meth.str.txt")
예제 #10
0
    def test_different(self):
        return_str_IO = StringIO.StringIO()

        # test incompatible attributes
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        test_cube_a.attributes['Conventions'] = 'CF-1.5'
        test_cube_b.attributes['Conventions'] = 'CF-1.6'

        iris.util.describe_diff(test_cube_a,
                                test_cube_b,
                                output_file=return_str_IO)
        return_str = return_str_IO.getvalue()

        self.assertString(return_str, 'incompatible_attr.str.txt')

        # test incompatible names
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        test_cube_a.standard_name = "relative_humidity"

        return_str_IO.truncate(0)
        iris.util.describe_diff(test_cube_a,
                                test_cube_b,
                                output_file=return_str_IO)
        return_str = return_str_IO.getvalue()

        self.assertString(return_str, 'incompatible_name.str.txt')

        # test incompatible unit
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        test_cube_a.units = iris.unit.Unit('m')

        return_str_IO.truncate(0)
        iris.util.describe_diff(test_cube_a,
                                test_cube_b,
                                output_file=return_str_IO)
        return_str = return_str_IO.getvalue()

        self.assertString(return_str, 'incompatible_unit.str.txt')

        # test incompatible methods
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d().collapsed('model_level_number',
                                                     iris.analysis.MEAN)

        return_str_IO.truncate(0)
        iris.util.describe_diff(test_cube_a,
                                test_cube_b,
                                output_file=return_str_IO)
        return_str = return_str_IO.getvalue()

        self.assertString(return_str, 'incompatible_meth.str.txt')
예제 #11
0
    def test_nonmesh_hybrid_dim(self):
        # Check a case with a hybrid non-mesh dimension
        cube = realistic_4d()
        # Strip off the time and longitude dims, to make it simpler.
        cube = cube[0, ..., 0]
        # Remove all the unwanted coords (also loses the coord-system)
        lose_coords = (
            "time",
            "forecast_period",
            "grid_longitude",
            "grid_latitude",
        )
        for coord in lose_coords:
            cube.remove_coord(coord)

        # Add a mesh on the remaining (now anonymous) horizontal dimension.
        i_horizontal_dim = len(cube.shape) - 1
        n_places = cube.shape[i_horizontal_dim]
        mesh = make_mesh(
            n_faces=n_places,
            n_nodes=30,  # arbitrary + unrealistic, but doesn't actually matter
        )
        # Attach the mesh by adding MeshCoords
        for coord in mesh.to_MeshCoords("face"):
            cube.add_aux_coord(coord, (i_horizontal_dim,))

        # Save and snapshot the result
        tempfile_path = self.check_save_cubes(cube)
        dims, vars = scan_dataset(tempfile_path)

        # have just 1 mesh, including face and node coordinates.
        (mesh_name,) = vars_meshnames(vars)
        face_dim = vars_meshdim(vars, "face", mesh_name)
        _ = vars_meshdim(vars, "node", mesh_name)

        # have hybrid vertical dimension, with all the usual term variables.
        self.assertIn("model_level_number", dims)
        vert_vars = list(vars_w_dims(vars, ["model_level_number"]).keys())
        # The list of file variables mapping the vertical dimension:
        # = the data-var, plus all the height terms
        self.assertEqual(
            vert_vars,
            [
                "air_potential_temperature",
                "model_level_number",
                "level_height",
                "level_height_bnds",
                "sigma",
                "sigma_bnds",
            ],
        )

        # have just 1 data-variable, which maps to hybrid-height and mesh dims
        ((data_name, data_props),) = vars_w_props(vars, mesh="*").items()
        self.assertEqual(
            data_props[_VAR_DIMS], ["model_level_number", face_dim]
        )
        self.assertEqual(data_props["mesh"], mesh_name)
        self.assertEqual(data_props["location"], "face")
 def test_argument_is_coord_instance(self):
     cube_a = stock.realistic_4d()
     cube_b = cube_a.copy()
     promote_aux_coord_to_dim_coord(cube_b, cube_b.coord('level_height'))
     self.assertEqual(cube_b.dim_coords,
                      (cube_a.coord('time'), cube_a.coord('level_height'),
                       cube_a.coord('grid_latitude'),
                       cube_a.coord('grid_longitude')))
 def test_argument_is_coord_instance(self):
     cube_a = stock.realistic_4d()
     cube_b = cube_a.copy()
     promote_aux_coord_to_dim_coord(cube_b, cube_b.coord('level_height'))
     self.assertEqual(
         cube_b.dim_coords,
         (cube_a.coord('time'), cube_a.coord('level_height'),
          cube_a.coord('grid_latitude'), cube_a.coord('grid_longitude')))
예제 #14
0
 def test_multiple_cubes_no_transform(self):
     target = ConcreteReferenceTarget("foo")
     src = stock.realistic_4d()
     for i in range(src.shape[0]):
         target.add_cube(src[i])
     dest = target.as_cube()
     self.assertIsNot(dest, src)
     self.assertEqual(dest, src)
예제 #15
0
파일: test_rules.py 프로젝트: bamundi/iris
 def test_multiple_cubes_no_transform(self):
     target = ConcreteReferenceTarget('foo')
     src = stock.realistic_4d()
     for i in range(src.shape[0]):
         target.add_cube(src[i])
     dest = target.as_cube()
     self.assertIsNot(dest, src)
     self.assertEqual(dest, src)
예제 #16
0
    def test_output_file(self):
        # test incompatible attributes
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d().collapsed('model_level_number', iris.analysis.MEAN)

        test_cube_a.attributes['Conventions'] = 'CF-1.5'
        test_cube_b.attributes['Conventions'] = 'CF-1.6'
        test_cube_a.standard_name = "relative_humidity"
        test_cube_a.units = cf_units.Unit('m')

        with self.temp_filename() as filename:
            with open(filename, 'w') as f:
                iris.util.describe_diff(test_cube_a, test_cube_b, output_file=f)
                f.close()

            self.assertFilesEqual(filename,
                              'incompatible_cubes.str.txt')
 def test_argument_is_coord_instance(self):
     cube_a = stock.realistic_4d()
     cube_b = cube_a.copy()
     coord = cube_b.coord('model_level_number').copy()
     demote_dim_coord_to_aux_coord(cube_b, coord)
     self.assertEqual(cube_b.dim_coords,
                      (cube_a.coord('time'), cube_a.coord('grid_latitude'),
                       cube_a.coord('grid_longitude')))
 def test_dimension_is_anonymous(self):
     cube_a = stock.realistic_4d()
     cube_b = cube_a.copy()
     cube_b.remove_coord('model_level_number')
     promote_aux_coord_to_dim_coord(cube_b, 'level_height')
     self.assertEqual(cube_b.dim_coords,
                      (cube_a.coord('time'), cube_a.coord('level_height'),
                       cube_a.coord('grid_latitude'),
                       cube_a.coord('grid_longitude')))
 def test_dimension_is_anonymous(self):
     cube_a = stock.realistic_4d()
     cube_b = cube_a.copy()
     cube_b.remove_coord('model_level_number')
     promote_aux_coord_to_dim_coord(cube_b, 'level_height')
     self.assertEqual(
         cube_b.dim_coords,
         (cube_a.coord('time'), cube_a.coord('level_height'),
          cube_a.coord('grid_latitude'), cube_a.coord('grid_longitude')))
예제 #20
0
def test_to_level():
    cube = stock.realistic_4d()
    result = irise.interpolate.to_level(cube[0], altitude=[5000])

    assert result.ndim == 3
    assert result.dim_coords[0].name() == "altitude"
    assert result.dim_coords[1].name() == "grid_latitude"
    assert result.dim_coords[2].name() == "grid_longitude"
    np.testing.assert_almost_equal(result.data[0, 0, 0], 312.4549, decimal=4)
 def test_argument_is_coord_instance(self):
     cube_a = stock.realistic_4d()
     cube_b = cube_a.copy()
     coord = cube_b.coord('model_level_number').copy()
     demote_dim_coord_to_aux_coord(cube_b, coord)
     self.assertEqual(cube_b.dim_coords,
                      (cube_a.coord('time'),
                       cube_a.coord('grid_latitude'),
                       cube_a.coord('grid_longitude')))
예제 #22
0
 def setUp(self):
     self.cube = stock.realistic_4d()
     # Define expected iterators for 1D and 2D test cases.
     self.exp_iter_1d = xrange(
         len(self.cube.coord('model_level_number').points))
     self.exp_iter_2d = np.ndindex(6, 70, 1, 1)
     # Define maximum number of interations for particularly long
     # (and so time-consuming) iterators.
     self.long_iterator_max = 5
예제 #23
0
    def test_multidimensional(self):
        """
        Check valid operation on a multidimensional cube.

        Calculation should repeat across multiple dimensions.
        Any attached orography is interpolated.

        NOTE: in future, extra dimensions may be passed through to ESMF:  At
        present, it repeats the calculation on 2d slices.  So we check that
        at least the results are equivalent (as it's quite easy to do).

        """
        # Get some higher-dimensional test data
        c1 = istk.realistic_4d()
        # Chop down to small size, and mask some data
        c1 = c1[:3, :4, :16, :12]
        c1.data[:, 2, :, :] = np.ma.masked
        c1.data[1, 1, 3:9, 4:7] = np.ma.masked
        # Give it a slightly more challenging indexing order: tzyx --> xzty
        c1.transpose((3, 1, 0, 2))

        # Construct a (coarser) target grid of about the same extent
        c1_cs = c1.coord(axis="x").coord_system
        xlims = _minmax(c1.coord(axis="x").contiguous_bounds())
        ylims = _minmax(c1.coord(axis="y").contiguous_bounds())
        # Reduce the dimensions slightly to avoid NaNs in regridded orography
        delta = 0.05
        # || NOTE: this is *not* a small amount.  Think there is a bug.
        # || NOTE: See https://github.com/SciTools/iris/issues/458
        xlims = np.interp([delta, 1.0 - delta], [0, 1], xlims)
        ylims = np.interp([delta, 1.0 - delta], [0, 1], ylims)
        pole_latlon = (
            c1_cs.grid_north_pole_latitude,
            c1_cs.grid_north_pole_longitude,
        )
        c2 = _make_test_cube((7, 8), xlims, ylims, pole_latlon=pole_latlon)

        # regrid onto new grid
        c1_to_c2 = regrid_conservative_via_esmpy(c1, c2)

        # check that all the original coords exist in the new cube
        # NOTE: this also effectively confirms we haven't lost the orography
        def list_coord_names(cube):
            return sorted([coord.name() for coord in cube.coords()])

        self.assertEqual(list_coord_names(c1_to_c2), list_coord_names(c1))

        # check that each xy 'slice' has same values as if done on its own.
        for i_p, i_t in np.ndindex(c1.shape[1:3]):
            c1_slice = c1[:, i_p, i_t]
            c2_slice = regrid_conservative_via_esmpy(c1_slice, c2)
            subcube = c1_to_c2[:, i_p, i_t]
            self.assertEqual(subcube, c2_slice)

        # check all other metadata
        self.assertEqual(c1_to_c2.metadata, c1.metadata)
예제 #24
0
    def test_hybrid(self):
        cube = stock.realistic_4d()

        # Write Cube to netCDF file.
        with self.temp_filename(suffix='.nc') as file_out:
            iris.save(cube, file_out, netcdf_format='NETCDF3_CLASSIC')

            # Check the netCDF file against CDL expected output.
            self.assertCDL(file_out,
                           ('netcdf', 'netcdf_save_realistic_4d.cdl'))
예제 #25
0
 def test_shared_primary(self):
     cube = stock.realistic_4d()
     factory = iris.aux_factory.HybridHeightFactory(
         cube.coord('level_height'), cube.coord('sigma'),
         cube.coord('surface_altitude'))
     factory.rename('another altitude')
     cube.add_aux_factory(factory)
     with self.temp_filename(suffix='.nc') as filename, \
             self.assertRaisesRegexp(ValueError, 'multiple aux factories'):
         iris.save(cube, filename)
예제 #26
0
파일: test_netcdf.py 프로젝트: cpelley/iris
    def test_hybrid(self):
        cube = stock.realistic_4d()

        # Write Cube to netCDF file.
        with self.temp_filename(suffix='.nc') as file_out:
            iris.save(cube, file_out, netcdf_format='NETCDF3_CLASSIC')

            # Check the netCDF file against CDL expected output.
            self.assertCDL(file_out, ('netcdf',
                                      'netcdf_save_realistic_4d.cdl'))
예제 #27
0
    def test_no_hybrid(self):
        cube = stock.realistic_4d()
        cube.remove_aux_factory(cube.aux_factories[0])

        # Write Cube to netCDF file.
        with self.temp_filename(suffix=".nc") as file_out:
            iris.save(cube, file_out, netcdf_format="NETCDF3_CLASSIC")

            # Check the netCDF file against CDL expected output.
            self.assertCDL(
                file_out, ("netcdf", "netcdf_save_realistic_4d_no_hybrid.cdl"))
예제 #28
0
파일: test_rules.py 프로젝트: bamundi/iris
 def test_multiple_cubes_with_transform(self):
     transform = lambda cube: {'long_name': 'wibble'}
     target = ConcreteReferenceTarget('foo', transform)
     src = stock.realistic_4d()
     for i in range(src.shape[0]):
         target.add_cube(src[i])
     dest = target.as_cube()
     self.assertEqual(dest.long_name, 'wibble')
     self.assertNotEqual(dest, src)
     dest.long_name = src.long_name
     self.assertEqual(dest, src)
예제 #29
0
파일: test_rules.py 프로젝트: nleush/iris
 def test_multiple_cubes_with_transform(self):
     transform = lambda cube: {'long_name': 'wibble'}
     target = ConcreteReferenceTarget('foo', transform)
     src = stock.realistic_4d()
     for i in range(src.shape[0]):
         target.add_cube(src[i])
     dest = target.as_cube()
     self.assertEqual(dest.long_name, 'wibble')
     self.assertNotEqual(dest, src)
     dest.long_name = src.long_name
     self.assertEqual(dest, src)
예제 #30
0
class TestSimple(tests.IrisTest):
    slices = iris.cube.CubeList(stock.realistic_4d().slices(
        ['grid_latitude', 'grid_longitude']))

    def test_constraints(self):
        constraint = iris.Constraint(model_level_number=10)
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 6)

        constraint = iris.Constraint(model_level_number=[10, 22])
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 2 * 6)

        constraint = iris.Constraint(
            model_level_number=lambda c: (c > 30) | (c <= 3))
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 43 * 6)

        constraint = iris.Constraint(
            coord_values={'model_level_number': lambda c: c > 1000})
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 0)

        constraint = (iris.Constraint(model_level_number=10)
                      & iris.Constraint(time=347922.))
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 1)

        constraint = iris.Constraint(SN_AIR_POTENTIAL_TEMPERATURE)
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 70 * 6)

    def test_mismatched_type(self):
        constraint = iris.Constraint(model_level_number='aardvark')
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 0)

    def test_cell(self):
        cell = iris.coords.Cell(10)
        constraint = iris.Constraint(model_level_number=cell)
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 6)

    def test_cell_equal_bounds(self):
        cell = self.slices[0].coord('level_height').cell(0)
        constraint = iris.Constraint(level_height=cell)
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 6)

    def test_cell_different_bounds(self):
        cell = iris.coords.Cell(10, bound=(9, 11))
        constraint = iris.Constraint(model_level_number=cell)
        sub_list = self.slices.extract(constraint)
        self.assertEqual(len(sub_list), 0)
예제 #31
0
파일: test_netcdf.py 프로젝트: pp-mo/iris
 def test_shared_primary(self):
     cube = stock.realistic_4d()
     factory = iris.aux_factory.HybridHeightFactory(
         cube.coord("level_height"), cube.coord("sigma"), cube.coord("surface_altitude")
     )
     factory.rename("another altitude")
     cube.add_aux_factory(factory)
     with self.temp_filename(suffix=".nc") as filename, self.assertRaisesRegexp(
         ValueError, "multiple aux factories"
     ):
         iris.save(cube, filename)
    def test_multidimensional(self):
        """
        Check valid operation on a multidimensional cube.

        Calculation should repeat across multiple dimensions.
        Any attached orography is interpolated.

        NOTE: in future, extra dimensions may be passed through to ESMF:  At
        present, it repeats the calculation on 2d slices.  So we check that
        at least the results are equivalent (as it's quite easy to do).

        """
        # Get some higher-dimensional test data
        c1 = istk.realistic_4d()
        # Chop down to small size, and mask some data
        c1 = c1[:3, :4, :16, :12]
        c1.data[:, 2, :, :] = np.ma.masked
        c1.data[1, 1, 3:9, 4:7] = np.ma.masked
        # Give it a slightly more challenging indexing order: tzyx --> xzty
        c1.transpose((3, 1, 0, 2))

        # Construct a (coarser) target grid of about the same extent
        c1_cs = c1.coord(axis='x').coord_system
        xlims = _minmax(c1.coord(axis='x').contiguous_bounds())
        ylims = _minmax(c1.coord(axis='y').contiguous_bounds())
        # Reduce the dimensions slightly to avoid NaNs in regridded orography
        delta = 0.05
            # NOTE: this is *not* a small amount.  Think there is a bug.
            # NOTE: See https://github.com/SciTools/iris/issues/458
        xlims = np.interp([delta, 1.0 - delta], [0, 1], xlims)
        ylims = np.interp([delta, 1.0 - delta], [0, 1], ylims)
        pole_latlon = (c1_cs.grid_north_pole_latitude,
                       c1_cs.grid_north_pole_longitude)
        c2 = _make_test_cube((7, 8), xlims, ylims, pole_latlon=pole_latlon)

        # regrid onto new grid
        c1_to_c2 = regrid_conservative_via_esmpy(c1, c2)

        # check that all the original coords exist in the new cube
        # NOTE: this also effectively confirms we haven't lost the orography
        def list_coord_names(cube):
            return sorted([coord.name() for coord in cube.coords()])

        self.assertEqual(list_coord_names(c1_to_c2), list_coord_names(c1))

        # check that each xy 'slice' has same values as if done on its own.
        for i_p, i_t in np.ndindex(c1.shape[1:3]):
            c1_slice = c1[:, i_p, i_t]
            c2_slice = regrid_conservative_via_esmpy(c1_slice, c2)
            subcube = c1_to_c2[:, i_p, i_t]
            self.assertEqual(subcube, c2_slice)

        # check all other metadata
        self.assertEqual(c1_to_c2.metadata, c1.metadata)
예제 #33
0
 def test_shared_primary(self):
     cube = stock.realistic_4d()
     factory = iris.aux_factory.HybridHeightFactory(
         cube.coord('level_height'),
         cube.coord('sigma'),
         cube.coord('surface_altitude'))
     factory.rename('another altitude')
     cube.add_aux_factory(factory)
     with self.temp_filename(suffix='.nc') as filename, \
             self.assertRaisesRegexp(ValueError, 'multiple aux factories'):
         iris.save(cube, filename)
예제 #34
0
 def setUp(self):
     self.cube = stock.realistic_4d()
     cmth = CellMethod("mean", "time", "6hr")
     self.cube.add_cell_method(cmth)
     cms = CellMeasure([0, 1, 2, 3, 4, 5], long_name="foo")
     self.cube.add_cell_measure(cms, 0)
     avr = AncillaryVariable([0, 1, 2, 3, 4, 5], long_name="bar")
     self.cube.add_ancillary_variable(avr, 0)
     scms = CellMeasure([0], long_name="baz")
     self.cube.add_cell_measure(scms)
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
예제 #35
0
    def test_no_hybrid(self):
        cube = stock.realistic_4d()
        cube.remove_aux_factory(cube.aux_factories[0])

        # Write Cube to netCDF file.
        file_out = iris.util.create_temp_filename(suffix='.nc')
        iris.save(cube, file_out, netcdf_format='NETCDF3_CLASSIC')

        # Check the netCDF file against CDL expected output.
        self.assertCDL(file_out,
                       ('netcdf', 'netcdf_save_realistic_4d_no_hybrid.cdl'))
        os.remove(file_out)
예제 #36
0
파일: test_netcdf.py 프로젝트: pp-mo/iris
 def test_hybrid_height_and_pressure(self):
     cube = stock.realistic_4d()
     cube.add_aux_coord(iris.coords.DimCoord(1200.0, long_name="level_pressure", units="hPa"))
     cube.add_aux_coord(iris.coords.DimCoord(0.5, long_name="other sigma"))
     cube.add_aux_coord(iris.coords.DimCoord(1000.0, long_name="surface_air_pressure", units="hPa"))
     factory = iris.aux_factory.HybridPressureFactory(
         cube.coord("level_pressure"), cube.coord("other sigma"), cube.coord("surface_air_pressure")
     )
     cube.add_aux_factory(factory)
     with self.temp_filename(suffix=".nc") as filename:
         iris.save(cube, filename)
         self.assertCDL(filename)
예제 #37
0
 def setUp(self):
     self.cube = stock.realistic_4d()
     cmth = CellMethod('mean', 'time', '6hr')
     self.cube.add_cell_method(cmth)
     cms = CellMeasure([0, 1, 2, 3, 4, 5], measure='area', long_name='foo')
     self.cube.add_cell_measure(cms, 0)
     avr = AncillaryVariable([0, 1, 2, 3, 4, 5], long_name='bar')
     self.cube.add_ancillary_variable(avr, 0)
     scms = CellMeasure([0], measure='area', long_name='baz')
     self.cube.add_cell_measure(scms)
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
예제 #38
0
파일: test_netcdf.py 프로젝트: ckmo/iris
    def test_no_hybrid(self):
        cube = stock.realistic_4d()
        cube.remove_aux_factory(cube.aux_factories[0])

        # Write Cube to netCDF file.
        file_out = iris.util.create_temp_filename(suffix='.nc')
        iris.save(cube, file_out, netcdf_format='NETCDF3_CLASSIC')

        # Check the netCDF file against CDL expected output.
        self.assertCDL(file_out, ('netcdf',
                                  'netcdf_save_realistic_4d_no_hybrid.cdl'))
        os.remove(file_out)
예제 #39
0
 def test_shared_primary(self):
     cube = stock.realistic_4d()
     factory = iris.aux_factory.HybridHeightFactory(
         cube.coord("level_height"),
         cube.coord("sigma"),
         cube.coord("surface_altitude"),
     )
     factory.rename("another altitude")
     cube.add_aux_factory(factory)
     with self.temp_filename(
             suffix=".nc") as filename, self.assertRaisesRegex(
                 ValueError, "multiple aux factories"):
         iris.save(cube, filename)
예제 #40
0
    def test_multiple_cubes_with_transform(self):
        def transform(cube):
            return {"long_name": "wibble"}

        target = ConcreteReferenceTarget("foo", transform)
        src = stock.realistic_4d()
        for i in range(src.shape[0]):
            target.add_cube(src[i])
        dest = target.as_cube()
        self.assertEqual(dest.long_name, "wibble")
        self.assertNotEqual(dest, src)
        dest.long_name = src.long_name
        self.assertEqual(dest, src)
예제 #41
0
파일: test_util.py 프로젝트: hjoliver/iris
    def test_different(self):
        return_str_IO = StringIO.StringIO()
        
        # test incompatible attributes
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()
        
        test_cube_a.attributes['Conventions'] = 'CF-1.5'
        test_cube_b.attributes['Conventions'] = 'CF-1.6'
        
        iris.util.describe_diff(test_cube_a, test_cube_b, output_file=return_str_IO)
        return_str = return_str_IO.getvalue()
        
        self.assertString(return_str, 'incompatible_attr.str.txt')
        
        # test incompatible names
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()

        test_cube_a.standard_name = "relative_humidity"

        return_str_IO.truncate(0)
        iris.util.describe_diff(test_cube_a, test_cube_b, output_file=return_str_IO)
        return_str = return_str_IO.getvalue()

        self.assertString(return_str, 'incompatible_name.str.txt')

        # test incompatible unit
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d()
        
        test_cube_a.units = iris.unit.Unit('m')

        return_str_IO.truncate(0)
        iris.util.describe_diff(test_cube_a, test_cube_b, output_file=return_str_IO)
        return_str = return_str_IO.getvalue()
        
        self.assertString(return_str, 'incompatible_unit.str.txt')
        
        # test incompatible methods
        test_cube_a = stock.realistic_4d()
        test_cube_b = stock.realistic_4d().collapsed('model_level_number', iris.analysis.MEAN)

        return_str_IO.truncate(0)
        iris.util.describe_diff(test_cube_a, test_cube_b, output_file=return_str_IO)
        return_str = return_str_IO.getvalue()

        self.assertString(return_str, 'incompatible_meth.str.txt')
 def test_dimension_is_anonymous(self):
     cube_a = stock.realistic_4d()
     cube_b = cube_a.copy()
     cube_b.remove_coord("model_level_number")
     promote_aux_coord_to_dim_coord(cube_b, "level_height")
     self.assertEqual(
         cube_b.dim_coords,
         (
             cube_a.coord("time"),
             cube_a.coord("level_height"),
             cube_a.coord("grid_latitude"),
             cube_a.coord("grid_longitude"),
         ),
     )
예제 #43
0
 def test_dimension_is_anonymous(self):
     cube_a = stock.realistic_4d()
     cube_b = cube_a.copy()
     cube_b.remove_coord("model_level_number")
     promote_aux_coord_to_dim_coord(cube_b, "level_height")
     self.assertEqual(
         cube_b.dim_coords,
         (
             cube_a.coord("time"),
             cube_a.coord("level_height"),
             cube_a.coord("grid_latitude"),
             cube_a.coord("grid_longitude"),
         ),
     )
예제 #44
0
 def test_hybrid_height_and_pressure(self):
     cube = stock.realistic_4d()
     cube.add_aux_coord(iris.coords.DimCoord(
         1200.0, long_name='level_pressure', units='hPa'))
     cube.add_aux_coord(iris.coords.DimCoord(
         0.5, long_name='other sigma'))
     cube.add_aux_coord(iris.coords.DimCoord(
         1000.0, long_name='surface_air_pressure', units='hPa'))
     factory = iris.aux_factory.HybridPressureFactory(
         cube.coord('level_pressure'),
         cube.coord('other sigma'),
         cube.coord('surface_air_pressure'))
     cube.add_aux_factory(factory)
     with self.temp_filename(suffix='.nc') as filename:
         iris.save(cube, filename)
         self.assertCDL(filename)
예제 #45
0
    def test_pp_append_lists(self):
        # Test PP append saving - lists of cubes.
        # For each of the first four time-steps in the 4D cube,
        # pull out the bottom two levels.
        cube_4d = stock.realistic_4d()
        cubes = [cube_4d[i, :2, :, :] for i in range(4)]

        reference_txt_path = tests.get_result_path(('cube_to_pp', 'append_multi.txt'))
        with self.cube_save_test(reference_txt_path, reference_cubes=cubes) as temp_pp_path:
            iris.save(cubes[:2], temp_pp_path)
            iris.save(cubes[2:], temp_pp_path, append=True)

        reference_txt_path = tests.get_result_path(('cube_to_pp', 'replace_multi.txt'))
        with self.cube_save_test(reference_txt_path, reference_cubes=cubes[2:]) as temp_pp_path:
            iris.save(cubes[:2], temp_pp_path)
            iris.save(cubes[2:], temp_pp_path)
예제 #46
0
    def test_pp_append_lists(self):
        # Test PP append saving - lists of cubes.
        # For each of the first four time-steps in the 4D cube,
        # pull out the bottom two levels.
        cube_4d = stock.realistic_4d()
        cubes = [cube_4d[i, :2, :, :] for i in range(4)]

        reference_txt_path = tests.get_result_path(('cube_to_pp', 'append_multi.txt'))
        with self.cube_save_test(reference_txt_path, reference_cubes=cubes) as temp_pp_path:
            iris.save(cubes[:2], temp_pp_path)
            iris.save(cubes[2:], temp_pp_path, append=True)

        reference_txt_path = tests.get_result_path(('cube_to_pp', 'replace_multi.txt'))
        with self.cube_save_test(reference_txt_path, reference_cubes=cubes[2:]) as temp_pp_path:
            iris.save(cubes[:2], temp_pp_path)
            iris.save(cubes[2:], temp_pp_path)
예제 #47
0
 def test_hybrid_height_and_pressure(self):
     cube = stock.realistic_4d()
     cube.add_aux_coord(
         iris.coords.DimCoord(1200.0,
                              long_name="level_pressure",
                              units="hPa"))
     cube.add_aux_coord(iris.coords.DimCoord(0.5, long_name="other sigma"))
     cube.add_aux_coord(
         iris.coords.DimCoord(1000.0,
                              long_name="surface_air_pressure",
                              units="hPa"))
     factory = iris.aux_factory.HybridPressureFactory(
         cube.coord("level_pressure"),
         cube.coord("other sigma"),
         cube.coord("surface_air_pressure"),
     )
     cube.add_aux_factory(factory)
     with self.temp_filename(suffix=".nc") as filename:
         iris.save(cube, filename)
         self.assertCDL(filename)
예제 #48
0
 def setUp(self):
     self.cube = stock.realistic_4d()
     self.dim_names = [c.name() for c in self.cube.coords(dim_coords=True)]
     self.representer = CubeRepresentation(self.cube)
예제 #49
0
 def setUp(self):
     self.src = realistic_4d()[:5, :2, ::40, ::30]
     self.mode = 'mask'
     self.methods = ('linear', 'nearest')
예제 #50
0
 def setUp(self):
     self.cube = stock.realistic_4d()
     cm = CellMethod('mean', 'time', '6hr')
     self.cube.add_cell_method(cm)
     self.representer = CubeRepresentation(self.cube)
     self.representer._get_bits(self.representer._get_lines())
예제 #51
0
 def setUp(self):
     self.src = realistic_4d()[:5, :2, ::40, ::30]
     self.mode = 'mask'
     self.methods = ('linear', 'nearest')
예제 #52
0
 def setUp(self):
     # The destination grid points are exactly the same as the
     # src grid points.
     self.src = realistic_4d()[:5, :2, ::40, ::30]
     self.grid = self.src.copy()
예제 #53
0
 def setUp(self):
     names = ['grid_latitude', 'grid_longitude']
     self.slices = iris.cube.CubeList(stock.realistic_4d().slices(names))
예제 #54
0
 def setUp(self):
     names = ['grid_latitude', 'grid_longitude']
     self.slices = iris.cube.CubeList(stock.realistic_4d().slices(names))
 def setUp(self):
     self.src = realistic_4d()[:5, :2, ::40, ::30]