Skip to content

Commit 2d70544

Browse files
committed
Remove code, reorder
1 parent eb4ddf5 commit 2d70544

File tree

1 file changed

+48
-73
lines changed

1 file changed

+48
-73
lines changed

src/muse/costs.py

Lines changed: 48 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -84,35 +84,32 @@ def net_present_value(
8484
"""
8585
from muse.quantities import production_amplitude
8686

87-
# Filtering of the inputs
88-
techs = technologies[
89-
[
90-
"technical_life",
91-
"interest_rate",
92-
"cap_par",
93-
"cap_exp",
94-
"var_par",
95-
"var_exp",
96-
"fix_par",
97-
"fix_exp",
98-
"fixed_outputs",
99-
"utilization_factor",
100-
]
101-
]
102-
10387
# Filters
10488
environmentals = is_pollutant(technologies.comm_usage)
10589
material = is_material(technologies.comm_usage)
10690
products = is_enduse(technologies.comm_usage)
10791
fuels = is_fuel(technologies.comm_usage)
10892

93+
# Evolution of rates with time
94+
life = technologies.technical_life.astype(int)
95+
iyears = range(life.values.max())
96+
years = xr.DataArray(iyears, coords={"year": iyears}, dims="year")
97+
rates = broadcast_timeslice(
98+
discount_factor(
99+
years=years,
100+
interest_rate=technologies.interest_rate,
101+
mask=years <= life,
102+
),
103+
level=timeslice_level,
104+
)
105+
109106
# Revenue (annual)
110107
prices_non_env = filter_input(prices, commodity=products)
111108
revenues = (production * prices_non_env).sum("commodity")
112109

113110
# Cost of installed capacity
114111
installed_capacity_costs = distribute_timeslice(
115-
techs.cap_par * (capacity**techs.cap_exp), level=timeslice_level
112+
technologies.cap_par * (capacity**technologies.cap_exp), level=timeslice_level
116113
)
117114

118115
# Cost related to environmental products (annual)
@@ -129,26 +126,15 @@ def net_present_value(
129126

130127
# Fixed costs (annual)
131128
fixed_costs = distribute_timeslice(
132-
techs.fix_par * (capacity**techs.fix_exp), level=timeslice_level
129+
technologies.fix_par * (capacity**technologies.fix_exp), level=timeslice_level
133130
)
134131

135132
# Variable costs (annual)
136-
tech_activity = production_amplitude(production, techs, timeslice_level)
133+
tech_activity = production_amplitude(production, technologies, timeslice_level)
137134
variable_costs = broadcast_timeslice(
138-
techs.var_par, level=timeslice_level
139-
) * tech_activity ** broadcast_timeslice(techs.var_exp, level=timeslice_level)
140-
141-
# Evolution of rates with time
142-
life = techs.technical_life.astype(int)
143-
iyears = range(life.values.max())
144-
years = xr.DataArray(iyears, coords={"year": iyears}, dims="year")
145-
rates = broadcast_timeslice(
146-
discount_factor(
147-
years=years,
148-
interest_rate=techs.interest_rate,
149-
mask=years <= life,
150-
),
151-
level=timeslice_level,
135+
technologies.var_par, level=timeslice_level
136+
) * tech_activity ** broadcast_timeslice(
137+
technologies.var_exp, level=timeslice_level
152138
)
153139

154140
# Total costs
@@ -270,34 +256,33 @@ def levelized_cost_of_energy(
270256
if method not in ["lifetime", "annual"]:
271257
raise ValueError("method must be either 'lifetime' or 'annual'.")
272258

273-
techs = technologies[
274-
[
275-
"technical_life",
276-
"interest_rate",
277-
"cap_par",
278-
"cap_exp",
279-
"var_par",
280-
"var_exp",
281-
"fix_par",
282-
"fix_exp",
283-
"fixed_outputs",
284-
"utilization_factor",
285-
]
286-
]
287-
288259
# Filters
289260
environmentals = is_pollutant(technologies.comm_usage)
290261
material = is_material(technologies.comm_usage)
291262
products = is_enduse(technologies.comm_usage)
292263
fuels = is_fuel(technologies.comm_usage)
293264

265+
# Evolution of rates with time
266+
if method == "lifetime":
267+
life = technologies.technical_life.astype(int)
268+
iyears = range(life.values.max())
269+
years = xr.DataArray(iyears, coords={"year": iyears}, dims="year")
270+
rates = discount_factor(
271+
years=years,
272+
interest_rate=technologies.interest_rate,
273+
mask=years <= life,
274+
)
275+
else:
276+
rates = xr.DataArray([1], coords={"year": [0]}, dims="year")
277+
rates = broadcast_timeslice(rates, level=timeslice_level)
278+
294279
# Cost of installed capacity
295280
installed_capacity_costs = distribute_timeslice(
296-
techs.cap_par * (capacity**techs.cap_exp), level=timeslice_level
281+
technologies.cap_par * (capacity**technologies.cap_exp), level=timeslice_level
297282
)
298283
if method == "annual":
299284
installed_capacity_costs /= broadcast_timeslice(
300-
techs.technical_life, level=timeslice_level
285+
technologies.technical_life, level=timeslice_level
301286
)
302287

303288
# Cost related to environmental products (annual)
@@ -314,28 +299,23 @@ def levelized_cost_of_energy(
314299

315300
# Fixed costs (annual)
316301
fixed_costs = distribute_timeslice(
317-
techs.fix_par * (capacity**techs.fix_exp), level=timeslice_level
302+
technologies.fix_par * (capacity**technologies.fix_exp), level=timeslice_level
318303
)
319304

320305
# Variable costs (annual)
321-
tech_activity = production_amplitude(production, techs, timeslice_level)
306+
tech_activity = production_amplitude(production, technologies, timeslice_level)
322307
variable_costs = broadcast_timeslice(
323-
techs.var_par, level=timeslice_level
324-
) * tech_activity ** broadcast_timeslice(techs.var_exp, level=timeslice_level)
308+
technologies.var_par, level=timeslice_level
309+
) * tech_activity ** broadcast_timeslice(
310+
technologies.var_exp, level=timeslice_level
311+
)
325312

326-
# Evolution of rates with time
327-
if method == "lifetime":
328-
life = techs.technical_life.astype(int)
329-
iyears = range(life.values.max())
330-
years = xr.DataArray(iyears, coords={"year": iyears}, dims="year")
331-
rates = discount_factor(
332-
years=years,
333-
interest_rate=techs.interest_rate,
334-
mask=years <= life,
335-
)
336-
else:
337-
rates = xr.DataArray([1], coords={"year": [0]}, dims="year")
338-
rates = broadcast_timeslice(rates, level=timeslice_level)
313+
# Production (annual)
314+
prod = (
315+
production.where(production > 0.0, 1e-6)
316+
.sel(commodity=products)
317+
.sum("commodity")
318+
)
339319

340320
# Total costs
341321
total_costs = installed_capacity_costs + (
@@ -349,12 +329,7 @@ def levelized_cost_of_energy(
349329
* rates
350330
).sum("year")
351331

352-
# Production
353-
prod = (
354-
production.where(production > 0.0, 1e-6)
355-
.sel(commodity=products)
356-
.sum("commodity")
357-
)
332+
# Total production
358333
total_prod = (prod * rates).sum("year")
359334

360335
# LCOE

0 commit comments

Comments
 (0)