示例#1
0
 def test_extent(self):
     cube = low_res_4d()
     _, extent = project(cube, ROBINSON)
     self.assertEqual(extent, [
         -17005833.33052523, 17005833.33052523, -8625155.12857459,
         8625155.12857459
     ])
示例#2
0
    def test_is_iris_coord_system(self):
        res, _ = project(self.cube, self.tcs)
        self.assertEqual(res.coord("projection_y_coordinate").coord_system, self.tcs)
        self.assertEqual(res.coord("projection_x_coordinate").coord_system, self.tcs)

        self.assertIsNot(res.coord("projection_y_coordinate").coord_system, self.tcs)
        self.assertIsNot(res.coord("projection_x_coordinate").coord_system, self.tcs)
示例#3
0
 def test_no_coord_system(self):
     cube = low_res_4d()
     cube.coord('grid_longitude').coord_system = None
     cube.coord('grid_latitude').coord_system = None
     with iris.tests.mock.patch('warnings.warn') as warn:
         _, _ = project(cube, ROBINSON)
     warn.assert_called_once_with('Coordinate system of latitude and '
                                  'longitude coordinates is not specified. '
                                  'Assuming WGS84 Geodetic.')
示例#4
0
 def test_no_coord_system(self):
     cube = low_res_4d()
     cube.coord('grid_longitude').coord_system = None
     cube.coord('grid_latitude').coord_system = None
     with iris.tests.mock.patch('warnings.warn') as warn:
         _, _ = project(cube, ROBINSON)
     warn.assert_called_once_with('Coordinate system of latitude and '
                                  'longitude coordinates is not specified. '
                                  'Assuming WGS84 Geodetic.')
示例#5
0
    def test_is_iris_coord_system(self):
        res, _ = project(self.cube, self.tcs)
        self.assertEqual(
            res.coord('projection_y_coordinate').coord_system, self.tcs)
        self.assertEqual(
            res.coord('projection_x_coordinate').coord_system, self.tcs)

        self.assertIsNot(
            res.coord('projection_y_coordinate').coord_system, self.tcs)
        self.assertIsNot(
            res.coord('projection_x_coordinate').coord_system, self.tcs)
示例#6
0
 def test_bad_resolution_non_numeric(self):
     cube = low_res_4d()
     with self.assertRaises(ValueError):
         project(cube, ROBINSON, nx=200, ny='abc')
示例#7
0
 def test_cube(self):
     cube = low_res_4d()
     new_cube, _ = project(cube, ROBINSON)
     self.assertCMLApproxData(new_cube)
示例#8
0
 def test_explicit_resolution_single_point(self):
     cube = low_res_4d()
     nx, ny = 1, 1
     new_cube, extent = project(cube, ROBINSON, nx=nx, ny=ny)
     self.assertEqual(new_cube.shape, cube.shape[:2] + (ny, nx))
示例#9
0
 def test_mismatched_coord_systems(self):
     cube = low_res_4d()
     cube.coord('grid_longitude').coord_system = None
     with self.assertRaises(ValueError):
         project(cube, ROBINSON)
示例#10
0
 def test_explicit_resolution_single_point(self):
     cube = low_res_4d()
     nx, ny = 1, 1
     new_cube, extent = project(cube, ROBINSON, nx=nx, ny=ny)
     self.assertEqual(new_cube.shape, cube.shape[:2] + (ny, nx))
示例#11
0
 def test_default_resolution(self):
     cube = low_res_4d()
     new_cube, extent = project(cube, ROBINSON)
     self.assertEqual(new_cube.shape, cube.shape)
示例#12
0
 def test_default_resolution(self):
     cube = low_res_4d()
     new_cube, extent = project(cube, ROBINSON)
     self.assertEqual(new_cube.shape, cube.shape)
示例#13
0
 def test_bad_resolution_non_numeric(self):
     cube = low_res_4d()
     with self.assertRaises(ValueError):
         project(cube, ROBINSON, nx=200, ny='abc')
示例#14
0
 def test_bad_resolution_negative(self):
     cube = low_res_4d()
     with self.assertRaises(ValueError):
         project(cube, ROBINSON, nx=-200, ny=200)
