mirror of
https://github.com/JHUAPL/SIMoN.git
synced 2026-01-09 14:57:56 -05:00
Merge branch 'jalen' into dev
Former-commit-id: 8bb6827eef9db52fa093b0d79cf45a24c84e26ab
This commit is contained in:
1
abstract-graph.geojson
Normal file
1
abstract-graph.geojson
Normal file
File diff suppressed because one or more lines are too long
@@ -26,7 +26,7 @@ class Broker:
|
||||
self.max_incstep = 50
|
||||
self.initial_year = 2016
|
||||
self.boot_timer = 60 # units: seconds
|
||||
self.watchdog_timer = 10 # units: seconds
|
||||
self.watchdog_timer = 30 # units: seconds
|
||||
self.client = None
|
||||
self.mongo_queue = Queue()
|
||||
self.broker_id = 'broker'
|
||||
|
||||
@@ -5,3 +5,5 @@ RUN wget https://download.opensuse.org/repositories/network:/messaging:/zeromq:/
|
||||
RUN apt-get install -y libzmq3-dev
|
||||
RUN pip3 install pymongo pyzmq jsonschema networkx geojson
|
||||
COPY ./outer_wrapper.py /.
|
||||
COPY ./instance-graph.geojson /.
|
||||
COPY ./abstract-graph.geojson /.
|
||||
|
||||
1
instance-graph.zip.REMOVED.git-id
Normal file
1
instance-graph.zip.REMOVED.git-id
Normal file
@@ -0,0 +1 @@
|
||||
df78e2a7a7f01c37df6803e3a25daa3a2507a221
|
||||
@@ -1,3 +1,5 @@
|
||||
FROM simon-model:latest
|
||||
RUN pip3 install pandas
|
||||
RUN pip3 install pandas fair
|
||||
RUN pip3 install fair
|
||||
RUN pip3 install numpy
|
||||
CMD ["python3", "/opt/src/inner_wrapper.py"]
|
||||
1
models/examples/climate/config/co2.json
Normal file
1
models/examples/climate/config/co2.json
Normal file
File diff suppressed because one or more lines are too long
1
models/examples/climate/config/thermo_water.json
Normal file
1
models/examples/climate/config/thermo_water.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
20
models/examples/climate/schemas/input/power_output.json
Normal file
20
models/examples/climate/schemas/input/power_output.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"co2": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"granularity": {"type": "string"}
|
||||
}
|
||||
},
|
||||
"thermo_water": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"granularity": {"type": "string"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["co2", "thermo_water"]
|
||||
}
|
||||
13
models/examples/climate/schemas/output/climate.json
Normal file
13
models/examples/climate/schemas/output/climate.json
Normal file
@@ -0,0 +1,13 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"climate": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"granularity": {"type": "string"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["climate"]
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
'''
|
||||
will return a dictionary of water consumption per year per county
|
||||
'''
|
||||
|
||||
import json
|
||||
import pandas as pd
|
||||
|
||||
with open('models/examples/population/config/county_populations.json','r') as file:
|
||||
cty = json.loads([x for x in file][0])
|
||||
with open('models/examples/waterdemand/config/rates.json','r') as file:
|
||||
waterdemand=json.loads([x for x in file][0])
|
||||
|
||||
cty={str(k).zfill(5):v for k, v in cty.items()}
|
||||
|
||||
def Water_Demand_Simulation(countypop,rate):
|
||||
|
||||
water={}
|
||||
for i in rate.keys():
|
||||
if i in countypop.keys():
|
||||
water[i]= (countypop[i]['2015']*rate[i])
|
||||
else:
|
||||
water[i]=(0)
|
||||
#with open('water_demand_2015.json', 'w') as file:
|
||||
# file.write(json.dumps(data))
|
||||
return water
|
||||
|
||||
|
||||
|
||||
|
||||
23
models/examples/climate/src/climate.py
Normal file
23
models/examples/climate/src/climate.py
Normal file
@@ -0,0 +1,23 @@
|
||||
import fair
|
||||
from fair.forward import fair_scm
|
||||
import numpy as np
|
||||
import json
|
||||
|
||||
#need to iterate through another dictionary that has counties as values
|
||||
#sum up the values set equaal to new variable
|
||||
#scale it then CFT
|
||||
def temperature_simulation(electric):
|
||||
total = sum(list(filter(None, electric.values())))
|
||||
#emissions[i]=
|
||||
emissions = np.array(total)
|
||||
#other_rf = np.zeros(emissions.size)
|
||||
|
||||
#for x in range(0, emissions.size):
|
||||
# other_rf[x] = 0.5 * np.sin(2 * np.pi * (x) / 14.0)
|
||||
|
||||
#emissions=emissions*6.66667*3.5714285 #scaling factors
|
||||
|
||||
C,F,T = fair.forward.fair_scm(emissions_driven=True, emissions=np.array([emissions*6.66667*3.5714285]), useMultigas=False)
|
||||
|
||||
return T
|
||||
#temperature_simulation({'co2':{'data':{5646:9.9,489247:6,234708:4.5}},'therm':[2,3,2]})
|
||||
@@ -1,32 +1,33 @@
|
||||
import glob
|
||||
import sys
|
||||
import fair
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from Water_Demand_Model import waterdemand1
|
||||
from climate import temperature_simulation
|
||||
|
||||
#put the json file from the output of power supply into the schemas/input file
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="waterdemand", num_expected_inputs=num_input_schemas)
|
||||
super().__init__(model_id="climate", num_expected_inputs=num_input_schemas)
|
||||
#self.electric=None
|
||||
|
||||
def configure(self, **kwargs):
|
||||
if 'rates' in kwargs.keys():
|
||||
self.rate=kwargs['rates']
|
||||
#replace the populations with the 2015 water consumption rate
|
||||
#need to take out the extra variable
|
||||
if 'co2' in kwargs.keys():
|
||||
self.electric = kwargs['co2']
|
||||
if 'thermo_water' in kwargs.keys():
|
||||
self.electric = kwargs['thermo_water']
|
||||
|
||||
def increment(self, **kwargs):
|
||||
if 'population' in kwargs.keys():
|
||||
self.countypop = kwargs['population']['population']['data']
|
||||
else:
|
||||
print('input population not found')
|
||||
if 'rate' in kwargs.keys()
|
||||
self.rate = kwargs['population']['data']
|
||||
else:
|
||||
print('input rate not found')
|
||||
demand = Water_Demand_Simulation(self.countypop)
|
||||
|
||||
return {'waterdemand': {'waterdemand': {'data': demand, 'granularity': 'county'}}}
|
||||
if 'power_output' in kwargs.keys():
|
||||
self.electric = kwargs['power_output']['co2']['data']
|
||||
else:
|
||||
print('input co2 not found')
|
||||
temperature=float(temperature_simulation(self.electric))
|
||||
|
||||
return {'climate': { 'climate': {'data': {'global_temp': temperature}, 'granularity': 'global'}}}
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
3
models/examples/logisticpopulation/Dockerfile
Normal file
3
models/examples/logisticpopulation/Dockerfile
Normal file
@@ -0,0 +1,3 @@
|
||||
FROM simon-model:latest
|
||||
RUN pip3 install pandas numpy statsmodels scipy==1.2.1
|
||||
CMD ["python3", "/opt/src/inner_wrapper.py"]
|
||||
File diff suppressed because one or more lines are too long
@@ -1,13 +1,12 @@
|
||||
{
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"population": {
|
||||
"logisticpopulation": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"granularity": {"type": "string"}
|
||||
}
|
||||
}
|
||||
},
|
||||
"required": ["population"]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{
|
||||
38
models/examples/logisticpopulation/src/LogisticGrowth.py
Normal file
38
models/examples/logisticpopulation/src/LogisticGrowth.py
Normal file
@@ -0,0 +1,38 @@
|
||||
|
||||
#def populationfunction(logisticpopulation):
|
||||
# pop={}
|
||||
# sum = 0
|
||||
# for i in logisticpopulation.keys():
|
||||
# N = logisticpopulation[i] #this is the county population
|
||||
# k = 300000000/3007 #this scales the max capacity to the county level (there are 3007 US counties)
|
||||
# r = 1.0061 #this is the growth rate
|
||||
# pop[i] = r*N*((k-N)/k) #this is the equation
|
||||
|
||||
# return pop
|
||||
|
||||
#def populationfunction(logisticpopulation):
|
||||
# pop={}
|
||||
# sum = 0
|
||||
# for i in logisticpopulation.keys():
|
||||
# sum += logisticpopulation[i]
|
||||
#print(sum)
|
||||
# N = logisticpopulation[i] #this is the county population
|
||||
# k = (N/sum) *300000000 #this scales the max capacity to the county level (there are 3007 US counties)
|
||||
# r = 1.0061 #this is the growth rate
|
||||
# pop[i] = r*N*((k-N)/k) #this is the equation
|
||||
|
||||
# return pop
|
||||
|
||||
def populationfunction(population):
|
||||
pop={}
|
||||
mysum = 0
|
||||
for i in population.keys():
|
||||
#or j in logisticpopulation.keys()[i]:
|
||||
mysum += population[i]
|
||||
|
||||
for i in population.keys():
|
||||
N = population[i] #this is the county population
|
||||
k = (N/mysum) *400000000 #this scales the max capacity to the county level (there are 3007 US counties)
|
||||
r = 1.0071 #this is the growth rate
|
||||
pop[i] = N + r*N*((k-N)/k) #this is the equation
|
||||
return pop
|
||||
36
models/examples/logisticpopulation/src/inner_wrapper.py
Normal file
36
models/examples/logisticpopulation/src/inner_wrapper.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import glob
|
||||
import sys
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from LogisticGrowth import populationfunction
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="logisticpopulation", num_expected_inputs=num_input_schemas)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
if '2016 populations' in kwargs.keys():
|
||||
self.population = kwargs['2016 populations']
|
||||
else:
|
||||
print('population initialization data not found')
|
||||
|
||||
def increment(self, **kwargs):
|
||||
#if 'logisticpopulation' in kwargs.keys():
|
||||
# self.population = kwargs['logistispopulation']['logisticpopulation']['data']
|
||||
#else:
|
||||
# print('input population not found')
|
||||
|
||||
population = populationfunction(self.population)
|
||||
self.population=population
|
||||
return {'logisticpopulation': {'logisticpopulation': {'data': population, 'granularity': 'county'}}}
|
||||
|
||||
|
||||
def main():
|
||||
wrapper = InnerWrapper()
|
||||
wrapper.run()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
File diff suppressed because one or more lines are too long
@@ -34,4 +34,20 @@ def gen_sim(demand,prof):
|
||||
|
||||
|
||||
return co2, h2o
|
||||
#water usage (withdrawals and consumption in the 860, we care about consumption), emissions of co2 (may also be in the 860), 923 should have total power produced by each power plant (would match regional demand), aggregating up then dividing by the state population, instead of doing on the state level, we want to instead do it on the nerc level, supply can be on nerc level,wrapper between the supply and demand does the granularity work so we don't have to worry about state vs. NERC, change the input file, he broke it out and was calculating stuff on counties, would adjust and repopulate, do on NERC and calculate on the NERC level, the point in the supply model is to make power demand equal to power supply on the nerc level, need to find the aggregation and disaggregation pairing
|
||||
#want to be able to do it in county nercs
|
||||
#1. read in P.P. data
|
||||
# P.P. I.D./County/Nerc/type/..
|
||||
# Max Capacity / 2016 Annual Predictions/C.F.?
|
||||
# CO2/Water Consumption
|
||||
#want it to be in popwer plant data
|
||||
# once we read in powerplant data, we have county demand, NERC Match: we are going to aggregate the powerplant data on nerc, and we will have county demand from the power demand model, it will say much power, SIMON will turn the county demand into nerc demand from the wrappers, will have a NERC demand read in, the NERC emand read in needs to be fulfilled by the power plants, we will aggregate all the pp data based off of nerc and then calculate a scaling factor
|
||||
# we will calculate scaling factor for county demand NERC match, it will be a regional nerc scaling factor for each NERC, we are going to take that scaling factor and apply it back to each pp and output co2 and water consumption, we are then going to take the scaling factor and go back to the powerplant level
|
||||
#we want supply and demand on the nerc level and then to depend what it means for each individual powerplant, want supply to match demand on nerc and then break it out at county level, maybe should not let powerplants be at maximum capacity, is there a different kind of capacity, or is it just historical use
|
||||
#capacity? there is generally a capacity factor which is like the maximum loading like if you took an integral over power usage (coal = 90%), might need a distribution network
|
||||
#2. county demand nerc match
|
||||
#3. scale p.p. data
|
||||
#4. aggregate it to anything you want, you want it as tight as possible so probably countynerc
|
||||
## will be easily able to do things and we will be happy the nerc is there, still being processed at powerplant but given a scaling factor
|
||||
|
||||
|
||||
|
||||
@@ -25,15 +25,16 @@ class InnerWrapper(OuterWrapper):
|
||||
else:
|
||||
print('input demand not found')
|
||||
emissions, water = gen_sim(self.dem, self.prof)
|
||||
translated_emissions = self.translate(emissions, 'county', 'NERC', self.model_id)
|
||||
translated_water = self.translate(water, 'county', 'NERC', self.model_id)
|
||||
|
||||
emissions_html = CountyMap(emissions, "co2 emissions")
|
||||
water_html = CountyMap(water, "thermo water")
|
||||
htmls = {"emissions_inc{}.html".format(self.incstep): emissions_html, "thermo_water_inc{}.html".format(self.incstep): water_html}
|
||||
results = {'power_output': { 'co2': {'data': emissions, 'granularity': 'county'},
|
||||
'thermo_water': {'data': water, 'granularity': 'county'}}}
|
||||
results = {'power_output': { 'co2': {'data': translated_emissions, 'granularity': 'NERC'},
|
||||
'thermo_water': {'data': translated_water, 'granularity': 'NERC'}}}
|
||||
return results, htmls, {}
|
||||
|
||||
|
||||
def main():
|
||||
wrapper = InnerWrapper()
|
||||
wrapper.run()
|
||||
|
||||
File diff suppressed because one or more lines are too long
1
models/examples/waterdemand/config/oldrates.json
Normal file
1
models/examples/waterdemand/config/oldrates.json
Normal file
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -24,10 +24,11 @@ class InnerWrapper(OuterWrapper):
|
||||
else:
|
||||
print('input population not found')
|
||||
demand = Water_Demand_Simulation(self.countypop, self.rate)
|
||||
translated_demand = self.translate(demand, 'county', 'HUC8', self.model_id)
|
||||
|
||||
html = CountyMap(demand)
|
||||
|
||||
results = {'waterdemand': {'waterdemand': {'data': demand, 'granularity': 'county'}}}
|
||||
results = {'waterdemand': {'waterdemand': {'data': translated_demand, 'granularity': 'HUC8'}}}
|
||||
htmls = {"water_demand_inc{}.html".format(self.incstep): html}
|
||||
images = {}
|
||||
return results, htmls, images
|
||||
|
||||
8
outer_wrapper.py
Normal file → Executable file
8
outer_wrapper.py
Normal file → Executable file
@@ -93,6 +93,10 @@ class OuterWrapper(ABC):
|
||||
self.broker_queue = Queue()
|
||||
self.action_queue = Queue()
|
||||
|
||||
self.abstract_graph = Graph("/abstract-graph.geojson")
|
||||
self.instance_graph = Graph("/instance-graph.geojson")
|
||||
self.instance_graph.nodes['UnitedStates']['area'] = 8081900
|
||||
|
||||
self.input_schemas = None
|
||||
self.output_schemas = None
|
||||
self.validated_schemas = {}
|
||||
@@ -243,11 +247,15 @@ class OuterWrapper(ABC):
|
||||
schemas = self.validated_schemas.copy()
|
||||
self.validated_schemas.clear()
|
||||
results, htmls, images = self.increment(**schemas)
|
||||
# translate results to the desired granularity?
|
||||
|
||||
# validate against output schemas
|
||||
for schema_name, data_msg in results.items():
|
||||
try:
|
||||
validate(data_msg, json.loads(self.generic_output_schema))
|
||||
print(schema_name)
|
||||
print(data_msg)
|
||||
print(self.output_schemas)
|
||||
validate(data_msg, self.output_schemas[schema_name])
|
||||
except Exception as e:
|
||||
logging.critical("message {} failed to validate schema {}".format(data_msg, schema_name))
|
||||
|
||||
Reference in New Issue
Block a user