Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fa7942d
to_hvplot function
bornagain1981 May 6, 2022
88d4002
Add to_hvplot function
bornagain1981 May 6, 2022
93c14ef
Merge remote-tracking branch 'origin/main' into main
bornagain1981 May 6, 2022
2fa9b87
bornagain1981 May 6, 2022
fcfd481
correction of whitespaces
bornagain1981 May 6, 2022
dfd93ec
correction whitespaces
bornagain1981 May 6, 2022
c0022f3
correction whitespaces
bornagain1981 May 6, 2022
249c420
function correction for pull request
bornagain1981 May 6, 2022
2f2e8a8
Add to_hvplot functon
bornagain1981 May 6, 2022
ac8a361
add hvplot in extras require
bornagain1981 May 6, 2022
d2c80fb
add hvplot in test require
bornagain1981 May 6, 2022
09b8f6e
Answer to #issuecomment-1120099909
bornagain1981 May 7, 2022
d0299dd
Update satpy/scene.py
May 7, 2022
aed6a91
Update satpy/scene.py
May 7, 2022
4687ba4
Update satpy/scene.py
May 7, 2022
1aff451
Update
bornagain1981 May 7, 2022
546bb5f
Update setup.py
Aug 2, 2022
4455ac2
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Feb 3, 2023
d574eeb
Merge tag 'v0.40.0' into main
bornagain1981 Feb 9, 2023
03b8056
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Feb 21, 2023
590d374
add holoviews to continuous_integration
bornagain1981 Feb 24, 2023
d319a9b
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Mar 20, 2023
09ad15d
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Mar 24, 2023
3aba218
Merge tag 'v0.42.1' into main
bornagain1981 May 5, 2023
9541b70
Merge tag 'v0.42.2' into main
bornagain1981 May 11, 2023
3369c93
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Jul 24, 2023
5beb117
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Dec 11, 2023
874f8d8
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Dec 12, 2023
2da489b
hvplot tests
bornagain1981 Dec 14, 2023
07b313b
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Dec 14, 2023
27041a4
add control for swath data
bornagain1981 Dec 14, 2023
fb8ff3b
import hvplot directly inside method
bornagain1981 Dec 14, 2023
91f96af
Merge remote-tracking branch 'pytroll/main' into main
bornagain1981 Dec 14, 2023
807357a
Add holoviews required library
bornagain1981 Dec 14, 2023
aad6ea8
Add holoviews required library
bornagain1981 Dec 14, 2023
fca35cd
Add holoviews required library
bornagain1981 Dec 14, 2023
7918f37
Revert "Add holoviews required library"
bornagain1981 Dec 14, 2023
258fd17
Add holoviews library
bornagain1981 Dec 14, 2023
f45e225
Merge remote-tracking branch 'origin/main' into main
bornagain1981 Dec 14, 2023
d16728b
Add holoviews in documentation
Dec 15, 2023
4d3153a
Merge remote-tracking branch 'pytroll/main'
Dec 15, 2023
9b0bcae
Holoviews inside to_hvplot method
Dec 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ The following people have made contributions to this project:
- [Andrea Meraner (ameraner)](https://github.com/ameraner)
- [Aronne Merrelli (aronnem)](https://github.com/aronnem)
- [Lucas Meyer (LTMeyer)](https://github.com/LTMeyer)
- [Luca Merucci (lmeru)](https://github.com/lmeru)
- [Ondrej Nedelcev (nedelceo)](https://github.com/nedelceo)
- [Oana Nicola](https://github.com/)
- [Esben S. Nielsen (storpipfugl)](https://github.com/storpipfugl)
Expand Down
64 changes: 64 additions & 0 deletions satpy/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
def to_hvplot(self,datasets=None,*args,**kwargs):
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
"""Convert satpy Scene to Hvplot.
Args:
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
datasets (list): Limit included products to these datasets.
kwargs: hvplot options list.
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved

Returns: hvplot object that contains within it the plots of datasets list.
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
As default it contains all Scene datasets plots and a plot title is shown.

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
Example usage:
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
scene_list = ['ash','IR_108']
plot = scn.to_hvplot(datasets=scene_list)

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
plot.ash+plot.IR_108

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The 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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Schermata del 2023-03-20 21-05-08

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pnuu does it work in your Jupyter Notebook?


"""
import hvplot.xarray
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
from holoviews import Overlay
from satpy import composites
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
from cartopy import crs
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved

Comment thread
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')

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
def _get_units(xarray_ds,variable):
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
return xarray_ds[variable].attrs['units']

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
def _plot_rgb(xarray_ds,variable,**defaults):
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
img = composites.enhance2dataset(xarray_ds[variable])
return img.hvplot.rgb(bands='bands',title=title,
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
clabel='',**defaults)
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved

def _plot_quadmesh(xarray_ds,variable,**defaults):
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
return xarray_ds[variable].hvplot.quadmesh(
clabel=f'[{_get_units(xarray_ds,variable)}]',
title=title,**defaults)
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
plot = Overlay()
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
xarray_ds = self.to_xarray_dataset(datasets)
ccrs = _get_crs(xarray_ds)

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
if datasets is None: datasets = list(xarray_ds.keys())
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved

defaults = dict(x='x',y='y',data_aspect=1,project=True,geo=True,
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
crs=ccrs,projection=ccrs,rasterize=True,
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
coastline='110m',cmap='Plasma',responsive=True,
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
dynamic=False,framewise=True,colorbar=False,
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
global_extent=False,xlabel='Longitude',ylabel='Latitude')
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
defaults.update(kwargs)

Comment thread
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)
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
else:
plot[element]=_plot_quadmesh(xarray_ds,element,**defaults)
Comment thread
bornagain1981 marked this conversation as resolved.
Resolved

Comment thread
bornagain1981 marked this conversation as resolved.
Resolved
return plot
Comment thread
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.
Expand Down