Spaces:
Sleeping
Sleeping
Cleaning
Browse files151 unmodified lines1521531541551561571581591601 unmodified line1621631641651661671681691701711721739 unmodified lines1831841851861871881891901911921937 unmodified lines2012022032042052062072082092102112122132142155 unmodified lines22122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626741 unmodified lines30931031131231331431531631731831932032132232332432532632744 unmodified lines372373374375376377378151 unmodified linesdef vectors_plot(ds, bathy, longitude_slider, latitude_slider,depth_range_slider, depth_2_range_slider, depth_3_range_slider,scale_factor_slider, sample,depth_2_checkbox=False, depth_3_checkbox=False, bathy_checkbox=False):"""Plot vectors filtered by depth on a map with specified features.1 unmodified lineParameters:ds (xarray.Dataset): Dataset containing current data.bathy (xarray.Dataset): Dataset containing bathymetry data.longitude_slider (tuple): Tuple containing the minimum and maximum longitude values.latitude_slider (tuple): Tuple containing the minimum and maximum latitude values.depth_range_slider (tuple): Tuple containing the minimum and maximum depth values for filtering.depth_2_range_slider (tuple): Tuple containing the minimum and maximum depth values for filtering depth 2.depth_3_range_slider (tuple): Tuple containing the minimum and maximum depth values for filtering depth 3.scale_factor_slider (float): Scaling factor for the magnitude of the current vectors.sample (int): Number of vectors used for downsampling.depth_2_checkbox (bool, optional): Whether to plot vectors for depth 2. Defaults to False.depth_3_checkbox (bool, optional): Whether to plot vectors for depth 3. Defaults to False.9 unmodified linesds = corsen_data(ds, sample)# Plot vectors filtered by depthquiver_depth_filtered(ax, ds, depth_range_slider, scale_factor_slider, color="blue")if depth_2_checkbox:quiver_depth_filtered(ax, ds, depth_2_range_slider, scale_factor_slider, color="green")if depth_3_checkbox:quiver_depth_filtered(ax, ds, depth_3_range_slider, scale_factor_slider, color="red")# Add map featuresax.add_feature(cfeature.COASTLINE)7 unmodified lineslevels=contour_levels, colors="black", transform=ccrs.PlateCarree())# Set extent and add gridlinesax.set_extent([longitude_slider[0], longitude_slider[1],latitude_slider[0], latitude_slider[1]])ax.gridlines(draw_labels=True)# Set labels and close plotplt.ylabel("Latitude", fontsize=15, labelpad=35)plt.xlabel("Longitude", fontsize=15, labelpad=20)plt.figure(figsize=(400, 400))plt.close()return fig5 unmodified linesfile_names = df["file_name"].tolist()years = sorted(df["year"].unique())year_slider = pn.widgets.IntRangeSlider(name="Year Range", start=df["year"].min(), end=df["year"].max())file_dropdown = pn.widgets.Select(name="File Selector")data_table = pn.widgets.Tabulator(df, name="metadata", height=200, width=300)# data_table2 = pn.widgets.Tabulator(df2, name="metadata", height=900, width=400)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")plot = pn.pane.HoloViews()plot_map = pn.pane.Matplotlib(width=800, height=600, sizing_mode="fixed")data_table = pn.widgets.Tabulator(width=400, height=200)metadata_table = pn.widgets.Tabulator(width=600, height=800)download_button = pn.widgets.Button(name="Download", button_type="primary")# plot = pn.Column()41 unmodified lines# Load selected file's dataself.ds = load_zarr(selected_file)# Update longitude slider rangelon_range = get_range(self.ds.LONGITUDE)self.longitude_slider.start, self.longitude_slider.end, self.longitude_slider.value = lon_range[0], lon_range[1], lon_range# Update latitude slider rangelat_range = get_range(self.ds.LATITUDE)self.latitude_slider.start, self.latitude_slider.end, self.latitude_slider.value = lat_range[0], lat_range[1], lat_range# Update depth slider ranges for all three depthsdepth_range = (int(self.ds.PROFZ.min()), int(self.ds.PROFZ.max()))self.depth_range_slider.start, self.depth_range_slider.end, self.depth_range_slider.value = depth_range[0], depth_range[1], depth_rangeself.depth_2_range_slider.start, self.depth_2_range_slider.end, self.depth_2_range_slider.value = depth_range[0], depth_range[1], depth_rangeself.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# Close dataset to free up resources# self.update_plots()44 unmodified linesself.plot_left = pn.Column(# '# Column',# vector_plot,vector_plot, sizing_mode="stretch_both")# Generate additional plots which will be plotted on the right row.other_plots = self.hvplot_plots()151 unmodified lines1521531541551561571581591601 unmodified line1621631641651661671681691701711721739 unmodified lines1831841851861871881891901911921937 unmodified lines2012022032042052062072082092102112122132145 unmodified lines22022122222322422522622722822923023123223323423523623723823924024124224324424524641 unmodified lines28828929029129229329429529629729829930044 unmodified lines345346347348349350351352353151 unmodified linesdef vectors_plot(ds, bathy, longitude_range, latitude_range ,depth_range, depth_2_range, depth_3_range,scale_factor, sample,depth_2_checkbox=False, depth_3_checkbox=False, bathy_checkbox=False):"""Plot vectors filtered by depth on a map with specified features.1 unmodified lineParameters:ds (xarray.Dataset): Dataset containing current data.bathy (xarray.Dataset): Dataset containing bathymetry data.longitude_range (tuple): Tuple containing the minimum and maximum longitude values.latitude_range (tuple): Tuple containing the minimum and maximum latitude values.depth_range (tuple): Tuple containing the minimum and maximum depth values for filtering.depth_2_range (tuple): Tuple containing the minimum and maximum depth values for filtering depth 2.depth_3_range (tuple): Tuple containing the minimum and maximum depth values for filtering depth 3.scale_factor (float): Scaling factor for the magnitude of the current vectors.sample (int): Number of vectors used for downsampling.depth_2_checkbox (bool, optional): Whether to plot vectors for depth 2. Defaults to False.depth_3_checkbox (bool, optional): Whether to plot vectors for depth 3. Defaults to False.9 unmodified linesds = corsen_data(ds, sample)# Plot vectors filtered by depthquiver_depth_filtered(ax, ds, depth_range, scale_factor, color="blue")if depth_2_checkbox:quiver_depth_filtered(ax, ds, depth_2_range, scale_factor, color="green")if depth_3_checkbox:quiver_depth_filtered(ax, ds, depth_3_range, scale_factor, color="red")# Add map featuresax.add_feature(cfeature.COASTLINE)7 unmodified lineslevels=contour_levels, colors="black", transform=ccrs.PlateCarree())# Set extent and add gridlinesax.set_extent([longitude_range[0], longitude_range[1],latitude_range[0], latitude_range[1]])ax.gridlines(draw_labels=True)# Set labels and close plotplt.ylabel("Latitude", fontsize=15, labelpad=35)plt.xlabel("Longitude", fontsize=15, labelpad=20)plt.close(fig) #https://panel.holoviz.org/reference/panes/Matplotlib.html#using-the-matplotlib-pyplot-interfacereturn fig5 unmodified linesfile_names = df["file_name"].tolist()years = sorted(df["year"].unique())# Widgetsyear_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")# plot = pn.pane.HoloViews()# plot_map = pn.pane.Matplotlib(width=800, height=600, sizing_mode="fixed")data_table = pn.widgets.Tabulator(width=400, height=200)metadata_table = pn.widgets.Tabulator(width=600, height=800)download_button = pn.widgets.Button(name="Download", button_type="primary")# plot = pn.Column()41 unmodified lines# Load selected file's dataself.ds = load_zarr(selected_file)# Update slider ranges for longitude, latitude, and depthfor 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.update_plots()44 unmodified linesself.plot_left = pn.Column(# '# Column',# vector_plot,pn.pane.Matplotlib(vector_plot, dpi=144),# vector_plot,sizing_mode="stretch_both")# Generate additional plots which will be plotted on the right row.other_plots = self.hvplot_plots()
app.py+38-63