From 0d0aae405c5896cafe60ba831fd249ce327bce07 Mon Sep 17 00:00:00 2001 From: mal84emma Date: Sat, 25 Jan 2025 12:26:44 +0000 Subject: [PATCH] Generalise to plots with multiple techs --- analysis/plot_scenario_operation.ipynb | 48 +++++++++++++++++--------- requirements.txt | 1 + 2 files changed, 33 insertions(+), 16 deletions(-) diff --git a/analysis/plot_scenario_operation.ipynb b/analysis/plot_scenario_operation.ipynb index 14760e0a..8590c64d 100644 --- a/analysis/plot_scenario_operation.ipynb +++ b/analysis/plot_scenario_operation.ipynb @@ -9,7 +9,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 1, "metadata": {}, "outputs": [], "source": [ @@ -20,7 +20,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 2, "metadata": {}, "outputs": [], "source": [ @@ -45,28 +45,38 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 3, "metadata": {}, "outputs": [], "source": [ - "expt_id = 1\n", + "expt_id = 'two_techs'\n", + "techs = ['CAES','Li-ion']" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": {}, + "outputs": [], + "source": [ + "techs_str = '-'.join(techs)\n", "settings, base_params = get_experiment_config(expt_id)\n", "available_technologies = list(settings['probability_settings']['storage'].keys())" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 5, "metadata": {}, "outputs": [], "source": [ - "design_fpath = os.path.join(*settings['results_dir'],'prior','CAES_design.yaml')\n", + "design_fpath = os.path.join(*settings['results_dir'],'prior',f'{techs_str}_design.yaml')\n", "scenario_fpaths = [os.path.join(*settings['scenarios_dir'],'thetas','scenario_0.yaml')]" ] }, { "cell_type": "code", - "execution_count": null, + "execution_count": 6, "metadata": {}, "outputs": [], "source": [ @@ -104,7 +114,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 9, "metadata": {}, "outputs": [], "source": [ @@ -146,7 +156,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 12, "metadata": {}, "outputs": [], "source": [ @@ -157,7 +167,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -204,7 +214,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ @@ -214,7 +224,7 @@ }, { "cell_type": "code", - "execution_count": null, + "execution_count": 16, "metadata": {}, "outputs": [], "source": [ @@ -233,9 +243,11 @@ "\n", "fig = add_profile(fig, scenario.load[:solved_model.T]/1e3, name='Plant',\n", " legendgroup='load', legendgrouptitle_text='Load',\n", + " visible='legendonly',\n", " line=dict(color='black', width=2.5, dash='dash'), zorder=10)\n", "fig = add_profile(fig, solved_model.grid_energies[m].solution.values/1e3, name='Grid',\n", " legendgroup='load',\n", + " visible='legendonly',\n", " line=dict(color='black', width=2.5), zorder=10)\n", "\n", "wind = solved_model.scenarios[m].norm_wind_gen*solved_model.model.variables.wind_capacity.solution.values\n", @@ -245,6 +257,7 @@ "solar = solved_model.scenarios[m].norm_solar_gen*solved_model.model.variables.solar_capacity.solution.values\n", "fig = add_profile(fig, solar/1e3, name=f'Solar',\n", " legendgroup='generation',\n", + " visible='legendonly',\n", " line=dict(color='#fac205', width=2.5), zorder=5)\n", "curtailment = getattr(solved_model.model.variables,f'generation_curtailment_s{m}').solution.values\n", "fig = add_profile(fig, curtailment/1e3, name='Curtailment',\n", @@ -256,11 +269,12 @@ " SOC = getattr(solved_model.model.variables,f'SOC_{tech}_s{m}').solution\n", " fig = add_profile(fig, SOC/1e6, name=tech, yaxis=f'y2',\n", " legendgroup='soc', legendgrouptitle_text='Storage SOC',\n", - " visible='legendonly',\n", + " #visible='legendonly',\n", " line=dict(color=colors[available_technologies.index(tech)], width=3), zorder=8)\n", "\n", "fig = add_profile(fig, solved_model.scenarios[m].elec_prices, name='Electricity price', yaxis='y3',\n", - " legendgroup='other', legendgrouptitle_text='Other', visible='legendonly',\n", + " legendgroup='other', legendgrouptitle_text='Other',\n", + " #visible='legendonly',\n", " line=dict(color='#ff028d', width=2.5), zorder=12)\n", "fig = add_profile(fig, solved_model.get_flared_energy()[f's{m}']['total_energy_dump']/1e3, name='Flared energy', yaxis='y',\n", " legendgroup='other', visible='legendonly',\n", @@ -269,7 +283,9 @@ "fig.update_layout(legend=dict(groupclick=\"toggleitem\"))\n", "fig.update_layout(hovermode=\"x\")\n", "\n", - "fig.write_html(f'temp_plot.html')\n", + "fig['layout']['xaxis'].update(range=['2000-05-26','2000-06-09'])\n", + "fig.write_html(os.path.join('plots',f'{techs_str}_operation_plot.html'))\n", + "fig.write_image(os.path.join('plots',f'{techs_str}_operation_plot.pdf'), width=1800, height=600)\n", "fig.show()" ] }, @@ -325,7 +341,7 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.19" + "version": "3.9.18" } }, "nbformat": 4, diff --git a/requirements.txt b/requirements.txt index edae60c5..70c08e8d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,7 @@ gurobipy==12.0.0 highspy==1.7.2 ipykernel==6.29.5 +kaleido==0.2.1 matplotlib==3.7.5 multiprocess==0.70.16 nbformat==5.10.4