pywis-pubsub provides subscription and download capability of WMO data from WIS2 infrastructure services
Project description
pywis-pubsub
Overview
pywis-pubsub provides subscription and download capability of WMO data from WIS2 infrastructure services.
Installation
The easiest way to install pywis-pubsub is via the Python pip utility:
pip3 install pywis-pubsub
Requirements
- Python 3
- virtualenv
Dependencies
Dependencies are listed in requirements.txt. Dependencies are automatically installed during pywis-pubsub installation.
Windows installations
Note that you will need Cython and Shapely Windows wheels for windows for your architecture prior to installing pywis-pubsub.
Installing pywis-pubsub
# setup virtualenv
python3 -m venv --system-site-packages pywis-pubsub
cd pywis-pubsub
source bin/activate
# clone codebase and install
git clone https://github.com/wmo-im/pywis-pubsub.git
cd pywis-pubsub
python3 setup.py install
Running
First check pywis-pubsub was correctly installed
pywis-pubsub --version
Create configuration
cp pywis-pubsub-config.yml local.yml
vim local.yml # update accordingly to configure subscribe options
Subscribing
# sync WIS2 notification schema
pywis-pubsub schema sync
# connect, and simply echo messages
pywis-pubsub subscribe --config local.yml
# subscribe, and download data from message
pywis-pubsub subscribe --config local.yml --download
# subscribe, and filter messages by geometry
pywis-pubsub subscribe --config local.yml --bbox=-142,42,-52,84
# subscribe, and filter messages by geometry, increase debugging verbosity
pywis-pubsub subscribe --config local.yml --bbox=-142,42,-52,84 --verbosity=DEBUG
Validating a message and verifying data
# validate a message
pywis-pubsub message validate /path/to/message1.json
# verify data from a message
pywis-pubsub message verify /path/to/message1.json
# validate WNM against abstract test suite (file on disk)
pywis-pubsub ets validate /path/to/file.json
# validate WNM against abstract test suite (URL)
pywis-pubsub ets validate https://example.org/path/to/file.json
# validate WNM against abstract test suite (URL), but turn JSON Schema validation off
pywis-pubsub ets validate https://example.org/path/to/file.json --no-fail-on-schema-validation
# key performance indicators
# set environment variable for GDC URL
export PYWIS_PUBSUB_GDC_URL=https://api.weather.gc.ca/collections/wis2-discovery-metadata
# all key performance indicators at once
pywis-pubsub kpi validate https://example.org/path/to/file.json --verbosity DEBUG
# all key performance indicators at once, but turn ETS validation off
pywis-pubsub kpi validate https://example.org/path/to/file.json --no-fail-on-ets --verbosity DEBUG
# all key performance indicators at once, in summary
pywis-pubsub kpi validate https://example.org/path/to/file.json --verbosity DEBUG --summary
# selected key performance indicator
pywis-pubsub kpi validate --kpi metadata_id /path/to/file.json -v INFO
Publishing
cp pub-config-example.yml pub-local.yml
vim pub-local.yml # update accordingly to configure publishing options
# example publishing a WIS2 notification message with attributes:
# unique-id=stationXYZ-20221111085500
# data-url=http://www.meteo.xx/stationXYZ-20221111085500.bufr4
# lon,lat,elevation=33.8,11.8,112
# wigos_station_identifier=0-20000-12345
pywis-pubsub publish --topic origin/a/wis2/centre-id/data/core/weather --config pub-local.yml -i stationXYZ-20221111085500 -u https://example.org/stationXYZ-20221111085500.bufr4 -g 33.8,-11.8,8.112 -w 0-20000-12345
# publish a message with a WCMP2 metadata id
pywis-pubsub publish --topic origin/a/wis2/centre-id/data/core/weather --config pub-local.yml -i stationXYZ-20221111085500 -u https://example.org/stationXYZ-20221111085500.bufr4 -g 33.8,-11.8,8.112 -w 0-20000-12345 --metadata-id "x-urn:wmo:md:test-foo:htebmal2001"
# publish a message with a datetime (instant)
pywis-pubsub publish --topic origin/a/wis2/centre-id/data/core/weather --config pub-local.yml -i stationXYZ-20221111085500 -u https://example.org/stationXYZ-20221111085500.bufr4 -g 33.8,-11.8,8.112 -w 0-20000-12345 --metadata-id "x-urn:wmo:md:test-foo:htebmal2001" --datetime 2024-01-08T22:56:23Z
# publish a message with a start and end datetime (extent)
pywis-pubsub publish --topic origin/a/wis2/centre-id/data/core/weather --config pub-local.yml -i stationXYZ-20221111085500 -u https://example.org/stationXYZ-20221111085500.bufr4 -g 33.8,-11.8,8.112 -w 0-20000-12345 --metadata-id "x-urn:wmo:md:test-foo:htebmal2001" --datetime 2024-01-08T20:56:23Z/2024-01-08T22:56:43Z
# publish a message as a data update
pywis-pubsub publish --topic origin/a/wis2/centre-id/data/core/weather --config pub-local.yml -i stationXYZ-20221111085500 -u https://example.org/stationXYZ-20221111085500.bufr4 -g 33.8,-11.8,8.112 -w 0-20000-12345 --metadata-id "x-urn:wmo:md:test-foo:htebmal2001" --operation update
# publish a message as a data deletion
pywis-pubsub publish --topic origin/a/wis2/centre-id/data/core/weather --config pub-local.yml -i stationXYZ-20221111085500 -u https://example.org/stationXYZ-20221111085500.bufr4 -g 33.8,-11.8,8.112 -w 0-20000-12345 --metadata-id "x-urn:wmo:md:test-foo:htebmal2001" --operation delete
# publish a message from file on disk
pywis-pubsub publish --topic origin/a/wis2/centre-id/data/core/weather --config pub-local.yml --file my_message.json
Using the API
Python examples:
Subscribing to a WIS2 Global Broker
from pywis_pubsub.mqtt import MQTTPubSubClient
options = {
'storage': {
'type': 'fs',
'basedir': '/tmp'
},
'bbox': [-90, -180, 90, 180]
}
topics = [
'topic1',
'topic2'
]
m = MQTTPubSubClient('mqtt://localhost:1883', options)
m.sub(topics)
Publishing a WIS2 Notification Message
from datetime import datetime, timezone
from pywis_pubsub.mqtt import MQTTPubSubClient
from pywis_pubsub.publish import create_message
message = create_message(
topic='foo/bar',
content_type='application/x-bufr',
url='http://www.meteo.xx/stationXYZ-20221111085500.bufr4',
identifier='stationXYZ-20221111085500',
datetime=datetime.now(timezone.utc),
geometry=[33.8, -11.8, 123],
metadata_id='x-urn:wmo:md:test-foo:htebmal2001',
wigos_station_identifier='0-20000-12345',
operation='update'
)
m = MQTTPubSubClient('mqtt://localhost:1883')
m.pub(topic, json.dumps(message))
Running KPIs
>>> # test KPI
>>> import json
>>> from pywis_pubsub.kpi import WNMKeyPerformanceIndicators
>>> with open('/path/to/file.json') as fh:
... data = json.load(fh)
>>> kpis = WNMKeyPerformanceIndicators(data)
>>> results = kpis.evaluate()
>>> results['summary']
Development
Running Tests
# install dev requirements
pip3 install -r requirements-dev.txt
# run tests like this:
python3 tests/run_tests.py
# or this:
python3 setup.py test
Releasing
# create release (x.y.z is the release version)
vi pywis_pubsub/__init__.py # update __version__
vi debian/changelog # add changelog entry
git commit -am 'update release version x.y.z'
git push origin main
git tag -a x.y.z -m 'tagging release version x.y.z'
git push --tags
# upload to PyPI
rm -fr build dist *.egg-info
python3 setup.py sdist bdist_wheel --universal
twine upload dist/*
# publish release on GitHub (https://github.com/wmo-im/pywis-pubsub/releases/new)
# bump version back to dev
vi pywis_pubsub/__init__.py # update __version__
git commit -am 'back to dev'
git push origin main
Code Conventions
Bugs and Issues
All bugs, enhancements and issues are managed on GitHub.
Contact
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pywis-pubsub-0.7.1.tar.gz
.
File metadata
- Download URL: pywis-pubsub-0.7.1.tar.gz
- Upload date:
- Size: 27.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/1.1.3 pkginfo/1.9.6 requests/2.28.2 requests-toolbelt/0.8.0 tqdm/4.64.1 CPython/3.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bdb9353bc233c2b6f07da66d663fca3c18214766b6d98021c8936d6070a7a366 |
|
MD5 | cd0f863601223e5e75f617521f85f593 |
|
BLAKE2b-256 | 8cec823fa150e3b6bee6c31cc398174819042ef89c4625ba1d6801ab4686045f |
File details
Details for the file pywis_pubsub-0.7.1-py2.py3-none-any.whl
.
File metadata
- Download URL: pywis_pubsub-0.7.1-py2.py3-none-any.whl
- Upload date:
- Size: 36.2 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/1.1.3 pkginfo/1.9.6 requests/2.28.2 requests-toolbelt/0.8.0 tqdm/4.64.1 CPython/3.7.12
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efeeba642cba7b521df176ff9564616442061fd5af36bb63b522925f6a037cc1 |
|
MD5 | 157a6634378bea04a9e6748148a01616 |
|
BLAKE2b-256 | df8701116c59577753a44e51102cc088bc70b99c0280d67280c844184d83d4db |