diff --git a/prepshot/_model/co2.py b/prepshot/_model/co2.py index ba2eafd..bb1ec05 100644 --- a/prepshot/_model/co2.py +++ b/prepshot/_model/co2.py @@ -88,10 +88,7 @@ def emission_calc_rule(self, y : int) -> poi.ConstraintIndex: A constraint of the model. """ model = self.model - return poi.quicksum( - model.carbon_capacity[y, z] - for z in model.zone - ) + return poi.quicksum(model.carbon_capacity.select(y, '*')) def emission_calc_by_zone_rule( self, y : int, z : str @@ -111,10 +108,7 @@ def emission_calc_by_zone_rule( A constraint of the model. """ model = self.model - return poi.quicksum( - model.carbon_breakdown[y, z, te] - for te in model.tech - ) + return poi.quicksum(model.carbon_breakdown.select(y, z, '*')) def carbon_breakdown( self, @@ -141,7 +135,4 @@ def carbon_breakdown( model = self.model ef = model.params['emission_factor'][te, y] dt = model.params['dt'] - return poi.quicksum( - ef * model.gen[h, m, y, z, te] * dt - for h in model.hour for m in model.month - ) + return ef * dt * poi.quicksum(model.gen.select('*', '*', y, z, te)) diff --git a/prepshot/_model/cost.py b/prepshot/_model/cost.py index 973f872..d89f397 100644 --- a/prepshot/_model/cost.py +++ b/prepshot/_model/cost.py @@ -105,8 +105,8 @@ def fuel_cost_breakdown( dt = model.params['dt'] vf = model.params['var_factor'][y] w = model.params['weight'] - return 1 / w * fp * sum(model.gen[h, m, y, z, te] - for h in model.hour for m in model.month) * dt * vf + return (1 / w * fp * dt * vf + * poi.quicksum(model.gen.select('*', '*', y, z, te))) def cost_var_line_breakdown( self, y : int, z : str, z1 : str @@ -134,9 +134,8 @@ def cost_var_line_breakdown( dt = model.params['dt'] vf = model.params['var_factor'][y] w = model.params['weight'] - return 0.5 / w * lvc * dt * vf * \ - sum(model.trans_export[h, m, y, z, z1] - for h in model.hour for m in model.month) + return (0.5 / w * lvc * dt * vf + * poi.quicksum(model.trans_export.select('*', '*', y, z, z1))) def cost_var_tech_breakdown( self, y : int, z : str, te : str @@ -163,8 +162,8 @@ def cost_var_tech_breakdown( dt = model.params['dt'] vf = model.params['var_factor'][y] w = model.params['weight'] - return 1 / w * tvc * sum(model.gen[h, m, y, z, te] - for h in model.hour for m in model.month) * dt * vf + return (1 / w * tvc * dt * vf + * poi.quicksum(model.gen.select('*', '*', y, z, te))) def cost_fix_line_breakdown( self, y : int, z : str, z1 : str diff --git a/prepshot/output_data.py b/prepshot/output_data.py index 48714a2..705fe82 100644 --- a/prepshot/output_data.py +++ b/prepshot/output_data.py @@ -41,8 +41,9 @@ def create_data_array( index_tuple = cartesian_product(*coords.values()) if len(dims) == 1: index_tuple = [i[0] for i in index_tuple] + data_values = data.map(model.get_value) data = np.array( - [model.get_value(data[tuple_]) for tuple_ in index_tuple] + [data_values[tuple_] for tuple_ in index_tuple] ).reshape([len(coord) for coord in coords.values()]) return xr.DataArray(data=data, dims=dims,