Пример #1
0
    def test_get_cuts_ldd(self):
        ldd = 'tests/data/cutmaps/ldd_eu.nc'
        clonemap = 'tests/data/cutmaps/area_eu.map'
        stations = 'tests/data/cutmaps/stations.txt'

        ldd_pcr = convert(ldd,
                          clonemap,
                          'tests/data/cutmaps/ldd_eu_test.map',
                          is_ldd=True)[0]
        mask, outlets_points = mask_from_ldd(ldd_pcr, stations)
        x_min, x_max, y_min, y_max = get_cuts(mask=mask)
        # 4067500.0 4397500.0 1282500.0 1577500.0
        assert (x_min, x_max, y_min, y_max) == (4067500, 4397500, 1282500,
                                                1577500)

        fin = 'tests/data/cutmaps/ldd_eu.nc'
        fout = 'tests/data/area_cut.nc'
        cutmap(fin, fout, x_min, x_max, y_min, y_max)
        with Dataset(fout) as nc:
            lons = nc.variables['x'][:]
            lats = nc.variables['y'][:]
            res_x = np.min(lons)
            res_y = np.min(lats)
        os.unlink(fout)
        os.unlink(ldd_pcr)
        assert res_x == 4067500
        assert res_y == 1282500
Пример #2
0
 def test_get_cuts_indices(self):
     # minxi_maxxi:minyi_maxyi
     cuts = '2_5:0_2'
     x_min, x_max, y_min, y_max = get_cuts(cuts=cuts)
     assert (x_min, x_max, y_min, y_max) == (2, 5, 0, 2)
     fin = 'tests/data/folder_a/ta.nc'
     fout = 'tests/data/folder_a/ta_cut.nc'
     cutmap(fin, fout, x_min, x_max, y_min, y_max)
     with Dataset(fout) as nc:
         lons = nc.variables['lon'][:]
         lats = nc.variables['lat'][:]
         res_x = np.round(np.min(lons), 2)
         res_y = np.round(np.min(lats), 2)
     os.unlink(fout)
     assert res_x == -127.05
     assert res_y == 53.25
Пример #3
0
 def test_get_cuts_withcoords(self):
     # lonmin_lonmax:latmin_latmax
     cuts = '-127.0_-126.5:53.2_53.4'
     x_min, x_max, y_min, y_max = get_cuts(cuts=cuts)
     assert (x_min, x_max, y_min, y_max) == (-127.0, -126.5, 53.2, 53.4)
     fin = 'tests/data/folder_a/ta.nc'
     fout = 'tests/data/folder_a/ta_cut.nc'
     cutmap(fin, fout, x_min, x_max, y_min, y_max)
     with Dataset(fout) as nc:
         lons = nc.variables['lon'][:]
         lats = nc.variables['lat'][:]
         res_x = np.round(np.min(lons), 2)
         res_y = np.round(np.min(lats), 2)
     os.unlink(fout)
     assert res_x == -126.95
     assert res_y == 53.25
Пример #4
0
 def test_get_cuts_withmaskpcr(self):
     maskfile = 'tests/data/asia.map'
     x_min, x_max, y_min, y_max = get_cuts(mask=maskfile)
     x_minr, x_maxr, y_minr, y_maxr = np.round(x_min, 2), np.round(
         x_max, 2), np.round(y_min, 2), np.round(y_max, 2)
     assert (x_minr, x_maxr, y_minr, y_maxr) == (58.65, 179.95, 0.65, 81.25)
     fin = 'tests/data/area_global.nc'
     fout = 'tests/data/area_cut.nc'
     cutmap(fin, fout, x_min, x_max, y_min, y_max)
     with Dataset(fout) as nc:
         lons = nc.variables['lon'][:]
         lats = nc.variables['lat'][:]
         res_x = np.round(np.min(lons), 2)
         res_y = np.round(np.min(lats), 2)
     os.unlink(fout)
     assert res_x == 58.75
     assert res_y == 0.65
Пример #5
0
 def test_get_cuts_withmaskfile(self):
     maskfile = 'tests/data/area.nc'
     x_min, x_max, y_min, y_max = get_cuts(mask=maskfile)
     x_minr, x_maxr, y_minr, y_maxr = np.round(x_min, 2), np.round(
         x_max, 2), np.round(y_min, 2), np.round(y_max, 2)
     assert (x_minr, x_maxr, y_minr, y_maxr) == (-127.25, -126.15, 53.05,
                                                 53.45)
     fin = 'tests/data/area_global.nc'
     fout = 'tests/data/area_cut.nc'
     cutmap(fin, fout, x_min, x_max, y_min, y_max)
     with Dataset(fout) as nc:
         lons = nc.variables['lon'][:]
         lats = nc.variables['lat'][:]
         res_x = np.round(np.min(lons), 2)
         res_y = np.round(np.min(lats), 2)
     os.unlink(fout)
     assert res_x == -127.25
     assert res_y == 53.05
Пример #6
0
 def test_get_cuts_withmaskfile_compare(self):
     maskfile = 'tests/data/submask/subcatchment_mask.map'
     x_min, x_max, y_min, y_max = get_cuts(mask=maskfile)
     x_minr, x_maxr, y_minr, y_maxr = np.round(x_min, 2), np.round(
         x_max, 2), np.round(y_min, 2), np.round(y_max, 2)
     assert (x_minr, x_maxr, y_minr, y_maxr) == (4052500.0, 4232500.0,
                                                 2332500.0, 2542500.0)
     fin = 'tests/data/submask/dis.nc'
     fout = 'tests/data/submask/dis_cut.nc'
     cutmap(fin, fout, x_min, x_max, y_min, y_max)
     with Dataset(fout) as nc:
         lons = nc.variables['x'][:]
         lats = nc.variables['y'][:]
         res_x = np.round(np.min(lons), 2)
         res_y = np.round(np.min(lats), 2)
     assert res_x == 4052500.0
     assert res_y == 2332500.0
     comparator = NetCDFComparator(mask=maskfile, array_equal=True)
     comparator.compare_files(fin, fout)
     comparator = NetCDFComparator(array_equal=True)
     comparator.compare_files(fout, 'tests/data/submask/dis_subdomain.nc')
     os.unlink(fout)