|
9 | 9 |
|
10 | 10 | from __future__ import annotations |
11 | 11 |
|
12 | | -from typing import cast |
13 | | - |
14 | 12 | import numpy as np |
15 | 13 | import xarray as xr |
16 | 14 |
|
@@ -143,98 +141,15 @@ def emission( |
143 | 141 | from muse.utilities import broadcast_techs |
144 | 142 |
|
145 | 143 | # just in case we are passed a technologies dataset, like in other functions |
146 | | - fouts = broadcast_techs( |
147 | | - getattr(fixed_outputs, "fixed_outputs", fixed_outputs), production |
148 | | - ) |
| 144 | + fixed_outputs = getattr(fixed_outputs, "fixed_outputs", fixed_outputs) |
| 145 | + fouts = broadcast_techs(fixed_outputs, production) |
149 | 146 | envs = is_pollutant(fouts.comm_usage) |
150 | 147 | enduses = is_enduse(fouts.comm_usage) |
151 | 148 | return production.sel(commodity=enduses).sum("commodity") * broadcast_timeslice( |
152 | 149 | fouts.sel(commodity=envs), level=timeslice_level |
153 | 150 | ) |
154 | 151 |
|
155 | 152 |
|
156 | | -def gross_margin( |
157 | | - technologies: xr.Dataset, |
158 | | - capacity: xr.DataArray, |
159 | | - prices: xr.Dataset, |
160 | | - timeslice_level: str | None = None, |
161 | | -) -> xr.DataArray: |
162 | | - """The percentage of revenue after direct expenses have been subtracted. |
163 | | -
|
164 | | - .. _reference: |
165 | | - https://www.investopedia.com/terms/g/grossmargin.asp |
166 | | - We first calculate the revenues, which depend on prices |
167 | | - We then deduct the direct expenses |
168 | | - - energy commodities INPUTS are related to fuel costs |
169 | | - - environmental commodities OUTPUTS are related to environmental costs |
170 | | - - variable costs is given as technodata inputs |
171 | | - - non-environmental commodities OUTPUTS are related to revenues. |
172 | | - """ |
173 | | - from muse.commodities import is_enduse, is_pollutant |
174 | | - from muse.utilities import broadcast_techs |
175 | | - |
176 | | - tech = broadcast_techs( # type: ignore |
177 | | - cast( |
178 | | - xr.Dataset, |
179 | | - technologies[ |
180 | | - [ |
181 | | - "technical_life", |
182 | | - "interest_rate", |
183 | | - "var_par", |
184 | | - "var_exp", |
185 | | - "fixed_outputs", |
186 | | - "fixed_inputs", |
187 | | - ] |
188 | | - ], |
189 | | - ), |
190 | | - capacity, |
191 | | - ) |
192 | | - |
193 | | - var_par = tech.var_par |
194 | | - var_exp = tech.var_exp |
195 | | - fixed_outputs = tech.fixed_outputs |
196 | | - fixed_inputs = tech.fixed_inputs |
197 | | - # We separate the case where we have one or more regions |
198 | | - caparegions = np.array(capacity.region.values).reshape(-1) |
199 | | - if len(caparegions) > 1: |
200 | | - prices.sel(region=capacity.region) |
201 | | - else: |
202 | | - prices = prices.where(prices.region == capacity.region, drop=True) |
203 | | - prices = prices.interp(year=capacity.year.values) |
204 | | - |
205 | | - # Filters for pollutants and output commodities |
206 | | - environmentals = is_pollutant(technologies.comm_usage) |
207 | | - enduses = is_enduse(technologies.comm_usage) |
208 | | - |
209 | | - # Variable costs depend on factors such as labour |
210 | | - variable_costs = distribute_timeslice( |
211 | | - var_par * ((fixed_outputs.sel(commodity=enduses)).sum("commodity")) ** var_exp, |
212 | | - level=timeslice_level, |
213 | | - ) |
214 | | - |
215 | | - # The individual prices are selected |
216 | | - # costs due to consumables, direct inputs |
217 | | - consumption_costs = ( |
218 | | - prices * distribute_timeslice(fixed_inputs, level=timeslice_level) |
219 | | - ).sum("commodity") |
220 | | - # costs due to pollutants |
221 | | - production_costs = prices * distribute_timeslice( |
222 | | - fixed_outputs, level=timeslice_level |
223 | | - ) |
224 | | - environmental_costs = (production_costs.sel(commodity=environmentals)).sum( |
225 | | - "commodity" |
226 | | - ) |
227 | | - # revenues due to product sales |
228 | | - revenues = (production_costs.sel(commodity=enduses)).sum("commodity") |
229 | | - |
230 | | - # Gross margin is the net between revenues and all costs |
231 | | - result = revenues - environmental_costs - variable_costs - consumption_costs |
232 | | - |
233 | | - # Gross margin is defined as a ratio on revenues and as a percentage |
234 | | - result *= 100 / revenues |
235 | | - return result |
236 | | - |
237 | | - |
238 | 153 | def consumption( |
239 | 154 | technologies: xr.Dataset, |
240 | 155 | production: xr.DataArray, |
@@ -352,8 +267,8 @@ def maximum_production( |
352 | 267 | capa = filter_input( |
353 | 268 | capacity, **{k: v for k, v in filters.items() if k in capacity.dims} |
354 | 269 | ) |
355 | | - btechs = broadcast_techs( # type: ignore |
356 | | - cast(xr.Dataset, technologies[["fixed_outputs", "utilization_factor"]]), capa |
| 270 | + btechs = broadcast_techs( |
| 271 | + technologies[["fixed_outputs", "utilization_factor"]], capa |
357 | 272 | ) |
358 | 273 | ftechs = filter_input( |
359 | 274 | btechs, **{k: v for k, v in filters.items() if k in btechs.dims} |
@@ -470,12 +385,8 @@ def minimum_production( |
470 | 385 | if "minimum_service_factor" not in technologies: |
471 | 386 | return broadcast_timeslice(xr.zeros_like(capa), level=timeslice_level) |
472 | 387 |
|
473 | | - btechs = broadcast_techs( # type: ignore |
474 | | - cast( |
475 | | - xr.Dataset, |
476 | | - technologies[["fixed_outputs", "minimum_service_factor"]], |
477 | | - ), |
478 | | - capa, |
| 388 | + btechs = broadcast_techs( |
| 389 | + technologies[["fixed_outputs", "minimum_service_factor"]], capa |
479 | 390 | ) |
480 | 391 | ftechs = filter_input( |
481 | 392 | btechs, **{k: v for k, v in filters.items() if k in btechs.dims} |
|
0 commit comments