Skip to content
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

Add Scene function to use Hvplot backend visualization #2106

Merged
merged 42 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
fa7942d
to_hvplot function
May 6, 2022
88d4002
Add to_hvplot function
May 6, 2022
93c14ef
Merge remote-tracking branch 'origin/main' into main
May 6, 2022
2fa9b87
trying to follow and correct stickler-ci messages
May 6, 2022
fcfd481
correction of whitespaces
May 6, 2022
dfd93ec
correction whitespaces
May 6, 2022
c0022f3
correction whitespaces
May 6, 2022
249c420
function correction for pull request
May 6, 2022
2f2e8a8
Add to_hvplot functon
May 6, 2022
ac8a361
add hvplot in extras require
May 6, 2022
d2c80fb
add hvplot in test require
May 6, 2022
09b8f6e
Answer to #issuecomment-1120099909
May 7, 2022
d0299dd
Update satpy/scene.py
bornagain1981 May 7, 2022
aed6a91
Update satpy/scene.py
bornagain1981 May 7, 2022
4687ba4
Update satpy/scene.py
bornagain1981 May 7, 2022
1aff451
Update
May 7, 2022
546bb5f
Update setup.py
bornagain1981 Aug 2, 2022
4455ac2
Merge remote-tracking branch 'pytroll/main' into main
Feb 3, 2023
d574eeb
Merge tag 'v0.40.0' into main
Feb 9, 2023
03b8056
Merge remote-tracking branch 'pytroll/main' into main
Feb 21, 2023
590d374
add holoviews to continuous_integration
Feb 24, 2023
d319a9b
Merge remote-tracking branch 'pytroll/main' into main
Mar 20, 2023
09ad15d
Merge remote-tracking branch 'pytroll/main' into main
Mar 24, 2023
3aba218
Merge tag 'v0.42.1' into main
May 5, 2023
9541b70
Merge tag 'v0.42.2' into main
May 11, 2023
3369c93
Merge remote-tracking branch 'pytroll/main' into main
Jul 24, 2023
5beb117
Merge remote-tracking branch 'pytroll/main' into main
Dec 11, 2023
874f8d8
Merge remote-tracking branch 'pytroll/main' into main
Dec 12, 2023
2da489b
hvplot tests
Dec 14, 2023
07b313b
Merge remote-tracking branch 'pytroll/main' into main
Dec 14, 2023
27041a4
add control for swath data
Dec 14, 2023
fb8ff3b
import hvplot directly inside method
Dec 14, 2023
91f96af
Merge remote-tracking branch 'pytroll/main' into main
Dec 14, 2023
807357a
Add holoviews required library
Dec 14, 2023
aad6ea8
Add holoviews required library
Dec 14, 2023
fca35cd
Add holoviews required library
Dec 14, 2023
7918f37
Revert "Add holoviews required library"
Dec 14, 2023
258fd17
Add holoviews library
Dec 14, 2023
f45e225
Merge remote-tracking branch 'origin/main' into main
Dec 14, 2023
d16728b
Add holoviews in documentation
bornagain1981 Dec 15, 2023
4d3153a
Merge remote-tracking branch 'pytroll/main'
bornagain1981 Dec 15, 2023
9b0bcae
Holoviews inside to_hvplot method
bornagain1981 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
65 changes: 65 additions & 0 deletions satpy/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,71 @@ 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):
"""
Convert satpy Scene to Hvplot.
Args:
datasets (list): Limit included products to these datasets.
kwargs: hvplot options list.

Returns: hvplot object that contains within it the plots of datasets list.
As default it contains all Scene datasets plots and a plot title is shown.

Example usage:
scene_list = ['ash','IR_108']
plot = scn.to_hvplot(datasets=scene_list)

plot.ash+plot.IR_108
Copy link
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
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
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
from holoviews import Overlay
from satpy import composites
from cartopy import crs

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

def _get_units(xarray_ds,variable):
return xarray_ds[variable].attrs['units']

def _plot_rgb(xarray_ds, variable,**defaults):
img = composites.enhance2dataset(xarray_ds[variable])
return img.hvplot.rgb(bands='bands',title=title,
clabel='',**defaults)

def _plot_quadmesh(xarray_ds,variable,**defaults):
return xarray_ds[variable].hvplot.quadmesh(
clabel=f'[{_get_units(xarray_ds,variable)}]',
title=title,**defaults)

plot = Overlay()
xarray_ds = self.to_xarray_dataset(datasets)
ccrs = _get_crs(xarray_ds)

if datasets is None: datasets = list(xarray_ds.keys())

defaults = dict(x='x',y='y',data_aspect=1,project=True,geo=True,
crs=ccrs,projection=ccrs,rasterize=True,
coastline='110m',cmap='Plasma',responsive=True,
dynamic=False,framewise=True,colorbar=False,
global_extent=False,xlabel='Longitude',ylabel='Latitude')

defaults.update(kwargs)

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)
else:
plot[element]=_plot_quadmesh(xarray_ds,element,**defaults)

return plot

def to_xarray_dataset(self, datasets=None):
"""Merge all xr.DataArrays of a scene to a xr.DataSet.
Expand Down