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

Monte carlo case study #78

Merged
merged 17 commits into from
Jul 31, 2024
Merged

Monte carlo case study #78

merged 17 commits into from
Jul 31, 2024

Conversation

GbotemiB
Copy link
Collaborator

This notebook describes an introduction to the Monte Carlo option in PyPSA-Earth configuration using Nigeria's power data.

@GbotemiB GbotemiB marked this pull request as ready for review February 16, 2024 11:29
"\n",
"The goal of this notebook is to analyze the results of the Monte-Carlo simulations and gain insights into the power system of Nigeria. It utilizes the Monte Carlo method to generate multiple scenarios and assess the uncertainty in the power system's performance.\n",
"\n",
"The Monte Carlo method is a statistical technique that involves running multiple simulations with randomly sampled input parameters to estimate the distribution of the output variables. By applying this method to Nigeria's power data, we can assess the reliability and robustness of the power system under different scenarios and identify potential areas for improvement.\n",
Copy link
Member

Choose a reason for hiding this comment

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

I think the method is applied rather to the model than to the data, right?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, you are right. The method is applied to the model.

Copy link
Member

Choose a reason for hiding this comment

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

Then, it would be good to revise a bit the description ;)

Copy link
Member

@ekatef ekatef left a comment

Choose a reason for hiding this comment

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

Hello @GbotemiB!

Great work! 😄 Added a couple of technical comments across the text. Two main points:

  1. would be great to briefly introduce the model to explain what exactly are we reproducing;

  2. the plots labels should be improved;

  3. we can probably think on how to make a conclusion more impressive.

What is your feeling about that?

