Skip to content

Commit

Permalink
add tool to query OSCAR to support station management (#469) (#504)
Browse files Browse the repository at this point in the history
* add tool to query OSCAR to support station management (#469)

* add click hook

* update docstring

* update docs

* update docs
  • Loading branch information
tomkralidis authored Sep 5, 2023
1 parent ef72ddf commit becde08
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
22 changes: 22 additions & 0 deletions docs/source/reference/running/station-metadata.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,30 @@ processing.

.. seealso:: :ref:`api-publishing`

OSCAR/Surface
-------------

wis2box can derive station information from `OSCAR/Surface`_. To verify station metadata from OSCAR/Surface:

.. code-block:: bash
wis2box metadata station get WSI
where ``WSI`` is the WIGOS Station Identifier. This command will return the information required in the
station list for wis2box data processing and publication. To add the station information to the station list,
copy and paste the output of the above command, or rerun the above command, writing to the station list
automatically:


.. code-block:: bash
wis2box metadata station get WSI >> ~/wis2box-data/metadata/station/station_list.csv
Summary
-------

At this point, you have cached the required station metadata for your given dataset(s).

.. _`OSCAR/Surface`: https://oscar.wmo.int/surface
14 changes: 13 additions & 1 deletion docs/source/user/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ wis2box requires information about the stations for which you will be sharing da

An example of the configuration file for the stations is provided in ``station_list.csv``.

You can copy this file to ``metadata/station/station_list.csv`` in your $WIS2BOX_HOST_DATADIR :
You can copy this file to ``metadata/station/station_list.csv`` in your $WIS2BOX_HOST_DATADIR:

.. code-block:: bash
Expand All @@ -176,6 +176,18 @@ And edit ``~/wis2box-data/metadata/station/station_list.csv`` to include the dat
The ``station_list.csv`` requires column names ``station_name`` and the ``wigos_station_identifier`` (WSI) with which the station is registered in `OSCAR`_. Optionally, you can provide a ``traditional_station_identifier (TSI)`` column.
The TSI can be left empty if your data contains a WSI. If your data contains a TSI but no WSI, the ``station_list.csv`` will be used to derive the corresponding WSI for that station.

To verify station metadata from OSCAR/Surface, run the following command:

.. code-block:: bash
wis2box metadata station get <WSI>
Then to add to the station list:

.. code-block:: bash
wis2box metadata station get <WSI> >> ~/wis2box-data/metadata/station/station_list.csv
Discovery metadata
------------------

Expand Down
1 change: 1 addition & 0 deletions wis2box-management/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ RUN apt-get update -y && apt-get install -y ${DEBIAN_PACKAGES} \
https://github.com/wmo-im/bufr2geojson/archive/refs/tags/v0.5.0.zip \
https://github.com/wmo-im/pymetdecoder/archive/refs/tags/v0.1.7.zip \
https://github.com/wmo-im/synop2bufr/archive/refs/tags/v0.4.1.zip \
https://github.com/wmo-cop/pyoscar/archive/refs/tags/0.5.0.zip \
https://github.com/geopython/pygeometa/archive/refs/tags/0.14.0.zip \
https://github.com/wmo-im/pywcmp/archive/refs/tags/0.4.0.zip \
# install shapely
Expand Down
39 changes: 39 additions & 0 deletions wis2box-management/wis2box/metadata/station.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,15 @@
###############################################################################

import click
from collections import OrderedDict
import csv
import json
import logging
from typing import Iterator, Union

from owslib.ogcapi.features import Features
from pygeometa.schemas.wmo_wigos import WMOWIGOSOutputSchema
from pyoscar import OSCARClient

from wis2box import cli_helpers
from wis2box.api import (
Expand Down Expand Up @@ -310,6 +312,42 @@ def get_geometry(wsi: str = '') -> Union[dict, None]:
return None


@click.command()
@click.pass_context
@click.option('--wigos-station-identifier', '-wsi',
help='WIGOS station identifier')
@cli_helpers.OPTION_VERBOSITY
def get(ctx, wigos_station_identifier, verbosity):
"""Queries OSCAR/Surface for station information"""

client = OSCARClient(env='prod')

station = client.get_station_report(wigos_station_identifier)

results = OrderedDict({
'station_name': station['name'],
'wigos_station_identifier': wigos_station_identifier,
'traditional_station_identifier': None,
'facility_type': station['typeName'],
'latitude': station['locations'][0]['latitude'],
'longitude': station['locations'][0]['longitude'],
'elevation': station['locations'][0].get('elevation'),
'territory_name': station['territories'][0]['territoryName'],
'wmo_region': WMO_RAS[station['wmoRaId']]
})

if '0-2000' in station['wigosIds'][0]['wid']:
results['traditional_station_identifier'] = station['wigosIds'][0]['wid'].split('-')[-1] # noqa

for v in ['station_name', 'territory_name']:
if ',' in results[v]:
results[v] = f'"{results[v]}"'

line = ','.join([(str(results[k]) if results[k] is not None else '') for k, v in results.items()]) # noqa

click.echo(line)


@click.command()
@click.pass_context
@cli_helpers.OPTION_VERBOSITY
Expand All @@ -320,4 +358,5 @@ def publish_collection(ctx, verbosity):
click.echo('Done')


station.add_command(get)
station.add_command(publish_collection)

0 comments on commit becde08

Please sign in to comment.