Skip to content

Instantly share code, notes, and snippets.

@steph-ben
Created January 24, 2023 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steph-ben/2ca96ef5242f120265a3e3cbe69c18ed to your computer and use it in GitHub Desktop.
Save steph-ben/2ca96ef5242f120265a3e3cbe69c18ed to your computer and use it in GitHub Desktop.
Expose dataset as WMS
import fsspec
import xarray as xr
import xpublish
from xpublish.routers import base_router, zarr_router
from xpublish_wms import cf_wms_router
fp = "arpege.json"
fs = fsspec.filesystem("reference", fo=str(fp))
m = fs.get_mapper("")
ds = xr.open_dataset(m, engine="zarr", backend_kwargs=dict(consolidated=False),
chunks={'valid_time': 1}, drop_variables='orderedSequenceData')
rest = xpublish.Rest(
ds,
routers=[
(base_router, {"tags": ["info"]}),
(cf_wms_router, {"tags": ["wms"], "prefix": "/wms"}),
(zarr_router, {"tags": ["zarr"], "prefix": "/zarr"}),
],
)
if __name__ == "__main__":
"""
Use online to check https://wms-viewer-online.appspot.com/indexmap.html
"""
rest.serve(workers=1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment