Spaces:
Runtime error
Runtime error
Cleaning
Browse files
app.py
CHANGED
|
@@ -14,22 +14,26 @@ pn.extension("tabulator")
|
|
| 14 |
|
| 15 |
def get_range(da):
|
| 16 |
return ( int(da.min().round() - 1), int(da.max().round() + 1),)
|
|
|
|
| 17 |
@pn.cache(max_items=32,policy='LRU',per_session=True)
|
| 18 |
-
def load_csv():
|
| 19 |
-
df = pd.read_csv(
|
| 20 |
df.sort_values(by="year") #inplace=True)
|
| 21 |
return df
|
| 22 |
|
| 23 |
@pn.cache(max_items=4,policy='LRU',per_session=True)
|
| 24 |
-
def load_bathymetry():
|
| 25 |
-
return xr.open_dataset(
|
| 26 |
|
| 27 |
@pn.cache(max_items=16,policy='LRU',per_session=True)
|
| 28 |
-
def load_zarr(
|
| 29 |
-
|
|
|
|
|
|
|
| 30 |
return tree[selected_file+"/"].ds
|
| 31 |
|
| 32 |
def filter_df(sorted_df,selected_file):
|
|
|
|
| 33 |
dataframe = sorted_df[sorted_df["file_name"] == selected_file].drop(
|
| 34 |
columns=[
|
| 35 |
"file_name",
|
|
@@ -49,6 +53,7 @@ def filter_df(sorted_df,selected_file):
|
|
| 49 |
"data_type",
|
| 50 |
]
|
| 51 |
)
|
|
|
|
| 52 |
dataframe2 = sorted_df[sorted_df["file_name"] == selected_file].drop(
|
| 53 |
columns=[
|
| 54 |
"file_name",
|
|
@@ -87,8 +92,6 @@ def quiver_depth_filtered(ax, ds, depth_range, scale_factor, color="blue"):
|
|
| 87 |
"""
|
| 88 |
# Filter data based on depth range
|
| 89 |
ds = ds.sel( PROFZ=slice(depth_range[1],depth_range[0]))
|
| 90 |
-
#print('depth_range',depth_range)
|
| 91 |
-
#print(ds.PROFZ)
|
| 92 |
|
| 93 |
# Calculate mean current vectors within the selected depth range
|
| 94 |
u_mean = ds.UCUR.mean(dim="PROFZ", skipna=True)
|
|
@@ -208,15 +211,14 @@ def vectors_plot(ds, bathy, longitude_range, latitude_range ,
|
|
| 208 |
# Set labels and close plot
|
| 209 |
plt.ylabel("Latitude", fontsize=15, labelpad=35)
|
| 210 |
plt.xlabel("Longitude", fontsize=15, labelpad=20)
|
| 211 |
-
|
| 212 |
-
|
| 213 |
return fig
|
| 214 |
|
| 215 |
-
# return ( int(np.round(da.min().values)), int(np.round(da.max().values)),)
|
| 216 |
-
|
| 217 |
class SADCP_Viewer(param.Parameterized):
|
| 218 |
df = load_csv()
|
| 219 |
bathy = load_bathymetry()
|
|
|
|
| 220 |
file_names = df["file_name"].tolist()
|
| 221 |
years = sorted(df["year"].unique())
|
| 222 |
|
|
@@ -234,19 +236,15 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 234 |
scale_factor_slider = pn.widgets.FloatSlider(start=0.1, end=1, step=0.1, value=0.5, name="Scale Factor")
|
| 235 |
bathy_checkbox = pn.widgets.Checkbox(value=False, name="Bathy Checkbox")
|
| 236 |
|
| 237 |
-
|
| 238 |
-
# plot = pn.pane.HoloViews()
|
| 239 |
-
# plot_map = pn.pane.Matplotlib(width=800, height=600, sizing_mode="fixed")
|
| 240 |
-
|
| 241 |
data_table = pn.widgets.Tabulator(width=400, height=200)
|
| 242 |
metadata_table = pn.widgets.Tabulator(width=600, height=800)
|
| 243 |
-
|
| 244 |
download_button = pn.widgets.Button(name="Download", button_type="primary")
|
| 245 |
-
# plot = pn.Column()
|
| 246 |
|
| 247 |
def __init__(self, **params):
|
| 248 |
super(SADCP_Viewer, self).__init__(**params)
|
| 249 |
-
self.file_dropdown.objects = self.
|
| 250 |
self.file_dropdown.value = (
|
| 251 |
self.file_dropdown.objects[0] if self.file_dropdown.objects else None
|
| 252 |
)
|
|
@@ -286,7 +284,7 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 286 |
self.data_table.value, self.metadata_table.value = filter_df(sorted_df, selected_file)
|
| 287 |
|
| 288 |
# Load selected file's data
|
| 289 |
-
self.ds =
|
| 290 |
|
| 291 |
# Update slider ranges for longitude, latitude, and depth
|
| 292 |
for slider, coord in zip([self.longitude_slider, self.latitude_slider, self.depth_range_slider,
|
|
@@ -297,8 +295,7 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 297 |
|
| 298 |
|
| 299 |
# Close dataset to free up resources
|
| 300 |
-
# self.
|
| 301 |
-
self.ds.close()
|
| 302 |
|
| 303 |
@param.depends(
|
| 304 |
"year_slider.value",
|
|
@@ -313,8 +310,7 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 313 |
"num_vectors_slider.value",
|
| 314 |
"scale_factor_slider.value",
|
| 315 |
"bathy_checkbox.value",
|
| 316 |
-
watch=False,
|
| 317 |
-
)
|
| 318 |
def update_plots(self):
|
| 319 |
"""
|
| 320 |
This function updates the plots based on the selected data and parameters.
|
|
@@ -327,8 +323,6 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 327 |
"""
|
| 328 |
# Filter the data
|
| 329 |
self.ds_filtered = filter_data(self.ds,self.longitude_slider.value,self.latitude_slider.value)
|
| 330 |
-
# vector_plot = self.vectors_plot()
|
| 331 |
-
|
| 332 |
|
| 333 |
# Prepare the plots shown in left
|
| 334 |
# Update vector plots
|
|
@@ -342,38 +336,24 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 342 |
)
|
| 343 |
|
| 344 |
|
|
|
|
| 345 |
self.plot_left = pn.Column(
|
| 346 |
# '# Column',
|
| 347 |
# vector_plot,
|
| 348 |
pn.pane.Matplotlib(vector_plot, dpi=144),
|
| 349 |
-
#
|
| 350 |
sizing_mode="stretch_both")
|
| 351 |
|
| 352 |
# Generate additional plots which will be plotted on the right row.
|
| 353 |
-
other_plots = self.
|
| 354 |
-
# self.plot_map = pn.pane.Matplotlib(vector_plot, width=800, height=600, sizing_mode="fixed")
|
| 355 |
-
|
| 356 |
-
# Create a Column of additional plots
|
| 357 |
self.plot_right = pn.Column(
|
| 358 |
*(pn.pane.HoloViews(plot, width=400, height=200) for plot in other_plots),
|
| 359 |
sizing_mode="stretch_width"
|
| 360 |
)
|
| 361 |
-
# other_plots = self.plots() # Update other plots
|
| 362 |
-
# self.plot.objects = [*(pn.pane.HoloViews(p, width=400, height=200) for p in other_plots)]
|
| 363 |
-
# self.plot.object=plot
|
| 364 |
|
| 365 |
# Return a Panel row containing the updated map plot and additional plots
|
| 366 |
return pn.Row(self.plot_left, self.plot_right, sizing_mode="stretch_both")
|
| 367 |
|
| 368 |
-
# pn.pane.Matplotlib(fig,width=800, height=600, sizing_mode="fixed", name="Plot")
|
| 369 |
-
|
| 370 |
-
# @param.depends( 'file_dropdown.value', 'longitude_slider.value', 'latitude_slider.value', watch=True)
|
| 371 |
-
def hvplot_plots(self):
|
| 372 |
-
return bathy_uship_vship_bottom_depth(self.ds_filtered)
|
| 373 |
-
|
| 374 |
-
def get_file_list(self):
|
| 375 |
-
return self.file_names
|
| 376 |
-
|
| 377 |
|
| 378 |
explorer = SADCP_Viewer()
|
| 379 |
# Instantiate the SADCP_Viewer class and create a template
|
|
@@ -402,10 +382,12 @@ sidebar = [
|
|
| 402 |
explorer.num_vectors_slider,
|
| 403 |
explorer.scale_factor_slider,
|
| 404 |
explorer.data_table,
|
| 405 |
-
"""You can consult detailed information on this data
|
| 406 |
To download full dataset, please go to https://cdi.seadatanet.org/search
|
| 407 |
and search with LOCAL_CDI_ID indicated above.""",
|
| 408 |
]
|
|
|
|
|
|
|
| 409 |
template = pn.template.FastListTemplate(
|
| 410 |
title="SADCP data Viewer", sidebar=sidebar, main=[tabs]
|
| 411 |
)
|
|
|
|
| 14 |
|
| 15 |
def get_range(da):
|
| 16 |
return ( int(da.min().round() - 1), int(da.max().round() + 1),)
|
| 17 |
+
|
| 18 |
@pn.cache(max_items=32,policy='LRU',per_session=True)
|
| 19 |
+
def load_csv(path='./data/zarr_table.csv'):
|
| 20 |
+
df = pd.read_csv(path,index_col=None)
|
| 21 |
df.sort_values(by="year") #inplace=True)
|
| 22 |
return df
|
| 23 |
|
| 24 |
@pn.cache(max_items=4,policy='LRU',per_session=True)
|
| 25 |
+
def load_bathymetry(path='./data/bathy6min.nc'):
|
| 26 |
+
return xr.open_dataset(path, decode_times=False, use_cftime=True)
|
| 27 |
|
| 28 |
@pn.cache(max_items=16,policy='LRU',per_session=True)
|
| 29 |
+
def load_zarr(path='./data/1H_file.zarr'):
|
| 30 |
+
return open_datatree(path, engine='zarr')
|
| 31 |
+
|
| 32 |
+
def load_file(tree,selected_file):
|
| 33 |
return tree[selected_file+"/"].ds
|
| 34 |
|
| 35 |
def filter_df(sorted_df,selected_file):
|
| 36 |
+
# include user_interface_url here
|
| 37 |
dataframe = sorted_df[sorted_df["file_name"] == selected_file].drop(
|
| 38 |
columns=[
|
| 39 |
"file_name",
|
|
|
|
| 53 |
"data_type",
|
| 54 |
]
|
| 55 |
)
|
| 56 |
+
# include LOCAL_CDI_ID here
|
| 57 |
dataframe2 = sorted_df[sorted_df["file_name"] == selected_file].drop(
|
| 58 |
columns=[
|
| 59 |
"file_name",
|
|
|
|
| 92 |
"""
|
| 93 |
# Filter data based on depth range
|
| 94 |
ds = ds.sel( PROFZ=slice(depth_range[1],depth_range[0]))
|
|
|
|
|
|
|
| 95 |
|
| 96 |
# Calculate mean current vectors within the selected depth range
|
| 97 |
u_mean = ds.UCUR.mean(dim="PROFZ", skipna=True)
|
|
|
|
| 211 |
# Set labels and close plot
|
| 212 |
plt.ylabel("Latitude", fontsize=15, labelpad=35)
|
| 213 |
plt.xlabel("Longitude", fontsize=15, labelpad=20)
|
| 214 |
+
#https://panel.holoviz.org/reference/panes/Matplotlib.html#using-the-matplotlib-pyplot-interface
|
| 215 |
+
plt.close(fig)
|
| 216 |
return fig
|
| 217 |
|
|
|
|
|
|
|
| 218 |
class SADCP_Viewer(param.Parameterized):
|
| 219 |
df = load_csv()
|
| 220 |
bathy = load_bathymetry()
|
| 221 |
+
tree=load_zarr()
|
| 222 |
file_names = df["file_name"].tolist()
|
| 223 |
years = sorted(df["year"].unique())
|
| 224 |
|
|
|
|
| 236 |
scale_factor_slider = pn.widgets.FloatSlider(start=0.1, end=1, step=0.1, value=0.5, name="Scale Factor")
|
| 237 |
bathy_checkbox = pn.widgets.Checkbox(value=False, name="Bathy Checkbox")
|
| 238 |
|
| 239 |
+
|
|
|
|
|
|
|
|
|
|
| 240 |
data_table = pn.widgets.Tabulator(width=400, height=200)
|
| 241 |
metadata_table = pn.widgets.Tabulator(width=600, height=800)
|
| 242 |
+
# Download button is not working : TODO
|
| 243 |
download_button = pn.widgets.Button(name="Download", button_type="primary")
|
|
|
|
| 244 |
|
| 245 |
def __init__(self, **params):
|
| 246 |
super(SADCP_Viewer, self).__init__(**params)
|
| 247 |
+
self.file_dropdown.objects = self.file_names
|
| 248 |
self.file_dropdown.value = (
|
| 249 |
self.file_dropdown.objects[0] if self.file_dropdown.objects else None
|
| 250 |
)
|
|
|
|
| 284 |
self.data_table.value, self.metadata_table.value = filter_df(sorted_df, selected_file)
|
| 285 |
|
| 286 |
# Load selected file's data
|
| 287 |
+
self.ds = load_file(self.tree,selected_file)
|
| 288 |
|
| 289 |
# Update slider ranges for longitude, latitude, and depth
|
| 290 |
for slider, coord in zip([self.longitude_slider, self.latitude_slider, self.depth_range_slider,
|
|
|
|
| 295 |
|
| 296 |
|
| 297 |
# Close dataset to free up resources
|
| 298 |
+
# self.ds.close()
|
|
|
|
| 299 |
|
| 300 |
@param.depends(
|
| 301 |
"year_slider.value",
|
|
|
|
| 310 |
"num_vectors_slider.value",
|
| 311 |
"scale_factor_slider.value",
|
| 312 |
"bathy_checkbox.value",
|
| 313 |
+
watch=False,)
|
|
|
|
| 314 |
def update_plots(self):
|
| 315 |
"""
|
| 316 |
This function updates the plots based on the selected data and parameters.
|
|
|
|
| 323 |
"""
|
| 324 |
# Filter the data
|
| 325 |
self.ds_filtered = filter_data(self.ds,self.longitude_slider.value,self.latitude_slider.value)
|
|
|
|
|
|
|
| 326 |
|
| 327 |
# Prepare the plots shown in left
|
| 328 |
# Update vector plots
|
|
|
|
| 336 |
)
|
| 337 |
|
| 338 |
|
| 339 |
+
# Generate plots which will be plotted on the left row.
|
| 340 |
self.plot_left = pn.Column(
|
| 341 |
# '# Column',
|
| 342 |
# vector_plot,
|
| 343 |
pn.pane.Matplotlib(vector_plot, dpi=144),
|
| 344 |
+
# add here the hvplot block of contour
|
| 345 |
sizing_mode="stretch_both")
|
| 346 |
|
| 347 |
# Generate additional plots which will be plotted on the right row.
|
| 348 |
+
other_plots = bathy_uship_vship_bottom_depth(self.ds_filtered)
|
|
|
|
|
|
|
|
|
|
| 349 |
self.plot_right = pn.Column(
|
| 350 |
*(pn.pane.HoloViews(plot, width=400, height=200) for plot in other_plots),
|
| 351 |
sizing_mode="stretch_width"
|
| 352 |
)
|
|
|
|
|
|
|
|
|
|
| 353 |
|
| 354 |
# Return a Panel row containing the updated map plot and additional plots
|
| 355 |
return pn.Row(self.plot_left, self.plot_right, sizing_mode="stretch_both")
|
| 356 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 357 |
|
| 358 |
explorer = SADCP_Viewer()
|
| 359 |
# Instantiate the SADCP_Viewer class and create a template
|
|
|
|
| 382 |
explorer.num_vectors_slider,
|
| 383 |
explorer.scale_factor_slider,
|
| 384 |
explorer.data_table,
|
| 385 |
+
"""You can consult detailed information on this data in the metadata tab shown on the right.
|
| 386 |
To download full dataset, please go to https://cdi.seadatanet.org/search
|
| 387 |
and search with LOCAL_CDI_ID indicated above.""",
|
| 388 |
]
|
| 389 |
+
|
| 390 |
+
pn.config.theme = 'dark'
|
| 391 |
template = pn.template.FastListTemplate(
|
| 392 |
title="SADCP data Viewer", sidebar=sidebar, main=[tabs]
|
| 393 |
)
|