Spaces:
Build error
Build error
cleaning
Browse files
app.py
CHANGED
|
@@ -1,14 +1,6 @@
|
|
| 1 |
-
import io
|
| 2 |
-
import math
|
| 3 |
-
|
| 4 |
-
# date=dataset['TIME']
|
| 5 |
-
#from datetime import date, datetime, timedelta
|
| 6 |
-
|
| 7 |
-
import cartopy.crs as ccrs
|
| 8 |
-
import cartopy.feature as cfeature
|
| 9 |
import cftime
|
| 10 |
import fsspec
|
| 11 |
-
|
| 12 |
import matplotlib.pyplot as plt
|
| 13 |
import numpy as np
|
| 14 |
import pandas as pd
|
|
@@ -16,24 +8,20 @@ import panel as pn
|
|
| 16 |
import xarray as xr
|
| 17 |
from ipywidgets import (
|
| 18 |
Checkbox,
|
| 19 |
-
FloatRangeSlider,
|
| 20 |
FloatSlider,
|
| 21 |
IntRangeSlider,
|
| 22 |
IntSlider,
|
| 23 |
-
interactive,
|
| 24 |
)
|
| 25 |
|
| 26 |
-
pn.extension("tabulator")
|
| 27 |
|
| 28 |
-
|
| 29 |
-
# df = df.sort_values(by="year")
|
| 30 |
-
# df2 = pd.read_csv("test_table.csv", index_col=None)
|
| 31 |
-
# file_names = df["file_name"].tolist()
|
| 32 |
-
# df = df.sort_values(by="year")
|
| 33 |
-
# years = sorted(df["year"].unique())
|
| 34 |
|
|
|
|
| 35 |
|
| 36 |
def greg_0h(jourjul):
|
|
|
|
| 37 |
# Julian days start and end at noon.
|
| 38 |
# Julian day 2440000 begins at 00 hours, May 23, 1968.
|
| 39 |
|
|
@@ -90,28 +78,6 @@ def fix_time(ds):
|
|
| 90 |
date = xr.DataArray(date, dims="MAXT")
|
| 91 |
return ds.assign(TIME=date)
|
| 92 |
|
| 93 |
-
|
| 94 |
-
import cartopy.crs as ccrs
|
| 95 |
-
import cartopy.feature as cfeature
|
| 96 |
-
import fsspec
|
| 97 |
-
import matplotlib.pyplot as plt
|
| 98 |
-
import numpy as np
|
| 99 |
-
import os
|
| 100 |
-
import panel as pn
|
| 101 |
-
import xarray as xr
|
| 102 |
-
from ipywidgets import (
|
| 103 |
-
Checkbox,
|
| 104 |
-
FloatRangeSlider,
|
| 105 |
-
FloatSlider,
|
| 106 |
-
IntRangeSlider,
|
| 107 |
-
IntSlider,
|
| 108 |
-
interactive,
|
| 109 |
-
)
|
| 110 |
-
|
| 111 |
-
import panel as pn
|
| 112 |
-
import param
|
| 113 |
-
import xarray as xr
|
| 114 |
-
|
| 115 |
@pn.cache(max_items=32,policy='LRU',per_session=True)
|
| 116 |
def load_csv():
|
| 117 |
url="https://data-eurogoship.ifremer.fr/data/table.csv"
|
|
@@ -129,6 +95,7 @@ def load_bathymetry():
|
|
| 129 |
|
| 130 |
@pn.cache(max_items=16,policy='LRU',per_session=True)
|
| 131 |
def load_netCDF(selected_file):
|
|
|
|
| 132 |
data_dir = "https://data-eurogoship.ifremer.fr/copy_seadatanet/"
|
| 133 |
file_path = os.path.join(data_dir, selected_file)
|
| 134 |
fs = fsspec.filesystem("https")
|
|
@@ -196,6 +163,32 @@ def filter_df(sorted_df,selected_file):
|
|
| 196 |
)
|
| 197 |
return dataframe.transpose(), dataframe2.transpose()
|
| 198 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
class SADCP_Viewer(param.Parameterized):
|
| 200 |
df = load_csv()
|
| 201 |
bathy = load_bathymetry()
|
|
@@ -323,7 +316,7 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 323 |
def update_plots(self):
|
| 324 |
self.ds_filtered = self.filter_data()
|
| 325 |
# vector_plot = self.vectors_plot()
|
| 326 |
-
other_plots = self.
|
| 327 |
|
| 328 |
# self.plot_map = pn.pane.Matplotlib(vector_plot, width=800, height=600, sizing_mode="fixed")
|
| 329 |
self.plot = pn.Column(
|
|
@@ -348,9 +341,11 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 348 |
)
|
| 349 |
|
| 350 |
def vectors_plot(self):
|
| 351 |
-
import
|
|
|
|
| 352 |
|
| 353 |
self.ds_filtered = self.filter_data()
|
|
|
|
| 354 |
# return self.ds_filtered['VSHIP'].hvplot(x='TIME',width=400, height=200) #if 'BATHY' in self.ds_filtered else hvplot.show(hvplot.text(0, 0, "No data available", fontsize=12))
|
| 355 |
|
| 356 |
fig, ax = plt.subplots(
|
|
@@ -364,76 +359,23 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 364 |
.mean()
|
| 365 |
.set_coords(coords)
|
| 366 |
)
|
|
|
|
| 367 |
# self.ds_filtered =self.ds_filtered.coarsen(MAXT = corsen, side = "center", boundary = "trim").mean()[["LONGITUDE", "LONGITUDE", "TIME"]].isel(MAXZ=0)
|
| 368 |
-
depth_filtered = self.ds_filtered.where(
|
| 369 |
-
(self.depth1 > self.depth_range_slider.value[0])
|
| 370 |
-
& (self.depth1 <= self.depth_range_slider.value[1])
|
| 371 |
-
)
|
| 372 |
|
| 373 |
-
|
| 374 |
-
lat = self.ds_filtered.coords["LATITUDE"].values
|
| 375 |
-
# skip = max(1, int(np.sqrt(lon.size) / self.num_vectors_slider.value))
|
| 376 |
-
# skip = (slice(None, None, skip), slice(None, None, skip))
|
| 377 |
-
|
| 378 |
-
# Moyenne des vecteurs de courant sur la plage de profondeur sélectionnée
|
| 379 |
-
u_mean = depth_filtered.UCUR.mean(dim="MAXZ", skipna=True)
|
| 380 |
-
v_mean = depth_filtered.VCUR.mean(dim="MAXZ", skipna=True)
|
| 381 |
-
ax.quiver(
|
| 382 |
-
lon,
|
| 383 |
-
lat,
|
| 384 |
-
u_mean * self.scale_factor_slider.value,
|
| 385 |
-
v_mean * self.scale_factor_slider.value,
|
| 386 |
-
color="blue",
|
| 387 |
-
scale=2,
|
| 388 |
-
width=0.001,
|
| 389 |
-
headwidth=3,
|
| 390 |
-
transform=ccrs.PlateCarree(),
|
| 391 |
-
)
|
| 392 |
|
| 393 |
if self.depth_2_checkbox.value:
|
| 394 |
-
|
| 395 |
-
(self.depth1 > self.depth2_range_slider.value[0])
|
| 396 |
-
& (self.depth1 <= self.depth2_range_slider.value[1])
|
| 397 |
-
)
|
| 398 |
-
u_mean = depth_filtered.UCUR.mean(dim="MAXZ", skipna=True)
|
| 399 |
-
v_mean = depth_filtered.VCUR.mean(dim="MAXZ", skipna=True)
|
| 400 |
-
ax.quiver(
|
| 401 |
-
lon,
|
| 402 |
-
lat,
|
| 403 |
-
u_mean * self.scale_factor_slider.value,
|
| 404 |
-
v_mean * self.scale_factor_slider.value,
|
| 405 |
-
color="green",
|
| 406 |
-
scale=2,
|
| 407 |
-
width=0.001,
|
| 408 |
-
headwidth=3,
|
| 409 |
-
transform=ccrs.PlateCarree(),
|
| 410 |
-
)
|
| 411 |
|
| 412 |
if self.depth_3_checkbox.value:
|
| 413 |
-
|
| 414 |
-
(self.depth1 > self.depth3_range_slider.value[0])
|
| 415 |
-
& (self.depth1 <= self.depth3_range_slider.value[1])
|
| 416 |
-
)
|
| 417 |
-
u_mean = depth_filtered.UCUR.mean(dim="MAXZ", skipna=True)
|
| 418 |
-
v_mean = depth_filtered.VCUR.mean(dim="MAXZ", skipna=True)
|
| 419 |
-
ax.quiver(
|
| 420 |
-
lon,
|
| 421 |
-
lat,
|
| 422 |
-
u_mean * self.scale_factor_slider.value,
|
| 423 |
-
v_mean * self.scale_factor_slider.value,
|
| 424 |
-
color="red",
|
| 425 |
-
scale=2,
|
| 426 |
-
width=0.001,
|
| 427 |
-
headwidth=3,
|
| 428 |
-
transform=ccrs.PlateCarree(),
|
| 429 |
-
)
|
| 430 |
|
| 431 |
ax.add_feature(cfeature.COASTLINE)
|
| 432 |
ax.add_feature(cfeature.BORDERS, linestyle=":")
|
| 433 |
ax.add_feature(cfeature.LAND, color="lightgray")
|
| 434 |
|
| 435 |
if self.bathy_checkbox.value:
|
| 436 |
-
contour_levels = [-
|
| 437 |
ax.contour(
|
| 438 |
self.bathy.longitude,
|
| 439 |
self.bathy.latitude,
|
|
@@ -460,7 +402,8 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 460 |
# pn.pane.Matplotlib(fig,width=800, height=600, sizing_mode="fixed", name="Plot")
|
| 461 |
|
| 462 |
# @param.depends( 'file_dropdown.value', 'longitude_slider.value', 'latitude_slider.value', watch=True)
|
| 463 |
-
def
|
|
|
|
| 464 |
return [
|
| 465 |
self.ds_filtered["BATHY"].max(dim="MAXZ").hvplot(x="TIME", width=400, height=200),
|
| 466 |
self.ds_filtered["USHIP"].max(dim="MAXZ").hvplot(x="TIME", width=400, height=200),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import cftime
|
| 2 |
import fsspec
|
| 3 |
+
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
import numpy as np
|
| 6 |
import pandas as pd
|
|
|
|
| 8 |
import xarray as xr
|
| 9 |
from ipywidgets import (
|
| 10 |
Checkbox,
|
| 11 |
+
# FloatRangeSlider,
|
| 12 |
FloatSlider,
|
| 13 |
IntRangeSlider,
|
| 14 |
IntSlider,
|
| 15 |
+
# interactive,
|
| 16 |
)
|
| 17 |
|
|
|
|
| 18 |
|
| 19 |
+
import param
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
pn.extension("tabulator")
|
| 22 |
|
| 23 |
def greg_0h(jourjul):
|
| 24 |
+
import math
|
| 25 |
# Julian days start and end at noon.
|
| 26 |
# Julian day 2440000 begins at 00 hours, May 23, 1968.
|
| 27 |
|
|
|
|
| 78 |
date = xr.DataArray(date, dims="MAXT")
|
| 79 |
return ds.assign(TIME=date)
|
| 80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
@pn.cache(max_items=32,policy='LRU',per_session=True)
|
| 82 |
def load_csv():
|
| 83 |
url="https://data-eurogoship.ifremer.fr/data/table.csv"
|
|
|
|
| 95 |
|
| 96 |
@pn.cache(max_items=16,policy='LRU',per_session=True)
|
| 97 |
def load_netCDF(selected_file):
|
| 98 |
+
import os
|
| 99 |
data_dir = "https://data-eurogoship.ifremer.fr/copy_seadatanet/"
|
| 100 |
file_path = os.path.join(data_dir, selected_file)
|
| 101 |
fs = fsspec.filesystem("https")
|
|
|
|
| 163 |
)
|
| 164 |
return dataframe.transpose(), dataframe2.transpose()
|
| 165 |
|
| 166 |
+
def quiver_depth_filterd(ax,ds_filtered, depth1, depth_range_slider, scale_factor_slider, color="blue"):
|
| 167 |
+
import cartopy.crs as ccrs
|
| 168 |
+
depth_filtered = ds_filtered.where(
|
| 169 |
+
(depth1 > depth_range_slider.value[0])
|
| 170 |
+
& (depth1 <= depth_range_slider.value[1])
|
| 171 |
+
)
|
| 172 |
+
|
| 173 |
+
lon = ds_filtered.coords["LONGITUDE"].values
|
| 174 |
+
lat = ds_filtered.coords["LATITUDE"].values
|
| 175 |
+
|
| 176 |
+
# Moyenne des vecteurs de courant sur la plage de profondeur sélectionnée
|
| 177 |
+
u_mean = depth_filtered.UCUR.mean(dim="MAXZ", skipna=True)
|
| 178 |
+
v_mean = depth_filtered.VCUR.mean(dim="MAXZ", skipna=True)
|
| 179 |
+
|
| 180 |
+
return ax.quiver(
|
| 181 |
+
lon,
|
| 182 |
+
lat,
|
| 183 |
+
u_mean * scale_factor_slider.value,
|
| 184 |
+
v_mean * scale_factor_slider.value,
|
| 185 |
+
color=color,
|
| 186 |
+
scale=2,
|
| 187 |
+
width=0.001,
|
| 188 |
+
headwidth=3,
|
| 189 |
+
transform=ccrs.PlateCarree(),
|
| 190 |
+
)
|
| 191 |
+
|
| 192 |
class SADCP_Viewer(param.Parameterized):
|
| 193 |
df = load_csv()
|
| 194 |
bathy = load_bathymetry()
|
|
|
|
| 316 |
def update_plots(self):
|
| 317 |
self.ds_filtered = self.filter_data()
|
| 318 |
# vector_plot = self.vectors_plot()
|
| 319 |
+
other_plots = self.hvplot_plots()
|
| 320 |
|
| 321 |
# self.plot_map = pn.pane.Matplotlib(vector_plot, width=800, height=600, sizing_mode="fixed")
|
| 322 |
self.plot = pn.Column(
|
|
|
|
| 341 |
)
|
| 342 |
|
| 343 |
def vectors_plot(self):
|
| 344 |
+
import cartopy.crs as ccrs
|
| 345 |
+
import cartopy.feature as cfeature
|
| 346 |
|
| 347 |
self.ds_filtered = self.filter_data()
|
| 348 |
+
|
| 349 |
# return self.ds_filtered['VSHIP'].hvplot(x='TIME',width=400, height=200) #if 'BATHY' in self.ds_filtered else hvplot.show(hvplot.text(0, 0, "No data available", fontsize=12))
|
| 350 |
|
| 351 |
fig, ax = plt.subplots(
|
|
|
|
| 359 |
.mean()
|
| 360 |
.set_coords(coords)
|
| 361 |
)
|
| 362 |
+
|
| 363 |
# self.ds_filtered =self.ds_filtered.coarsen(MAXT = corsen, side = "center", boundary = "trim").mean()[["LONGITUDE", "LONGITUDE", "TIME"]].isel(MAXZ=0)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 364 |
|
| 365 |
+
quiver_depth_filterd(ax,self.ds_filtered, self.depth1, self.depth_range_slider,self.scale_factor_slider,color="blue")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 366 |
|
| 367 |
if self.depth_2_checkbox.value:
|
| 368 |
+
quiver_depth_filterd(ax,self.ds_filtered, self.depth1, self.depth2_range_slider,self.scale_factor_slider,color="green")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 369 |
|
| 370 |
if self.depth_3_checkbox.value:
|
| 371 |
+
quiver_depth_filterd(ax,self.ds_filtered, self.depth1, self.depth3_range_slider,self.scale_factor_slider,color="red")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 372 |
|
| 373 |
ax.add_feature(cfeature.COASTLINE)
|
| 374 |
ax.add_feature(cfeature.BORDERS, linestyle=":")
|
| 375 |
ax.add_feature(cfeature.LAND, color="lightgray")
|
| 376 |
|
| 377 |
if self.bathy_checkbox.value:
|
| 378 |
+
contour_levels = [-1000]
|
| 379 |
ax.contour(
|
| 380 |
self.bathy.longitude,
|
| 381 |
self.bathy.latitude,
|
|
|
|
| 402 |
# pn.pane.Matplotlib(fig,width=800, height=600, sizing_mode="fixed", name="Plot")
|
| 403 |
|
| 404 |
# @param.depends( 'file_dropdown.value', 'longitude_slider.value', 'latitude_slider.value', watch=True)
|
| 405 |
+
def hvplot_plots(self):
|
| 406 |
+
import hvplot.xarray
|
| 407 |
return [
|
| 408 |
self.ds_filtered["BATHY"].max(dim="MAXZ").hvplot(x="TIME", width=400, height=200),
|
| 409 |
self.ds_filtered["USHIP"].max(dim="MAXZ").hvplot(x="TIME", width=400, height=200),
|