-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinvisible.py
143 lines (121 loc) · 3.82 KB
/
invisible.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
from dash import Dash, dcc, html, Input, Output, State, exceptions, callback_context
import plotly.express as px
import plotly.graph_objects as go
import dash_design_kit as ddk
import numpy as np
import pandas as pd
import random
import PIL
import math
zoom = .5
center180 = {'lon': 180.0, 'lat': 0.0}
map_limits360 = {"west": 0, "east": 360, "south": -89, "north": 89}
title180 = 'Map Centered at the International Dateline'
lat_lon0 = [[180.0, -66.51326], [359.0, 66.5132]]
image_coordinates0 = [
[lat_lon0[0][0], lat_lon0[1][1]],
[lat_lon0[1][0], lat_lon0[1][1]],
[lat_lon0[1][0], lat_lon0[0][1]],
[lat_lon0[0][0], lat_lon0[0][1]],
]
lat_lon1 = [[0, -66.51326], [180, 66.5132]]
image_coordinates1 = [
[lat_lon1[0][0], lat_lon1[1][1]],
[lat_lon1[1][0], lat_lon1[1][1]],
[lat_lon1[1][0], lat_lon1[0][1]],
[lat_lon1[0][0], lat_lon1[0][1]],
]
with PIL.Image.open('i0.png') as img0:
img0.load()
with PIL.Image.open('i1.png') as img1:
img1.load()
initial_map_layers = [
{"sourcetype": "image", "source": img0, "coordinates": image_coordinates0, 'below': 'traces'},
{"sourcetype": "image", "source": img1, "coordinates": image_coordinates1, 'below': 'traces'}
]
map_height = 520
map_width = 1100
lon = range(160, 275, 5)
lat = np.random.default_rng().uniform(low=-6.0, high=6.0, size=(len(lon)))
temp = np.random.default_rng().uniform(low=24, high=30, size=(len(lon)))
cats = ['ship', 'glider', 'UCV', 'drifting buoy']
types = []
for i in range(0, len(lon)):
types.append(cats[random.randint(0, 3)])
df = pd.DataFrame(zip(lon, lat, temp, types), columns=['longitude', 'latitude', 'sst', 'platform'])
# Define Dash application structure
app = Dash(__name__)
server = app.server # expose server variable for Procfile
app.layout = ddk.App(children=[
ddk.Header([
ddk.Logo(src='https://www.socat.info/wp-content/uploads/2017/06/cropped-socat_cat.png'),
ddk.Title('Marker Test'),
]),
html.Div(id='kick'),
ddk.Card(width=.7,
children=[
dcc.Loading(
ddk.CardHeader(
modal=True,
modal_config={'height': 90, 'width': 95},
fullscreen=True,
id='map-graph-header',
title='Invisible Markers',
),
),
ddk.Graph(
id='map-graph',
),
]
),
])
@app.callback(
[
Output('map-graph', 'figure'),
],
[
Input('kick','n_clicks'),
Input('map-graph', 'relayoutData')
]
)
def update_map(in_map_center, map_state):
my_center = center180
my_zoom = zoom
if map_state is not None and 'mapbox.center' in map_state:
my_center = map_state['mapbox.center']
if map_state is not None and 'mapbox.zoom' in map_state:
my_zoom = map_state['mapbox.zoom']
my_limits = map_limits360
if math.isclose(zoom, my_zoom):
map_layers = initial_map_layers
figure = go.Figure()
map_b = go.Scattermapbox()
figure.add_traces(map_b)
else:
map_layers = None
figure = px.scatter_mapbox(
df,
lat='latitude',
lon='longitude',
color='sst',
hover_name='platform',
hover_data=['platform'],
color_continuous_scale=px.colors.sequential.Viridis)
figure.update_layout(
height=map_height,
mapbox_style="open-street-map",
mapbox_zoom=my_zoom,
mapbox_center=my_center,
mapbox_layers=map_layers,
mapbox_bounds=my_limits,
margin={"r": 0, "t": 0, "l": 0, "b": 0},
legend=dict(
orientation="v",
xanchor='left',
x=.99,
),
modebar_orientation='v',
)
return [figure]
if __name__ == '__main__':
app.run_server(debug=True)