Spaces:
Build error
Build error
File size: 9,448 Bytes
d1e1878 8eaab2a d1e1878 af23075 613f71e 8eaab2a af23075 8eaab2a af23075 8eaab2a af23075 fec3245 af23075 d1e1878 d48b6bc af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 5930638 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 f37af5b d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 d1e1878 af23075 8eaab2a d1e1878 af23075 d1e1878 0339174 d1e1878 1504343 5930638 55e18c7 1504343 d48b6bc d1e1878 af23075 d1e1878 9ae138d af23075 9ae138d af23075 d1e1878 af23075 5930638 af23075 5930638 eba100b |
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 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 |
import numpy as np
import pandas as pd
import panel as pn
import xarray as xr
import param
import hvplot.xarray
import matplotlib.pyplot as plt
import cartopy.crs as ccrs
import cartopy.feature as cfeature
from datatree import open_datatree
from xsadcp import get_range, load_csv, load_bathymetry, load_zarr, load_file, filter_df, filter_data, quiver_depth_filtered, bathy_uship_vship_bottom_depth, corsen_data, vectors_plot, fix_time, transform_netCDF, get_info, get_file_names, open_ds
class SADCP_Viewer(param.Parameterized):
"""
A parameterized class for viewing SADCP data.
This class provides widgets for selecting data parameters, updating data based on selections,
and generating plots to visualize the SADCP data.
Available functions:
- update_name_options: Update dropdown options and slider ranges based on selected years and file.
- update_plots: Update plots based on selected data and parameters.
"""
# Load data and initialize widgets
df = load_csv()
bathy = load_bathymetry()
tree=load_zarr()
file_names = df["file_name"].tolist()
years = sorted(df["year"].unique())
# Widgets for selecting data parameters
year_slider = pn.widgets.IntRangeSlider(name="Year Range", start=df["year"].min(), end=df["year"].max())
file_dropdown = pn.widgets.Select(name="File Selector")
longitude_slider = pn.widgets.RangeSlider(name="Longitude Range", start=-180, end=180, step=1)
latitude_slider = pn.widgets.RangeSlider(name="Latitude Range", start=-90, end=90, step=1)
depth_range_slider = pn.widgets.IntRangeSlider(start=100, end=300, value=(100, 300), step=1, name="Depth Range")
depth_2_checkbox = pn.widgets.Checkbox(value=False, name="Depth 2 Checkbox")
depth_3_checkbox = pn.widgets.Checkbox(value=False, name="Depth 3 Checkbox")
depth_2_range_slider = pn.widgets.IntRangeSlider(start=100, end=300, value=(100, 300), step=1, name="Depth 2 Range")
depth_3_range_slider = pn.widgets.IntRangeSlider(start=100, end=300, value=(100, 300), step=1, name="Depth 3 Range")
num_vectors_slider = pn.widgets.IntSlider(start=40, end=800, step=1, value=100, name="Number of Vectors")
scale_factor_slider = pn.widgets.FloatSlider(start=0.1, end=1, step=0.1, value=0.5, name="Scale Factor")
bathy_checkbox = pn.widgets.Checkbox(value=False, name="Bathy Checkbox")
data_table = pn.widgets.Tabulator(width=400, height=200)
metadata_table = pn.widgets.Tabulator(width=600, height=800)
# Download button is not working : TODO
download_button = pn.widgets.Button(name="Download", button_type="primary")
def __init__(self, **params):
"""
Initialize the SADCP_Viewer class.
Parameters:
**params: Additional parameters to be passed to the superclass.
"""
super(SADCP_Viewer, self).__init__(**params)
self.file_dropdown.objects = self.file_names
self.file_dropdown.value = (
self.file_dropdown.objects[0] if self.file_dropdown.objects else None
)
self.update_name_options()
@param.depends("year_slider.value", "file_dropdown.value", watch=True)
def update_name_options(self):
"""
Update dropdown options and slider ranges based on selected years and file.
This function updates the dropdown options and slider ranges based on the selected years
and file. It also loads the selected file's data and adjusts slider ranges accordingly.
"""
# Extract selected start and end years
start_year, end_year = self.year_slider.value
# Filter DataFrame based on selected years and sort by year
mask = (self.df["year"] >= start_year) & (self.df["year"] <= end_year)
sorted_df = self.df[mask].sort_values(by="year")
# Get unique file names
files = sorted_df["file_name"].unique().tolist()
# Update file dropdown options
self.file_dropdown.options = files
if files:
selected_file = self.file_dropdown.value
# Set default selected file if not selected or not in options
if not selected_file or selected_file not in files:
selected_file = files[0]
self.file_dropdown.value = selected_file
# Update data table and metadata table based on selected file
self.data_table.value, self.metadata_table.value = filter_df(sorted_df, selected_file)
# Load selected file's data
self.ds = load_file(self.tree,selected_file)
# Update slider ranges for longitude, latitude, and depth
for slider, coord in zip([self.longitude_slider, self.latitude_slider, self.depth_range_slider,
self.depth_2_range_slider, self.depth_3_range_slider],
[self.ds.LONGITUDE, self.ds.LATITUDE, self.ds.PROFZ,self.ds.PROFZ,self.ds.PROFZ]):
coord_range = get_range(coord)
slider.start, slider.end, slider.value = coord_range[0], coord_range[1], coord_range
# Close dataset to free up resources
# self.ds.close()
@param.depends(
"year_slider.value",
"file_dropdown.value",
"depth_range_slider.value",
"depth_2_checkbox.value",
"depth_3_checkbox.value",
"depth_2_range_slider.value",
"depth_3_range_slider.value",
"longitude_slider.value",
"latitude_slider.value",
"num_vectors_slider.value",
"scale_factor_slider.value",
"bathy_checkbox.value",
watch=False,)
def update_plots(self):
"""
This function updates the plots based on the selected data and parameters.
The function filters the data, generates additional plots, and updates the main vector plot based on the selected parameters.
Returns:
pn.Row: A Panel row containing the updated map plot and additional plots.
"""
# Filter the data
self.ds_filtered = filter_data(self.ds,self.longitude_slider.value,self.latitude_slider.value)
# Prepare the plots shown in left
# Update vector plots
vector_plot = vectors_plot(self.ds_filtered, self.bathy,
self.longitude_slider.value, self.latitude_slider.value,
self.depth_range_slider.value, self.depth_2_range_slider.value, self.depth_3_range_slider.value,
self.scale_factor_slider.value,self.num_vectors_slider.value,
depth_2_checkbox= self.depth_2_checkbox.value,
depth_3_checkbox= self.depth_3_checkbox.value,
bathy_checkbox=self.bathy_checkbox.value,
)
# Generate plots which will be plotted on the left row.
self.plot_left = pn.Column(
# Here adjust the style option later TODO
# https://panel.holoviz.org/how_to/styling/matplotlib.html
pn.pane.Matplotlib(vector_plot, dpi=144),
# Add here the hvplot block of contour TODO
sizing_mode="stretch_both")
# Generate additional plots which will be plotted on the right row.
other_plots = bathy_uship_vship_bottom_depth(self.ds_filtered)
self.plot_right = pn.Column(
*(pn.pane.HoloViews(plot, width=400, height=200) for plot in other_plots),
sizing_mode="stretch_width"
)
# Return a Panel row containing the updated map plot and additional plots
return pn.Row(self.plot_left, self.plot_right, sizing_mode="stretch_both")
pn.extension("tabulator")
pn.config.theme = 'dark'
explorer = SADCP_Viewer()
# Instantiate the SADCP_Viewer class and create a template
tabs = pn.Tabs(
("Plots", pn.Column(explorer.update_plots)),
(
"Metadata",
pn.Column(
explorer.metadata_table, explorer.download_button, height=500, margin=10
),
),
)
sidebar = [
pn.panel('./EuroGO-SHIP_logo_wide_tagline_1.2.png',width=300 ),
"""This application, developed in the frame of Euro Go Shop, helps to interactively visualise and download ship ADCP data.""",
explorer.year_slider,
explorer.file_dropdown,
explorer.longitude_slider,
explorer.latitude_slider,
explorer.bathy_checkbox,
explorer.depth_range_slider,
explorer.depth_2_checkbox,
explorer.depth_3_checkbox,
explorer.depth_2_range_slider,
explorer.depth_3_range_slider,
explorer.num_vectors_slider,
explorer.scale_factor_slider,
explorer.data_table,
"""You can consult detailed information on this data in the metadata tab shown on the right.
To download full dataset, please go to https://cdi.seadatanet.org/search
and search with LOCAL_CDI_ID indicated above.""",
#pn.panel('https://upload.wikimedia.org/wikipedia/commons/4/47/PNG_transparency_demonstration_1.png', ),
#width=10)
]
template = pn.template.FastListTemplate(
title="SADCP data Viewer", logo='https://avatars.githubusercontent.com/u/123177533?s=200&v=4',
sidebar=sidebar, main=[tabs]
)
template.servable()
|