Skip to content

Commit

Permalink
fixed bug in aggregation
Browse files Browse the repository at this point in the history
  • Loading branch information
Sven Eggimann committed Mar 4, 2019
1 parent ac95e4f commit 321f8cd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 17 deletions.
23 changes: 12 additions & 11 deletions energy_demand/basic/demand_supply_interaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,6 @@ def constrained_results(
supply_results = {}
fueltypes = lookup_tables.basic_lookups()['fueltypes']

#--------------------------------
# Get all non heating related enduse
# --------------------------------
# Substract constrained fuel from nonconstrained (total) fuel
non_heating_ed_unrounded = results_unconstrained - sum(results_constrained.values())

# Remove all rounding errors
##non_heating_ed = basic_functions.remove_neg_rounding_errors(non_heating_ed_unrounded)

assert not testing_functions.test_if_minus_value_in_array(results_unconstrained)

# ----------------------------------------
# Add all constrained results (technology specific results)
# Aggregate according to submodel, fueltype, technology, region, timestep
Expand All @@ -90,6 +79,18 @@ def constrained_results(
if testing_functions.test_if_minus_value_in_array(values):
raise Exception("TTT {} {}".format(key_name, np.sum(values)))

#--------------------------------
# Get all non heating related enduse
# --------------------------------
# Substract constrained fuel from nonconstrained (total) fuel
print("AAA {} {}".format(results_unconstrained.shape()), results_constrained.shape())
non_heating_ed = results_unconstrained - sum(results_constrained.values())

# Remove all rounding errors
##non_heating_ed = basic_functions.remove_neg_rounding_errors(non_heating_ed_unrounded)

assert not testing_functions.test_if_minus_value_in_array(results_unconstrained)

# ---------------------------------
# Add non_heating for all fueltypes
# ---------------------------------
Expand Down
35 changes: 29 additions & 6 deletions energy_demand/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def __init__(
# ---------------------------------------------
# Aggregate results specifically over regions
# ---------------------------------------------
aggr_results = aggregate_results_constrained(
aggr_results = aggregate_single_region(
assumptions,
assumptions.reg_nrs,
assumptions.lookup_enduses,
Expand Down Expand Up @@ -723,7 +723,7 @@ def aggregate_result_unconstrained(

return constrained_array

def aggregate_results_constrained(
def aggregate_single_region(
assumptions,
reg_nrs,
lookup_enduses,
Expand Down Expand Up @@ -777,12 +777,13 @@ def aggregate_results_constrained(
# Iterate all simulation results
for enduse_object in all_submodels:

'''
if isinstance(get_fuels_yh(enduse_object, 'techs_fuel_yh'), dict):
techs_fueltypes_yh = get_fuels_yh(enduse_object, 'techs_fuel_yh')
enduse_array_nr = lookup_enduses[enduse_object.enduse]
submodel_nr = submodel_to_idx[enduse_object.submodel_name]
'''#----------
#----------
#SCRAP TESTING KAMEL
#----------
print("TECHNOLOGES {} {} {} {}".format(
Expand All @@ -799,7 +800,7 @@ def aggregate_results_constrained(
# -----------------------------------------------------------------
# Aggregate fuel of constrained technologies for heating
# -----------------------------------------------------------------
if mode_constrained:
'''if mode_constrained:
if enduse_object.enduse in enduse_space_heating:
#_tot_sum_constrained = 0
Expand All @@ -817,15 +818,37 @@ def aggregate_results_constrained(
aggr_results['results_constrained'][heating_tech] = np.zeros((len(submodel_to_idx), reg_nrs, fueltypes_nr, 8760), dtype="float")
aggr_results['results_constrained'][heating_tech][submodel_nr][reg_array_nr][fueltype_tech_int] += tech_fuel.reshape(8760)
#_tot_sum_constrained += tech_fuel.reshape(8760)

'''
# -----------------------------------------------------------------
# Aggregate fuel of all technologies
# -----------------------------------------------------------------
#_tot_sum_unconstrained = 0
techs_fueltypes_yh = get_fuels_yh(enduse_object, 'techs_fuel_yh')

if isinstance(techs_fueltypes_yh, dict):

enduse_array_nr = lookup_enduses[enduse_object.enduse]
submodel_nr = submodel_to_idx[enduse_object.submodel_name]

for tech, fuel_tech in techs_fueltypes_yh.items():
tech_fueltype = technologies[tech].fueltype_int

# -----------------------------------------------------------------
# Aggregate fuel of constrained technologies for heating
# -----------------------------------------------------------------
if mode_constrained:
if enduse_object.enduse in enduse_space_heating:

# Aggregate Submodel (sector) specific enduse for fueltype
if tech in aggr_results['results_constrained'].keys():
aggr_results['results_constrained'][tech][submodel_nr][reg_array_nr][tech_fueltype] += fuel_tech.reshape(8760)
#_tot_sum_constrained += tech_fuel.reshape(8760)
else:
if tech not in aggr_results['results_constrained']:
aggr_results['results_constrained'][tech] = np.zeros((len(submodel_to_idx), reg_nrs, fueltypes_nr, 8760), dtype="float")
aggr_results['results_constrained'][tech][submodel_nr][reg_array_nr][tech_fueltype] += fuel_tech.reshape(8760)

# SUm non heating techs
aggr_results['ed_enduse_fueltype_regs_yh'][enduse_array_nr][tech_fueltype][reg_array_nr] += fuel_tech.reshape(8760)
#_tot_sum_unconstrained += fuel_tech.reshape(8760)
else:
Expand Down

0 comments on commit 321f8cd

Please sign in to comment.