예제 #1
0
def test_gmap_transformed():
    dem = GeoTiff(get_demo_file('hef_srtm.tif'))
    dem.set_subset(margin=-100)

    dem = mercator_grid(center_ll=(10.76, 46.798444), extent=(10000, 7000))

    i, j = dem.ij_coordinates
    g = GoogleVisibleMap(x=i, y=j, crs=dem, size_x=500, size_y=400)
    img = g.get_vardata()

    m = Map(dem, countries=False)

    with pytest.raises(ValueError):
        m.set_data(img)

    m.set_lonlat_contours(interval=0.025)
    m.set_shapefile(get_demo_file('Hintereisferner.shp'),
                    linewidths=2,
                    edgecolor='darkred')
    m.set_rgb(img, g.grid)

    fig, ax = plt.subplots(1, 1)
    m.visualize(ax=ax, addcbar=False)
    plt.tight_layout()
    return fig
예제 #2
0
def test_plot_region_model():

    gdirs = random_for_plot()

    dfc = utils.compile_task_log(gdirs, task_names=['run_random_climate_plot'])
    assert np.all(dfc['run_random_climate_plot'] == 'SUCCESS')

    # We prepare for the plot, which needs our own map to proceed.
    # Lets do a local mercator grid
    g = salem.mercator_grid(center_ll=(10.86, 46.85), extent=(27000, 21000))
    # And a map accordingly
    sm = salem.Map(g, countries=False)
    sm.set_topography(get_demo_file('srtm_oetztal.tif'))

    # Give this to the plot function
    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdirs,
                                  smap=sm,
                                  ax=ax,
                                  filesuffix='_plot',
                                  vmax=250,
                                  modelyr=10,
                                  linewidth=1.5)

    fig.tight_layout()
    return fig
예제 #3
0
def test_gmap_transformed():
    dem = GeoTiff(get_demo_file('hef_srtm.tif'))
    dem.set_subset(margin=-100)

    dem = mercator_grid(center_ll=(10.76, 46.798444),
                        extent=(10000, 7000))

    i, j = dem.ij_coordinates
    g = GoogleVisibleMap(x=i, y=j, crs=dem, size_x=500, size_y=400)
    img = g.get_vardata()

    m = Map(dem, countries=False)

    with pytest.raises(ValueError):
        m.set_data(img)

    m.set_lonlat_contours(interval=0.025)
    m.set_shapefile(get_demo_file('Hintereisferner.shp'),
                    linewidths=2, edgecolor='darkred')
    m.set_rgb(img, g.grid)

    fig, ax = plt.subplots(1, 1)
    m.visualize(ax=ax, addcbar=False)
    plt.tight_layout()
    return fig
예제 #4
0
def test_ice_cap():

    testdir = os.path.join(get_test_dir(), 'tmp_icecap')
    utils.mkdir(testdir, reset=True)

    cfg.initialize()
    cfg.PARAMS['use_intersects'] = False
    cfg.PATHS['dem_file'] = get_demo_file('dem_RGI50-05.08389.tif')
    cfg.PARAMS['border'] = 60
    cfg.PATHS['working_dir'] = testdir

    df = gpd.read_file(get_demo_file('divides_RGI50-05.08389.shp'))
    df['Area'] = df.Area * 1e-6  # cause it was in m2
    df['RGIId'] = ['RGI50-05.08389_d{:02d}'.format(d + 1) for d in df.index]

    gdirs = workflow.init_glacier_regions(df)
    workflow.gis_prepro_tasks(gdirs)

    from salem import mercator_grid, Map
    smap = mercator_grid((gdirs[0].cenlon, gdirs[0].cenlat),
                         extent=[20000, 23000])
    smap = Map(smap)

    fig, ax = plt.subplots()
    graphics.plot_catchment_width(gdirs,
                                  ax=ax,
                                  add_intersects=True,
                                  add_touches=True,
                                  smap=smap)
    fig.tight_layout()
    shutil.rmtree(testdir)
    return fig
