From 123576cdd41ad4c1fca4d966098c15a3bc4d2be2 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Thu, 31 Aug 2023 15:44:44 -0400 Subject: [PATCH 1/5] add tool to query OSCAR to support station management (#469) --- wis2box-management/Dockerfile | 1 + .../wis2box/metadata/station.py | 38 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/wis2box-management/Dockerfile b/wis2box-management/Dockerfile index 63f8903c4..37c7ff8a1 100644 --- a/wis2box-management/Dockerfile +++ b/wis2box-management/Dockerfile @@ -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 diff --git a/wis2box-management/wis2box/metadata/station.py b/wis2box-management/wis2box/metadata/station.py index 9295e7475..bbfe296d4 100644 --- a/wis2box-management/wis2box/metadata/station.py +++ b/wis2box-management/wis2box/metadata/station.py @@ -20,6 +20,7 @@ ############################################################################### import click +from collections import OrderedDict import csv import json import logging @@ -27,6 +28,7 @@ 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 ( @@ -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): + """Publishes collection of stations to API config and backend""" + + 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 From 56e8bf60ac3987bbfea8fb66b6944821e9147a1c Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Thu, 31 Aug 2023 15:45:43 -0400 Subject: [PATCH 2/5] add click hook --- wis2box-management/wis2box/metadata/station.py | 1 + 1 file changed, 1 insertion(+) diff --git a/wis2box-management/wis2box/metadata/station.py b/wis2box-management/wis2box/metadata/station.py index bbfe296d4..e979c88b8 100644 --- a/wis2box-management/wis2box/metadata/station.py +++ b/wis2box-management/wis2box/metadata/station.py @@ -358,4 +358,5 @@ def publish_collection(ctx, verbosity): click.echo('Done') +station.add_command(get) station.add_command(publish_collection) From 475d148f9afa1ca3c3e76e6d17eb7bba258504b3 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Fri, 1 Sep 2023 07:13:06 -0400 Subject: [PATCH 3/5] update docstring --- wis2box-management/wis2box/metadata/station.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wis2box-management/wis2box/metadata/station.py b/wis2box-management/wis2box/metadata/station.py index e979c88b8..4fcad6908 100644 --- a/wis2box-management/wis2box/metadata/station.py +++ b/wis2box-management/wis2box/metadata/station.py @@ -318,7 +318,7 @@ def get_geometry(wsi: str = '') -> Union[dict, None]: help='WIGOS station identifier') @cli_helpers.OPTION_VERBOSITY def get(ctx, wigos_station_identifier, verbosity): - """Publishes collection of stations to API config and backend""" + """Queries OSCAR/Surface for station information""" client = OSCARClient(env='prod') From cdbae0329907be11472c7222feaeef7c40570864 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Tue, 5 Sep 2023 07:25:51 -0400 Subject: [PATCH 4/5] update docs --- .../reference/running/station-metadata.rst | 22 +++++++++++++++++++ docs/source/user/setup.rst | 14 +++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/docs/source/reference/running/station-metadata.rst b/docs/source/reference/running/station-metadata.rst index ece1472ef..77212bcbf 100644 --- a/docs/source/reference/running/station-metadata.rst +++ b/docs/source/reference/running/station-metadata.rst @@ -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 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 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 diff --git a/docs/source/user/setup.rst b/docs/source/user/setup.rst index c34faedb8..d910d49c2 100644 --- a/docs/source/user/setup.rst +++ b/docs/source/user/setup.rst @@ -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 @@ -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 + +Then to add to the station list: + +.. code-block:: bash + + wis2box metadata station get >> ~/wis2box-data/metadata/station/station_list.csv + Discovery metadata ------------------ From 4adec7785691dee160cd145ad3cb58ec6da33e82 Mon Sep 17 00:00:00 2001 From: Tom Kralidis Date: Tue, 5 Sep 2023 07:27:23 -0400 Subject: [PATCH 5/5] update docs --- docs/source/reference/running/station-metadata.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/reference/running/station-metadata.rst b/docs/source/reference/running/station-metadata.rst index 77212bcbf..507004bdf 100644 --- a/docs/source/reference/running/station-metadata.rst +++ b/docs/source/reference/running/station-metadata.rst @@ -27,7 +27,7 @@ wis2box can derive station information from `OSCAR/Surface`_. To verify station .. code-block:: bash - wis2box metadata station WSI + wis2box metadata station get WSI where ``WSI`` is the WIGOS Station Identifier. This command will return the information required in the @@ -38,7 +38,7 @@ automatically: .. code-block:: bash - wis2box metadata station WSI >> ~/wis2box-data/metadata/station/station_list.csv + wis2box metadata station get WSI >> ~/wis2box-data/metadata/station/station_list.csv Summary