Пример #1
0
 def test_dimension_already_has_dimcoord(self):
     cube_a = stock.hybrid_height()
     cube_b = cube_a.copy()
     promote_aux_coord_to_dim_coord(cube_b, "model_level_number")
     self.assertEqual(
         cube_b.dim_coords, (cube_a.coord("model_level_number"),)
     )
 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')))
 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')))
Пример #6
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"),
         ),
     )
 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"),
         ),
     )
Пример #8
0
def main():
    # Load the three files of sample NEMO data.
    fname = iris.sample_data_path("NEMO/nemo_1m_*.nc")
    cubes = iris.load(fname)

    # Some attributes are unique to each file and must be blanked
    # to allow concatenation.
    differing_attrs = ["file_name", "name", "timeStamp", "TimeStamp"]
    for cube in cubes:
        for attribute in differing_attrs:
            cube.attributes[attribute] = ""

    # The cubes still cannot be concatenated because their time dimension is
    # time_counter rather than time. time needs to be promoted to allow
    # concatenation.
    for cube in cubes:
        promote_aux_coord_to_dim_coord(cube, "time")

    # The cubes can now be concatenated into a single time series.
    cube = cubes.concatenate_cube()

    # Generate a time series plot of a single point
    plt.figure()
    y_point_index = 100
    x_point_index = 100
    qplt.plot(cube[:, y_point_index, x_point_index], "o-")

    # Include the point's position in the plot's title
    lat_point = cube.coord("latitude").points[y_point_index, x_point_index]
    lat_string = "{:.3f}\u00B0 {}".format(abs(lat_point),
                                          "N" if lat_point > 0.0 else "S")
    lon_point = cube.coord("longitude").points[y_point_index, x_point_index]
    lon_string = "{:.3f}\u00B0 {}".format(abs(lon_point),
                                          "E" if lon_point > 0.0 else "W")
    plt.title("{} at {} {}".format(cube.long_name.capitalize(), lat_string,
                                   lon_string))

    iplt.show()
Пример #9
0
def main():
    # Load the three files of sample NEMO data.
    fname = iris.sample_data_path('NEMO/nemo_1m_*.nc')
    cubes = iris.load(fname)

    # Some attributes are unique to each file and must be blanked
    # to allow concatenation.
    differing_attrs = ['file_name', 'name', 'timeStamp', 'TimeStamp']
    for cube in cubes:
        for attribute in differing_attrs:
            cube.attributes[attribute] = ''

    # The cubes still cannot be concatenated because their time dimension is
    # time_counter rather than time. time needs to be promoted to allow
    # concatenation.
    for cube in cubes:
        promote_aux_coord_to_dim_coord(cube, 'time')

    # The cubes can now be concatenated into a single time series.
    cube = cubes.concatenate_cube()

    # Generate a time series plot of a single point
    plt.figure()
    y_point_index = 100
    x_point_index = 100
    qplt.plot(cube[:, y_point_index, x_point_index], 'o-')

    # Include the point's position in the plot's title
    lat_point = cube.coord('latitude').points[y_point_index, x_point_index]
    lat_string = '{:.3f}\u00B0 {}'.format(abs(lat_point),
                                          'N' if lat_point > 0. else 'S')
    lon_point = cube.coord('longitude').points[y_point_index, x_point_index]
    lon_string = '{:.3f}\u00B0 {}'.format(abs(lon_point),
                                          'E' if lon_point > 0. else 'W')
    plt.title('{} at {} {}'.format(cube.long_name.capitalize(), lat_string,
                                   lon_string))
    iplt.show()
Пример #10
0
 def test_already_a_dim_coord(self):
     cube_a = stock.simple_2d_w_multidim_and_scalars()
     cube_b = cube_a.copy()
     promote_aux_coord_to_dim_coord(cube_b, "dim1")
     self.assertEqual(cube_a, cube_b)
