Example #1
0
    def test38(self):
        grid = datamodel.new_cartesian_grid((10,), 1)
        sub = grid[::2]
        self.assertEqual(sub[0].x, 0.5)
        self.assertEqual(sub[(0,)].x, 0.5)

        grid = datamodel.new_cartesian_grid((10, 10), 1)
        sub = grid[::2, ::]
        self.assertEqual(sub[0, 0].x, 0.5)
        self.assertEqual(sub[(0, 1)].y, 1.5)
Example #2
0
    def test38(self):
        grid = datamodel.new_cartesian_grid((10, ), 1)
        sub = grid[::2]
        self.assertEqual(sub[0].x, 0.5)
        self.assertEqual(sub[(0, )].x, 0.5)

        grid = datamodel.new_cartesian_grid((10, 10), 1)
        sub = grid[::2, ::]
        self.assertEqual(sub[0, 0].x, 0.5)
        self.assertEqual(sub[(0, 1)].y, 1.5)
Example #3
0
    def test2(self):
        source = new_cartesian_grid((10, 20), 1.)
        target = new_cartesian_grid((8, 8), 0.125, offset=[0.5, 0.5])

        source.xcopy = source.x
        source.ycopy = source.y

        remapper = grid_remappers.bilinear_2D_remapper(source, target)
        remapper.forward_mapping(["xcopy", "ycopy"])
        self.assertEqual(target.x, target.xcopy)
        self.assertEqual(target.y, target.ycopy)
Example #4
0
 def test2(self):
     source=new_cartesian_grid((10,20),1. | units.m)
     target=new_cartesian_grid((5,10),2. | units.m,offset=[0.,0.15] | units.m)
     
     source.xcopy=source.x
     source.ycopy=source.y
     
     remapper=grid_remappers.interpolating_2D_remapper(source,target)
     remapper.forward_mapping(["xcopy","ycopy"])
     self.assertEqual(target.x,target.xcopy)
     self.assertEqual(target.y,target.ycopy)
Example #5
0
    def test1(self):
        source = new_cartesian_grid((10, 20), 1.)
        target = new_cartesian_grid((5, 10), 2., offset=[0., 0.15])

        source.xcopy = source.x
        source.ycopy = source.y

        remapper = grid_remappers.interpolating_2D_remapper(source, target)
        remapper.forward_mapping(["xcopy", "ycopy"])
        self.assertEqual(target.x, target.xcopy)
        self.assertEqual(target.y, target.ycopy)
Example #6
0
 def test2(self):
     source=new_cartesian_grid((10,20),1. | units.m)
     target=new_cartesian_grid((5,10),2. | units.m ,offset=[0.,0.5] | units.m)
     
     channel=source.new_remapping_channel_to(target,grid_remappers.interpolating_2D_remapper)
             
     source.xcopy=source.x
     source.ycopy=source.y
     
     channel.copy_attributes(["xcopy","ycopy"])
     self.assertEqual(target.x,target.xcopy)
     self.assertEqual(target.y,target.ycopy)
Example #7
0
    def test4(self):
        source = new_cartesian_grid((10, 20), 1.)
        target = new_cartesian_grid((10, 20), 1.5, offset=[-0.5, -0.5])

        source.xcopy = source.x
        source.ycopy = source.y

        remapper = grid_remappers.bilinear_2D_remapper(source,
                                                       target,
                                                       check_inside=False)
        remapper.forward_mapping(["xcopy", "ycopy"])
        self.assertEqual(target.xcopy, numpy.clip(target.x, 0.5, 9.5))
        self.assertEqual(target.ycopy, numpy.clip(target.y, 0.5, 19.5))
Example #8
0
    def test1(self):
        source = new_cartesian_grid((10, 20), 1.)
        target = new_cartesian_grid((5, 10), 2., offset=[0., 0.5])

        channel = source.new_remapping_channel_to(
            target, grid_remappers.interpolating_2D_remapper)

        source.xcopy = source.x
        source.ycopy = source.y

        channel.copy_attributes(["xcopy", "ycopy"])
        self.assertEqual(target.x, target.xcopy)
        self.assertEqual(target.y, target.ycopy)
Example #9
0
    def test3(self):
        source = new_cartesian_grid((10, 20), 1. | units.m)
        target = new_cartesian_grid((5, 10),
                                    2. | units.m,
                                    offset=[0., 0.25] | units.m)

        source.xcopy = source.x
        source.ycopy = source.y

        remapper = grid_remappers.bilinear_2D_remapper(source, target)
        remapper.forward_mapping(["xcopy", "ycopy"])
        self.assertEqual(target.x, target.xcopy)
        self.assertEqual(target.y, target.ycopy)
Example #10
0
 def test39(self):
     grid = datamodel.new_cartesian_grid((10, 10), 1)
     sub = grid[3:6, 5:8]
     self.assertEqual(sub[0:-1, 0:-1].x, sub.x[0:-1, 0:-1])
     self.assertEqual(sub[0:-1, -1].x, sub.x[0:-1, -1])
     self.assertEqual(sub[-1, -1].x, sub.x[-1, -1])
     self.assertEqual(sub[-1, -2].x, sub.x[-1, -2])
