Skip to content
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

Fix tests #33

Open
wants to merge 18 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions opencdms_process/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
def main(args=None):
"""Console script for opencdms_process."""
# See click documentation at https://click.palletsprojects.com/
click.echo("Replace this message by putting your code into "
"opencdms_process.cli.main")
click.echo(
"Replace this message by putting your code into " "opencdms_process.cli.main"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was the formatting change here accidental? It looks a bit odd being >79 chars and also the unnecessary concatenation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it was due to black, not formatting strings. I have added a make command in the makefile with a preview flag for black so that black takes care of strings as well.

)
return 0


Expand Down
12 changes: 7 additions & 5 deletions opencdms_process/process/climatol/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,18 @@ def windrose(obs):

script = os.path.join(
os.path.dirname(__file__),
'windrose.r',
"windrose.r",
)

r.source(script)

with localconverter(default_converter + pandas2ri.converter):
_obs = conversion.py2rpy(obs)

globalenv['observations'] = _obs
globalenv["observations"] = _obs

r(f"""
r(
f"""
library('magick')

figure <- image_graph(width = 350, height = 350, res = 96)
Expand All @@ -34,8 +35,9 @@ def windrose(obs):
windrose(data,'838','Bracknell Beaufort Park')

image <- image_write(figure, path = NULL, format = "png")
""")
image_data = globalenv['image']
"""
)
image_data = globalenv["image"]
image = Image.open(BytesIO(bytes(image_data)))

return image
144 changes: 64 additions & 80 deletions opencdms_process/process/climatol/windrose_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,83 +11,67 @@

#: Process metadata and description
PROCESS_METADATA = {
'version': '0.2.0',
'id': 'windrose-generator',
'title': {
'en': 'Windrose Generator'
"version": "0.2.0",
"id": "windrose-generator",
"title": {"en": "Windrose Generator"},
"description": {
"en": "Generates windrose chart.",
},
'description': {
'en': 'Generates windrose chart.',
},
'keywords': ['windrose-generator', 'opencdms'],
'links': [],
'inputs': {
'src_id': {
'title': 'Source ID',
'description': 'Source ID of the observation data.',
'schema': {
'type': 'integer'
},
'minOccurs': 1,
'maxOccurs': 1,
'metadata': None, # TODO how to use?
'keywords': ['src_id', 'personal']
"keywords": ["windrose-generator", "opencdms"],
"links": [],
"inputs": {
"src_id": {
"title": "Source ID",
"description": "Source ID of the observation data.",
"schema": {"type": "integer"},
"minOccurs": 1,
"maxOccurs": 1,
"metadata": None, # TODO how to use?
"keywords": ["src_id", "personal"],
},
'period': {
'title': 'Period',
'description': 'Period of the observation data.',
'schema': {
'type': 'string'
},
'minOccurs': 1,
'maxOccurs': 1,
'metadata': None, # TODO how to use?
'keywords': ['period', 'midas-open']
"period": {
"title": "Period",
"description": "Period of the observation data.",
"schema": {"type": "string"},
"minOccurs": 1,
"maxOccurs": 1,
"metadata": None, # TODO how to use?
"keywords": ["period", "midas-open"],
},
'year': {
'title': 'Year',
'description': 'Year of the observation data.',
'schema': {
'type': 'integer'
},
'minOccurs': 1,
'maxOccurs': 1,
'metadata': None, # TODO how to use?
'keywords': ['year', 'midas-open']
"year": {
"title": "Year",
"description": "Year of the observation data.",
"schema": {"type": "integer"},
"minOccurs": 1,
"maxOccurs": 1,
"metadata": None, # TODO how to use?
"keywords": ["year", "midas-open"],
},
'elements': {
'title': 'Elements',
'description': 'Elements of the observation data.',
'schema': {
'type': 'array',
'items': {
'type': 'string'
}
},
'minOccurs': 1,
'maxOccurs': 1,
'metadata': None, # TODO how to use?
'keywords': ['elements', 'midas-open']
"elements": {
"title": "Elements",
"description": "Elements of the observation data.",
"schema": {"type": "array", "items": {"type": "string"}},
"minOccurs": 1,
"maxOccurs": 1,
"metadata": None, # TODO how to use?
"keywords": ["elements", "midas-open"],
},
},
'outputs': {
'windrose': {
'title': 'Windrose chart',
'description': 'Return a chart with windrose visualization.',
'schema': {
'type': 'object',
'contentMediaType': 'application/json'
}
"outputs": {
"windrose": {
"title": "Windrose chart",
"description": "Return a chart with windrose visualization.",
"schema": {"type": "object", "contentMediaType": "application/json"},
}
},
'example': {
'inputs': {
'src_id': 838,
'period': 'hourly',
'year': 1991,
'elements': ['wind_speed', 'wind_direction'],
"example": {
"inputs": {
"src_id": 838,
"period": "hourly",
"year": 1991,
"elements": ["wind_speed", "wind_direction"],
}
}
},
}


Expand Down Expand Up @@ -127,23 +111,23 @@ def __init__(self, processor_def):
super().__init__(processor_def, PROCESS_METADATA)

def execute(self, data):
mimetype = 'application/json'
mimetype = "application/json"
filters = {
'src_id': 838,
'period': 'hourly',
'year': 1991,
'elements': ['wind_speed', 'wind_direction'],
"src_id": 838,
"period": "hourly",
"year": 1991,
"elements": ["wind_speed", "wind_direction"],
}

if not {'src_id', 'period', 'year', 'elements'} - set(data.keys()):
if not {"src_id", "period", "year", "elements"} - set(data.keys()):
filters = data

connection = opencdms_test_data.connections.midas_open
windrose_chart = WindroseDataProcessor(filters, connection)\
.generate_chart(base64_encoded=True)
windrose_chart = WindroseDataProcessor(filters, connection).generate_chart(
base64_encoded=True
)

return mimetype, {
'windrose': windrose_chart
}
return mimetype, {"windrose": windrose_chart}

def __repr__(self):
return '<WindroseProcessor> {}'.format(self.name)
return "<WindroseProcessor> {}".format(self.name)
Loading