Пример #11
0
 def test_old_dim_coord_is_now_aux_coord(self):
     cube_a = stock.hybrid_height()
     cube_b = cube_a.copy()
     promote_aux_coord_to_dim_coord(cube_b, "model_level_number")
     self.assertTrue(cube_a.coord("level_height") in cube_b.aux_coords)
 def test_old_dim_coord_is_now_aux_coord(self):
     cube_a = stock.hybrid_height()
     cube_b = cube_a.copy()
     promote_aux_coord_to_dim_coord(cube_b, "model_level_number")
     self.assertTrue(cube_a.coord("level_height") in cube_b.aux_coords)
Пример #13
0
 def test_trying_to_promote_a_scalar_coord(self):
     cube_a = stock.simple_2d_w_multidim_and_scalars()
     with self.assertRaises(ValueError):
         promote_aux_coord_to_dim_coord(cube_a, "an_other")
Пример #14
0
 def test_argument_is_wrong_type(self):
     cube_a = stock.simple_1d()
     with self.assertRaises(TypeError):
         promote_aux_coord_to_dim_coord(cube_a, 0.0)
 def test_trying_to_promote_a_multidim_coord(self):
     cube_a = stock.simple_2d_w_multidim_coords()
     with self.assertRaises(ValueError):
         promote_aux_coord_to_dim_coord(cube_a, "bar")
 def test_argument_is_wrong_type(self):
     cube_a = stock.simple_1d()
     with self.assertRaises(TypeError):
         promote_aux_coord_to_dim_coord(cube_a, 0.0)
 def test_coord_does_not_exist(self):
     cube_a = stock.simple_2d_w_multidim_and_scalars()
     coord = cube_a.coord("dim1").copy()
     coord.rename("new")
     with self.assertRaises(ValueError):
         promote_aux_coord_to_dim_coord(cube_a, coord)
 def test_coord_of_that_name_does_not_exist(self):
     cube_a = stock.simple_2d_w_multidim_and_scalars()
     with self.assertRaises(iris.exceptions.CoordinateNotFoundError):
         promote_aux_coord_to_dim_coord(cube_a, "wibble")
 def test_already_a_dim_coord(self):
     cube_a = stock.simple_2d_w_multidim_and_scalars()
     cube_b = cube_a.copy()
     promote_aux_coord_to_dim_coord(cube_b, "dim1")
     self.assertEqual(cube_a, cube_b)
Пример #20
0
 def test_coord_of_that_name_does_not_exist(self):
     cube_a = stock.simple_2d_w_multidim_and_scalars()
     with self.assertRaises(iris.exceptions.CoordinateNotFoundError):
         promote_aux_coord_to_dim_coord(cube_a, "wibble")
Пример #21
0
 def test_coord_does_not_exist(self):
     cube_a = stock.simple_2d_w_multidim_and_scalars()
     coord = cube_a.coord("dim1").copy()
     coord.rename("new")
     with self.assertRaises(ValueError):
         promote_aux_coord_to_dim_coord(cube_a, coord)
 def test_trying_to_promote_a_nonmonotonic_coord(self):
     cube_a = stock.hybrid_height()
     with self.assertRaises(ValueError):
         promote_aux_coord_to_dim_coord(cube_a, "surface_altitude")
Пример #23
0
 def test_trying_to_promote_a_multidim_coord(self):
     cube_a = stock.simple_2d_w_multidim_coords()
     with self.assertRaises(ValueError):
         promote_aux_coord_to_dim_coord(cube_a, "bar")
 def test_trying_to_promote_a_scalar_coord(self):
     cube_a = stock.simple_2d_w_multidim_and_scalars()
     with self.assertRaises(ValueError):
         promote_aux_coord_to_dim_coord(cube_a, "an_other")
Пример #25
0
 def test_trying_to_promote_a_nonmonotonic_coord(self):
     cube_a = stock.hybrid_height()
     with self.assertRaises(ValueError):
         promote_aux_coord_to_dim_coord(cube_a, "surface_altitude")
 def test_dimension_already_has_dimcoord(self):
     cube_a = stock.hybrid_height()
     cube_b = cube_a.copy()
     promote_aux_coord_to_dim_coord(cube_b, "model_level_number")
     self.assertEqual(cube_b.dim_coords, (cube_a.coord("model_level_number"),))