def geoview_flat_plot(region_da, time_sel=0, level_sel=False, wide_chile=True): if type(level_sel) is int: da = region_da.isel(level=level_sel) else: da = region_da gv_ds = gv.Dataset(da.isel(time=time_sel)) plot = gv_ds.to(gv.Image, ['lon', 'lat'], 't', 'time').opts(cmap='viridis', colorbar=True) extras = [] if wide_chile: easter_island_text = gv.Text(-104.360481, -24.104671, 'Easter Island').opts(color='white') easter_island_point = gv.Points([(-109.360481, -27.104671)]).opts(color='red') easter = easter_island_point * easter_island_text falkland_islands_text = gv.Text(-49.563412, -56.820557, 'Falklands').opts(color='white') falkland_islands_point = gv.Points([(-51.563412, -59.820557)]).opts(color='red') falkland = falkland_islands_point * falkland_islands_text extras.append(easter * falkland) plot = contours(plot, filled=True, overlaid=True) with warnings.catch_warnings(): warnings.simplefilter("ignore") final_plot = plot * gf.coastline for extra in extras: final_plot *= extra gv.output(final_plot)
def view_time_series(filename, cmap='jet'): """ Visualize and interact with time series netcdf files. """ # Open geoviews interactive session. gv.extension('bokeh', 'matplotlib') with xr.open_dataset(filename, decode_times=False) as da: dataset = gv.Dataset(da) ensemble = dataset.to(gv.Image, ['x', 'y']) gv.output(ensemble.opts(cmap=cmap, colorbar=True, fig_size=200, backend='matplotlib'), backend='matplotlib') return
def shapeplot(dframe, var, coords, raxis, cm='Jet_r', extralayers=[], lcolor='black'): lcoords = len(coords) xly = len(extralayers) if lcoords == 2 and xly > 0: gvdata = gv.Dataset(dframe, kdims=[coords[0], coords[1], raxis], vdims=var) back = gvdata.to(gv.Image, [coords[0], coords[1]], var) back = back.opts(colorbar=True, backend='bokeh', cmap=cm, width=600, height=400) for layer in extralayers: ss = gv.Shape.from_shapefile(layer).opts(line_color=lcolor) back *= ss return gv.output(back.opts(width=600, height=400), backend='bokeh') else: print("Incomplete coordinates")
def fastplot(dframe, var, coords, raxis, cm='Jet'): lcoords = len(coords) if lcoords == 2: gvdata = gv.Dataset(dframe, kdims=[coords[0], coords[1], raxis], vdims=var) back = gvdata.to(gv.Image, [coords[0], coords[1]], var) return gv.output(back.opts(colorbar=True, backend='bokeh', cmap=cm, width=600, height=400), backend='bokeh') else: print("Incomplete coordinates")
def quick_map(da, dims=["lon", "lat"], redim_range=None, **user_options): options = dict( cmap="viridis", colorbar=True, fig_size=300, projection=crs.Robinson(central_longitude=180), ) options.update(user_options) name = da.name dataset = gv.Dataset(da) image = dataset.to(gv.Image, dims, dynamic=True).options(**options) if redim_range is not None: image = image.redim.range(**{name: redim_range}) return gv.output(image * gf.coastline(), backend="matplotlib")
# Evalúa qué puntos del grid del CRU corresponden a # la Cuenca del Valle de México. import os import pandas as pd import numpy as np import geoviews as gv import geopandas as gpd gv.extension("matplotlib") gv.output(size = 150) fdir_d = os.getcwd() + "/data/Cuencas/Regiones_Hidrologicas_Administrativas/" fdir_r = os.getcwd() + "/results/sequia/" fname = "rha250kgw.shp" # Si no existe la carpeta, la crea. if not os.path.exists(fdir_r): os.mkdir(fdir_r) # Se cargan las regiones hidrológico administrativas. gdf = gpd.read_file(fdir_d + fname) # Se obtiene el contorno de las cuencas- gdf["boundary"] = gdf.boundary # Se selecciona la Cuenca del Valle de México. cuenca = gv.Path(
import warnings from pathlib import Path import shutil import xarray as xr # Plotting Libraries import matplotlib.pyplot as plt from holoviews.operation import contours import geoviews as gv import geoviews.feature as gf # Plot Options gv.extension('matplotlib') gv.output(size=200) from IPython.core.display import HTML # Center matplotlib's figures HTML(""" <style> .output_png { display: table-cell; text-align: center; vertical-align: middle; } </style> """)
import os import h5py import pandas as pd import geopandas as gp import holoviews as hv import geoviews as gv from shapely.geometry import Point from geoviews import opts from geoviews import tile_sources as gvts gv.extension('bokeh', 'matplotlib', display_formats=['svg', 'html']) gv.output(fig='png') def point_visual(features, vdims): """ :param features: :param vdims: :return: """ return (gvts.EsriImagery * gv.Points(features, vdims=vdims).options(tools=['hover'], height=500, width=900, size=5, color='yellow', fontsize={ 'xticks': 10, 'yticks': 10, 'xlabel': 16,