Example #1
0
 def test_2d_anti_meridian(self):
     gm = GridMapping.from_coords(x_coords=xr.DataArray([
         [+177.5, +178.5, +179.5, -179.5],
         [+178.5, +179.5, -179.5, -178.5],
         [+179.5, -179.5, -178.5, -177.5],
     ],
                                                        dims=('lat',
                                                              'lon')),
                                  y_coords=xr.DataArray([
                                      [52.4, 52.4, 52.4, 52.4],
                                      [52.6, 52.6, 52.6, 52.6],
                                      [52.8, 52.8, 52.8, 52.8],
                                  ],
                                                        dims=('lat',
                                                              'lon')),
                                  crs=GEO_CRS)
     self.assertEqual((4, 3), gm.size)
     self.assertEqual((4, 3), gm.tile_size)
     self.assertAlmostEqual(0.2, gm.x_res)
     self.assertAlmostEqual(0.2, gm.y_res)
     self.assertEqual((177.4, 52.3, 182.6, 52.9), gm.xy_bbox)
     self.assertEqual(GEO_CRS, gm.crs)
     self.assertEqual(False, gm.is_regular)
     self.assertEqual(True, gm.is_j_axis_up)
     self.assertEqual(True, gm.is_lon_360)
Example #2
0
 def test_2d_regular(self):
     gm = GridMapping.from_coords(x_coords=xr.DataArray([
         [10.2, 10.3, 10.4, 10.5],
         [10.2, 10.3, 10.4, 10.5],
         [10.2, 10.3, 10.4, 10.5],
     ],
                                                        dims=('lat',
                                                              'lon')),
                                  y_coords=xr.DataArray([
                                      [52.4, 52.4, 52.4, 52.4],
                                      [52.6, 52.6, 52.6, 52.6],
                                      [52.8, 52.8, 52.8, 52.8],
                                  ],
                                                        dims=('lat',
                                                              'lon')),
                                  crs=GEO_CRS)
     self.assertEqual((4, 3), gm.size)
     self.assertEqual((4, 3), gm.tile_size)
     self.assertAlmostEqual(0.1, gm.x_res)
     self.assertAlmostEqual(0.2, gm.y_res)
     self.assertAlmostEqual(10.15, gm.x_min)
     self.assertAlmostEqual(52.3, gm.y_min)
     self.assertAlmostEqual(10.55, gm.x_max)
     self.assertAlmostEqual(52.9, gm.y_max)
     self.assertEqual(GEO_CRS, gm.crs)
     self.assertEqual(True, gm.is_regular)
     self.assertEqual(True, gm.is_j_axis_up)
     self.assertEqual(False, gm.is_lon_360)
Example #3
0
 def test_1d_xy_coords(self):
     gm = GridMapping.from_coords(
         x_coords=xr.DataArray(np.linspace(1.5, 8.5, 8), dims='lon'),
         y_coords=xr.DataArray(np.linspace(4.5, -4.5, 10), dims='lat'),
         crs=GEO_CRS)
     xy_coords = gm.xy_coords
     self.assertIsInstance(xy_coords, xr.DataArray)
     self.assertIs(xy_coords, gm.xy_coords)
     self.assertEqual(('coord', 'lat', 'lon'), xy_coords.dims)
     self.assertEqual((2, 10, 8), xy_coords.shape)
     self.assertEqual(('lon', 'lat'), gm.xy_var_names)
     self.assertEqual(('lon', 'lat'), gm.xy_dim_names)
Example #4
0
 def test_1d_lon_360(self):
     gm = GridMapping.from_coords(
         x_coords=xr.DataArray(np.linspace(177.5, 184.5, 8), dims='lon'),
         y_coords=xr.DataArray(np.linspace(4.5, -4.5, 10), dims='lat'),
         crs=GEO_CRS)
     self.assertEqual((8, 10), gm.size)
     self.assertEqual((8, 10), gm.tile_size)
     self.assertEqual((1, 1), gm.xy_res)
     self.assertEqual((177, -5, 185, 5), gm.xy_bbox)
     self.assertEqual(GEO_CRS, gm.crs)
     self.assertEqual(True, gm.is_regular)
     self.assertEqual(False, gm.is_j_axis_up)
     self.assertEqual(True, gm.is_lon_360)
Example #5
0
 def test_1d_x_irregular(self):
     gm = GridMapping.from_coords(
         x_coords=xr.DataArray([1.5, 2.5, 3.5, 4.5, 5.49, 6.5, 7.5, 8.5],
                               dims='lon'),
         y_coords=xr.DataArray(np.linspace(4.5, -4.5, 10), dims='lat'),
         crs=GEO_CRS)
     self.assertEqual((8, 10), gm.size)
     self.assertEqual((8, 10), gm.tile_size)
     self.assertEqual((1, 1), gm.xy_res)
     self.assertEqual((1, -5, 9, 5), gm.xy_bbox)
     self.assertEqual(GEO_CRS, gm.crs)
     self.assertEqual(False, gm.is_regular)
     self.assertEqual(False, gm.is_j_axis_up)
     self.assertEqual(False, gm.is_lon_360)
