from satpy import Scene, MultiScene, find_files_and_readers
from satpy.utils import debug_on
from pyresample import geometry
from pyresample.utils import load_area
from glob import glob
from cartopy import crs
from tqdm import tqdm_notebook
import warnings
warnings.filterwarnings('ignore')
import holoviews as hv
import geoviews as gv
import geoviews.feature as gf
gv.extension("bokeh", "matplotlib")
Geoviews is a library which extends Holoviews to easily visualize and explore geographic datasets. Starting with SatPy 0.12 Geoviews can be used with Satpy Scenes.
For further options and documentation regarding geoviews visit: http://geo.holoviews.org/
Note: not everything shown in the Geoviews documentation is currently possible with the satpy geoviews feature.
Following are some examples on how to use Geoviews with SatPy
fname = glob("msg/decompressed_fulldisk/*")
msgscn = Scene(reader = "seviri_l1b_hrit", filenames = fname)
msgscn.load(["VIS008"])
msgscn = msgscn.resample("EuropeCanary")
Plot with bokeh backend and adding some options for plot size etc. By default geoviews plots in web mercator projection, therefore plotting takes a little because reprojection is done on the fly.
%output backend = "bokeh"
%opts QuadMesh Image [width=600 height=400 colorbar=True] Feature [apply_ranges=False]
%opts QuadMesh Image (cmap='RdBu_r')
plt1_a = msgscn.to_geoviews(vdims = ["VIS008"])
plt1_a[::5,::5] * gf.coastline * gf.borders
With additional options this can be changed to any projection supported by cartopy.
%opts Image [projection=crs.Geostationary()]
plt1_a[::5,::5] * gf.coastline * gf.borders
Plotting of panels with geoviews is easy. Here the matplotlib backend is used since bokeh does not support filled contour plots.
%output backend = "matplotlib" size = 200
%opts QuadMesh Image [width=600 height=400 colorbar=True] Feature [apply_ranges=False]
%opts QuadMesh Image (cmap='RdBu_r')
plt1_b = msgscn.to_geoviews(gvtype = gv.FilledContours, vdims = ["VIS008"])
plt1_a[::5,::5] * gf.coastline * gf.borders + plt1_b
WARNING:root:FilledContours10374: Setting non-parameter attribute dynamic=False using a mechanism intended only for parameters
Load data from multiple time slots with the Multiscene.
from satpy.multiscene import timeseries
from datetime import datetime, timedelta
#logging needed to supress loggin INFO messages from KDtreeresampler
import logging
logger = logging.getLogger()
logger.setLevel(logging.CRITICAL)
starttime = datetime(2016, 1, 15, 0, 0, 0)
scenes = []
for i in range(0,20):
s1 = starttime + timedelta(minutes = i * 15 - 4)
s2 = starttime + timedelta(minutes = i * 15 + 4)
files = find_files_and_readers(reader = "seviri_l1b_hrit", base_dir = "msg/timeseries", start_time = s1, end_time = s2)
scenes.append(Scene(filenames = files))
multimsg = MultiScene(scenes)
multimsg.load(["IR_108"])
multimsg = multimsg.resample("EuropeCanary")
Blend them to a Scene with the timeseries blending function.
from satpy.multiscene import timeseries
tsmsg = multimsg.blend(timeseries)
Make a dynamic plot with a slider. Depending on the size of the domain and the choosen projection moving the slider might be slow.
plt3 = tsmsg.to_geoviews(vdims = ["IR_108"], kdims = ["y", "x"], dynamic = True)
plt3 * gf.coastline * gf.borders