Skip to content

Commit

Permalink
Make explorer geo more optimized (#1353)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahuang11 authored Jul 16, 2024
1 parent 667aaab commit 9d2a8da
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 29 deletions.
7 changes: 7 additions & 0 deletions hvplot/tests/testui.py
Original file line number Diff line number Diff line change
Expand Up @@ -388,3 +388,10 @@ def test_explorer_xarray_multi_var_extra_dims_no_coord():
ds = xr.tutorial.open_dataset('air_temperature')
ds['lat_bnds'] = (('bnds', 'lat'), np.vstack([ds['lat'], ds['lat']]))
assert ds.hvplot.explorer()


@pytest.mark.parametrize('kind_tuple', [('scatter', 'points'), ('line', 'paths')])
def test_explorer_geo_revise_kind(kind_tuple):
da = ds_air_temperature['air'].isel(time=0)
explorer = hvplot.explorer(da, x='lon', y='lat', kind=kind_tuple[0], geo=True)
assert explorer.kind == kind_tuple[1]
65 changes: 36 additions & 29 deletions hvplot/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
set(_hvConverter._kind_mapping)
- set(_hvConverter._gridded_types)
- set(_hvConverter._geom_types)
| set(['points'])
| set(['points', 'paths'])
),
'gridded': sorted(set(_hvConverter._gridded_types) - set(['dataset'])),
'geom': _hvConverter._geom_types,
}

KINDS['2d'] = (
['bivariate', 'heatmap', 'hexbin', 'labels', 'vectorfield', 'points']
['bivariate', 'heatmap', 'hexbin', 'labels', 'vectorfield', 'points', 'paths']
+ KINDS['gridded']
+ KINDS['geom']
)
Expand Down Expand Up @@ -383,37 +383,43 @@ def __init__(self, data, **params):

@param.depends('geo', watch=True)
def _update_crs_projection(self):
enabled = bool(self.geo or self.project)
for key in GEO_KEYS:
self.param[key].constant = not enabled
self.geo = enabled
if not enabled:
return
with param.parameterized.batch_call_watchers(self):
enabled = bool(self.geo or self.project)
for key in GEO_KEYS:
self.param[key].constant = not enabled
self.geo = enabled
if not enabled:
return

from cartopy.crs import CRS

crs_list = sorted(
k
for k in param.concrete_descendents(CRS).keys()
if not k.startswith('_') and k != 'CRS'
)
crs_list.insert(0, 'GOOGLE_MERCATOR')
crs_list.insert(0, 'PlateCarree')
crs_list.remove('PlateCarree')

from cartopy.crs import CRS
if self.explorer.kind == 'scatter':
self.explorer.kind = 'points'
elif self.explorer.kind == 'line':
self.explorer.kind = 'paths'

crs_list = sorted(
k
for k in param.concrete_descendents(CRS).keys()
if not k.startswith('_') and k != 'CRS'
)
crs_list.insert(0, 'GOOGLE_MERCATOR')
crs_list.insert(0, 'PlateCarree')
crs_list.remove('PlateCarree')
self.param.crs.objects = crs_list
self.param.projection.objects = crs_list
updates = {}
if self.projection is None:
updates['projection'] = crs_list[0]

self.param.crs.objects = crs_list
self.param.projection.objects = crs_list
updates = {}
if self.projection is None:
updates['projection'] = crs_list[0]
if self.global_extent is None:
updates['global_extent'] = True

if self.global_extent is None:
updates['global_extent'] = True
if self.features is None:
updates['features'] = ['coastline']

if self.features is None:
updates['features'] = ['coastline']

self.param.update(**updates)
self.param.update(**updates)


class Operations(Controls):
Expand Down Expand Up @@ -670,9 +676,10 @@ def _plot(self):
self.geographic.crs = 'PlateCarree' if xmax <= 360 else 'GOOGLE_MERCATOR'
kwargs['crs'] = self.geographic.crs
for key in ['crs', 'projection']:
if key not in kwargs:
continue
crs_kwargs = kwargs.pop(f'{key}_kwargs', {})
kwargs[key] = instantiate_crs_str(kwargs.pop(key), **crs_kwargs)

feature_scale = kwargs.pop('feature_scale', None)
kwargs['features'] = {feature: feature_scale for feature in kwargs.pop('features', [])}

Expand Down

0 comments on commit 9d2a8da

Please sign in to comment.