Example #6
0
    def test_to_regular(self):
        lon = xr.DataArray([[1.0, 6.0], [0.0, 2.0]], dims=('y', 'x'))
        lat = xr.DataArray([[56.0, 53.0], [52.0, 50.0]], dims=('y', 'x'))

        gm_irr = GridMapping.from_coords(lon, lat, GEO_CRS)
        gm_reg_actual = gm_irr.to_regular()
        gm_reg_expected = GridMapping.regular(size=(4, 4),
                                              xy_min=(-2, 48),
                                              xy_res=4.0,
                                              crs=GEO_CRS)
        self.assertEqual(gm_reg_expected.size, gm_reg_actual.size)
        self.assertEqual(gm_reg_expected.tile_size, gm_reg_actual.tile_size)
        self.assertEqual(gm_reg_expected.xy_res, gm_reg_actual.xy_res)
        self.assertEqual(gm_reg_expected.xy_bbox, gm_reg_actual.xy_bbox)
        self.assertEqual(gm_reg_expected.crs, gm_reg_actual.crs)
Example #7
0
 def test_2d_tile_size_from_chunks(self):
     gm = GridMapping.from_coords(x_coords=xr.DataArray(da.array([
         [10.0, 10.1, 10.2, 10.3],
         [10.1, 10.2, 10.3, 10.4],
         [10.2, 10.3, 10.4, 10.5],
     ]).rechunk((2, 3)),
                                                        dims=('lat',
                                                              'lon')),
                                  y_coords=xr.DataArray(da.array([
                                      [52.0, 52.2, 52.4, 52.6],
                                      [52.2, 52.4, 52.6, 52.8],
                                      [52.4, 52.6, 52.8, 53.0],
                                  ]).rechunk((2, 3)),
                                                        dims=('lat',
                                                              'lon')),
                                  crs=GEO_CRS)
     self.assertEqual((4, 3), gm.size)
     self.assertEqual((3, 2), gm.tile_size)
Example #8
0
 def test_2d_xy_coords(self):
     gm = GridMapping.from_coords(x_coords=xr.DataArray([
         [10.0, 10.1, 10.2, 10.3],
         [10.1, 10.2, 10.3, 10.4],
         [10.2, 10.3, 10.4, 10.5],
     ],
                                                        dims=('lat',
                                                              'lon')),
                                  y_coords=xr.DataArray([
                                      [52.0, 52.2, 52.4, 52.6],
                                      [52.2, 52.4, 52.6, 52.8],
                                      [52.4, 52.6, 52.8, 53.0],
                                  ],
                                                        dims=('lat',
                                                              'lon')),
                                  crs=GEO_CRS)
     xy_coords = gm.xy_coords
     self.assertIsInstance(xy_coords, xr.DataArray)
     self.assertIs(xy_coords, gm.xy_coords)
     self.assertEqual(('coord', 'lat', 'lon'), xy_coords.dims)
     self.assertEqual((2, 3, 4), xy_coords.shape)
     self.assertEqual(('lon', 'lat'), gm.xy_var_names)
     self.assertEqual(('lon', 'lat'), gm.xy_dim_names)
Example #9
0
 def test_2d(self):
     gm = GridMapping.from_coords(x_coords=xr.DataArray([
         [10.0, 10.1, 10.2, 10.3],
         [10.1, 10.2, 10.3, 10.4],
         [10.2, 10.3, 10.4, 10.5],
     ],
                                                        dims=('lat',
                                                              'lon')),
                                  y_coords=xr.DataArray([
                                      [52.0, 52.2, 52.4, 52.6],
                                      [52.2, 52.4, 52.6, 52.8],
                                      [52.4, 52.6, 52.8, 53.0],
                                  ],
                                                        dims=('lat',
                                                              'lon')),
                                  crs=GEO_CRS)
     self.assertEqual((4, 3), gm.size)
     self.assertEqual((4, 3), gm.tile_size)
     self.assertEqual((0.3, 0.3), gm.xy_res)
     self.assertEqual((9.85, 51.85, 10.65, 53.15), gm.xy_bbox)
     self.assertEqual(GEO_CRS, gm.crs)
     self.assertEqual(False, gm.is_regular)
     self.assertEqual(True, gm.is_j_axis_up)
     self.assertEqual(False, gm.is_lon_360)