예제 #5
0
def test_merca_map():
    grid = mercator_grid(center_ll=(11.38, 47.26), extent=(2000000, 2000000))

    m1 = Map(grid)

    grid = mercator_grid(center_ll=(11.38, 47.26),
                         extent=(2000000, 2000000),
                         origin='upper-left')
    m2 = Map(grid)

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6))
    m1.visualize(ax=ax1, addcbar=False)
    m2.visualize(ax=ax2, addcbar=False)
    plt.tight_layout()

    return fig
예제 #6
0
    def test_increase_coverage(self):

        # Just for coverage -> empty shapes should not trigger an error
        grid = mercator_grid(center_ll=(-20, 40), extent=(2000, 2000), nx=10)
        c = graphics.Map(grid)

        # Assigning wrongly shaped data should, however
        self.assertRaises(ValueError, c.set_data, np.zeros((3, 8)))
예제 #7
0
    def test_increase_coverage(self):

        # Just for coverage -> empty shapes should not trigger an error
        grid = mercator_grid(center_ll=(-20, 40), extent=(2000, 2000), nx=10)
        c = graphics.Map(grid)

        # Assigning wrongly shaped data should, however
        self.assertRaises(ValueError, c.set_data, np.zeros((3, 8)))
예제 #8
0
def test_merca_map():
    grid = mercator_grid(center_ll=(11.38, 47.26),
                         extent=(2000000, 2000000))

    m1 = Map(grid)

    grid = mercator_grid(center_ll=(11.38, 47.26),
                         extent=(2000000, 2000000),
                         order='ul')
    m2 = Map(grid)

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6))
    m1.visualize(ax=ax1, addcbar=False)
    m2.visualize(ax=ax2, addcbar=False)
    plt.tight_layout()

    return fig
예제 #9
0
def test_merca_map():
    grid = mercator_grid(center_ll=(11.38, 47.26), extent=(2000000, 2000000))

    m1 = Map(grid)
    m1.set_scale_bar(color='red')

    grid = mercator_grid(center_ll=(11.38, 47.26),
                         extent=(2000000, 2000000),
                         origin='upper-left')
    m2 = Map(grid)
    m2.set_scale_bar(length=700000, location=(0.3, 0.05))

    fig, (ax1, ax2) = plt.subplots(1, 2, figsize=(12, 6))
    m1.visualize(ax=ax1, addcbar=False)
    m2.visualize(ax=ax2, addcbar=False)
    plt.tight_layout()

    return fig
예제 #10
0
    def test_visible(self):
        import matplotlib as mpl

        x = [91.176036, 92.05, 88.880927]
        y = [29.649702, 31.483333, 29.264956]

        g = GoogleVisibleMap(x=x,
                             y=y,
                             size_x=400,
                             size_y=400,
                             maptype='terrain')
        img = g.get_vardata()[..., :3]

        i, j = g.grid.transform(x, y, nearest=True)

        for _i, _j in zip(i, j):
            img[_j - 3:_j + 4, _i - 3:_i + 4, 0] = 1
            img[_j - 3:_j + 4, _i - 3:_i + 4, 1:] = 0

        # from PIL import Image
        # Image.fromarray((img * 255).astype(np.uint8)).save(
        #     get_demo_file('hef_google_visible.png'))
        ref = mpl.image.imread(get_demo_file('hef_google_visible.png'))
        rmsd = np.sqrt(np.mean((ref - img)**2))
        self.assertTrue(rmsd < 1e-1)

        self.assertRaises(ValueError, GoogleVisibleMap, x=x, y=y, zoom=12)

        fw = get_demo_file('wrf_tip_d1.nc')
        d = GeoNetcdf(fw)
        i, j = d.grid.ij_coordinates
        g = GoogleVisibleMap(x=i, y=j, crs=d.grid, size_x=500, size_y=500)
        img = g.get_vardata()[..., :3]
        mask = g.grid.map_gridded_data(i * 0 + 1, d.grid)

        img[np.nonzero(mask)] = np.clip(img[np.nonzero(mask)] + 0.3, 0, 1)

        # from PIL import Image
        # Image.fromarray((img * 255).astype(np.uint8)).save(
        #     get_demo_file('hef_google_visible_grid.png'))
        ref = mpl.image.imread(get_demo_file('hef_google_visible_grid.png'))
        rmsd = np.sqrt(np.mean((ref - img)**2))
        self.assertTrue(rmsd < 5e-1)

        gm = GoogleVisibleMap(x=i, y=j, crs=d.grid, size_x=500, size_y=500)
        gm2 = GoogleVisibleMap(x=i,
                               y=j,
                               crs=d.grid,
                               scale=2,
                               size_x=500,
                               size_y=500)
        assert (gm.grid.nx * 2) == gm2.grid.nx
        assert gm.grid.extent == gm2.grid.extent

        # Test regression for non array inputs
        grid = mercator_grid(center_ll=(72.5, 30.), extent=(2.0e6, 2.0e6))
        GoogleVisibleMap(x=[0, grid.nx - 1], y=[0, grid.ny - 1], crs=grid)
