Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature EV controlled charging custom constraints #356

Conversation

adrienmellot
Copy link
Contributor

@adrienmellot adrienmellot commented Apr 12, 2024

Fixes #350.
Fixes #81.

Within the realm of full electrification of road transport, this PR allows the controlled charging share of this electricity demand to be constrained.

Possibly, we want to have the run.py file to be integrated in a better way, and also in workflow tests.

Checklist

Any checks which are not relevant to the PR can be pre-checked by the PR creator. All others should be checked by the reviewer. You can add extra checklist items here if required by the PR.

  • CHANGELOG updated
  • Minimal workflow tests pass
  • Tests added to cover contribution
  • Documentation updated
  • Configuration schema updated

adrienmellot and others added 16 commits April 10, 2024 18:10
Co-Authored-By: Francesco Sanvito <[email protected]>
Co-Authored-By: Francesco Sanvito <[email protected]>
Co-Authored-By: Francesco Sanvito <[email protected]>
Co-Authored-By: Francesco Sanvito <[email protected]>
Co-Authored-By: Francesco Sanvito <[email protected]>
Copy link
Member

@brynpickering brynpickering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @adrienmellot, shows how complex our EV modelling is. Too complex...?

Anyway, some reasonably major comments about reorganising file structures:

  1. run.py could be restructured into a snakemake rule script that calls constraint adding scripts on-the-fly
  2. the controlled EV annual demand and installed capacities rule should probably be split in two since they have some mutually exclusive inputs/params. They can use the same script (since they share the regionalisation step) but some parameter / wildcard is used in the script to decide whether df_demand or df_charging_potentials is generated.

config/schema.yaml Outdated Show resolved Hide resolved
rules/transport.smk Outdated Show resolved Hide resolved
rules/transport.smk Show resolved Hide resolved
rules/transport.smk Show resolved Hide resolved
scripts/transport/road_transport_controlled_charging.py Outdated Show resolved Hide resolved
scripts/transport/road_transport_controlled_charging.py Outdated Show resolved Hide resolved
scripts/transport/road_transport_controlled_constraints.py Outdated Show resolved Hide resolved
config/run.py Outdated
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest having a run.py in scripts and then a add_constraints.py in the scripts/transport/ directory. The run.py has most of the content of this file except the constraints. It then lods constraints as modules and loads them into the model:

import importlib.util


model = calliope.read_netcdf(path_to_temp_model)
model.run(build_only=True)

for file in constraint_files:
    spec=importlib.util.spec_from_file_location("constraints", file)

    # creates a new module based on spec
    constraint_adder = importlib.util.module_from_spec(spec)

    # executes the module in its own namespace
    # when a module is imported or reloaded.
    spec.loader.exec_module(constraint_adder)

    constraint_adder.add_eurocalliope_constraints(model)

new_model = model.backend.rerun()
new_model.to_netcdf(path_to_output)

Then you can have the run step be a snakemake rule with the reference to the constraint scripts in the inputs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is untested by me, loading files as modules might need some trial and error work

@adrienmellot
Copy link
Contributor Author

@brynpickering I've addressed the first part of the comments regarding style, not yet the part concerning the run.py and the file structure for the custom constraints.

Regarding your comment about splitting the controlled EV annual demand and installed capacities rule into two rules, I've discussed it with Tim and it makes life harder to split it. The reason for that is that the rule outputs one .csv file only which is later read to generate the .yaml for the model.

Splitting the rule into two would either require generating two .csv files, which makes it harder for the .yaml file to be generated afterwards (or two .yaml files, which we don't really want), or to have a rule order where one rule first generates a .csv and the second rule appends to this. All in all, a little more complex than having just one rule?

@brynpickering
Copy link
Member

OK, it's because the template filler can only handle one location-specific CSV. This probably needs fixing as it leads to quite messy implementations like this. Not something to solve in this PR!

@adrienmellot
Copy link
Contributor Author

For now custom constraints are not implemented (#385). I've thus removed the run.py file that there was to avoid any confusion. We discussed that the data processing could still be let through even though for now it is not immediately useful. I haven't updated the changelog and documentation for this PR as I don't think that it would not make much sense for now, it should probably be done once #385 is solved!

Copy link
Member

@brynpickering brynpickering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Final set of suggestions, otherwise OK to go ahead!

Comment on lines 92 to 94
country_codes=([
pycountry.countries.lookup(c).alpha_3 for c in snakemake.params.countries
]),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
country_codes=([
pycountry.countries.lookup(c).alpha_3 for c in snakemake.params.countries
]),
country_codes=utils.convert_valid_countries(snakemake.params.countries).values()

@@ -0,0 +1,103 @@
import pandas as pd
import pycountry
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
import pycountry
from eurocalliopelib import utils

@@ -368,9 +371,43 @@ properties:
motorcycles:
type: string
description: JRC-IDEES name of motorcycles.
ev-battery-sizes:
type: object
description: EV battery size per vehicle type.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Give unit here rather than as a comment in the config

@brynpickering brynpickering self-requested a review May 31, 2024 13:58
Copy link
Member

@brynpickering brynpickering left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, can't approve - it needs a changelog entry ;)

@brynpickering brynpickering self-requested a review June 6, 2024 11:31
@brynpickering brynpickering merged commit f929d09 into calliope-project:develop Jun 6, 2024
4 checks passed
jnnr pushed a commit to jnnr/euro-calliope that referenced this pull request Aug 27, 2024
…controlled-charging-constraints

Feature EV controlled charging custom constraints
jnnr pushed a commit to jnnr/euro-calliope that referenced this pull request Aug 27, 2024
…controlled-charging-constraints

Feature EV controlled charging custom constraints
jnnr pushed a commit to jnnr/euro-calliope that referenced this pull request Sep 3, 2024
…controlled-charging-constraints

Feature EV controlled charging custom constraints
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Constrain controlled charging of EVs in custom constraints Add electric vehicles with timeseries demand
3 participants