Skip to content

Commit 169ce74

Browse files
committed
Provide example configuration from model metadata YAML for /model_config/ endpoint
1 parent cf01f05 commit 169ce74

11 files changed

+64
-43
lines changed

REST-Server/openapi_server/controllers/exploration_controller.py

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -87,30 +87,8 @@ def model_config_model_name_get(ModelName): # noqa: E501
8787
:rtype: ModelConfig
8888
"""
8989
# get model
90-
try:
91-
api_instance = mint_client.ModelApi(mint_client.ApiClient(configuration))
92-
model = api_instance.get_model(ModelName, username=username)
93-
versions = [v['id'] for v in model.has_software_version]
94-
95-
# for each model version, obtain configuration ids
96-
configuration_ids = []
97-
api_instance = mint_client.ModelversionApi(mint_client.ApiClient(configuration))
98-
for v in versions:
99-
version = api_instance.get_model_version(v, username=username)
100-
c_ids = [c.id for c in version.has_configuration]
101-
configuration_ids.extend(c_ids)
102-
103-
# get configurations
104-
configurations = []
105-
api_instance = mint_client.ModelconfigurationApi(mint_client.ApiClient(configuration))
106-
for _id in configuration_ids:
107-
config = api_instance.get_model_configuraton(_id, username=username)
108-
configurations.append({'name': ModelName, 'config': config.to_dict()})
109-
110-
return configurations
111-
112-
except ApiException as e:
113-
return "Exception when calling MINT: %s\n" % e
90+
m = json.loads(r.get(f'{ModelName}-meta').decode('utf-8'))
91+
return util.format_config(m)
11492

11593
def model_info_model_name_get(ModelName): # noqa: E501
11694
"""Get basic metadata information for a specified model.

REST-Server/openapi_server/openapi/openapi.yaml

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,7 @@ paths:
8888
content:
8989
application/json:
9090
schema:
91-
items:
92-
$ref: '#/components/schemas/Parameter'
93-
type: array
91+
$ref: '#/components/schemas/Parameter'
9492
description: SUCCESS
9593
summary: Obtain information about a model's parameters.
9694
tags:
@@ -114,9 +112,7 @@ paths:
114112
content:
115113
application/json:
116114
schema:
117-
items:
118-
$ref: '#/components/schemas/ModelConfig'
119-
type: array
115+
$ref: '#/components/schemas/ModelConfig'
120116
description: SUCCESS
121117
summary: Obtain configurations for a given model.
122118
tags:

REST-Server/openapi_server/util.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -585,6 +585,16 @@ def format_parameters(m):
585585
out_p.append(o_p)
586586
return out_p
587587

588+
def format_config(m):
589+
"""
590+
Takes in a model metadata JSON from Redis and formats the config the MaaS API.
591+
"""
592+
c = m.get('configuration',[])
593+
out_c = {'name': m.get('id'), 'config': {}}
594+
if len(c) > 0:
595+
out_c['config'] = c[0]
596+
return out_c
597+
588598
def sortOD(od):
589599
res = OrderedDict()
590600
for k, v in sorted(od.items()):

metadata/models/CHIRPS-GEFS-model-metadata.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ parameters:
5858
words, the coordinates of a SW point and a NE point define your region of interest.
5959
metadata:
6060
type: GeoParameter
61-
default: [33.512234, 2.719907, 49.981710, 16.501768]
61+
default: [33.512234, 2.719907, 49.981710, 16.501768]
62+
63+
configuration:
64+
- _type: mm_data
65+
dekad: 01
66+
year: 2019
67+
bbox: [33.512234, 2.719907, 49.981710, 16.501768]

metadata/models/CHIRPS-model-metadata.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,10 @@ parameters:
5858
words, the coordinates of a SW point and a NE point define your region of interest.
5959
metadata:
6060
type: GeoParameter
61-
default: [33.512234, 2.719907, 49.981710, 16.501768]
61+
default: [33.512234, 2.719907, 49.981710, 16.501768]
62+
63+
configuration:
64+
- _type: mm_data
65+
dekad: 01
66+
year: 2019
67+
bbox: [33.512234, 2.719907, 49.981710, 16.501768]

metadata/models/DSSAT-model-metadata.yaml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,14 @@ parameters:
110110
type: TimeParameter
111111
default: "05-20"
112112
minumum: "01-01"
113-
maximum: "12-31"
113+
maximum: "12-31"
114+
115+
configuration:
116+
- samples: 0
117+
start_year: 2017
118+
number_Years: 2
119+
management_practice: combined
120+
rainfall: 1
121+
fertilizer: 100
122+
planting_start: 03-01
123+
planting_end: 05-20

metadata/models/FSC-model-metadata.yaml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,10 @@ parameters:
5353
The year in which to induce the shock in YYYY format.
5454
metadata:
5555
type: TimeParameter
56-
default: 2005
56+
default: 2005
57+
58+
configuration:
59+
- country: USA
60+
fractional_reserve_access: 1
61+
production_decrease: 0.5
62+
year: 2005

metadata/models/malnutrition-model-metadata.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,7 @@ parameters:
3333
type: NumberParameter
3434
minimum: 0
3535
maximum: 200
36-
default: 100
36+
default: 100
37+
38+
configuration:
39+
- percent_of_normal_rainfall: 1

metadata/models/population-model-metadata.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,7 @@ parameters:
3232
choices:
3333
- Ethiopia
3434
- South Sudan
35-
default: Ethiopia
35+
default: Ethiopia
36+
37+
configuration:
38+
- country_level: Ethiopia

metadata/models/yield-anomalies-model-metadata.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,11 @@ parameters:
8787
- mean
8888
- std
8989
- pctl,5
90-
- pctl,95
90+
- pctl,95
91+
92+
configuration:
93+
- crop: maize
94+
irrigation: LIM
95+
nitrogen: LIM
96+
area: global
97+
statistic: mean

0 commit comments

Comments
 (0)