Skip to content

Commit

Permalink
import hvplot directly inside method
Browse files Browse the repository at this point in the history
As Martin has suggested I'm importing directly inside method the hvplot library to remove an if condition and resolve "too complex" pre-commit control
  • Loading branch information
Dario Stelitano committed Dec 14, 2023
1 parent 27041a4 commit fb8ff3b
Showing 1 changed file with 6 additions and 20 deletions.
26 changes: 6 additions & 20 deletions satpy/scene.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@
from satpy.utils import convert_remote_files_to_fsspec, get_storage_options_from_reader_kwargs
from satpy.writers import load_writer

#try:
# import hvplot.xarray as hvplot_xarray # noqa
#except ImportError:
# hvplot_xarray = None


LOG = logging.getLogger(__name__)


Expand Down Expand Up @@ -1074,23 +1068,24 @@ def to_geoviews(self, gvtype=None, datasets=None, kdims=None, vdims=None, dynami
return gview

def to_hvplot(self, datasets=None, *args, **kwargs):
"""Convert satpy Scene to Hvplot.
"""Convert satpy Scene to Hvplot. The method could not be used with composites of swath data.
Args:
datasets (list): Limit included products to these datasets.
kwargs: hvplot options dictionary.
args: Arguments coming from hvplot
kwargs: hvplot options dictionary.
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']
scn = Scene()
scn.load(scene_list)
scn = scn.resample('eurol')
plot = scn.to_hvplot(datasets=scene_list)
plot.ash+plot.IR_108
"""

def _get_crs(xarray_ds):
Expand All @@ -1113,12 +1108,7 @@ def _plot_quadmesh(xarray_ds, variable, **defaults):
clabel=f"[{_get_units(xarray_ds,variable)}]", title=title,
**defaults)

#def _check_hvplot_library():
# if hvplot_xarray is None:
# raise ImportError("'hvplot' must be installed to use this feature")
#
# _check_hvplot_library()

import hvplot.xarray as hvplot_xarray # noqa
plot = Overlay()
xarray_ds = self.to_xarray_dataset(datasets)

Expand All @@ -1129,7 +1119,6 @@ def _plot_quadmesh(xarray_ds, variable, **defaults):
ccrs = None
defaults={"x":"longitude","y":"latitude"}


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

Expand All @@ -1141,9 +1130,6 @@ def _plot_quadmesh(xarray_ds, variable, **defaults):

defaults.update(kwargs)

#if "latitude" in xarray_ds.coords:
# defaults.update({"x":"longitude","y":"latitude"})

for element in datasets:
title = f"{element} @ {_get_timestamp(xarray_ds)}"
if xarray_ds[element].shape[0] == 3:
Expand Down

0 comments on commit fb8ff3b

Please sign in to comment.