def test_contourf(): a = np.zeros((4, 5)) a[0, 0] = -1 a[1, 1] = 1.1 a[2, 2] = 2.2 a[2, 4] = 1.9 a[3, 3] = 9 s = a * 0. s[2, 2] = 1 # UL Corner g = Grid(nxny=(5, 4), dxdy=(1, -1), ul_corner=(-1, 3), proj=wgs84, pixel_ref='corner') c = Map(g, ny=400, countries=False) c.set_cmap(mpl.cm.get_cmap('viridis')) c.set_plot_params(levels=[0, 1, 2, 3]) c.set_data(a) c.set_contourf(s, interp='linear', hatches=['xxx'], colors='none', levels=[0.5, 1.5]) c.set_lonlat_contours(interval=0.5) c.visualize() # remove it c.set_contourf() c.visualize()
def test_hef(): grid = salem.grids.local_mercator_grid(center_ll=(10.76, 46.798444), extent=(10000, 7000)) c = Map(grid, countries=False) c.set_lonlat_countours(interval=10) c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp')) c.set_topography(get_demo_file('hef_srtm.tif'), interp='linear') c.visualize(addcbar=False, title='linear') c.set_topography(get_demo_file('hef_srtm.tif'), interp='spline', ks=2) c.visualize(addcbar=False, title='spline deg 2') c.set_topography(get_demo_file('hef_srtm.tif')) c.visualize(addcbar=False, title='Default: spline deg 3') h = c.set_topography(get_demo_file('hef_srtm.tif'), interp='spline', ks=5) c.visualize(addcbar=False, title='spline deg 5') dem = salem.GeoTiff(get_demo_file('hef_srtm.tif')) mytopo = dem.get_vardata() c.set_topography(mytopo, crs=dem.grid, interp='spline') c.visualize(addcbar=False, title='From array') c.set_lonlat_countours() c.set_cmap(cleo.get_cm('topo')) c.set_plot_params(nlevels=256) c.set_data(h) c.visualize()
def test_map(self): a = np.zeros((4, 5)) a[0, 0] = -1 a[1, 1] = 1.1 a[2, 2] = 2.2 a[2, 4] = 1.9 a[3, 3] = 9 cmap = copy.deepcopy(mpl.cm.get_cmap('jet')) # ll_corner (type geotiff) g = Grid(nxny=(5, 4), dxdy=(1, 1), ll_corner=(0, 0), proj=wgs84, pixel_ref='corner') c = Map(g, ny=4, countries=False) c.set_cmap(cmap) c.set_plot_params(levels=[0, 1, 2, 3]) c.set_data(a) rgb1 = c.to_rgb() c.set_data(a, crs=g) assert_array_equal(rgb1, c.to_rgb()) c.set_data(a, interp='linear') rgb1 = c.to_rgb() c.set_data(a, crs=g, interp='linear') assert_array_equal(rgb1, c.to_rgb()) # centergrid (type WRF) g = Grid(nxny=(5, 4), dxdy=(1, 1), ll_corner=(0.5, 0.5), proj=wgs84, pixel_ref='center') c = Map(g, ny=4, countries=False) c.set_cmap(cmap) c.set_plot_params(levels=[0, 1, 2, 3]) c.set_data(a) rgb1 = c.to_rgb() c.set_data(a, crs=g) assert_array_equal(rgb1, c.to_rgb()) c.set_data(a, interp='linear') rgb1 = c.to_rgb() c.set_data(a, crs=g.corner_grid, interp='linear') assert_array_equal(rgb1, c.to_rgb()) c.set_data(a, crs=g.center_grid, interp='linear') assert_array_equal(rgb1, c.to_rgb()) # More pixels c = Map(g, ny=500, countries=False) c.set_cmap(cmap) c.set_plot_params(levels=[0, 1, 2, 3]) c.set_data(a) rgb1 = c.to_rgb() c.set_data(a, crs=g) assert_array_equal(rgb1, c.to_rgb()) c.set_data(a, interp='linear') rgb1 = c.to_rgb() c.set_data(a, crs=g, interp='linear') rgb2 = c.to_rgb() # The interpolation is conservative with the grid... srgb = np.sum(rgb2[..., 0:3], axis=2) pok = np.nonzero(srgb != srgb[0, 0]) rgb1 = rgb1[np.min(pok[0]):np.max(pok[0]), np.min(pok[1]):np.max(pok[1]),...] rgb2 = rgb2[np.min(pok[0]):np.max(pok[0]), np.min(pok[1]):np.max(pok[1]),...] assert_array_equal(rgb1, rgb2) cmap.set_bad('pink') # Add masked arrays a[1, 1] = np.NaN c.set_data(a) rgb1 = c.to_rgb() c.set_data(a, crs=g) assert_array_equal(rgb1, c.to_rgb()) # Interp? c.set_data(a, interp='linear') rgb1 = c.to_rgb() c.set_data(a, crs=g, interp='linear') rgb2 = c.to_rgb()