mirror of
https://github.com/JHUAPL/SIMoN.git
synced 2026-01-09 14:57:56 -05:00
python black formatting (black simon -S -l 79)
Former-commit-id: f599b58ae5f4562ad00034ecd5b26a51e8ae6fbf
This commit is contained in:
@@ -3,21 +3,27 @@ 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
|
||||
# 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)
|
||||
total = sum(list(filter(None, electric.values())))
|
||||
# emissions[i]=
|
||||
emissions = np.array(total)
|
||||
# other_rf = np.zeros(emissions.size)
|
||||
|
||||
#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]})
|
||||
# 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,18 +1,21 @@
|
||||
import glob
|
||||
import sys
|
||||
import fair
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from climate import temperature_simulation
|
||||
|
||||
#put the json file from the output of power supply into the schemas/input file
|
||||
# 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="climate", num_expected_inputs=num_input_schemas)
|
||||
#self.electric=None
|
||||
super().__init__(
|
||||
model_id="climate", num_expected_inputs=num_input_schemas
|
||||
)
|
||||
# self.electric=None
|
||||
|
||||
def configure(self, **kwargs):
|
||||
if 'co2' in kwargs.keys():
|
||||
@@ -23,11 +26,18 @@ class InnerWrapper(OuterWrapper):
|
||||
def increment(self, **kwargs):
|
||||
if 'power_output' in kwargs.keys():
|
||||
self.electric = kwargs['power_output']['co2']['data']
|
||||
else:
|
||||
else:
|
||||
print('input co2 not found')
|
||||
temperature=float(temperature_simulation(self.electric))
|
||||
|
||||
return {'climate': { 'climate': {'data': {'global_temp': temperature}, 'granularity': 'global'}}}
|
||||
temperature = float(temperature_simulation(self.electric))
|
||||
|
||||
return {
|
||||
'climate': {
|
||||
'climate': {
|
||||
'data': {'global_temp': temperature},
|
||||
'granularity': 'global',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -10,7 +10,7 @@ import json
|
||||
|
||||
def temp_inc(init_data, year):
|
||||
json1_data = init_data
|
||||
year = year-1
|
||||
year = year - 1
|
||||
mean_glob_temps = []
|
||||
with open("/opt/src/weights.json") as f:
|
||||
weights = json.load(f)
|
||||
@@ -29,11 +29,13 @@ def temp_inc(init_data, year):
|
||||
# Contiguous U.S bounded by (49 N, 122W), (24N 66W)
|
||||
if 49 >= float(i) >= 23 and -68 >= float(j) >= -128:
|
||||
single_year_US[i][j] = (
|
||||
json1_data[i][j][year][0], json1_data[i][j][year][1], json1_data[i][j][year][2]-273.15
|
||||
json1_data[i][j][year][0],
|
||||
json1_data[i][j][year][1],
|
||||
json1_data[i][j][year][2] - 273.15,
|
||||
)
|
||||
|
||||
# Apply weights
|
||||
weighted_sum = np.sum([a*b for a, b in zip(mean_glob_temps, weights)])
|
||||
weighted_sum = np.sum([a * b for a, b in zip(mean_glob_temps, weights)])
|
||||
|
||||
# Output: Global average (C) +
|
||||
# grid of U.S (precipitation (mm), evaporation (mm), surface temp(C))
|
||||
@@ -44,7 +46,15 @@ def temp_inc(init_data, year):
|
||||
lon = float(lon)
|
||||
if lon < 0:
|
||||
lon += 180
|
||||
translated_pr["lat_" + str(lat) + "_lon_" + str(lon)] = lon_values[0]
|
||||
translated_ev["lat_" + str(lat) + "_lon_" + str(lon)] = lon_values[1]
|
||||
translated_pr["lat_" + str(lat) + "_lon_" + str(lon)] = lon_values[
|
||||
0
|
||||
]
|
||||
translated_ev["lat_" + str(lat) + "_lon_" + str(lon)] = lon_values[
|
||||
1
|
||||
]
|
||||
|
||||
return weighted_sum-273.15, translated_pr, translated_ev #single_year_US
|
||||
return (
|
||||
weighted_sum - 273.15,
|
||||
translated_pr,
|
||||
translated_ev,
|
||||
) # single_year_US
|
||||
|
||||
@@ -1,35 +1,48 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from climate_model import temp_inc
|
||||
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="gfdl_cm3", num_expected_inputs=num_input_schemas)
|
||||
super().__init__(
|
||||
model_id="gfdl_cm3", num_expected_inputs=num_input_schemas
|
||||
)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
self.raw_data = kwargs['rcp26data']
|
||||
if 'rcp26data' in kwargs.keys():
|
||||
self.mean_temp, self.climate_data0, self.climate_data1 = temp_inc(self.raw_data, self.incstep)
|
||||
self.mean_temp, self.climate_data0, self.climate_data1 = temp_inc(
|
||||
self.raw_data, self.incstep
|
||||
)
|
||||
else:
|
||||
print('rcp data not found')
|
||||
|
||||
def increment(self, **kwargs):
|
||||
self.global_temp, self.precipitation, self.evaporation = temp_inc(self.raw_data, self.incstep)
|
||||
self.global_temp, self.precipitation, self.evaporation = temp_inc(
|
||||
self.raw_data, self.incstep
|
||||
)
|
||||
|
||||
results ={'gfdl_cm3':
|
||||
{'global_temp':
|
||||
{'data': {'temp': self.global_temp}, 'granularity': 'global'},
|
||||
'precipitation':
|
||||
{'data': self.precipitation, 'granularity': 'climate'},
|
||||
'evaporation':
|
||||
{'data': self.evaporation, 'granularity': 'climate'}
|
||||
}
|
||||
}
|
||||
results = {
|
||||
'gfdl_cm3': {
|
||||
'global_temp': {
|
||||
'data': {'temp': self.global_temp},
|
||||
'granularity': 'global',
|
||||
},
|
||||
'precipitation': {
|
||||
'data': self.precipitation,
|
||||
'granularity': 'climate',
|
||||
},
|
||||
'evaporation': {
|
||||
'data': self.evaporation,
|
||||
'granularity': 'climate',
|
||||
},
|
||||
}
|
||||
}
|
||||
return results
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
import pyhector
|
||||
@@ -7,10 +8,11 @@ import json
|
||||
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="hector", num_expected_inputs=num_input_schemas)
|
||||
super().__init__(
|
||||
model_id="hector", num_expected_inputs=num_input_schemas
|
||||
)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
self.rcp = kwargs['bootstrap']['rcp']
|
||||
@@ -23,7 +25,16 @@ class InnerWrapper(OuterWrapper):
|
||||
print("rcp85")
|
||||
pandas_df = pyhector.run(pyhector.rcp85)
|
||||
|
||||
return {'climate': {'climate': {'data': json.loads(pandas_df["temperature.Tgav"].to_json()), 'granularity': 'global'}}}
|
||||
return {
|
||||
'climate': {
|
||||
'climate': {
|
||||
'data': json.loads(
|
||||
pandas_df["temperature.Tgav"].to_json()
|
||||
),
|
||||
'granularity': 'global',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -1,38 +1,40 @@
|
||||
|
||||
#def populationfunction(logisticpopulation):
|
||||
# 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
|
||||
# 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
|
||||
# return pop
|
||||
|
||||
#def populationfunction(logisticpopulation):
|
||||
# def populationfunction(logisticpopulation):
|
||||
# pop={}
|
||||
# sum = 0
|
||||
# for i in logisticpopulation.keys():
|
||||
# sum += logisticpopulation[i]
|
||||
#print(sum)
|
||||
# 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
|
||||
# r = 1.0061 #this is the growth rate
|
||||
# pop[i] = r*N*((k-N)/k) #this is the equation
|
||||
|
||||
# return pop
|
||||
|
||||
# return pop
|
||||
|
||||
def populationfunction(population):
|
||||
pop={}
|
||||
pop = {}
|
||||
mysum = 0
|
||||
for i in population.keys():
|
||||
#or j in logisticpopulation.keys()[i]:
|
||||
mysum += population[i]
|
||||
|
||||
# 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
|
||||
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
|
||||
|
||||
@@ -1,30 +1,41 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from LogisticGrowth import populationfunction
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
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)
|
||||
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']
|
||||
self.population = kwargs['2016 populations']
|
||||
else:
|
||||
print('population initialization data not found')
|
||||
|
||||
def increment(self, **kwargs):
|
||||
#if 'logisticpopulation' in kwargs.keys():
|
||||
# if 'logisticpopulation' in kwargs.keys():
|
||||
# self.population = kwargs['logistispopulation']['logisticpopulation']['data']
|
||||
#else:
|
||||
# else:
|
||||
# print('input population not found')
|
||||
|
||||
population = populationfunction(self.population)
|
||||
self.population=population
|
||||
return {'logisticpopulation': {'logisticpopulation': {'data': population, 'granularity': 'county'}}}
|
||||
self.population = population
|
||||
return {
|
||||
'logisticpopulation': {
|
||||
'logisticpopulation': {
|
||||
'data': population,
|
||||
'granularity': 'county',
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
@@ -24,12 +24,14 @@ def pop_sim(init_data):
|
||||
# of {county1_index: {2000: pop, 2001: pop, etc}, county2_index:...}
|
||||
# applies Holt linear trend method to predict one year ahead
|
||||
# outputted data is dict of {county_index: next_year_pop}
|
||||
|
||||
|
||||
temp = {}
|
||||
|
||||
for key, county in data.items():
|
||||
population = pd.Series(county)
|
||||
fit1 = Holt(np.asarray(population)).fit(smoothing_level=0.7, smoothing_slope=0.3)
|
||||
fit1 = Holt(np.asarray(population)).fit(
|
||||
smoothing_level=0.7, smoothing_slope=0.3
|
||||
)
|
||||
next_year = fit1.forecast(1)[0]
|
||||
temp[key] = next_year
|
||||
data[key][str(int(max(data[key].keys())) + 1)] = next_year
|
||||
@@ -38,4 +40,3 @@ def pop_sim(init_data):
|
||||
file.write(json.dumps(data))
|
||||
|
||||
return temp
|
||||
|
||||
|
||||
@@ -1,27 +1,37 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from PopulationSimulation import pop_sim
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="population", num_expected_inputs=num_input_schemas)
|
||||
super().__init__(
|
||||
model_id="population", num_expected_inputs=num_input_schemas
|
||||
)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
if 'county_populations' in kwargs.keys():
|
||||
self.data = kwargs['county_populations']
|
||||
self.data = kwargs['county_populations']
|
||||
else:
|
||||
print('population initialization data not found')
|
||||
|
||||
def increment(self, **kwargs):
|
||||
data = pop_sim(self.data)
|
||||
self.data = data
|
||||
results = {'population': {'population': {'data': data, 'granularity': 'county'}}}
|
||||
results = {
|
||||
'population': {
|
||||
'population': {'data': data, 'granularity': 'county'}
|
||||
}
|
||||
}
|
||||
return results
|
||||
#is taking in the data from the previous run
|
||||
|
||||
|
||||
# is taking in the data from the previous run
|
||||
|
||||
|
||||
def main():
|
||||
wrapper = InnerWrapper()
|
||||
|
||||
@@ -8,33 +8,38 @@ Created on Wed Jul 11 14:10:24 2018
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def pow_dem_sim(pop,cons):
|
||||
#sets baseline initialization if no data received
|
||||
|
||||
def pow_dem_sim(pop, cons):
|
||||
# sets baseline initialization if no data received
|
||||
|
||||
# Must receive data as dict of {county_id: current_population, ...}
|
||||
# loads in static state values
|
||||
# simply multiplies current pop by state consumption per capita
|
||||
temp = {}
|
||||
|
||||
count = pd.DataFrame(pop,index=['pop'])
|
||||
|
||||
count = pd.DataFrame(pop, index=['pop'])
|
||||
count = count.T
|
||||
count.reset_index(inplace=True)
|
||||
count['State'] = count['index'].apply(lambda x: x[:-3])
|
||||
state_pops = count.groupby('State').sum().reset_index()
|
||||
count = pd.merge(count,state_pops,on='State',how='left')
|
||||
count = pd.merge(count, state_pops, on='State', how='left')
|
||||
count['perc'] = count.apply(lambda x: x.pop_x / x.pop_y, axis=1)
|
||||
|
||||
cons_pc = pd.DataFrame(cons,index=['cons'])
|
||||
cons_pc = pd.DataFrame(cons, index=['cons'])
|
||||
cons_pc = cons_pc.T
|
||||
|
||||
count = pd.merge(count,cons_pc.reset_index(), left_on='State',right_on='index',how='left')
|
||||
count['demand'] = count.apply(lambda x: (x.pop_y * x.cons) * x.perc,axis=1)
|
||||
count = count[['index_x','demand']].set_index('index_x')
|
||||
|
||||
count = pd.merge(
|
||||
count,
|
||||
cons_pc.reset_index(),
|
||||
left_on='State',
|
||||
right_on='index',
|
||||
how='left',
|
||||
)
|
||||
count['demand'] = count.apply(
|
||||
lambda x: (x.pop_y * x.cons) * x.perc, axis=1
|
||||
)
|
||||
count = count[['index_x', 'demand']].set_index('index_x')
|
||||
|
||||
for index, row in count.iterrows():
|
||||
temp[index] = row['demand']
|
||||
|
||||
|
||||
|
||||
return temp
|
||||
|
||||
|
||||
@@ -1,35 +1,59 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from DemandSimulation import pow_dem_sim #for water demand, going to do something similar ##
|
||||
from DemandSimulation import (
|
||||
pow_dem_sim,
|
||||
) # for water demand, going to do something similar ##
|
||||
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="power_demand", num_expected_inputs=num_input_schemas)
|
||||
super().__init__(
|
||||
model_id="power_demand", num_expected_inputs=num_input_schemas
|
||||
)
|
||||
|
||||
def configure(self, **kwargs): #this would be the water consumption rate in here
|
||||
if 'state_consumption_per_capita' in kwargs.keys(): #instead of state, do water 2015, the json we made
|
||||
self.cons = kwargs['state_consumption_per_capita'] #copy the file name
|
||||
def configure(
|
||||
self, **kwargs
|
||||
): # this would be the water consumption rate in here
|
||||
if (
|
||||
'state_consumption_per_capita' in kwargs.keys()
|
||||
): # instead of state, do water 2015, the json we made
|
||||
self.cons = kwargs[
|
||||
'state_consumption_per_capita'
|
||||
] # copy the file name
|
||||
else:
|
||||
print('State consumption data not found')
|
||||
if '2016_populations' in kwargs.keys(): #instead of 2016 populations would put the name of the 2015 water consumption rate
|
||||
if (
|
||||
'2016_populations' in kwargs.keys()
|
||||
): # instead of 2016 populations would put the name of the 2015 water consumption rate
|
||||
self.pop = kwargs['2016_populations']
|
||||
|
||||
def increment(self, **kwargs): #this is handling all the new data that is coming from other models, the whole function would be similar besides power instead of water
|
||||
def increment(
|
||||
self, **kwargs
|
||||
): # this is handling all the new data that is coming from other models, the whole function would be similar besides power instead of water
|
||||
if 'population' in kwargs.keys():
|
||||
self.pop = kwargs['population']['population']['data'] #assume you can keep as is for now and it may work
|
||||
self.pop = kwargs['population']['population'][
|
||||
'data'
|
||||
] # assume you can keep as is for now and it may work
|
||||
else:
|
||||
print('input population not found')
|
||||
demand = pow_dem_sim(self.pop, self.cons) #instead of power demand simulation, have water demand, your inputs will be population and consumption rate, #do water demand sim, #and change inputs to the actual name of our arguments
|
||||
demand = pow_dem_sim(
|
||||
self.pop, self.cons
|
||||
) # instead of power demand simulation, have water demand, your inputs will be population and consumption rate, #do water demand sim, #and change inputs to the actual name of our arguments
|
||||
|
||||
results = {'power_demand': {'power_demand': {'data': demand, 'granularity': 'county'}}} #obviously this will all say water demand isntead of power demand
|
||||
#checks to see if it has data on population, writes it to selfpop and outputs power demand
|
||||
#does not use self because it doesnt use its own previous data
|
||||
results = {
|
||||
'power_demand': {
|
||||
'power_demand': {'data': demand, 'granularity': 'county'}
|
||||
}
|
||||
} # obviously this will all say water demand isntead of power demand
|
||||
# checks to see if it has data on population, writes it to selfpop and outputs power demand
|
||||
# does not use self because it doesnt use its own previous data
|
||||
return results
|
||||
|
||||
|
||||
def main():
|
||||
wrapper = InnerWrapper()
|
||||
wrapper.run()
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"granularity": {"type": "string", "value": "NERC"}
|
||||
"granularity": {"type": "string", "value": "county"}
|
||||
}
|
||||
},
|
||||
"thermo_water": {
|
||||
"type": "object",
|
||||
"properties":{
|
||||
"data": {"type": "object"},
|
||||
"granularity": {"type": "string", "value": "NERC"}
|
||||
"granularity": {"type": "string", "value": "HUC8"}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -6,46 +6,65 @@ Created on Wed Jul 11 15:14:47 2018
|
||||
|
||||
import pandas as pd
|
||||
|
||||
def gen_sim(demand,prof):
|
||||
|
||||
|
||||
def gen_sim(demand, prof):
|
||||
|
||||
# multiply by county demand to yield county generation profile
|
||||
# aggregate up to state level to apply profile then project back down
|
||||
counties = pd.DataFrame(demand,index=['demand']).T.reset_index().rename(columns={'index':'county'})
|
||||
counties = (
|
||||
pd.DataFrame(demand, index=['demand'])
|
||||
.T.reset_index()
|
||||
.rename(columns={'index': 'county'})
|
||||
)
|
||||
counties['state'] = counties.county.apply(lambda x: x[:-3])
|
||||
state_demand = counties.groupby('state')['demand'].sum()
|
||||
state_prof = pd.DataFrame(prof).T.reset_index().rename(columns={'index':'state'})
|
||||
state_prof = (
|
||||
pd.DataFrame(prof).T.reset_index().rename(columns={'index': 'state'})
|
||||
)
|
||||
state_demand = state_demand.to_frame().reset_index()
|
||||
counties = pd.merge(counties, state_demand, on='state',how='left')
|
||||
counties = pd.merge(counties, state_prof, on='state',how='left')
|
||||
counties['Fuel Used (MMBtu)'] = counties.apply(lambda x: (x['MMBtu per MWh']) * (x.demand_x),axis=1)
|
||||
counties['CO2 Emissions (tons)'] = counties.apply(lambda x: (x['Tons CO2 per MWh']) * (x.demand_x),axis=1)
|
||||
counties['Water Used (Mgal)'] = counties.apply(lambda x: (x['Mgal_per_MWh']) * (x.demand_x),axis=1)
|
||||
counties = counties[['county','Fuel Used (MMBtu)','CO2 Emissions (tons)','Water Used (Mgal)']].set_index('county')
|
||||
|
||||
# data = counties.to_dict(orient='index')
|
||||
|
||||
counties = pd.merge(counties, state_demand, on='state', how='left')
|
||||
counties = pd.merge(counties, state_prof, on='state', how='left')
|
||||
counties['Fuel Used (MMBtu)'] = counties.apply(
|
||||
lambda x: (x['MMBtu per MWh']) * (x.demand_x), axis=1
|
||||
)
|
||||
counties['CO2 Emissions (tons)'] = counties.apply(
|
||||
lambda x: (x['Tons CO2 per MWh']) * (x.demand_x), axis=1
|
||||
)
|
||||
counties['Water Used (Mgal)'] = counties.apply(
|
||||
lambda x: (x['Mgal_per_MWh']) * (x.demand_x), axis=1
|
||||
)
|
||||
counties = counties[
|
||||
[
|
||||
'county',
|
||||
'Fuel Used (MMBtu)',
|
||||
'CO2 Emissions (tons)',
|
||||
'Water Used (Mgal)',
|
||||
]
|
||||
].set_index('county')
|
||||
|
||||
# data = counties.to_dict(orient='index')
|
||||
|
||||
co2 = {}
|
||||
h2o = {}
|
||||
for index, row in counties.iterrows():
|
||||
co2[index] = row['CO2 Emissions (tons)']
|
||||
h2o[index] = row['Water Used (Mgal)']
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
# 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
|
||||
# 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
|
||||
# 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
|
||||
|
||||
|
||||
@@ -1,14 +1,17 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from GenerationSimulation import gen_sim
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="power_supply", num_expected_inputs=num_input_schemas)
|
||||
super().__init__(
|
||||
model_id="power_supply", num_expected_inputs=num_input_schemas
|
||||
)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
if 'state_energy_profiles' in kwargs.keys():
|
||||
@@ -25,10 +28,15 @@ class InnerWrapper(OuterWrapper):
|
||||
print('input demand not found')
|
||||
emissions, water = gen_sim(self.dem, self.prof)
|
||||
|
||||
results = {'power_supply': { 'co2': {'data': emissions, 'granularity': 'county'},
|
||||
'thermo_water': {'data': water, 'granularity': 'county'}}}
|
||||
results = {
|
||||
'power_supply': {
|
||||
'co2': {'data': emissions, 'granularity': 'county'},
|
||||
'thermo_water': {'data': water, 'granularity': 'county'},
|
||||
}
|
||||
}
|
||||
return results
|
||||
|
||||
|
||||
def main():
|
||||
wrapper = InnerWrapper()
|
||||
wrapper.run()
|
||||
|
||||
@@ -6,18 +6,14 @@ import json
|
||||
import pandas as pd
|
||||
|
||||
|
||||
def Water_Demand_Simulation(countypop,rate):
|
||||
def Water_Demand_Simulation(countypop, rate):
|
||||
|
||||
water={}
|
||||
water = {}
|
||||
for i in rate.keys():
|
||||
if i in countypop.keys():
|
||||
water[i]= (countypop[i]*rate[i])
|
||||
else:
|
||||
water[i]=(0)
|
||||
#with open('water_demand_2015.json', 'w') as file:
|
||||
if i in countypop.keys():
|
||||
water[i] = countypop[i] * rate[i]
|
||||
else:
|
||||
water[i] = 0
|
||||
# with open('water_demand_2015.json', 'w') as file:
|
||||
# file.write(json.dumps(data))
|
||||
return water
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,22 +1,28 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
from Water_Demand_Model import Water_Demand_Simulation
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="water_demand", num_expected_inputs=num_input_schemas)
|
||||
super().__init__(
|
||||
model_id="water_demand", num_expected_inputs=num_input_schemas
|
||||
)
|
||||
|
||||
def configure(self, **kwargs):
|
||||
if 'rates' in kwargs.keys():
|
||||
self.rate=kwargs['rates']
|
||||
if '2016_populations' in kwargs.keys(): #instead of 2016 populations would put the name of the 2015 water consumption rate
|
||||
self.rate = kwargs['rates']
|
||||
if (
|
||||
'2016_populations' in kwargs.keys()
|
||||
): # instead of 2016 populations would put the name of the 2015 water consumption rate
|
||||
self.countypop = kwargs['2016_populations']
|
||||
#replace the populations with the 2015 water consumption rate
|
||||
#need to take out the extra variable
|
||||
|
||||
# replace the populations with the 2015 water consumption rate
|
||||
# need to take out the extra variable
|
||||
def increment(self, **kwargs):
|
||||
if 'population' in kwargs.keys():
|
||||
self.countypop = kwargs['population']['population']['data']
|
||||
@@ -24,7 +30,11 @@ class InnerWrapper(OuterWrapper):
|
||||
print('input population not found')
|
||||
demand = Water_Demand_Simulation(self.countypop, self.rate)
|
||||
|
||||
results = {'water_demand': {'water_demand': {'data': demand, 'granularity': 'county'}}}
|
||||
results = {
|
||||
'water_demand': {
|
||||
'water_demand': {'data': demand, 'granularity': 'county'}
|
||||
}
|
||||
}
|
||||
return results
|
||||
|
||||
|
||||
|
||||
@@ -1,21 +1,27 @@
|
||||
import glob
|
||||
import sys
|
||||
|
||||
sys.path.append('/')
|
||||
from outer_wrapper import OuterWrapper
|
||||
|
||||
|
||||
class InnerWrapper(OuterWrapper):
|
||||
|
||||
def __init__(self):
|
||||
num_input_schemas = len(glob.glob("/opt/schemas/input/*.json"))
|
||||
super().__init__(model_id="unique_model_name", num_expected_inputs=num_input_schemas)
|
||||
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']
|
||||
|
||||
def increment(self, **kwargs):
|
||||
return {'schema_name': {'data_variable_name': {'data': {}, 'granularity': 'county'}}}
|
||||
return {
|
||||
'schema_name': {
|
||||
'data_variable_name': {'data': {}, 'granularity': 'county'}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def main():
|
||||
|
||||
Reference in New Issue
Block a user