mirror of
https://github.com/JHUAPL/SIMoN.git
synced 2026-01-09 14:57:56 -05:00
updating template model
Former-commit-id: 004a8f88a5f3088279363bd9d4b3357596d34f42
This commit is contained in:
@@ -2,7 +2,8 @@
|
||||
FROM simon-model:latest
|
||||
|
||||
# install dependencies
|
||||
RUN pip3 install numpy pandas
|
||||
COPY requirements.txt /
|
||||
RUN pip3 install -r /requirements.txt
|
||||
|
||||
# run the inner wrapper (required)
|
||||
CMD ["python3", "/opt/src/inner_wrapper.py"]
|
||||
|
||||
2
models/template/config/config_data2.json
Normal file
2
models/template/config/config_data2.json
Normal file
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
2
models/template/config/config_data3.json
Normal file
2
models/template/config/config_data3.json
Normal file
@@ -0,0 +1,2 @@
|
||||
{
|
||||
}
|
||||
3
models/template/requirements.txt
Normal file
3
models/template/requirements.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
# List Python packages below. For example:
|
||||
numpy
|
||||
pandas
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"title": "empty schema",
|
||||
"description": "matches everything"
|
||||
}
|
||||
24
models/template/schemas/input/input_model_name1.json
Normal file
24
models/template/schemas/input/input_model_name1.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"example_input1": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"agg": {"type": "string", "value": "simple_sum"},
|
||||
"dagg": {"type": "string", "value": "distribute_by_area"},
|
||||
"granularity": {"type": "string", "value": "state"}
|
||||
}
|
||||
},
|
||||
"example_input2": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"agg": {"type": "string", "value": "weighted_average"},
|
||||
"dagg": {"type": "string", "value": "distribute_identically"},
|
||||
"granularity": {"type": "string", "value": "huc8"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["example_input1", "example_input2"]
|
||||
}
|
||||
15
models/template/schemas/input/input_model_name2.json
Normal file
15
models/template/schemas/input/input_model_name2.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"example_input3": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"agg": {"type": "string", "value": "weighted_average"},
|
||||
"dagg": {"type": "string", "value": "distribute_identically"},
|
||||
"granularity": {"type": "string", "value": "huc8"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["example_input3"]
|
||||
}
|
||||
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"title": "empty schema",
|
||||
"description": "matches everything"
|
||||
}
|
||||
24
models/template/schemas/output/template_output_schema.json
Normal file
24
models/template/schemas/output/template_output_schema.json
Normal file
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"example_output1": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"agg": {"type": "string", "value": "simple_sum"},
|
||||
"dagg": {"type": "string", "value": "distribute_uniformly"},
|
||||
"granularity": {"type": "string", "value": "county"}
|
||||
}
|
||||
},
|
||||
"example_output2": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"agg": {"type": "string", "value": "simple_average"},
|
||||
"dagg": {"type": "string", "value": "distribute_identically"},
|
||||
"granularity": {"type": "string", "value": "latlon"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["example_output1, example_output2"]
|
||||
}
|
||||
@@ -1,25 +1,61 @@
|
||||
# Copyright 2020 The Johns Hopkins University Applied Physics Laboratory LLC
|
||||
# All rights reserved.
|
||||
# Distributed under the terms of the MIT License
|
||||
|
||||
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
|
||||
# import helper functions
|
||||
from my_module import my_function
|
||||
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
def __init__(self):
|
||||
|
||||
# count the number of JSON files in the input schemas directory
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
|
||||
# unique_model_name is the name of the model (must match the name of the model's directory)
|
||||
super().__init__(
|
||||
model_id="unique_model_name", num_expected_inputs=num_input_schemas
|
||||
)
|
||||
self.data = None
|
||||
|
||||
def configure(self, **kwargs):
|
||||
self.data = kwargs['schema_name']
|
||||
# config_datax refers to the names of the JSON files in the config directory
|
||||
self.input_data1 = kwargs['config_data1']
|
||||
self.input_data2 = kwargs['config_data2']
|
||||
self.input_data3 = kwargs['config_data3']
|
||||
|
||||
# this model has two input schemas, and so expects input from two other models
|
||||
def increment(self, **kwargs):
|
||||
|
||||
# input_model_name1 matches the name of a JSON file in the input schemas directory
|
||||
if 'input_model_name1' in kwargs.keys():
|
||||
# example_input1 and example_input2 refer to fields in the input schema
|
||||
self.input_data1 = kwargs['input_model_name1']['example_input1']['data']
|
||||
self.input_data2 = kwargs['input_model_name1']['example_input2']['data']
|
||||
|
||||
# input_model_name2 matches the name of a JSON file in the input schemas directory
|
||||
if 'input_model_name2' in kwargs.keys():
|
||||
# example_input3 refers to a field in the input schema
|
||||
self.input_data3 = kwargs['input_model_name2']['example_input3']['data']
|
||||
|
||||
# calculate the model's outputs
|
||||
output1, output2 = my_function(self.input_data1, self.input_data2, self.input_data3)
|
||||
|
||||
# template_output_schema matches the name of the JSON file in the output schemas directory
|
||||
# example_output1 and example_output2 refer to fields in the output schema
|
||||
# example_output1 is returned by my_function() in the county granularity
|
||||
# example_output2 is returned by my_function() in the latlon granularity
|
||||
# before it is published, the data will automatically be translated to the granularities specified in template_output_schema
|
||||
return {
|
||||
'schema_name': {
|
||||
'data_variable_name': {'data': {}, 'granularity': 'county'}
|
||||
'template_output_schema': {
|
||||
'example_output1': {'data': output1, 'granularity': 'county'},
|
||||
'example_output2': {'data': output2, 'granularity': 'latlon'}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
10
models/template/src/my_module.py
Normal file
10
models/template/src/my_module.py
Normal file
@@ -0,0 +1,10 @@
|
||||
# Copyright 2020 The Johns Hopkins University Applied Physics Laboratory LLC
|
||||
# All rights reserved.
|
||||
# Distributed under the terms of the MIT License
|
||||
|
||||
|
||||
# use the input data to calculate output data
|
||||
def my_function(input1, input2, input3):
|
||||
output1 = {}
|
||||
output2 = {}
|
||||
return output1, output2
|
||||
Reference in New Issue
Block a user