示例#15
0
 def test_cube(self):
     cube = low_res_4d()
     new_cube, _ = project(cube, ROBINSON)
     self.assertCMLApproxData(new_cube)
示例#16
0
 def test_extent(self):
     cube = low_res_4d()
     _, extent = project(cube, ROBINSON)
     self.assertEqual(extent, [-17005833.33052523, 17005833.33052523,
                               -8625155.12857459, 8625155.12857459])
示例#17
0
 def test_mismatched_coord_systems(self):
     cube = low_res_4d()
     cube.coord('grid_longitude').coord_system = None
     with self.assertRaises(ValueError):
         project(cube, ROBINSON)
示例#18
0
 def test_bad_resolution_negative(self):
     cube = low_res_4d()
     with self.assertRaises(ValueError):
         project(cube, ROBINSON, nx=-200, ny=200)
示例#19
0
 def test_missing_latlon(self):
     cube = low_res_4d()
     cube.remove_coord('grid_longitude')
     cube.remove_coord('grid_latitude')
     with self.assertRaises(ValueError):
         project(cube, ROBINSON)
示例#20
0
 def test_missing_lon(self):
     cube = low_res_4d()
     cube.remove_coord('grid_longitude')
     with self.assertRaises(ValueError):
         project(cube, ROBINSON)
def main():
    import os#, sys

    #smoothing_width = float(sys.argv[1])
    #resolution = int(sys.argv[2])

    smoothing_width = 10.
    resolution = 48


    dlat = 180. / int(resolution*1.5)
    lat_p = np.arange(-90.+dlat/2, 90., dlat)

    dlon = 360. / int(resolution*2)
    lon_p = np.arange(dlon/2, 360.,dlon)

    lat = iris.coords.DimCoord(lat_p, 'latitude',  units = 'degrees')
    lon = iris.coords.DimCoord(lon_p, 'longitude', units = 'degrees')
    data = np.empty((len(lat_p),len(lon_p)))

    source_cube = iris.cube.Cube(data, dim_coords_and_dims = [(lat,0),(lon,1)])

#    smoothing_width = 2.
#    fn = lambda x: np.exp(-x**2 / (2. *smoothing_width**2))

    fn = lambda x: (x <= smoothing_width) * 1.0
    gs = GridSmoother()
    
    filename = "simple_%s_grid_smoother_%s_%s.json.gz" %(smoothing_width,dlat,dlon)

    if os.path.exists(filename):
        print "loading ", filename
        gs.load(filename)
    else:
        print "generating smoother for %sx%s (lat x lon) degree source grid" %(dlat,dlon)
        gs.build(source_cube, fn, quiet=False, metadata={'source_grid':"N48","smoothing radius":smoothing_width})
        print "saving to ", filename
        gs.save(filename)

    print "filling test cube with data"
    source_cube.data.fill(0)
    source_cube.long_name = "Source data"
    for i,ilat in enumerate(lat_p):
        for j,jlon in enumerate(lon_p):
            R = np.sqrt((ilat-0)**2 + (jlon-60.)**2)
            if R > 20 and R < 25:
                source_cube.data[i,j] = 10
    
    tmpcube, extent = iac.project(source_cube, ccrs.RotatedPole(90, 20))
    source_cube.data = tmpcube.data + tmpcube.data[:, ::-1]
    
    for i,ilat in enumerate(lat_p):
        for j,jlon in enumerate(lon_p):
            if 17.5 <= ilat <= 22.5 and (jlon < 60 or jlon > 300):
                source_cube.data[i,j] = 10

    print "smoothing test cube"
    result_cube = gs.smooth_2d_cube(source_cube)
    result_cube.long_name = "Smoothed data"
    print "plotting"
    
    
    proj = ccrs.Orthographic(0,65)
    #proj = ccrs.PlateCarree()
    fig = plt.figure()
    s = fig.add_subplot(121, projection=proj)
    qplt.pcolormesh(source_cube, cmap='Greens')
    s.set_global()
    s.gridlines()
    plt.gca().coastlines()
    r = fig.add_subplot(122, projection= proj)
    qplt.pcolormesh(result_cube,cmap='Blues')
    r.set_global()
    r.gridlines()
    plt.gca().coastlines()
#    plt.savefig(filename[:-8]+".png")
    plt.show()