Exemplo n.º 1
0
    def setUp(self):
        lat, lon = np.arange(180) - 90, np.arange(360) - 180
        self.lats, self.lons = np.meshgrid(lat, lon)
        self.lats, self.lons = self.lats.flatten(), self.lons.flatten()
        self.cells = grids.lonlat2cell(self.lons, self.lats)
        self.subset = np.sort(np.random.choice(np.arange(self.lats.size),
                                               size=500, replace=False))
        self.basic = grids.BasicGrid(self.lons, self.lats, subset=self.subset,
                                     shape=(360, 180))

        self.basic_shape_gpis = grids.BasicGrid(self.lons, self.lats,
                                                gpis=np.arange(self.lats.size),
                                                subset=self.subset,
                                                shape=(360, 180))
        self.basic_generated = grids.genreg_grid(1, 1)
        self.basic_irregular = grids.BasicGrid(np.random.random(360 * 180) * 360 - 180,
                                               np.random.random(
                                                   360 * 180) * 180 - 90,
                                               subset=self.subset)
        self.cellgrid = grids.CellGrid(self.lons, self.lats, self.cells,
                                       subset=self.subset)

        self.cellgrid_shape = grids.CellGrid(self.lons, self.lats, self.cells,
                                             subset=self.subset,
                                             shape=(360, 180))

        self.testfile = tempfile.NamedTemporaryFile().name
Exemplo n.º 2
0
def test_setup_cellgrid_with_lists():

    grid = grids.CellGrid([1, 2, 3, 4, 5], [1, 2, 3, 4, 5], [1, 1, 1, 1, 1])

    nptest.assert_allclose(grid.arrlon, np.array([1, 2, 3, 4, 5]))
    nptest.assert_allclose(grid.arrlat, np.array([1, 2, 3, 4, 5]))
    nptest.assert_allclose(grid.arrcell, np.array([1, 1, 1, 1, 1]))
Exemplo n.º 3
0
 def test_subgrid_from_gpis(self):
     """
     Test subgrid selection.
     """
     gpis = [200, 255]
     subgrid = self.cellgrid.subgrid_from_gpis(gpis)
     assert type(subgrid) == type(self.cellgrid)
     lons_should, lats_should = self.cellgrid.gpi2lonlat(gpis)
     cells_should = self.cellgrid.gpi2cell(gpis)
     subgrid_should = grids.CellGrid(lons_should,
                                     lats_should,
                                     cells_should,
                                     gpis=gpis)
     assert subgrid == subgrid_should
Exemplo n.º 4
0
def test_reorder_to_cellsize():
    """
    Test reordering to different cellsize
    """
    lons = np.array([-177, -177, -176, -176])
    lats = np.array([51, 57, 51, 57])
    gpis = np.array([1, 2, 3, 4])
    cells = np.array([14, 14, 14, 14])
    orig_grid = grids.CellGrid(lons, lats, cells, gpis=gpis)
    reordered_grid = grids.reorder_to_cellsize(orig_grid, 5.0, 5.0)
    nptest.assert_almost_equal(reordered_grid.gpis, np.array([1, 3, 2, 4]))
    nptest.assert_almost_equal(reordered_grid.arrlon,
                               np.array([-177, -176, -177, -176]))
    nptest.assert_almost_equal(reordered_grid.arrlat,
                               np.array([51, 51, 57, 57]))
    nptest.assert_almost_equal(reordered_grid.arrcell,
                               np.array([14, 14, 14, 14]))