0

我尝试使用以下代码在彼此之间绘制一些 hvplots。

feat_prep=rivers.hvplot(width=600,height=500,color='red')*\
    roads.hvplot(width=600,height=500,color='yellow')*\
    borders.hvplot(width=600,height=500,color='orange')*\
    cities_gdf.hvplot(width=600,height=500,color='magenta',hover=True)*\
cities_gdf.hvplot.labels(x='lon',y='lat',text='city',width=600,height=500,text_baseline='bottom',hover=False,fontsize=15,text_color='white')

a=ipw.IntSlider(description='level',min=0,max=29,continuous_update=False)
def f1(i):
    # Uses previously prepared features, but it doesn't seem to reduce rendering time
    display(r.paw.interactive.isel(lev=i).hvplot(cmap='viridis_r',xlabel='lon (Degrees East)',ylabel='lat (Degrees North)',width=600,height=500)*\
    feat_prep
         )

out = ipw.interactive_output(f1, {'i': a})
out.layout={'height':'550px'}
ipw.VBox([a, out])

河流、道路、边界和城市_gdf 生成如下:

r=xr.open_dataset('/f/work/julich/dg-rr/analytcis/plant_available_water/results/2021-09-30T00:00:00/2442-07-11_00:00:00.nc') # Open the netCDF file as dataset instead of dataarray as some weidgest (e.g., panel slider) needs a named dataarray which still produces some errors
r=r.rename({'__xarray_dataarray_variable__':'paw'})

# Read shape files for different features in the specified coordinates
river_path="/f/work/julich/dg-rr/analytcis/plant_available_water/sample_visualization/shp_data/rivers_OSM/rivers_OSM.shp"
roads_path="/f/work/julich/dg-rr/analytcis/plant_available_water/sample_visualization/shp_data/roads_OSM/roads_OSM.shp"
borders_path="/f/work/julich/dg-rr/analytcis/plant_available_water/sample_visualization/shp_data/borders_OSM/borders_OSM.shp"

rivers=gpd.read_file(river_path) # Read rivers features
roads=gpd.read_file(roads_path) # Read roads features
borders=gpd.read_file(borders_path) # Read borders features

# Create a bounding box for required coordinates
b=box(r['lon'].min().item(),r['lat'].min().item(),r['lon'].max().item(),r['lat'].max().item())
b_gdf=gpd.GeoDataFrame([1],geometry=[b],crs=rivers.crs)

# Clip feature to specified input data box
rivers=rivers.clip(b_gdf)
roads=roads.clip(b_gdf)
borders=borders.clip(b_gdf)

# Create a geodataframe of required cities
cities_df=pd.DataFrame({'city':['Jülich','Köln','Bonn','Düsseldorf','Koblenz','Bitburg','Maastricht','Aachen','Nürburg','Malmedy','Lüttich'],\
                    'lon':[6.371537,6.952778,7.109601,6.777019,7.594615,6.521794,5.691512,6.084142,6.978922,6.029222,5.575556],\
                    'lat':[50.916966,50.936389,50.727647,51.222089,50.351882,49.964940,50.844460,50.771486,50.344968,50.421748,50.645278]})
cities_gdf=gpd.GeoDataFrame(cities_df,geometry=gpd.points_from_xy(cities_df.lon, cities_df.lat))

决赛out需要很长时间才能抽签。此外,更改 Intslider 值需要很长时间才能重新绘制绘图。我尝试了不同的选项,如“rasterize”和“datashade”,但仍然需要很长时间。我想知道如何减少绘图时间?

谢谢

4

0 回答 0