Skip to content

Commit 6f1fa8d

Browse files
Fix Velocity import (#579)
Fix Velocity import
1 parent 187f8dc commit 6f1fa8d

File tree

3 files changed

+56
-58
lines changed

3 files changed

+56
-58
lines changed

docs/source/api_reference/velocity.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ Example
66

77
.. jupyter-execute::
88

9-
from ipyleaflet import Map, Velocity, TileLayer, basemaps
9+
from ipyleaflet import Map, TileLayer, basemaps
10+
from ipyleaflet.velocity import Velocity
1011
import xarray as xr
1112
import os
1213

ipyleaflet/leaflet.py

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@
2121

2222
from branca.colormap import linear, ColorMap
2323

24-
from traittypes import Dataset
25-
26-
from .xarray_ds import ds_x_to_json
27-
2824
from ._version import EXTENSION_VERSION
2925

3026
def_loc = [0.0, 0.0]
@@ -329,59 +325,6 @@ class VideoOverlay(RasterLayer):
329325
attribution = Unicode().tag(sync=True, o=True)
330326

331327

332-
class Velocity(Layer):
333-
try:
334-
import xarray
335-
except ModuleNotFoundError:
336-
raise ImportError(
337-
'The `xarray` module (required for use of the Velocity layer) is '
338-
'not installed.'
339-
)
340-
341-
_view_name = Unicode('LeafletVelocityView').tag(sync=True)
342-
_model_name = Unicode('LeafletVelocityModel').tag(sync=True)
343-
344-
zonal_speed = Unicode('', help='Name of the zonal speed in the dataset')
345-
meridional_speed = Unicode('', help='Name of the meridional speed in the dataset')
346-
latitude_dimension = Unicode('latitude', help='Name of the latitude dimension in the dataset')
347-
longitude_dimension = Unicode('longitude', help='Name of the longitude dimension in the dataset')
348-
units = Unicode(None, allow_none=True)
349-
350-
data = Dataset().tag(dtype=None, sync=True, to_json=ds_x_to_json)
351-
352-
# Options
353-
display_values = Bool(True).tag(sync=True, o=True)
354-
display_options = Dict({
355-
'velocityType': 'Global Wind',
356-
'position': 'bottomleft',
357-
'emptyString': 'No velocity data',
358-
'angleConvention': 'bearingCW',
359-
'displayPosition': 'bottomleft',
360-
'displayEmptyString': 'No velocity data',
361-
'speedUnit': 'kt'
362-
}).tag(sync=True)
363-
min_velocity = Float(0).tag(sync=True, o=True)
364-
max_velocity = Float(10).tag(sync=True, o=True)
365-
velocity_scale = Float(0.005).tag(sync=True, o=True)
366-
color_scale = List([
367-
"rgb(36,104, 180)",
368-
"rgb(60,157, 194)",
369-
"rgb(128,205,193)",
370-
"rgb(151,218,168)",
371-
"rgb(198,231,181)",
372-
"rgb(238,247,217)",
373-
"rgb(255,238,159)",
374-
"rgb(252,217,125)",
375-
"rgb(255,182,100)",
376-
"rgb(252,150,75)",
377-
"rgb(250,112,52)",
378-
"rgb(245,64,32)",
379-
"rgb(237,45,28)",
380-
"rgb(220,24,32)",
381-
"rgb(180,0,35)"
382-
]).tag(sync=True, o=True)
383-
384-
385328
class Heatmap(RasterLayer):
386329
_view_name = Unicode('LeafletHeatmapView').tag(sync=True)
387330
_model_name = Unicode('LeafletHeatmapModel').tag(sync=True)

ipyleaflet/velocity.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# Copyright (c) Jupyter Development Team.
2+
# Distributed under the terms of the Modified BSD License.
3+
#
4+
5+
from traittypes import Dataset
6+
from traitlets import Unicode, Bool, Dict, Float, List
7+
8+
from .leaflet import Layer
9+
from .xarray_ds import ds_x_to_json
10+
11+
12+
class Velocity(Layer):
13+
_view_name = Unicode('LeafletVelocityView').tag(sync=True)
14+
_model_name = Unicode('LeafletVelocityModel').tag(sync=True)
15+
16+
zonal_speed = Unicode('', help='Name of the zonal speed in the dataset')
17+
meridional_speed = Unicode('', help='Name of the meridional speed in the dataset')
18+
latitude_dimension = Unicode('latitude', help='Name of the latitude dimension in the dataset')
19+
longitude_dimension = Unicode('longitude', help='Name of the longitude dimension in the dataset')
20+
units = Unicode(None, allow_none=True)
21+
22+
data = Dataset().tag(dtype=None, sync=True, to_json=ds_x_to_json)
23+
24+
# Options
25+
display_values = Bool(True).tag(sync=True, o=True)
26+
display_options = Dict({
27+
'velocityType': 'Global Wind',
28+
'position': 'bottomleft',
29+
'emptyString': 'No velocity data',
30+
'angleConvention': 'bearingCW',
31+
'displayPosition': 'bottomleft',
32+
'displayEmptyString': 'No velocity data',
33+
'speedUnit': 'kt'
34+
}).tag(sync=True)
35+
min_velocity = Float(0).tag(sync=True, o=True)
36+
max_velocity = Float(10).tag(sync=True, o=True)
37+
velocity_scale = Float(0.005).tag(sync=True, o=True)
38+
color_scale = List([
39+
"rgb(36,104, 180)",
40+
"rgb(60,157, 194)",
41+
"rgb(128,205,193)",
42+
"rgb(151,218,168)",
43+
"rgb(198,231,181)",
44+
"rgb(238,247,217)",
45+
"rgb(255,238,159)",
46+
"rgb(252,217,125)",
47+
"rgb(255,182,100)",
48+
"rgb(252,150,75)",
49+
"rgb(250,112,52)",
50+
"rgb(245,64,32)",
51+
"rgb(237,45,28)",
52+
"rgb(220,24,32)",
53+
"rgb(180,0,35)"
54+
]).tag(sync=True, o=True)

0 commit comments

Comments
 (0)