Repository navigation
Add Scene function to use Hvplot backend visualization #2106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 4 commits
fa7942d
88d4002
93c14ef
2fa9b87
fcfd481
dfd93ec
c0022f3
249c420
2f2e8a8
ac8a361
d2c80fb
09b8f6e
d0299dd
aed6a91
4687ba4
1aff451
546bb5f
4455ac2
d574eeb
03b8056
590d374
d319a9b
09ad15d
3aba218
9541b70
3369c93
5beb117
874f8d8
2da489b
07b313b
27041a4
fb8ff3b
91f96af
807357a
aad6ea8
fca35cd
7918f37
258fd17
f45e225
d16728b
4d3153a
9b0bcae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1021,6 +1021,70 @@ def to_geoviews(self, gvtype=None, datasets=None, kdims=None, vdims=None, dynami | |
| gview = gvds.to(gvtype, kdims=["x", "y"], vdims=vdims, dynamic=dynamic) | ||
|
|
||
| return gview | ||
|
|
||
| def to_hvplot(self,datasets=None,*args,**kwargs): | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| """Convert satpy Scene to Hvplot. | ||
| Args: | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| datasets (list): Limit included products to these datasets. | ||
| kwargs: hvplot options list. | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
|
|
||
| Returns: hvplot object that contains within it the plots of datasets list. | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| As default it contains all Scene datasets plots and a plot title is shown. | ||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| Example usage: | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| scene_list = ['ash','IR_108'] | ||
| plot = scn.to_hvplot(datasets=scene_list) | ||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| plot.ash+plot.IR_108 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This isn't enough to show the plot, what else needs to be done? I was testing this in IPython command line prompt.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @pnuu does it work in your Jupyter Notebook? |
||
|
|
||
| """ | ||
| import hvplot.xarray | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| from holoviews import Overlay | ||
| from satpy import composites | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| from cartopy import crs | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| def _get_crs(xarray_ds): | ||
| return xarray_ds.area.to_cartopy_crs() | ||
|
|
||
| def _get_timestamp(xarray_ds): | ||
| time = xarray_ds.attrs['start_time'] | ||
| return time.strftime('%Y %m %d -- %H:%M UTC') | ||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| def _get_units(xarray_ds,variable): | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| return xarray_ds[variable].attrs['units'] | ||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| def _plot_rgb(xarray_ds,variable,**defaults): | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| img = composites.enhance2dataset(xarray_ds[variable]) | ||
| return img.hvplot.rgb(bands='bands',title=title, | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| clabel='',**defaults) | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
|
|
||
| def _plot_quadmesh(xarray_ds,variable,**defaults): | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| return xarray_ds[variable].hvplot.quadmesh( | ||
| clabel=f'[{_get_units(xarray_ds,variable)}]', | ||
| title=title,**defaults) | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| plot = Overlay() | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| xarray_ds = self.to_xarray_dataset(datasets) | ||
| ccrs = _get_crs(xarray_ds) | ||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| if datasets is None: datasets = list(xarray_ds.keys()) | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
|
|
||
| defaults = dict(x='x',y='y',data_aspect=1,project=True,geo=True, | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| crs=ccrs,projection=ccrs,rasterize=True, | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| coastline='110m',cmap='Plasma',responsive=True, | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| dynamic=False,framewise=True,colorbar=False, | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| global_extent=False,xlabel='Longitude',ylabel='Latitude') | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| defaults.update(kwargs) | ||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| for element in datasets: | ||
| title = f'{element} @ {_get_timestamp(xarray_ds)}' | ||
| if xarray_ds[element].shape[0] == 3: | ||
| plot[element] =_plot_rgb(xarray_ds,element,**defaults) | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| else: | ||
| plot[element]=_plot_quadmesh(xarray_ds,element,**defaults) | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
|
|
||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
| return plot | ||
|
bornagain1981 marked this conversation as resolved.
Resolved
|
||
|
|
||
| def to_xarray_dataset(self, datasets=None): | ||
| """Merge all xr.DataArrays of a scene to a xr.DataSet. | ||
|
|
||

Uh oh!
There was an error while loading. Please reload this page.