# Import libraries for visualization and coordinate transformation
import hvplot.xarray
import xarray as xr
import s3fs
import zarr
from pyproj import Transformer
from holoviews.element.tiles import EsriImagery
# Open the Zarr store
fs = s3fs.S3FileSystem(profile="default", asynchronous=True)
zstore = zarr.storage.FsspecStore(fs, path=model_outputs[5:])
ds = xr.open_zarr(zstore)
# Create a transformer to convert from lat/lon to meters
transformer = Transformer.from_crs("EPSG:4326", "EPSG:3857", always_xy=True)
# Transform bounding box coordinates from lat/lon to meters
min_lon = -76.95
max_lon = -76.93
min_lat = 38.98
max_lat = 38.995
(min_x, max_x), (min_y, max_y) = transformer.transform(
[min_lon, max_lon],
[min_lat, max_lat]
)
# Select the height variable and slice the dataset to the bounding box
# y=slice(max_y, min_y) handles the standard "North-to-South" image orientation
ds_subset = ds.sel(band="sidewalk",
x=slice(min_x, max_x),
y=slice(max_y, min_y)
)
# Select the first time step and extract the variables array
arr_subset = ds_subset.isel(time=0)["variables"]
# Create a base map layer using Esri satellite imagery
base_map = EsriImagery()
# Create an overlay layer from the model outputs with hvplot
output_layer = arr_subset.hvplot(
x = "x",
y = "y",
geo = True, # Enable geographic plotting
dynamic = True, # Enable dynamic rendering for interactivity
rasterize = True, # Use datashader for efficient rendering of large datasets
cmap = "viridis", # Color map for visualization
aspect = "equal", # Maintain equal aspect ratio
title = "Tile2Net Model Outputs"
).opts(
width = 600,
height = 600,
alpha = .7 # Set transparency to see the base map underneath
)
# Combine the base map and output layer
final_plot = base_map * output_layer
final_plot