"source": [
"## Sensitivity Analysis\n",
"\n",
"Sensitivity analysis helps us explore how variations in input parameters affect the model’s output. These inputs might include energy prices, efficiency factors, renewable energy availability, and demand patterns.\n",
Copy link
Member

Choose a reason for hiding this comment

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

It would be great to shortly introduce the model to clarify what are we actually doing.

}
],
"source": [
"import os\n",
Copy link
Member

Choose a reason for hiding this comment

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

Just a technical comment: os has been imported before.

" network = pypsa.Network(path)\n",
" network_list.append(network)\n",
"\n",
"print(\"All Networks loaded successfully\")"
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't it make sense to use logging instead of prints? We have anyway loaded logging import.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yh, Totally fine to use logging.

"metadata": {},
"outputs": [],
"source": [
"MONTE_CARLO_PYPSA_FEATURES = [\n",
Copy link
Member

Choose a reason for hiding this comment

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

Have we inherited the capitalised variable names from some previous set-up of Monte-Carlo part? Not sure they look consistent...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could make it smaller cases.

What I did was to copy the code implementation from the monte_carlo.py script

Comment on lines 449 to 466
"sns.barplot(src_beta_coefficients)\n",
"plt.title(\"Beta coefficients of the parameters\")\n",
"plt.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Here is labelling for the x-axis of the plots with regards to the selected parameters\n",
"\n",
"0: 'loads_t.p_set <br>\n",
"1: 'generators_t.p_max_pu.loc[:, n.generators.carrier == \"solar\"]'<br>\n",
"2: 'generators_t.p_max_pu.loc[:, n.generators.carrier == \"onwind\"]'<br>\n",
"3: 'generators.capital_cost.loc[n.generators.carrier == \"solar\"]'<br>\n",
"4: 'generators.capital_cost.loc[n.generators.carrier == \"onwind\"]'<br>\n",
"5: 'generators.weight.loc[n.generators.carrier == \"onwind\"]'<br>\n",
"6: 'generators.weight.loc[n.generators.carrier == \"solar\"]"
Copy link
Member

Choose a reason for hiding this comment

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

The plots labels must be fixed on the plot, otherwise it's a bit difficult to comprehend.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We might have a much larger plot if the label is inserted directly into the x-axis. I tried using labels but it took a considerably large amount of space in the plot, covering some of the bars in the plot.

I am open to different ideas.

Copy link
Member

Choose a reason for hiding this comment

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

Fair point. Can we use short yet meaningful version of the labels?

@GbotemiB
Copy link
Collaborator Author

Hi @Katia, Thanks for the review so far.

I have updated the notebook based on the review. I think the notebook is ready for another round of review.

@ekatef
Copy link
Member

ekatef commented Mar 22, 2024

Hello @GbotemiB!
Perfect, thanks a lot for introducing the changes. We are converging 🙂

A couple of additional comments, which are mainly follow-ups of our discussion.

Tutorial notebook

  1. It could be probably easier for a reader to get the whole picture if we would organise the plots in a facet-like structure. It can be archived for example by using subplot methods of mathplotlib.
  2. Agree that the negative objective values are of concern, so it could make sense to address this issue (tracked as this PR and issue a dedicated PR ) to make the notebook look nice and avoid confusing notebook users.

Sensitivity analysis notebook

  1. I wonder if it could make sense to briefly explain how exactly the base case Nigeria simulation is designed? Not sure if it's obvious if you are out of this modeling flow (like ourselves in a couple of months ;) ). I see the following possible ways to improve clarity:
    • add a link to the paper;
    • provide a configuration file;
    • insert a small plot of the network.
      The list is by no means exhaustive, and feel free to consider also other ways.
  2. In my perception, replacing plot labels with the text has improved the clarity significantly. Could we probably make the next iteration making the labels "nicer" and explaining what do they mean?

What do you think?

@GbotemiB
Copy link
Collaborator Author

Hello @ekatef, Thank you very much for the comment. I will let you know when I have updated the notebook based on the review.

@GbotemiB
Copy link
Collaborator Author

GbotemiB commented Apr 8, 2024

Hi @ekatef,

I have made some recent changes to the notebook, happy to have you review them.

@GbotemiB
Copy link
Collaborator Author

Following the negative objective issue pypsa-meets-earth/pypsa-earth#961, there seems to be a significant change in the charts for the monte-carlo objectives from the notebook.

image

@ekatef
Copy link
Member

ekatef commented Jun 10, 2024

Perfect, thanks a lot for the updates @GbotemiB!

Adding a review on the PR (sorry for taking so long for the next iteration):

  1. My feeling is that presentation of the method could be more precise. Currently, we state in the both notebooks that Monte-Carlo approach is needed to estimate the distribution of the output variables. That is true, of course, but may need some clarifications and additions.

  2. Explanations can be probably improved a bit in these fragments:

  • assess the uncertainty in the power system's performance;
  • reliability and robustness of the power system.
    I'd say that M-C approach allows to address the model features: the uncertainty is basically modeling uncertainty, while reliability and robustness relate rather to the model rather than to the power system itself. Does it make sense for you?
  1. If feels like the flow could be probably made smoother in this paragraph:Decision-makers use this information to understand the implications of different choices on system performance and costs. Energy models inform policy decisions. Sensitivity analysis helps policymakers understand which factors drive energy transitions. (Happy to discuss on that)

  2. A part of the path seems to be hard-coded (mc part) in a few places, e.g. f"mc/pypsa-earth/results/NG/networks/elec_s_10_ec_lcopt_Co2L-24H_m{count}.nc".

  3. Would be nice to have a header when loading a network (just before # load the config file used for the Monte-Carlo simulation).

  4. Probably, we can also add some words here and under Loading simulation results to explain which exactly results are we loading.

  5. Here is labelling for the x-axis of the plots with regards to the selected parameters -- perfect! Looks clear and consistent now. Can we elaborate a bit on human-redable explanation for each of the parameters in Config Parameters section? I mean that it would be nice to

  6. Correlations are calculated against the objective function, right? Would be great to state is explicitly somewhere along the case-study notebook.

@ekatef
Copy link
Member

ekatef commented Jun 10, 2024

@GbotemiB a really great work!

Would be great to address the points above to make the notebooks shine. But the current explanations are still good enough to help start with Monte-Carlo in PyPSA-Earth. So, not much is left to finalise the tutorials :)

@GbotemiB
Copy link
Collaborator Author

Thanks for the review @ekatef.

I have factored all the changes into the notebooks.

  1. If feels like the flow could be probably made smoother in this paragraph:Decision-makers use this information to understand the implications of different choices on system performance and costs. Energy models inform policy decisions. Sensitivity analysis helps policymakers understand which factors drive energy transitions. (Happy to discuss on that)

I also made changes to this. But, feel free to revise.

Once again, thanks for the review.

Well, We wont still be able to proceed with the merge until the negative objective issue is solved, which is fine.

@GbotemiB
Copy link
Collaborator Author

@ekatef
I have made recent changes to the notebooks with some code revisions to remove hard coding.

I think we are getting closer.

@ekatef
Copy link
Member

ekatef commented Jul 15, 2024

Hello @GbotemiB, brilliant work! Agree, we are almost there 😄

I have a few final comments which mainly relate to polishing of the description in monte_carlo_case_study_nigeria_data.ipynb.

  1. Not sure about presentation of weightings under 5 & 6: Generator Weight (Solar/Wind):

These parameters assign a weighting to solar and wind generators. This weight can be used in optimization to prioritize or penalize certain types of generation based on various criteria, such as cost-effectiveness, reliability, or environmental impact.

Agree that it's a usual and general description of how weights are normally used, but in case of wind and solar, I'd rather say that generator weight rather account for the dynamics of renewable potential.

  1. Description of Sensitivity Analysis sounds great, but it may feel a bit repetitive in some parts, especially when we are talking about decision making. Can you please go through it and make the flow a bit smoother?

  2. The fragment can assess the reliability and robustness of the model under different scenarios and identify potential areas for improvement: not sure what is mean by potential areas of improvement. Can we add a couple of clarifying words, like interprete the results in a meaningful way or exclude and identify potential areas for improvement?

  3. The fragment: The simulation results is based on the monte-carlo configuration defined in the monte_carlo_tutorial notebook focusing on the Nigeria power data. This allows to analyse and interprete the results. It feels like some details can be added there for more clarity, for example interprete the results in a meaningful way.

Could you please look into these points? You have done a really nice work and it would be great to polish it presentation.

@GbotemiB
Copy link
Collaborator Author

Thanks @ekatef for the review. I will let you know when the changes are ready.

@ekatef
Copy link
Member

ekatef commented Jul 31, 2024

Hello @GbotemiB!
Thanks a lot for the revisions! Both notebooks look really great now, and the PR is ready to merge.

@ekatef ekatef merged commit 394eb5a into pypsa-meets-earth:main Jul 31, 2024
2 checks passed
@ekatef
Copy link
Member

ekatef commented Jul 31, 2024

Merged 😄
Many thanks for an amazing contribution @GbotemiB!! 🎉 🎉 🎉

@GbotemiB
Copy link
Collaborator Author

@ekatef
Thanks a lot for the support.

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.

2 participants