diff --git a/hypatia/backend/Build.py b/hypatia/backend/Build.py index 5e59b69..ee169e6 100644 --- a/hypatia/backend/Build.py +++ b/hypatia/backend/Build.py @@ -486,19 +486,6 @@ def _calc_variable_planning(self): self.sets.data[reg]["inv_taxsub"]["Sub"][key], ) - salvage_inv_regional[key] = cp.multiply( - salvage_factor( - self.sets.main_years, - self.sets.Technologies[reg][key], - self.sets.data[reg]["tech_lifetime"].loc[:, key], - self.sets.data[reg]["interest_rate"].loc[:, key], - self.sets.data[reg]["discount_rate"], - self.sets.data[reg]["economic_lifetime"].loc[:, key], - self.sets.period_step - ), - cost_inv_regional[key], - ) - accumulated_newcapacity_regional[key] = newcap_accumulated( self.variables["newcapacity"][reg][key], self.sets.Technologies[reg][key], @@ -523,18 +510,7 @@ def _calc_variable_planning(self): self.sets.data[reg]["fix_taxsub"]["Sub"][key], ) - decomcapacity_regional[key] = decomcap( - self.variables["newcapacity"][reg][key], - self.sets.Technologies[reg][key], - self.sets.main_years, - self.sets.data[reg]["tech_lifetime"].loc[:, key], - self.sets.period_step, - ) - cost_decom_regional[key] = cp.multiply( - self.sets.data[reg]["tech_decom_cost"].loc[:, key].values, - decomcapacity_regional[key], - ) production_annual_regional[key] = annual_activity( self.variables["productionbyTechnology"][reg][key], @@ -568,16 +544,45 @@ def _calc_variable_planning(self): CO2_equivalent_regional[key], self.sets.data[reg]["carbon_tax"].loc[:, key], ) + + if not self.sets.snapshot: + + salvage_inv_regional[key] = cp.multiply( + salvage_factor( + self.sets.main_years, + self.sets.Technologies[reg][key], + self.sets.data[reg]["tech_lifetime"].loc[:, key], + self.sets.data[reg]["interest_rate"].loc[:, key], + self.sets.data[reg]["discount_rate"], + self.sets.data[reg]["economic_lifetime"].loc[:, key], + self.sets.period_step + ), + cost_inv_regional[key], + ) + + decomcapacity_regional[key] = decomcap( + self.variables["newcapacity"][reg][key], + self.sets.Technologies[reg][key], + self.sets.main_years, + self.sets.data[reg]["tech_lifetime"].loc[:, key], + self.sets.period_step, + ) + + cost_decom_regional[key] = cp.multiply( + self.sets.data[reg]["tech_decom_cost"].loc[:, key].values, + decomcapacity_regional[key], + ) + + cost_fvalue_regional[key] = invcosts_annuity( + cost_inv_regional[key], + self.sets.data[reg]["interest_rate"].loc[:, key], + self.sets.data[reg]["economic_lifetime"].loc[:, key], + self.sets.Technologies[reg][key], + self.sets.main_years, + self.sets.data[reg]["discount_rate"], + self.sets.period_step + ) - cost_fvalue_regional[key] = invcosts_annuity( - cost_inv_regional[key], - self.sets.data[reg]["interest_rate"].loc[:, key], - self.sets.data[reg]["economic_lifetime"].loc[:, key], - self.sets.Technologies[reg][key], - self.sets.main_years, - self.sets.data[reg]["discount_rate"], - self.sets.period_step - ) self.cost_inv[reg] = cost_inv_regional self.cost_inv_tax[reg] = cost_inv_tax_regional @@ -646,20 +651,7 @@ def _calc_variable_planning_line(self): + self.sets.trade_data["line_residual_cap"].loc[:, line].values ) - self.line_decommissioned_capacity[line] = line_decomcap( - self.line_newcapacity[line], - self.sets.trade_line[line], - self.sets.main_years, - self.sets.trade_data["line_lifetime"].loc[:, line], - self.sets.period_step, - ) - self.cost_decom_line[line] = cp.multiply(cp.multiply( - self.sets.trade_data["line_decom_cost"].loc[:, line].values, - self.line_decommissioned_capacity[line], - ), self.sets.trade_data["line_length"].loc[:,line].values) - - self.cost_inv_line[line] = cp.multiply(cp.multiply(self.sets.trade_data["line_inv_{}".format(self.sets.sizes[0])].loc[:,line].values , self.variables["line_newcapacity_lump"][self.sets.sizes[0]][line]), @@ -681,19 +673,33 @@ def _calc_variable_planning_line(self): self.variables["line_newcapacity_lump"][size][line]), self.sets.trade_data["line_length"].loc[:,line].values) - self.salvage_inv_line[line] = cp.multiply( - salvage_factor_line( + + if not self.sets.snapshot: + self.line_decommissioned_capacity[line] = line_decomcap( + self.line_newcapacity[line], + self.sets.trade_line[line], self.sets.main_years, - carr_list, self.sets.trade_data["line_lifetime"].loc[:, line], - self.sets.trade_data["interest_rate"].loc[:, line], - self.sets.global_data["global_discount_rate"], - self.sets.trade_data["line_economic_lifetime"].loc[:, line], - self.sets.period_step - ), - self.cost_inv_line[line], + self.sets.period_step, ) - + + self.cost_decom_line[line] = cp.multiply(cp.multiply( + self.sets.trade_data["line_decom_cost"].loc[:, line].values, + self.line_decommissioned_capacity[line], + ), self.sets.trade_data["line_length"].loc[:,line].values) + + self.salvage_inv_line[line] = cp.multiply( + salvage_factor_line( + self.sets.main_years, + carr_list, + self.sets.trade_data["line_lifetime"].loc[:, line], + self.sets.trade_data["interest_rate"].loc[:, line], + self.sets.global_data["global_discount_rate"], + self.sets.trade_data["line_economic_lifetime"].loc[:, line], + self.sets.period_step + ), + self.cost_inv_line[line], + ) self.cost_variable_line = line_varcost( self.sets.trade_data["line_var_cost"], @@ -1605,24 +1611,38 @@ def _set_regional_objective_planning(self): # axis=1, # ) - totalcost_regional += cp.sum( - self.cost_inv_tax[reg][ctgry] - - self.cost_inv_sub[reg][ctgry] - + self.cost_fix[reg][ctgry] - + self.cost_fix_tax[reg][ctgry] - - self.cost_fix_sub[reg][ctgry] - + self.cost_variable_annual[reg][ctgry] - + self.cost_decom[reg][ctgry] - - self.salvage_inv[reg][ctgry], - axis=1, - ) - + if not self.sets.snapshot: + + totalcost_regional += cp.sum( + self.cost_inv_tax[reg][ctgry] + - self.cost_inv_sub[reg][ctgry] + + self.cost_fix[reg][ctgry] + + self.cost_fix_tax[reg][ctgry] + - self.cost_fix_sub[reg][ctgry] + + self.cost_variable_annual[reg][ctgry] + + self.cost_decom[reg][ctgry] + - self.salvage_inv[reg][ctgry], + axis=1, + ) + + + self.inv_allregions += self.cost_inv_fvalue[reg][ctgry] + + + else: + + totalcost_regional += cp.sum( + self.cost_inv_tax[reg][ctgry] + - self.cost_inv_sub[reg][ctgry] + + self.cost_fix[reg][ctgry] + + self.cost_fix_tax[reg][ctgry] + - self.cost_fix_sub[reg][ctgry] + + self.cost_variable_annual[reg][ctgry], + + axis=1, + ) #total_salvage_regional += cp.sum(self.salvage_inv[reg][ctgry], axis =1) - - - - self.inv_allregions += self.cost_inv_fvalue[reg][ctgry] if ctgry != "Transmission" and ctgry != "Storage": @@ -1688,16 +1708,25 @@ def _set_lines_objective_planning(self): #self.total_salvage_line = np.zeros((len(self.sets.main_years), 1)) for line in self.sets.trade_line.keys(): - - self.totalcost_lines += cp.sum( - self.cost_inv_line[line] - + self.cost_fix_line[line] - + self.cost_decom_line[line] - - self.salvage_inv_line[line], - axis=1, - ) - + if not self.sets.snapshot: + + self.totalcost_lines += cp.sum( + self.cost_inv_line[line] + + self.cost_fix_line[line] + + self.cost_decom_line[line] + - self.salvage_inv_line[line], + axis=1, + ) + + else: + + self.totalcost_lines += cp.sum( + self.cost_inv_line[line] + + self.cost_fix_line[line], + axis=1, + ) + #self.total_salvage_line += cp.sum(self.salvage_inv_line[line],axis=1) for reg_ in self.sets.trade_regions.keys(): diff --git a/hypatia/backend/StrData.py b/hypatia/backend/StrData.py index ea4c3cb..7aa66ab 100644 --- a/hypatia/backend/StrData.py +++ b/hypatia/backend/StrData.py @@ -85,11 +85,12 @@ class ReadSets: A nested dictionary for storing the regional data """ - def __init__(self, path, mode="Planning", period_step = 1): + def __init__(self, path, mode="Planning", period_step = 1, snapshot=False): self.mode = mode self.path = path self.period_step = period_step + self.snapshot = snapshot self._init_by_xlsx() diff --git a/hypatia/core/main.py b/hypatia/core/main.py index 4b76ecc..201edab 100644 --- a/hypatia/core/main.py +++ b/hypatia/core/main.py @@ -34,7 +34,7 @@ class Model: A Hypatia Model """ - def __init__(self, path, mode, name="unknown", period_step=1): + def __init__(self, path, mode, name="unknown", period_step=1,snapshot=False): """Initializes a Hypatia model by passing the optimization mode and the path of the structural input files diff --git a/test.py b/test.py index 06b3465..1732ae6 100644 --- a/test.py +++ b/test.py @@ -10,16 +10,16 @@ #%% test = Model( - path = 'test/Trilateral/tests/test_DS/central_offshore_offshore_final/sets', - mode = 'Planning', period_step = 10) + path = 'test/Trilateral/tests/test_snapshot/dummy/sets', + mode = 'Planning', period_step = 1, snapshot=True) #%% -#test.create_data_excels(path = 'test/Trilateral/tests/test_DS/central_offshore_offshore_final/parameters') +test.create_data_excels(path = 'test/Trilateral/tests/test_snapshot/dummy/parameters') #%% test.read_input_data( - path = 'test/Trilateral/tests/test_DS/central_offshore_offshore_final/parameters_new' + path = 'test/Trilateral/tests/test_snapshot/dummy/parameters' ) #%% -test.resample_input_data(downsample=2) +#test.resample_input_data(downsample=2) #%% #import gurobipy