Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -9,13 +9,11 @@ import cartopy.feature as cfeature
|
|
| 9 |
import cftime
|
| 10 |
import fsspec
|
| 11 |
import hvplot.xarray
|
| 12 |
-
|
| 13 |
import matplotlib.pyplot as plt
|
| 14 |
import numpy as np
|
| 15 |
import pandas as pd
|
| 16 |
import panel as pn
|
| 17 |
import xarray as xr
|
| 18 |
-
|
| 19 |
from ipywidgets import (
|
| 20 |
Checkbox,
|
| 21 |
Dropdown,
|
|
@@ -26,14 +24,14 @@ from ipywidgets import (
|
|
| 26 |
interactive,
|
| 27 |
)
|
| 28 |
|
| 29 |
-
pn.extension(
|
| 30 |
|
| 31 |
-
#df = pd.read_csv("table.csv", index_col=None)
|
| 32 |
-
#df = df.sort_values(by="year")
|
| 33 |
-
#df2 = pd.read_csv("test_table.csv", index_col=None)
|
| 34 |
-
#file_names = df["file_name"].tolist()
|
| 35 |
-
#df = df.sort_values(by="year")
|
| 36 |
-
#years = sorted(df["year"].unique())
|
| 37 |
|
| 38 |
|
| 39 |
def greg_0h(jourjul):
|
|
@@ -84,7 +82,7 @@ def fix_time(dataset):
|
|
| 84 |
|
| 85 |
time = dataset["TIME"]
|
| 86 |
time2 = time.dropna(dim="MAXT")
|
| 87 |
-
time2 = time2.reindex_like(time, method=
|
| 88 |
jourjul = [greg_0h(jourjul) for jourjul in time2.values]
|
| 89 |
date = [
|
| 90 |
datetime(jourjul[0], jourjul[1], jourjul[2], jourjul[3], jourjul[4], jourjul[5])
|
|
@@ -93,6 +91,7 @@ def fix_time(dataset):
|
|
| 93 |
|
| 94 |
return date
|
| 95 |
|
|
|
|
| 96 |
from datetime import datetime, timedelta
|
| 97 |
|
| 98 |
import cartopy.crs as ccrs
|
|
@@ -112,9 +111,10 @@ from ipywidgets import (
|
|
| 112 |
)
|
| 113 |
|
| 114 |
# Loaddonnées bathymétry data
|
| 115 |
-
fs = fsspec.filesystem("https")
|
| 116 |
-
bathy = xr.open_dataset(
|
| 117 |
-
|
|
|
|
| 118 |
|
| 119 |
|
| 120 |
import os
|
|
@@ -124,12 +124,46 @@ import panel as pn
|
|
| 124 |
import param
|
| 125 |
import xarray as xr
|
| 126 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
class SADCP_Viewer(param.Parameterized):
|
| 129 |
-
file_csv=
|
| 130 |
-
file=fs.open(file_csv)
|
| 131 |
-
df =
|
| 132 |
-
|
|
|
|
|
|
|
| 133 |
file_names = df["file_name"].tolist()
|
| 134 |
years = sorted(df["year"].unique())
|
| 135 |
|
|
@@ -138,7 +172,7 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 138 |
)
|
| 139 |
file_dropdown = pn.widgets.Select(name="File Selector")
|
| 140 |
data_table = pn.widgets.Tabulator(df, name="metadata", height=200, width=300)
|
| 141 |
-
|
| 142 |
|
| 143 |
longitude_slider = pn.widgets.RangeSlider(
|
| 144 |
name="Longitude Range", start=-180, end=180, step=1
|
|
@@ -170,14 +204,10 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 170 |
|
| 171 |
plot = pn.pane.HoloViews()
|
| 172 |
plot_map = pn.pane.Matplotlib(width=800, height=600, sizing_mode="fixed")
|
| 173 |
-
|
| 174 |
-
data_table = pn.widgets.Tabulator(
|
| 175 |
-
|
| 176 |
-
)
|
| 177 |
-
|
| 178 |
-
metadata_table = pn.widgets.Tabulator(
|
| 179 |
-
width=600, height=800
|
| 180 |
-
)
|
| 181 |
download_button = pn.widgets.Button(name="Download", button_type="primary")
|
| 182 |
# plot = pn.Column()
|
| 183 |
|
|
@@ -203,24 +233,48 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 203 |
selected_file = files[0]
|
| 204 |
self.file_dropdown.value = selected_file
|
| 205 |
dataframe = sorted_df[sorted_df["file_name"] == selected_file].drop(
|
| 206 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 207 |
)
|
| 208 |
dataframe2 = sorted_df[sorted_df["file_name"] == selected_file].drop(
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
data_dir = "https://data-eurogoship.ifremer.fr/copy_seadatanet/"
|
| 213 |
file_path = os.path.join(data_dir, selected_file)
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
|
|
|
| 224 |
|
| 225 |
lon_range = (
|
| 226 |
int(self.ds["LONGITUDE"].min().round() - 1),
|
|
@@ -289,9 +343,6 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 289 |
self.depth3_range_slider.start = deph_range[0]
|
| 290 |
self.depth3_range_slider.end = deph_range[1]
|
| 291 |
self.depth3_range_slider.value = deph_range
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
|
| 296 |
# self.update_plots()
|
| 297 |
self.ds.close()
|
|
@@ -431,9 +482,9 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 431 |
if self.bathy_checkbox.value:
|
| 432 |
contour_levels = [-2000]
|
| 433 |
ax.contour(
|
| 434 |
-
bathy.longitude,
|
| 435 |
-
bathy.latitude,
|
| 436 |
-
bathy.z,
|
| 437 |
levels=contour_levels,
|
| 438 |
colors="black",
|
| 439 |
transform=ccrs.PlateCarree(),
|
|
@@ -468,13 +519,12 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 468 |
return self.file_names
|
| 469 |
|
| 470 |
|
| 471 |
-
|
| 472 |
explorer = SADCP_Viewer()
|
| 473 |
# Instantiate the SADCP_Viewer class and create a template
|
| 474 |
tabs = pn.Tabs(
|
| 475 |
("Plots", pn.Column(explorer.update_plots)),
|
| 476 |
(
|
| 477 |
-
|
| 478 |
pn.Column(
|
| 479 |
explorer.metadata_table, explorer.download_button, height=500, margin=10
|
| 480 |
),
|
|
@@ -497,6 +547,8 @@ sidebar = [
|
|
| 497 |
explorer.scale_factor_slider,
|
| 498 |
explorer.data_table,
|
| 499 |
]
|
| 500 |
-
template = pn.template.FastListTemplate(
|
| 501 |
-
|
|
|
|
|
|
|
| 502 |
|
|
|
|
| 9 |
import cftime
|
| 10 |
import fsspec
|
| 11 |
import hvplot.xarray
|
|
|
|
| 12 |
import matplotlib.pyplot as plt
|
| 13 |
import numpy as np
|
| 14 |
import pandas as pd
|
| 15 |
import panel as pn
|
| 16 |
import xarray as xr
|
|
|
|
| 17 |
from ipywidgets import (
|
| 18 |
Checkbox,
|
| 19 |
Dropdown,
|
|
|
|
| 24 |
interactive,
|
| 25 |
)
|
| 26 |
|
| 27 |
+
pn.extension("tabulator")
|
| 28 |
|
| 29 |
+
# df = pd.read_csv("table.csv", index_col=None)
|
| 30 |
+
# df = df.sort_values(by="year")
|
| 31 |
+
# df2 = pd.read_csv("test_table.csv", index_col=None)
|
| 32 |
+
# file_names = df["file_name"].tolist()
|
| 33 |
+
# df = df.sort_values(by="year")
|
| 34 |
+
# years = sorted(df["year"].unique())
|
| 35 |
|
| 36 |
|
| 37 |
def greg_0h(jourjul):
|
|
|
|
| 82 |
|
| 83 |
time = dataset["TIME"]
|
| 84 |
time2 = time.dropna(dim="MAXT")
|
| 85 |
+
time2 = time2.reindex_like(time, method="nearest")
|
| 86 |
jourjul = [greg_0h(jourjul) for jourjul in time2.values]
|
| 87 |
date = [
|
| 88 |
datetime(jourjul[0], jourjul[1], jourjul[2], jourjul[3], jourjul[4], jourjul[5])
|
|
|
|
| 91 |
|
| 92 |
return date
|
| 93 |
|
| 94 |
+
|
| 95 |
from datetime import datetime, timedelta
|
| 96 |
|
| 97 |
import cartopy.crs as ccrs
|
|
|
|
| 111 |
)
|
| 112 |
|
| 113 |
# Loaddonnées bathymétry data
|
| 114 |
+
#fs = fsspec.filesystem("https")
|
| 115 |
+
#bathy = xr.open_dataset(
|
| 116 |
+
#fs.open("https://data-eurogoship.ifremer.fr/bathymetrie/bathy6min.nc")
|
| 117 |
+
#)
|
| 118 |
|
| 119 |
|
| 120 |
import os
|
|
|
|
| 124 |
import param
|
| 125 |
import xarray as xr
|
| 126 |
|
| 127 |
+
@pn.cache(max_items=32,policy='LRU')
|
| 128 |
+
def load_csv(url):
|
| 129 |
+
fs = fsspec.filesystem("https")
|
| 130 |
+
with fs.open(url) as f:
|
| 131 |
+
df = pd.read_csv(f,index_col=None)
|
| 132 |
+
df.sort_values(by="year")
|
| 133 |
+
return df
|
| 134 |
+
|
| 135 |
+
@pn.cache(max_items=4,policy='LRU')
|
| 136 |
+
def load_bathymetry(url):
|
| 137 |
+
fs = fsspec.filesystem("https")
|
| 138 |
+
return xr.open_dataset(fs.open(url), decode_times=False, use_cftime=True)
|
| 139 |
+
|
| 140 |
+
@pn.cache(max_items=16,policy='LRU')
|
| 141 |
+
def load_netCDF(file_path):
|
| 142 |
+
fs = fsspec.filesystem("https")
|
| 143 |
+
ds= ds = (
|
| 144 |
+
xr.open_dataset(
|
| 145 |
+
fs.open(file_path), decode_cf=True, decode_times=False, engine="scipy"
|
| 146 |
+
)
|
| 147 |
+
.squeeze()
|
| 148 |
+
.set_coords(["LONGITUDE", "LATITUDE", "TIME", "PROFZ"])
|
| 149 |
+
.set_xindex("PROFZ")
|
| 150 |
+
.set_xindex("TIME")
|
| 151 |
+
)
|
| 152 |
+
return ds
|
| 153 |
+
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
|
| 157 |
+
|
| 158 |
+
|
| 159 |
|
| 160 |
class SADCP_Viewer(param.Parameterized):
|
| 161 |
+
#file_csv = "https://data-eurogoship.ifremer.fr/data/table.csv"
|
| 162 |
+
#file = fs.open(file_csv)
|
| 163 |
+
df = load_csv("https://data-eurogoship.ifremer.fr/data/table.csv")
|
| 164 |
+
bathy = load_bathymetry("https://data-eurogoship.ifremer.fr/bathymetrie/bathy6min.nc")
|
| 165 |
+
#df = pd.read_csv(file, index_col=None).sort_values(by="year")
|
| 166 |
+
# df = pd.read_csv("table.csv", index_col=None).sort_values(by="year")
|
| 167 |
file_names = df["file_name"].tolist()
|
| 168 |
years = sorted(df["year"].unique())
|
| 169 |
|
|
|
|
| 172 |
)
|
| 173 |
file_dropdown = pn.widgets.Select(name="File Selector")
|
| 174 |
data_table = pn.widgets.Tabulator(df, name="metadata", height=200, width=300)
|
| 175 |
+
# data_table2 = pn.widgets.Tabulator(df2, name="metadata", height=900, width=400)
|
| 176 |
|
| 177 |
longitude_slider = pn.widgets.RangeSlider(
|
| 178 |
name="Longitude Range", start=-180, end=180, step=1
|
|
|
|
| 204 |
|
| 205 |
plot = pn.pane.HoloViews()
|
| 206 |
plot_map = pn.pane.Matplotlib(width=800, height=600, sizing_mode="fixed")
|
| 207 |
+
|
| 208 |
+
data_table = pn.widgets.Tabulator(width=400, height=200)
|
| 209 |
+
|
| 210 |
+
metadata_table = pn.widgets.Tabulator(width=600, height=800)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 211 |
download_button = pn.widgets.Button(name="Download", button_type="primary")
|
| 212 |
# plot = pn.Column()
|
| 213 |
|
|
|
|
| 233 |
selected_file = files[0]
|
| 234 |
self.file_dropdown.value = selected_file
|
| 235 |
dataframe = sorted_df[sorted_df["file_name"] == selected_file].drop(
|
| 236 |
+
columns=[
|
| 237 |
+
"file_name",
|
| 238 |
+
"title",
|
| 239 |
+
"Conventions",
|
| 240 |
+
"featureType",
|
| 241 |
+
"date_update",
|
| 242 |
+
"ADCP_beam_angle",
|
| 243 |
+
"ADCP_ship_angle",
|
| 244 |
+
"middle_bin1_depth",
|
| 245 |
+
"heading_corr",
|
| 246 |
+
"pitch_corr",
|
| 247 |
+
"ampli_corr",
|
| 248 |
+
"pitch_roll_used",
|
| 249 |
+
"date_creation",
|
| 250 |
+
"ADCP_type",
|
| 251 |
+
"data_type",
|
| 252 |
+
]
|
| 253 |
)
|
| 254 |
dataframe2 = sorted_df[sorted_df["file_name"] == selected_file].drop(
|
| 255 |
+
columns=[
|
| 256 |
+
"file_name",
|
| 257 |
+
"date_start",
|
| 258 |
+
"date_end",
|
| 259 |
+
"ADCP_frequency(kHz)",
|
| 260 |
+
"bin_length(meter)",
|
| 261 |
+
"year",
|
| 262 |
+
]
|
| 263 |
+
)
|
| 264 |
+
|
| 265 |
data_dir = "https://data-eurogoship.ifremer.fr/copy_seadatanet/"
|
| 266 |
file_path = os.path.join(data_dir, selected_file)
|
| 267 |
+
self.ds=load_netCDF(file_path)
|
| 268 |
+
#file_path = fs.open(file_path)
|
| 269 |
+
#self.ds = (
|
| 270 |
+
#xr.open_dataset(
|
| 271 |
+
#file_path, decode_cf=True, decode_times=False, engine="scipy"
|
| 272 |
+
#)
|
| 273 |
+
# .squeeze()
|
| 274 |
+
# .set_coords(["LONGITUDE", "LATITUDE", "TIME", "PROFZ"])
|
| 275 |
+
#@.set_xindex("PROFZ")
|
| 276 |
+
# .set_xindex("TIME")
|
| 277 |
+
# )
|
| 278 |
|
| 279 |
lon_range = (
|
| 280 |
int(self.ds["LONGITUDE"].min().round() - 1),
|
|
|
|
| 343 |
self.depth3_range_slider.start = deph_range[0]
|
| 344 |
self.depth3_range_slider.end = deph_range[1]
|
| 345 |
self.depth3_range_slider.value = deph_range
|
|
|
|
|
|
|
|
|
|
| 346 |
|
| 347 |
# self.update_plots()
|
| 348 |
self.ds.close()
|
|
|
|
| 482 |
if self.bathy_checkbox.value:
|
| 483 |
contour_levels = [-2000]
|
| 484 |
ax.contour(
|
| 485 |
+
self.bathy.longitude,
|
| 486 |
+
self.bathy.latitude,
|
| 487 |
+
self.bathy.z,
|
| 488 |
levels=contour_levels,
|
| 489 |
colors="black",
|
| 490 |
transform=ccrs.PlateCarree(),
|
|
|
|
| 519 |
return self.file_names
|
| 520 |
|
| 521 |
|
|
|
|
| 522 |
explorer = SADCP_Viewer()
|
| 523 |
# Instantiate the SADCP_Viewer class and create a template
|
| 524 |
tabs = pn.Tabs(
|
| 525 |
("Plots", pn.Column(explorer.update_plots)),
|
| 526 |
(
|
| 527 |
+
"Metadata",
|
| 528 |
pn.Column(
|
| 529 |
explorer.metadata_table, explorer.download_button, height=500, margin=10
|
| 530 |
),
|
|
|
|
| 547 |
explorer.scale_factor_slider,
|
| 548 |
explorer.data_table,
|
| 549 |
]
|
| 550 |
+
template = pn.template.FastListTemplate(
|
| 551 |
+
title="SADCP data Viewer", sidebar=sidebar, main=[tabs]
|
| 552 |
+
)
|
| 553 |
+
template.show()
|
| 554 |
|