예제 #11
0
def test_merca_nolabels():
    grid = mercator_grid(center_ll=(11.38, 47.26), extent=(2000000, 2000000))

    m1 = Map(grid)

    m1.set_lonlat_contours(add_tick_labels=False)
    fig, ax = plt.subplots(1)
    m1.visualize(ax=ax)
    fig.tight_layout()

    return fig
예제 #12
0
def test_hef_default_spline():
    grid = mercator_grid(center_ll=(10.76, 46.798444), extent=(10000, 7000))
    c = Map(grid, countries=False)
    c.set_lonlat_contours(interval=0)
    c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp'))
    c.set_topography(get_demo_file('hef_srtm.tif'))

    fig, ax = plt.subplots(1, 1)
    c.visualize(ax=ax, addcbar=False, title='Default: spline deg 3')
    plt.tight_layout()
    return fig
예제 #13
0
def test_hef_default_spline():
    grid = mercator_grid(center_ll=(10.76, 46.798444),
                         extent=(10000, 7000))
    c = Map(grid, countries=False)
    c.set_lonlat_contours(interval=0)
    c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp'))
    c.set_topography(get_demo_file('hef_srtm.tif'))

    fig, ax = plt.subplots(1, 1)
    c.visualize(ax=ax, addcbar=False, title='Default: spline deg 3')
    plt.tight_layout()
    return fig
예제 #14
0
def test_merca_nolabels():
    grid = mercator_grid(center_ll=(11.38, 47.26),
                         extent=(2000000, 2000000))

    m1 = Map(grid)

    m1.set_lonlat_contours(add_tick_labels=False)
    fig, ax = plt.subplots(1)
    m1.visualize(ax=ax)
    fig.tight_layout()

    return fig
예제 #15
0
def test_hef_from_array():
    grid = mercator_grid(center_ll=(10.76, 46.798444), extent=(10000, 7000))
    c = Map(grid, countries=False)
    c.set_lonlat_contours(interval=0)
    c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp'))

    dem = GeoTiff(get_demo_file('hef_srtm.tif'))
    mytopo = dem.get_vardata()
    c.set_topography(mytopo, crs=dem.grid, interp='spline')

    fig, ax = plt.subplots(1, 1)
    c.visualize(ax=ax, addcbar=False, title='From array')
    plt.tight_layout()
    return fig
예제 #16
0
def test_hef_from_array():
    grid = mercator_grid(center_ll=(10.76, 46.798444),
                         extent=(10000, 7000))
    c = Map(grid, countries=False)
    c.set_lonlat_contours(interval=0)
    c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp'))

    dem = GeoTiff(get_demo_file('hef_srtm.tif'))
    mytopo = dem.get_vardata()
    c.set_topography(mytopo, crs=dem.grid, interp='spline')

    fig, ax = plt.subplots(1, 1)
    c.visualize(ax=ax, addcbar=False, title='From array')
    plt.tight_layout()
    return fig
예제 #17
0
def test_plot_region_inversion():

    gdirs = up_to_inversion()

    # We prepare for the plot, which needs our own map to proceed.
    # Lets do a local mercator grid
    g = salem.mercator_grid(center_ll=(10.86, 46.85), extent=(27000, 21000))
    # And a map accordingly
    sm = salem.Map(g, countries=False)
    sm.set_topography(get_demo_file('srtm_oetztal.tif'))

    # Give this to the plot function
    fig, ax = plt.subplots()
    graphics.plot_inversion(gdirs, smap=sm, ax=ax, linewidth=1.5, vmax=250)

    fig.tight_layout()
    return fig
