pypsa-eur
pypsa-eur copied to clipboard
Refactor `prepare_costs`
prepare_costs can cause confusion.
Suggestion is to refactor to make the logic more clear and maintainable.
Spun from #1879
The prepare_costs function do the following:
- Enforce unit convention > this could be delegated to technology-data
- Fill missing values
- Overwrite values if applicable (raw values) > removing the deprecated code will make the code leaner
- Compute capital and marginal costs
- Assign OCGT and CCGT fuel cost and CO2 intensity using the gas values
- Define the
solarcapital cost usingsolar-utilityassumption - Rename
solar-utility single-axis trackingtosolar-hsat> this could be delegated to technology-datastanding lossestostanding_losses> this could be delegated to technology-data
- Calculate storage costs for H2 and batteries
- Overwrite values if applicable (processed values, i.e. marginal and capital costs)
We could make things clearer with
def prepare_costs(...):
# Stage 1: Apply custom costs to raw attributes (before computation)
costs = fill_missing_values(costs, config)
costs = apply_custom_costs(costs, custom_raw)
# Compute derived costs from raw attributes
costs = compute_derived_costs(costs, config, nyears)
costs = calculate_storage_costs(costs, max_hours)
# Stage 2: Apply custom costs to computed attributes (after computation)
costs = apply_custom_costs(costs, custom_prepared)
return costs
However, if we want to maintain the same set of attributes, I think that the two-stage overwrite must be kept. Better logging could help as well.
Sounds good the way @tgilon describes it.