MarcSkovMadsen commited on
Commit
864777a
1 Parent(s): 31a4543

speed up by removing dask

Browse files
Files changed (4) hide show
  1. assets/major-tom-esa-logo.png +0 -0
  2. components.py +8 -7
  3. requirements.txt +0 -1
  4. utils.py +12 -7
assets/major-tom-esa-logo.png ADDED
components.py CHANGED
@@ -1,4 +1,3 @@
1
- import dask.dataframe as dd
2
  import holoviews as hv
3
  import numpy as np
4
  import pandas as pd
@@ -66,9 +65,9 @@ class MapInput(pn.viewable.Viewer):
66
  @param.depends("data", watch=True, on_init=True)
67
  def _handle_data_dask_change(self):
68
  with self.param.update(updating=True):
69
- data_dask = dd.from_pandas(self.data).persist()
70
  points = hv.Points(
71
- data_dask, kdims=["centre_easting", "centre_northing"], vdims=[]
72
  )
73
 
74
  rangexy = hv.streams.RangeXY(source=points)
@@ -149,6 +148,7 @@ class ImageInput(pn.viewable.Viewer):
149
  self.param._timestamp,
150
  button_style="outline",
151
  align="end",
 
152
  ),
153
  pn.widgets.Select.from_param(
154
  self.param.column_name, disabled=self.param.updating
@@ -157,7 +157,6 @@ class ImageInput(pn.viewable.Viewer):
157
  pn.Tabs(
158
  pn.pane.HoloViews(
159
  self.param.plot,
160
- loading=self.param.updating,
161
  height=800,
162
  width=800,
163
  name="Interactive Image",
@@ -165,17 +164,16 @@ class ImageInput(pn.viewable.Viewer):
165
  pn.pane.Image(
166
  self.param.image,
167
  name="Static Image",
168
- loading=self.param.updating,
169
  width=800,
170
  ),
171
  pn.widgets.Tabulator(
172
  self.param.meta_data,
173
  name="Meta Data",
174
- loading=self.param.updating,
175
  disabled=True,
176
  ),
177
  pn.pane.Markdown(self.code, name="Code"),
178
  dynamic=True,
 
179
  ),
180
  )
181
 
@@ -291,7 +289,10 @@ class App(param.Parameterized):
291
  def _create_sidebar(self):
292
  return pn.Column(
293
  pn.pane.Image(
294
- MAJOR_TOM_LOGO, link_url=MAJOR_TOM_REF_URL, sizing_mode="stretch_width"
 
 
 
295
  ),
296
  pn.pane.Image(
297
  MAJOR_TOM_PICTURE,
 
 
1
  import holoviews as hv
2
  import numpy as np
3
  import pandas as pd
 
65
  @param.depends("data", watch=True, on_init=True)
66
  def _handle_data_dask_change(self):
67
  with self.param.update(updating=True):
68
+ data = self.data[["centre_easting", "centre_northing"]].copy()
69
  points = hv.Points(
70
+ data, kdims=["centre_easting", "centre_northing"], vdims=[]
71
  )
72
 
73
  rangexy = hv.streams.RangeXY(source=points)
 
148
  self.param._timestamp,
149
  button_style="outline",
150
  align="end",
151
+ disabled=self.param.updating,
152
  ),
153
  pn.widgets.Select.from_param(
154
  self.param.column_name, disabled=self.param.updating
 
157
  pn.Tabs(
158
  pn.pane.HoloViews(
159
  self.param.plot,
 
160
  height=800,
161
  width=800,
162
  name="Interactive Image",
 
164
  pn.pane.Image(
165
  self.param.image,
166
  name="Static Image",
 
167
  width=800,
168
  ),
169
  pn.widgets.Tabulator(
170
  self.param.meta_data,
171
  name="Meta Data",
 
172
  disabled=True,
173
  ),
174
  pn.pane.Markdown(self.code, name="Code"),
175
  dynamic=True,
176
+ loading=self.param.updating,
177
  ),
178
  )
179
 
 
289
  def _create_sidebar(self):
290
  return pn.Column(
291
  pn.pane.Image(
292
+ MAJOR_TOM_LOGO,
293
+ link_url=MAJOR_TOM_REF_URL,
294
+ height=60,
295
+ sizing_mode="stretch_width",
296
  ),
297
  pn.pane.Image(
298
  MAJOR_TOM_PICTURE,
requirements.txt CHANGED
@@ -1,5 +1,4 @@
1
  aiohttp
2
- dask[dataframe]
3
  datashader
4
  fsspec
5
  holoviews
 
1
  aiohttp
 
2
  datashader
3
  fsspec
4
  holoviews
utils.py CHANGED
@@ -9,7 +9,7 @@ from fsspec.parquet import open_parquet_file
9
  from holoviews import opts
10
  from PIL import Image
11
 
12
- MAJOR_TOM_LOGO = "https://cdn-uploads.huggingface.co/production/uploads/6304c06eeb6d777a838eab63/BJKsLwX0GG4W3-gdf40TJ.png"
13
  MAJOR_TOM_PICTURE = (
14
  "https://upload.wikimedia.org/wikipedia/en/6/6d/Major_tom_space_oddity_video.JPG"
15
  )
@@ -135,6 +135,7 @@ def _meta_data_path(dataset="Core-S2L2A", repository=REPOSITORY):
135
 
136
 
137
  def get_meta_data(dataset="Core-S2L2A", repository=REPOSITORY):
 
138
  path = _meta_data_path(dataset=dataset)
139
  if not path.exists():
140
  data = pd.read_parquet(_meta_data_url(dataset=dataset))
@@ -146,6 +147,10 @@ def get_meta_data(dataset="Core-S2L2A", repository=REPOSITORY):
146
  data["centre_lon"], data["centre_lat"]
147
  )
148
  )
 
 
 
 
149
 
150
  return data
151
 
@@ -167,17 +172,17 @@ def euclidean_distance(x, y, target_x, target_y):
167
  return np.sqrt((x - target_x) ** 2 + (y - target_y) ** 2)
168
 
169
 
170
- def get_closest_row(df, target_easting, target_northing):
171
  distance = euclidean_distance(
172
- df["centre_easting"], df["centre_northing"], target_easting, target_northing
173
  )
174
- closest_row = df.loc[distance.idxmin()]
175
  return closest_row
176
 
177
 
178
- def get_closest_rows(df, target_easting, target_northing):
179
  distance = euclidean_distance(
180
- df["centre_easting"], df["centre_northing"], target_easting, target_northing
181
  )
182
- closest_rows = df[distance == distance.min()]
183
  return closest_rows
 
9
  from holoviews import opts
10
  from PIL import Image
11
 
12
+ MAJOR_TOM_LOGO = "assets/major-tom-esa-logo.png"
13
  MAJOR_TOM_PICTURE = (
14
  "https://upload.wikimedia.org/wikipedia/en/6/6d/Major_tom_space_oddity_video.JPG"
15
  )
 
135
 
136
 
137
  def get_meta_data(dataset="Core-S2L2A", repository=REPOSITORY):
138
+ print(f"Loading {dataset}")
139
  path = _meta_data_path(dataset=dataset)
140
  if not path.exists():
141
  data = pd.read_parquet(_meta_data_url(dataset=dataset))
 
147
  data["centre_lon"], data["centre_lat"]
148
  )
149
  )
150
+ # Optimize Performance
151
+ data["timestamp"] = pd.to_datetime(data["timestamp"])
152
+ numeric_cols = ["cloud_cover", "nodata", "centre_lat", "centre_lon"]
153
+ data[numeric_cols] = data[numeric_cols].astype("float32")
154
 
155
  return data
156
 
 
172
  return np.sqrt((x - target_x) ** 2 + (y - target_y) ** 2)
173
 
174
 
175
+ def get_closest_row(data, target_easting, target_northing):
176
  distance = euclidean_distance(
177
+ data["centre_easting"], data["centre_northing"], target_easting, target_northing
178
  )
179
+ closest_row = data.loc[distance.idxmin()]
180
  return closest_row
181
 
182
 
183
+ def get_closest_rows(data, target_easting, target_northing):
184
  distance = euclidean_distance(
185
+ data["centre_easting"], data["centre_northing"], target_easting, target_northing
186
  )
187
+ closest_rows = data[distance == distance.min()]
188
  return closest_rows