-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Addition of pygeoapi process #33
Closed
Closed
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bd743ad
pygeoapi plugin added
david-i-berry 348989d
pygeoapi plugin added
david-i-berry 46e6038
pygeoapi plugin added
david-i-berry 6d99acf
debugging, no messages produced in test data
david-i-berry b3e82c7
debugging, no messages produced in test data
david-i-berry 435f8ca
bugfix: wsi referenced before assignmnet, now set to none when TSI no…
david-i-berry ddc14d1
Issue with returning binary, now b64 returned.
david-i-berry 33c38a1
Import bas64
david-i-berry a61d6a7
debugging result.
david-i-berry 5c21dec
debugging result.
david-i-berry 6a2a0ca
debugging result.
david-i-berry 9595bfa
debugging result.
david-i-berry 7cbadd8
flake8
david-i-berry 11f1de8
flake8
david-i-berry File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
attrs==22.2.0 | ||
click==8.1.3 | ||
numpy==1.21.6 | ||
csv2bufr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
############################################################################### | ||
# | ||
# Licensed to the Apache Software Foundation (ASF) under one | ||
# or more contributor license agreements. See the NOTICE file | ||
# distributed with this work for additional information | ||
# regarding copyright ownership. The ASF licenses this file | ||
# to you under the Apache License, Version 2.0 (the | ||
# "License"); you may not use this file except in compliance | ||
# with the License. You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, | ||
# software distributed under the License is distributed on an | ||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
# KIND, either express or implied. See the License for the | ||
# specific language governing permissions and limitations | ||
# under the License. | ||
# | ||
############################################################################### | ||
import base64 | ||
import json | ||
import logging | ||
from pygeoapi.process.base import BaseProcessor | ||
|
||
from synop2bufr import transform | ||
|
||
LOGGER = logging.getLogger(__name__) | ||
|
||
PROCESS_METADATA = { | ||
"version": "0.1.0", | ||
"id": "x-wmo:synop2bufr", | ||
"title": {"en": "synop2bufr"}, | ||
"description": {"en": "Process to convert FM 12-SYNOP bulletin to BUFR"}, | ||
"keywords": ["SYNOP", "BUFR", "FM 12"], | ||
"links": [{ | ||
"type": "text/html", | ||
"rel": "about", | ||
"title": "homepage", | ||
"href": "https://github.com/wmo-im/synop2bufr", | ||
"hreflang": "en-US", | ||
}], | ||
"inputs": { | ||
"data": { | ||
"title": "FM 12-SYNOP bulletin string", | ||
"description": "Input FM 12-SYNOP bulletin to convert to BUFR.", | ||
"schema": {"type": "string"}, | ||
"minOccurs": 1, | ||
"maxOccurs": 1, | ||
"metadata": None, | ||
"keywords": [], | ||
}, | ||
"metadata": { | ||
"title": "Station metadata", | ||
"description": "CSV formatted data containing list of stations required by synop2bufr.", # noqa | ||
"schema": {"type": "string"}, | ||
"minOccurs": 1, | ||
"maxOccurs": 1, | ||
"metadata": None, | ||
"keywords": [], | ||
}, | ||
"year": { | ||
"title": "Year", | ||
"description": "Year (UTC) corresponding to FM 12-SYNOP bulletin", | ||
"schema": {"type": "integer"}, | ||
"minOccurs": 1, | ||
"maxOccurs": 1, | ||
"metadata": None, | ||
"keywords": [] | ||
}, | ||
"month": { | ||
"title": "Month", | ||
"description": "Month (UTC) corresponding to FM 12-SYNOP bulletin", | ||
"schema": {"type": "integer"}, | ||
"minOccurs": 1, | ||
"maxOccurs": 1, | ||
"metadata": None, | ||
"keywords": [] | ||
} | ||
}, | ||
"outputs": { | ||
"result": { | ||
"title": "BUFR encoded data in base64", # noqa | ||
"schema": {"contentMediaType": "application/json"} | ||
}, | ||
"errors": { | ||
"title": "Errors", | ||
"schema": {"contentMediaType": "application/json"} | ||
} | ||
}, | ||
"example": { | ||
"inputs": { | ||
"data": r"AAXX 21121 15015 02999 02501 10103 21090 39765 42952 57020 60001 333 4/000 55310 0//// 22591 3//// 60007 91003 91104=", # noqa | ||
"metadata": r"station_name,wigos_station_identifier,traditional_station_identifier,facility_type,latitude,longitude,elevation,territory_name,wmo_region\\nOCNA SUGATAG,0-20000-0-15015,15015,Land (fixed),47.77706163,23.94046026,503,Romania,6", # noqa | ||
"year": 2022, | ||
"month": 2 | ||
}, | ||
"output": {} | ||
}, | ||
} | ||
|
||
|
||
class processor(BaseProcessor): | ||
def __init__(self, processor_def): | ||
""" | ||
Initialize object | ||
:param processor_def: provider definition | ||
:returns: pygeoapi.process.csv2bufr.csv2bufr | ||
""" | ||
|
||
super().__init__(processor_def, PROCESS_METADATA) | ||
|
||
def execute(self, data): | ||
""" | ||
This method is invoked by pygeoapi when this class is set as a | ||
`process` type resource in pygeoapi config file. | ||
|
||
:return: media_type, json | ||
""" | ||
|
||
mimetype = "application/json" | ||
errors = [] | ||
bufr = [] | ||
try: | ||
fm12 = data['data'] | ||
metadata = data['metadata'] | ||
year = data['year'] | ||
month = data['month'] | ||
bufr_generator = transform(data=fm12, | ||
metadata=metadata, | ||
year=year, | ||
month=month) | ||
|
||
# transform returns a generator, we need to iterate over | ||
# and add to single output object | ||
for result in bufr_generator: | ||
# need to convert BUFR binary to base64 | ||
result['bufr4'] = base64.b64encode(result['bufr4']).decode("utf-8") # noqa | ||
# convert datetime to string | ||
result['_meta']['properties']['datetime'] = \ | ||
result['_meta']['properties']['datetime'].isoformat() | ||
bufr.append(result) | ||
|
||
except Exception as e: | ||
LOGGER.error(e) | ||
errors.append(f"{e}") | ||
|
||
output = {"result": json.dumps(bufr), "errors": json.dumps(errors)} | ||
|
||
return mimetype, output | ||
|
||
def __repr__(self): | ||
return "<synop2bufr> {}".format(self.name) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are
attrs
andnumpy
used in this PR?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They're used and installed by the underlying eccodes, a recent update to the packages breaks things without pinning (we probably need to pin in the base docker image as well).