Example #11
0
    def test1(self):
        grid1 = datamodel.new_cartesian_grid((4, 5), 1.0 | units.m)
        grid2 = datamodel.new_regular_grid((4, 5), [4.0, 5.0] | units.m)
        grid3 = datamodel.new_rectilinear_grid((4, 5), [numpy.arange(5.0) | units.m, numpy.arange(6.0) | units.m])

        self.assertEqual(grid1.position, grid2.position)
        self.assertEqual(grid2.position, grid3.position)
Example #12
0
 def test39(self):
     grid = datamodel.new_cartesian_grid((10, 10), 1)
     sub = grid[3:6, 5:8]
     self.assertEqual(sub[0:-1, 0:-1].x, sub.x[0:-1, 0:-1])
     self.assertEqual(sub[0:-1, -1].x, sub.x[0:-1, -1])
     self.assertEqual(sub[-1, -1].x, sub.x[-1, -1])
     self.assertEqual(sub[-1, -2].x, sub.x[-1, -2])
Example #13
0
    def generate_initial_grid(self):
        grid = None
        for variable in self.invariate_variables:
            data = self.get_dataset(variable,
                                    nwse_boundingbox=self.nwse_boundingbox,
                                    grid_resolution=self.grid_resolution)

            shortname = self._get_shortname(data, variable)

            lat = data["latitude"][:]
            lon = data["longitude"][:]

            dx = lon[1] - lon[0]
            dy = lat[1] - lat[0]

            assert lon[1] > lon[0]
            assert lat[1] < lat[0]
            assert dx == -dy

            if grid is None:
                grid = new_cartesian_grid(
                    data[shortname][0, :, :].shape,
                    dx | units.deg,
                    offset=([lat[-1] - dx / 2, lon[0] - dx / 2] | units.deg),
                    axes_names=["lat", "lon"])

            value = data[shortname][0, ::-1, :] | _era5_units_to_omuse[
                era5.UNITS[variable]]

            setattr(grid, variable, value)

        return grid
Example #14
0
    def test1(self):
        grid1 = datamodel.new_cartesian_grid((4, 5), 1.0 | units.m)
        grid2 = datamodel.new_regular_grid((4, 5), [4.0, 5.0] | units.m)
        grid3 = datamodel.new_rectilinear_grid(
            (4, 5), [numpy.arange(5.) | units.m,
                     numpy.arange(6.) | units.m])

        self.assertEqual(grid1.position, grid2.position)
        self.assertEqual(grid2.position, grid3.position)
Example #15
0
 def test2(self):
     grid = datamodel.new_rectilinear_grid((10,), (1.0 * numpy.arange(11),))
     self.assertEqual(grid._axes_cell_boundaries, 1.0 * numpy.arange(11))
     grid = datamodel.new_regular_grid((10,), [10.0])
     self.assertEqual(grid._lengths, [10.0])
     grid = datamodel.new_cartesian_grid((10,), 1.0)
     self.assertEqual(grid._cellsize, 1.0)
     grid = datamodel.new_regular_grid((10, 20), [10.0, 15.0])
     self.assertEquals(grid._lengths, [10.0, 15.0])
Example #16
0
 def test2(self):
     grid = datamodel.new_rectilinear_grid((10, ),
                                           (1. * numpy.arange(11), ))
     self.assertEqual(grid._axes_cell_boundaries, 1. * numpy.arange(11))
     grid = datamodel.new_regular_grid((10, ), [10.])
     self.assertEqual(grid._lengths, [10.])
     grid = datamodel.new_cartesian_grid((10, ), 1.)
     self.assertEqual(grid._cellsize, 1.)
     grid = datamodel.new_regular_grid((
         10,
         20,
     ), [10., 15.])
     self.assertEquals(grid._lengths, [10., 15.])
Example #17
0
    def generate_initial_grid(self):
        grid = None
        for variable in self.invariate_variables:
            data = self.get_dataset(variable,
                                    nwse_boundingbox=self.nwse_boundingbox,
                                    grid_resolution=self.grid_resolution)

            shortname = self._get_shortname(data, variable)

            lat = data["latitude"][:]
            lon = data["longitude"][:]

            dx = lon[1] - lon[0]
            dy = lat[1] - lat[0]

            assert lon[1] > lon[0]
            assert lat[1] < lat[0]
            assert dx == -dy

            self.shape = data[shortname][0, :, :].shape
            if self.extra_lon:
                if self.nwse_boundingbox is None:
                    dlon = 360
                else:
                    dlon = self.nwse_boundingbox[3] - self.nwse_boundingbox[1]
                assert dlon.value_in(units.deg) == dx * (self.shape[1])
                self.shape = (self.shape[0], self.shape[1] + 1)

            if grid is None:
                grid = new_cartesian_grid(
                    self.shape,
                    dx | units.deg,
                    offset=([lat[-1] - dx / 2, lon[0] - dx / 2] | units.deg),
                    axes_names=["lat", "lon"])

            value = numpy.zeros(self.shape)
            if self.extra_lon:
                value[:, :self.shape[1] - 1] = data[shortname][0, ::-1, :]
                value[:, -1] = data[shortname][0, ::-1, 0]
            else:
                value = data[shortname][0, ::-1, :]

            setattr(grid, variable,
                    value | _era5_units_to_omuse[era5.UNITS[variable]])

        return grid