예제 #18
0
def test_plot_region_inversion():

    gdirs = up_to_inversion()

    # We prepare for the plot, which needs our own map to proceed.
    # Lets do a local mercator grid
    g = salem.mercator_grid(center_ll=(10.86, 46.85),
                            extent=(27000, 21000))
    # And a map accordingly
    sm = salem.Map(g, countries=False)
    sm.set_topography(get_demo_file('srtm_oetztal.tif'))

    # Give this to the plot function
    fig, ax = plt.subplots()
    graphics.plot_inversion(gdirs, smap=sm, ax=ax, linewidth=1.5, vmax=250)

    fig.tight_layout()
    return fig
예제 #19
0
def test_hef_topo_withnan():
    grid = mercator_grid(center_ll=(10.76, 46.798444), extent=(10000, 7000))
    c = Map(grid, countries=False)
    c.set_lonlat_contours(interval=10)
    c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp'))

    dem = GeoTiff(get_demo_file('hef_srtm.tif'))
    mytopo = dem.get_vardata()
    h = c.set_topography(mytopo, crs=dem.grid, interp='spline')

    c.set_lonlat_contours()
    c.set_cmap(get_cmap('topo'))
    c.set_plot_params(nlevels=256)
    # Try with nan data
    h[-100:, -100:] = np.NaN
    c.set_data(h)
    fig, ax = plt.subplots(1, 1)
    c.visualize(ax=ax, title='color with NaN')
    plt.tight_layout()
    return fig
예제 #20
0
def test_hef_topo_withnan():
    grid = mercator_grid(center_ll=(10.76, 46.798444),
                         extent=(10000, 7000))
    c = Map(grid, countries=False)
    c.set_lonlat_contours(interval=10)
    c.set_shapefile(get_demo_file('Hintereisferner_UTM.shp'))

    dem = GeoTiff(get_demo_file('hef_srtm.tif'))
    mytopo = dem.get_vardata()
    h = c.set_topography(mytopo, crs=dem.grid, interp='spline')

    c.set_lonlat_contours()
    c.set_cmap(get_cmap('topo'))
    c.set_plot_params(nlevels=256)
    # Try with nan data
    h[-100:, -100:] = np.NaN
    c.set_data(h)
    fig, ax = plt.subplots(1, 1)
    c.visualize(ax=ax, title='color with NaN')
    plt.tight_layout()
    return fig
예제 #21
0
def test_plot_region_model():

    gdirs = random_for_plot()

    dfc = utils.compile_task_log(gdirs,
                                 task_names=['run_random_climate_plot'])
    assert np.all(dfc['run_random_climate_plot'] == 'SUCCESS')

    # We prepare for the plot, which needs our own map to proceed.
    # Lets do a local mercator grid
    g = salem.mercator_grid(center_ll=(10.86, 46.85),
                            extent=(27000, 21000))
    # And a map accordingly
    sm = salem.Map(g, countries=False)
    sm.set_topography(get_demo_file('srtm_oetztal.tif'))

    # Give this to the plot function
    fig, ax = plt.subplots()
    graphics.plot_modeloutput_map(gdirs, smap=sm, ax=ax,
                                  filesuffix='_plot', vmax=250,
                                  modelyr=10, linewidth=1.5)

    fig.tight_layout()
    return fig
예제 #22
0
===================
Topographic shading
===================

Add topographic shading to a plot

"""

from salem import mercator_grid, Map, get_demo_file
import matplotlib.pyplot as plt

# prepare the figure
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(8, 7))

# map extent
grid = mercator_grid(center_ll=(10.76, 46.79), extent=(18000, 14000))
sm = Map(grid, countries=False)
sm.set_lonlat_contours(interval=0)
sm.set_scale_bar()

# add topography
fpath = get_demo_file('hef_srtm.tif')
sm.set_topography(fpath)
sm.visualize(ax=ax1, addcbar=False, title='relief_factor=0.7 (default)')

# stronger shading
sm.set_topography(fpath, relief_factor=1.4)
sm.visualize(ax=ax2, addcbar=False, title='relief_factor=1.4')

# add color shading
z = sm.set_topography(fpath)
예제 #23
0
# -*- coding: utf-8 -*-
"""
==============================
Add a Natural Earth background
==============================

