Spaces:
Runtime error
Runtime error
Cleaning
Browse files
app.py
CHANGED
|
@@ -152,9 +152,9 @@ def corsen_data(ds, sample):
|
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
-
def vectors_plot(ds, bathy,
|
| 156 |
-
|
| 157 |
-
|
| 158 |
depth_2_checkbox=False, depth_3_checkbox=False, bathy_checkbox=False):
|
| 159 |
"""
|
| 160 |
Plot vectors filtered by depth on a map with specified features.
|
|
@@ -162,12 +162,12 @@ def vectors_plot(ds, bathy, longitude_slider, latitude_slider,
|
|
| 162 |
Parameters:
|
| 163 |
ds (xarray.Dataset): Dataset containing current data.
|
| 164 |
bathy (xarray.Dataset): Dataset containing bathymetry data.
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
sample (int): Number of vectors used for downsampling.
|
| 172 |
depth_2_checkbox (bool, optional): Whether to plot vectors for depth 2. Defaults to False.
|
| 173 |
depth_3_checkbox (bool, optional): Whether to plot vectors for depth 3. Defaults to False.
|
|
@@ -183,11 +183,11 @@ def vectors_plot(ds, bathy, longitude_slider, latitude_slider,
|
|
| 183 |
ds = corsen_data(ds, sample)
|
| 184 |
|
| 185 |
# Plot vectors filtered by depth
|
| 186 |
-
quiver_depth_filtered(ax, ds,
|
| 187 |
if depth_2_checkbox:
|
| 188 |
-
quiver_depth_filtered(ax, ds,
|
| 189 |
if depth_3_checkbox:
|
| 190 |
-
quiver_depth_filtered(ax, ds,
|
| 191 |
|
| 192 |
# Add map features
|
| 193 |
ax.add_feature(cfeature.COASTLINE)
|
|
@@ -201,15 +201,14 @@ def vectors_plot(ds, bathy, longitude_slider, latitude_slider,
|
|
| 201 |
levels=contour_levels, colors="black", transform=ccrs.PlateCarree())
|
| 202 |
|
| 203 |
# Set extent and add gridlines
|
| 204 |
-
ax.set_extent([
|
| 205 |
-
|
| 206 |
ax.gridlines(draw_labels=True)
|
| 207 |
|
| 208 |
# Set labels and close plot
|
| 209 |
plt.ylabel("Latitude", fontsize=15, labelpad=35)
|
| 210 |
plt.xlabel("Longitude", fontsize=15, labelpad=20)
|
| 211 |
-
plt.
|
| 212 |
-
plt.close()
|
| 213 |
|
| 214 |
return fig
|
| 215 |
|
|
@@ -221,47 +220,27 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 221 |
file_names = df["file_name"].tolist()
|
| 222 |
years = sorted(df["year"].unique())
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
)
|
| 227 |
file_dropdown = pn.widgets.Select(name="File Selector")
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
longitude_slider = pn.widgets.RangeSlider(
|
| 232 |
-
name="Longitude Range", start=-180, end=180, step=1
|
| 233 |
-
)
|
| 234 |
-
latitude_slider = pn.widgets.RangeSlider(
|
| 235 |
-
name="Latitude Range", start=-90, end=90, step=1
|
| 236 |
-
)
|
| 237 |
-
|
| 238 |
-
depth_range_slider = pn.widgets.IntRangeSlider(
|
| 239 |
-
start=100, end=300, value=(100, 300), step=1, name="Depth Range"
|
| 240 |
-
)
|
| 241 |
depth_2_checkbox = pn.widgets.Checkbox(value=False, name="Depth 2 Checkbox")
|
| 242 |
depth_3_checkbox = pn.widgets.Checkbox(value=False, name="Depth 3 Checkbox")
|
| 243 |
-
|
| 244 |
-
|
| 245 |
-
|
| 246 |
-
)
|
| 247 |
-
depth_3_range_slider = pn.widgets.IntRangeSlider(
|
| 248 |
-
start=100, end=300, value=(100, 300), step=1, name="Depth 3 Range"
|
| 249 |
-
)
|
| 250 |
-
|
| 251 |
-
num_vectors_slider = pn.widgets.IntSlider(
|
| 252 |
-
start=40, end=800, step=1, value=100, name="Number of Vectors"
|
| 253 |
-
)
|
| 254 |
-
scale_factor_slider = pn.widgets.FloatSlider(
|
| 255 |
-
start=0.1, end=1, step=0.1, value=0.5, name="Scale Factor"
|
| 256 |
-
)
|
| 257 |
bathy_checkbox = pn.widgets.Checkbox(value=False, name="Bathy Checkbox")
|
| 258 |
|
| 259 |
-
plot = pn.pane.HoloViews()
|
| 260 |
-
plot_map = pn.pane.Matplotlib(width=800, height=600, sizing_mode="fixed")
|
| 261 |
|
| 262 |
-
|
|
|
|
| 263 |
|
|
|
|
| 264 |
metadata_table = pn.widgets.Tabulator(width=600, height=800)
|
|
|
|
| 265 |
download_button = pn.widgets.Button(name="Download", button_type="primary")
|
| 266 |
# plot = pn.Column()
|
| 267 |
|
|
@@ -309,19 +288,13 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 309 |
# Load selected file's data
|
| 310 |
self.ds = load_zarr(selected_file)
|
| 311 |
|
| 312 |
-
# Update longitude
|
| 313 |
-
|
| 314 |
-
|
| 315 |
-
|
| 316 |
-
|
| 317 |
-
|
| 318 |
-
|
| 319 |
-
|
| 320 |
-
# Update depth slider ranges for all three depths
|
| 321 |
-
depth_range = (int(self.ds.PROFZ.min()), int(self.ds.PROFZ.max()))
|
| 322 |
-
self.depth_range_slider.start, self.depth_range_slider.end, self.depth_range_slider.value = depth_range[0], depth_range[1], depth_range
|
| 323 |
-
self.depth_2_range_slider.start, self.depth_2_range_slider.end, self.depth_2_range_slider.value = depth_range[0], depth_range[1], depth_range
|
| 324 |
-
self.depth_3_range_slider.start, self.depth_3_range_slider.end, self.depth_3_range_slider.value = depth_range[0], depth_range[1], depth_range
|
| 325 |
|
| 326 |
# Close dataset to free up resources
|
| 327 |
# self.update_plots()
|
|
@@ -372,7 +345,9 @@ class SADCP_Viewer(param.Parameterized):
|
|
| 372 |
self.plot_left = pn.Column(
|
| 373 |
# '# Column',
|
| 374 |
# vector_plot,
|
| 375 |
-
|
|
|
|
|
|
|
| 376 |
|
| 377 |
# Generate additional plots which will be plotted on the right row.
|
| 378 |
other_plots = self.hvplot_plots()
|
|
|
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
+
def vectors_plot(ds, bathy, longitude_range, latitude_range ,
|
| 156 |
+
depth_range, depth_2_range, depth_3_range,
|
| 157 |
+
scale_factor, sample,
|
| 158 |
depth_2_checkbox=False, depth_3_checkbox=False, bathy_checkbox=False):
|
| 159 |
"""
|
| 160 |
Plot vectors filtered by depth on a map with specified features.
|
|
|
|
| 162 |
Parameters:
|
| 163 |
ds (xarray.Dataset): Dataset containing current data.
|
| 164 |
bathy (xarray.Dataset): Dataset containing bathymetry data.
|
| 165 |
+
longitude_range (tuple): Tuple containing the minimum and maximum longitude values.
|
| 166 |
+
latitude_range (tuple): Tuple containing the minimum and maximum latitude values.
|
| 167 |
+
depth_range (tuple): Tuple containing the minimum and maximum depth values for filtering.
|
| 168 |
+
depth_2_range (tuple): Tuple containing the minimum and maximum depth values for filtering depth 2.
|
| 169 |
+
depth_3_range (tuple): Tuple containing the minimum and maximum depth values for filtering depth 3.
|
| 170 |
+
scale_factor (float): Scaling factor for the magnitude of the current vectors.
|
| 171 |
sample (int): Number of vectors used for downsampling.
|
| 172 |
depth_2_checkbox (bool, optional): Whether to plot vectors for depth 2. Defaults to False.
|
| 173 |
depth_3_checkbox (bool, optional): Whether to plot vectors for depth 3. Defaults to False.
|
|
|
|
| 183 |
ds = corsen_data(ds, sample)
|
| 184 |
|
| 185 |
# Plot vectors filtered by depth
|
| 186 |
+
quiver_depth_filtered(ax, ds, depth_range, scale_factor, color="blue")
|
| 187 |
if depth_2_checkbox:
|
| 188 |
+
quiver_depth_filtered(ax, ds, depth_2_range, scale_factor, color="green")
|
| 189 |
if depth_3_checkbox:
|
| 190 |
+
quiver_depth_filtered(ax, ds, depth_3_range, scale_factor, color="red")
|
| 191 |
|
| 192 |
# Add map features
|
| 193 |
ax.add_feature(cfeature.COASTLINE)
|
|
|
|
| 201 |
levels=contour_levels, colors="black", transform=ccrs.PlateCarree())
|
| 202 |
|
| 203 |
# Set extent and add gridlines
|
| 204 |
+
ax.set_extent([longitude_range[0], longitude_range[1],
|
| 205 |
+
latitude_range[0], latitude_range[1]])
|
| 206 |
ax.gridlines(draw_labels=True)
|
| 207 |
|
| 208 |
# Set labels and close plot
|
| 209 |
plt.ylabel("Latitude", fontsize=15, labelpad=35)
|
| 210 |
plt.xlabel("Longitude", fontsize=15, labelpad=20)
|
| 211 |
+
plt.close(fig) #https://panel.holoviz.org/reference/panes/Matplotlib.html#using-the-matplotlib-pyplot-interface
|
|
|
|
| 212 |
|
| 213 |
return fig
|
| 214 |
|
|
|
|
| 220 |
file_names = df["file_name"].tolist()
|
| 221 |
years = sorted(df["year"].unique())
|
| 222 |
|
| 223 |
+
# Widgets
|
| 224 |
+
year_slider = pn.widgets.IntRangeSlider(name="Year Range", start=df["year"].min(), end=df["year"].max())
|
|
|
|
| 225 |
file_dropdown = pn.widgets.Select(name="File Selector")
|
| 226 |
+
longitude_slider = pn.widgets.RangeSlider(name="Longitude Range", start=-180, end=180, step=1)
|
| 227 |
+
latitude_slider = pn.widgets.RangeSlider(name="Latitude Range", start=-90, end=90, step=1)
|
| 228 |
+
depth_range_slider = pn.widgets.IntRangeSlider(start=100, end=300, value=(100, 300), step=1, name="Depth Range")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 229 |
depth_2_checkbox = pn.widgets.Checkbox(value=False, name="Depth 2 Checkbox")
|
| 230 |
depth_3_checkbox = pn.widgets.Checkbox(value=False, name="Depth 3 Checkbox")
|
| 231 |
+
depth_2_range_slider = pn.widgets.IntRangeSlider(start=100, end=300, value=(100, 300), step=1, name="Depth 2 Range")
|
| 232 |
+
depth_3_range_slider = pn.widgets.IntRangeSlider(start=100, end=300, value=(100, 300), step=1, name="Depth 3 Range")
|
| 233 |
+
num_vectors_slider = pn.widgets.IntSlider(start=40, end=800, step=1, value=100, name="Number of Vectors")
|
| 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 |
|
|
|
|
| 288 |
# Load selected file's data
|
| 289 |
self.ds = load_zarr(selected_file)
|
| 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,
|
| 293 |
+
self.depth_2_range_slider, self.depth_3_range_slider],
|
| 294 |
+
[self.ds.LONGITUDE, self.ds.LATITUDE, self.ds.PROFZ,self.ds.PROFZ,self.ds.PROFZ]):
|
| 295 |
+
coord_range = get_range(coord)
|
| 296 |
+
slider.start, slider.end, slider.value = coord_range[0], coord_range[1], coord_range
|
| 297 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 298 |
|
| 299 |
# Close dataset to free up resources
|
| 300 |
# self.update_plots()
|
|
|
|
| 345 |
self.plot_left = pn.Column(
|
| 346 |
# '# Column',
|
| 347 |
# vector_plot,
|
| 348 |
+
pn.pane.Matplotlib(vector_plot, dpi=144),
|
| 349 |
+
# vector_plot,
|
| 350 |
+
sizing_mode="stretch_both")
|
| 351 |
|
| 352 |
# Generate additional plots which will be plotted on the right row.
|
| 353 |
other_plots = self.hvplot_plots()
|