Skip to content

Commit

Permalink
Merge pull request #145 from nismod/update/cluster
Browse files Browse the repository at this point in the history
Update/cluster
  • Loading branch information
eggimasv committed Dec 6, 2018
2 parents 20064e1 + ca87135 commit 49899ea
Show file tree
Hide file tree
Showing 15 changed files with 708 additions and 88 deletions.
3 changes: 0 additions & 3 deletions energy_demand/assumptions/fuel_shares.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ def assign_by_fuel_tech_p(
fuel_tech_p_by['rs_space_heating'][fueltypes['gas']] = {
'boiler_condensing_gas': 0.60,
'boiler_gas': 0.37,
'stirling_micro_CHP_gas': 0.0,
'district_heating_CHP_gas': 0.03}

fuel_tech_p_by['rs_space_heating'][fueltypes['electricity']] = {
Expand All @@ -179,7 +178,6 @@ def assign_by_fuel_tech_p(
fuel_tech_p_by['rs_water_heating'][fueltypes['gas']] = {
'boiler_condensing_gas': 0.60,
'boiler_gas': 0.37,
'stirling_micro_CHP_gas': 0.0,
'district_heating_CHP_gas': 0.03}

fuel_tech_p_by['rs_water_heating'][fueltypes['electricity']] = {
Expand Down Expand Up @@ -246,7 +244,6 @@ def assign_by_fuel_tech_p(
fuel_tech_p_by['ss_water_heating'][fueltypes['gas']] = {
'boiler_condensing_gas': 0.60,
'boiler_gas': 0.37,
'stirling_micro_CHP_gas': 0.0,
'district_heating_CHP_gas': 0.03}

fuel_tech_p_by['ss_water_heating'][fueltypes['electricity']] = {
Expand Down
16 changes: 15 additions & 1 deletion energy_demand/basic/date_prop.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,25 @@

from energy_demand.basic import basic_functions

def convert_yearday_to_8760h_selection(yearday):
"""Select from 8760 hours the 24 hours of yearday
Arguments
---------
yearday : int
Range between 0 and 364
"""
hour_start = yearday * 24
hour_end = (yearday + 1) * 24

hours = range(hour_start, hour_end, 1)
return hours

def convert_h_to_day_year_and_h(hour):
"""Convert a 8760 hour in a year
to the yearday and hour of that day
Input
Arguments
-----
hour : int
Hour of 8760 hours in a year
Expand Down
3 changes: 1 addition & 2 deletions energy_demand/basic/demand_supply_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ def constrained_results(
fueltype_int = technologies[tech].fueltype_int

key_name = "{}_{}_{}".format(submodel, fueltype_str, tech_simplified)

supply_results[key_name] = fuel_tech[submodel_nr][:, fueltype_int, :]

# ---------------------------------
Expand All @@ -97,7 +96,7 @@ def constrained_results(
pass #Do not add non_heating demand for fueltype heat
else:
key_name = "{}_{}_{}".format(submodel, fueltype_str, "non_heating")

logging.info("key_name d: " + str(key_name))
# Add fuel for all regions for specific fueltype
supply_results[key_name] = non_heating_ed[submodel_nr][:, fueltype_int, :]

Expand Down
57 changes: 35 additions & 22 deletions energy_demand/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Allows to run HIRE locally outside the SMIF framework
write_national_results_amman
Note
----
Always execute from root folder. (e.g. energy_demand/energy_demand/main.py
Expand Down Expand Up @@ -78,18 +80,17 @@ def energy_demand_model(
if __name__ == "__main__":
"""
"""

# ------------------------------------------
# Local run model configuration
# ------------------------------------------

# Paths
local_data_path = os.path.abspath('data')
path_main = os.path.abspath(
os.path.join(
os.path.dirname(__file__), '..', "energy_demand/config_data"))
path_config = os.path.abspath(os.path.join(
os.path.dirname(__file__), '..', 'local_run_config_file.ini'))
#os.path.dirname(__file__), '..', 'local_run_config_file_cluster.ini'))

print("Configuration path: " + str(path_config))

# Get configuration
Expand All @@ -105,51 +106,49 @@ def energy_demand_model(

# Simulated yrs
sim_yrs = [base_yr, user_defined_simulation_end_yr]
weather_yr_scenario = 2015 # Default weather year

if len(sys.argv) > 1: #user defined arguments are provide

scenario_name = str(sys.argv[1])
weather_yr_scenario = int(sys.argv[2]) # Weather year
try:
weather_station_count_nr = int(sys.argv[3]) # Weather station cnt
except:
weather_station_count_nr = []
weather_realisation = str(sys.argv[2]) # Weather realisation
else:
scenario_name = "_run_"
weather_yr_scenario = 2015 # Default weather year
weather_station_count_nr = [] # Default weather year
weather_realisation = 'NF1'

print("Information")
print("-------------------------------------")
print("weather_yr_scenario: " + str(weather_yr_scenario))
print("weather_station_count_nr: " + str(weather_station_count_nr))
print("weather_realisation: " + str(weather_realisation))

path_weather_data = "X:/nismod/data/energy_demand/J-MARIUS_data/_weather_realisation"
#path_weather_data = "/soge-home/staff/cenv0553/_weather_realisation"

path_strategy_vars = os.path.join(local_data_path, 'energy_demand', '00_user_defined_variables')

# --- Region definition configuration
name_region_set = os.path.join(local_data_path, 'energy_demand', 'region_definitions', "lad_2016_uk_simplified.shp")

local_scenario = 'pop-a_econ-c_fuel-c'
weather_realisation = 'NF1'

name_population_dataset = os.path.join(local_data_path, 'scenarios', 'MISTRAL_pop_gva', 'data', '{}/population__lad.csv'.format(local_scenario))
name_gva_dataset = os.path.join(local_data_path, 'scenarios', 'MISTRAL_pop_gva', 'data', '{}/gva_per_head__lad_sector.csv'.format(local_scenario))
name_gva_dataset_per_head = os.path.join(local_data_path, 'scenarios', 'MISTRAL_pop_gva', 'data', '{}/gva_per_head__lad.csv'.format(local_scenario))

path_weather_data = "X:/nismod/data/energy_demand/J-MARIUS_data/_weather_realisation"

simulation_name = str(weather_realisation) + "__" + "all_stations"
#simulation_name = str(weather_realisation) + "__" + "all_stations"
simulation_name = "simulation_results"

name_scenario_run = "{}_result_local_{}".format(scenario_name, str(time.ctime()).replace(":", "_").replace(" ", "_"))

# ------------------------------------------

# --------------------
# Load all other paths
# --------------------
data['paths'] = data_loader.load_paths(path_main)
data['local_paths'] = data_loader.get_local_paths(local_data_path)
#print("data['local_paths']")
#print(data['local_paths']['data_processed'])
#raise Exception("T")

# Manually overwrriting startegy variable path
data['local_paths']['path_strategy_vars'] = path_strategy_vars

data['path_new_scenario'] = os.path.abspath(os.path.join(os.path.dirname(local_data_path), "results", name_scenario_run))
data['result_paths'] = data_loader.get_result_paths(data['path_new_scenario'])

Expand All @@ -166,7 +165,7 @@ def energy_demand_model(

reg_centroids = read_data.get_region_centroids(name_region_set)
data['reg_coord'] = basic_functions.get_long_lat_decimal_degrees(reg_centroids)
print("AA " + str(name_population_dataset))

data['scenario_data']['population'] = data_loader.read_scenario_data(name_population_dataset)

# Read GVA sector specific data
Expand Down Expand Up @@ -524,8 +523,22 @@ def energy_demand_model(
path_runs = data['result_paths']['data_results_model_runs']

print("... Start writing results to file: " + str(path_runs))
plot_only_selection = False
plot_only_selection = True
if plot_only_selection:
write_data.write_only_peak_total_regional(
sim_yr,
"only_total",
path_runs,
sim_obj.ed_fueltype_regs_yh,
'tot_fueltype_reg')

write_data.write_only_peak(
sim_yr,
"only_peak",
path_runs,
sim_obj.ed_fueltype_regs_yh,
'fueltype_reg_peak_day')

# PLot only residential total regional annual demand and
write_data.write_residential_tot_demands(
sim_yr,
Expand Down
76 changes: 38 additions & 38 deletions energy_demand/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -966,47 +966,47 @@ def aggregate_from_full_results(
"""
for enduse_array_yr, reg_fueltype_8760h in enumerate(full_sim_data):

# Test if reshaping and annual or hourly
if time_resolution == 'annual':
demand = np.sum(reg_fueltype_8760h, axis=2) # Sum all hours
elif time_resolution == '8760_h':
demand = reg_fueltype_8760h
elif time_resolution == '365_24':
demand = reg_fueltype_8760h.reshape(
reg_fueltype_8760h.shape[0],
reg_fueltype_8760h.shape[1],
365, 24)
# Test if reshaping and annual or hourly
if time_resolution == 'annual':
demand = np.sum(reg_fueltype_8760h, axis=2) # Sum all hours
elif time_resolution == '8760_h':
demand = reg_fueltype_8760h
elif time_resolution == '365_24':
demand = reg_fueltype_8760h.reshape(
reg_fueltype_8760h.shape[0],
reg_fueltype_8760h.shape[1],
365, 24)
else:
raise Exception("Provide either 'annual' or 'hourly' or '365_24'")

# Aggregate according to criteria
if per_sector:
if per_region:
if per_enduse:
pass
else:
pass
else:
raise Exception("Provide either 'annual' or 'hourly' or '365_24'")

# Aggregate according to criteria
if per_sector:
if per_region:
if per_enduse:
pass
else:
pass
if per_enduse:
pass
else:
if per_enduse:
pass
else:
pass
pass
else:
if per_region:
if per_enduse:
aggregated_container[enduse_array_yr] += demand
else:
aggregated_container += demand
else:
if per_region:
if per_enduse:
aggregated_container[enduse_array_yr] += demand
else:
aggregated_container += demand
# Sum across all regions
demand = np.sum(demand, axis=1)

# Get enduse str
enduse_str = get_enduse_from_array_nr(enduse_array_yr, lookup_enduse)

if per_enduse:
aggregated_container[enduse_str] += demand
else:
# Sum across all regions
demand = np.sum(demand, axis=1)

# Get enduse str
enduse_str = get_enduse_from_array_nr(enduse_array_yr, lookup_enduse)

if per_enduse:
aggregated_container[enduse_str] += demand
else:
aggregated_container += demand
aggregated_container += demand

return aggregated_container

0 comments on commit 49899ea

Please sign in to comment.