PyGeoAPI#

Here we are going it explore setting up and using PyGeoAPI and the OGC EDR API to request timeseries data.

We’re going to use a Wave Watch 3 forecast for the East Coast, and request data for Buoy E01 (Lat: 43.72 Lon: -69.35).

We’ll start with a quick look a the dataset (and grabbing some info from it that we need to setup the PyGeoAPI config).

import xarray as xr
import requests

This dataset is avaliable from https://gmri-research-data.nyc3.digitaloceanspaces.com/IOOS-code-sprint/ww3_72_east_coast_2022041112.nc

ds = xr.open_dataset("../datasets/ww3_72_east_coast_2022041112.nc")
ds
<xarray.Dataset>
Dimensions:                  (longitude: 381, latitude: 351, time: 73,
                              forecast_reference_time: 1)
Coordinates:
  * longitude                (longitude) float32 -93.0 -92.9 ... -55.1 -55.0
  * latitude                 (latitude) float32 20.0 20.1 20.2 ... 54.9 55.0
  * time                     (time) datetime64[ns] 2022-04-11T12:00:00 ... 20...
  * forecast_reference_time  (forecast_reference_time) datetime64[ns] 2022-04...
Data variables: (12/21)
    hs                       (forecast_reference_time, time, latitude, longitude) float32 ...
    t02                      (forecast_reference_time, time, latitude, longitude) float32 ...
    t0m1                     (forecast_reference_time, time, latitude, longitude) float32 ...
    t01                      (forecast_reference_time, time, latitude, longitude) float32 ...
    fp                       (forecast_reference_time, time, latitude, longitude) float32 ...
    dir                      (forecast_reference_time, time, latitude, longitude) float32 ...
    ...                       ...
    pdir2                    (forecast_reference_time, time, latitude, longitude) float32 ...
    pws0                     (forecast_reference_time, time, latitude, longitude) float32 ...
    pws1                     (forecast_reference_time, time, latitude, longitude) float32 ...
    pws2                     (forecast_reference_time, time, latitude, longitude) float32 ...
    tws                      (forecast_reference_time, time, latitude, longitude) float32 ...
    pnr                      (forecast_reference_time, time, latitude, longitude) float32 ...
Attributes: (12/16)
    WAVEWATCH_III_version_number:     5.16
    WAVEWATCH_III_switches:           F90 SHRD NOGRB NOPA LRB4 NC4 TRKNC PR3 ...
    SIN4 namelist parameter BETAMAX:  1.65
    product_name:                     ww3.20220411.nc
    area:                             NW Atlantic  6 arc min grd2
    latitude_resolution:              0.1000000
    ...                               ...
    easternmost_longitude:            -55.00000
    minimum_altitude:                 -12000 m
    maximum_altitude:                 9000 m
    altitude_resolution:              n/a
    start_date:                       2022-04-11 12:00:00
    stop_date:                        2022-04-11 23:00:00

PyGeoAPI needs the bounds of the dataset. I’ve already got most of the config needed for the dataset, it just needs updated temporal extents.

ds['time'].min(), ds['time'].max()
(<xarray.DataArray 'time' ()>
 array('2022-04-11T12:00:00.000000000', dtype='datetime64[ns]'),
 <xarray.DataArray 'time' ()>
 array('2022-04-14T12:00:00.000000000', dtype='datetime64[ns]'))

PyGeoAPI configuration#

PyGeoAPI uses a YAML config file. Individual datasets are setup as resources, and different providers within a resource are responsible for API types.

There is a lot of general configuration it does not like you to skip.

!cat ./config.yaml
server:
  bind:
    host: 0.0.0.0
    port: 5002
  cors: true
  language: en-US
  manager:
    connection: /tmp/pygeoapi-process-manager.db
    name: TinyDB
    output_dir: /tmp/
  map:
    attribution:
      <a href="https://wikimediafoundation.org/wiki/Maps_Terms_of_Use">Wikimedia
      maps</a> | Map data &copy; <a href="https://openstreetmap.org/copyright">OpenStreetMap
      contributors</a>
    url: https://maps.wikimedia.org/osm-intl/{z}/{x}/{y}.png
  url: http://localhost:5002
logging:
  level: DEBUG
metadata:
  contact:
    address: 195 New Hampshire Ave, Suite 240
    city: Portsmouth
    country: United States
    email: tom@neracoos.org
    name: Shyka, Tom
    phone: +01-603-319-1785
    position: Product & Engagement Manager
    postalcode: 03801
    role: pointOfContact
    stateorprovince: New Hampshire
    url: http://neracoos.org
  identification:
    description: OGC APIs for NERACOOS services
    keywords:
      - geospatial
      - data
      - api
      - oceanographic
    keywords_type: theme
    terms_of_service: https://creativecommons.org/licenses/by/4.0/
    title: data.neracoos.org
    url: http://neracoos.org
  license:
    name: CC-BY 4.0 license
    url: https://creativecommons.org/licenses/by/4.0/
  provider:
    name: NERACOOS
    url: https://neracoos.org
resources:
  bio_ww3_east_coast_latest:
    description:
      Bedford Institute of Oceanography Wave Watch 3 72 hour forecast for
      the East Coast
    extents:
      spatial:
        bbox:
          - -93.0
          - 20.0
          - -55.0
          - 55.0
        crs: http://www.opengis.net/def/crs/OGC/1.3/CRS84
      temporal:
        begin: 2022-04-11 12:00:00
        end: 2022-04-14 12:00:00
    keywords:
      - forecast
      - wave
    links: []
    providers:
      - data: ../datasets/ww3_72_east_coast_2022041112.nc
        format:
          mimetype: application/x-netcdf
          name: NetCDF
        name: xarray-edr
        time_field: time
        type: edr
        x_field: longitude
        y_field: latitude
    title:
      Bedford Institute of Oceanography Wave Watch 3 72 hour forecast for the East
      Coast
    type: collection

Running PyGeoAPI#

From this directory run PYGEOAPI_CONFIG=./config.yaml pygeoapi serve.

Then you should be able to access PyGeoAPI at http://localhost:5002/

image.png

From there you can explore into collections, then check out the collection that we defined.

image.png