An alternative to Google Static Maps
"""

import salem
import matplotlib.pyplot as plt

# get the map from a predefined grid
grid = salem.mercator_grid(transverse=False,
                           center_ll=(16., 0.),
                           extent=(8e6, 9e6))
smap = salem.Map(grid)

# Add the background (other resolutions include: 'mr', 'hr')
smap.set_rgb(natural_earth='lr')

# done!
smap.visualize()
plt.show()
예제 #24
0
                    filesuffix='_defaults')
execute_entity_task(tasks.random_glacier_evolution, gdirs,
                    nyears=500, bias=0, seed=seed, temperature_bias=-0.2,
                    filesuffix='_tbias')

utils.compile_run_output(gdirs, filesuffix='_defaults')
utils.compile_run_output(gdirs, filesuffix='_tbias')

# ds = xr.open_dataset(os.path.join(base_dir, 'run_output_defaults.nc'))
# (ds.volume.sum(dim='rgi_id') * 1e-9).plot()
# plt.show()
# exit()

# We prepare for the plot, which needs our own map to proceed.
# Lets do a local mercator grid
g = salem.mercator_grid(center_ll=(-19.61, 63.63),
                        extent=(18000, 14500))
# And a map accordingly
sm = salem.Map(g, countries=False)
sm.set_lonlat_contours(add_xtick_labels=False)
z = sm.set_topography('/home/mowglie/disk/OGGM_INPUT/tmp/ISL.tif')
sm.set_data(z)

# Figs
f = 0.9
f, axs = plt.subplots(2, 1, figsize=(7*f, 10*f))

graphics.plot_domain(gdirs, ax=axs[0], smap=sm)


sm.set_data()
sm.set_lonlat_contours()
예제 #25
0
    print(f.read())

g, maps = geogrid_simulator(fpath)
print(g)
print('ss')
print(maps[0])
maps[0].set_rgb(natural_earth='lr')
maps[0].visualize(title='Anidamiento Qollpana Marzo 2018', addcbar=False)
plt.savefig('QollpanaMarzo2018.png', dpi=300)

plt.show()
plt.close()
#ALBBCK
ds = open_xr_dataset(
    "/home/opti3040a/Documentos/WRF15-08-19/wrfout_d01_2018-03-05_00:00:00")
grid = mercator_grid(center_ll=(-60.0, -17.9), extent=(75e5, 75e5))
smap = Map(grid, nx=500)
# VAR_SSO
smap.set_data(ds.LANDMASK)
smap.visualize()
plt.show()

# # get the data at the latest time step
# ds = salem.open_wrf_dataset("/home/opti3040a/Documentos/WRF_1s/WRF_OUT/wrfout_d03_2018-06-01_09:00:00").isel(time=-1)
# print(ds.WS)
# # get the wind data at 10000 m a.s.l.
# u = ds.salem.wrf_zlevel('U', 2800.)
# v = ds.salem.wrf_zlevel('V', 2800.)
# ws = ds.salem.wrf_zlevel('WS', 2800.)

# # get the axes ready
예제 #26
0
===================
Topographic shading
===================

Add topographic shading to a plot

"""

from salem import mercator_grid, Map, get_demo_file
import matplotlib.pyplot as plt

# prepare the figure
f, ((ax1, ax2), (ax3, ax4)) = plt.subplots(2, 2, figsize=(8, 7))

# map extent
grid = mercator_grid(center_ll=(10.76, 46.79), extent=(18000, 14000))
sm = Map(grid, countries=False)
sm.set_lonlat_contours(interval=0)

# add topography
fpath = get_demo_file('hef_srtm.tif')
sm.set_topography(fpath)
sm.visualize(ax=ax1, addcbar=False, title='relief_factor=0.7 (default)')

# stronger shading
sm.set_topography(fpath, relief_factor=1.4)
sm.visualize(ax=ax2, addcbar=False, title='relief_factor=1.4')

# add color shading
z = sm.set_topography(fpath)
sm.set_data(z)