{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Calculate probabilistic impact yearset\n", "\n", "This module generates an `annual_impacts` object which contains probabilistic annual impacts for a specified amount of years (`sampled_years`). The impact values are extracted from a given `event_impact` object that contains impact values per event. The amount of `sampled_years` can be specified as an integer or as a list of years to be sampled for. The amount of events per sampled year (`events_per_year`) are determined with a Poisson distribution centered around n_events per year (n_events = sum(event_impacts.frequency). Then, the probabilistic events occuring in each sampled year (`selected_event`) are sampled uniformaly from the input `event_impacs` object and summed up per year (`impacts_per_year`). Thus, the `annual_impacts` object contains the sum of sampled (event) impacts for each sampled year. In contrast to the expected annual impact (eai), an `annual_impacts` object contains an impact for EACH sampled year and this value differs among years. The selected_events and the number of events_per_year are saved in a sampling dictionary (`sampling_dict`). \n", "\n", "The function impact_yearsets performs all these computational steps, taking an event_impacts object and the number of sampled_years as input. The output of the function is the annual_impacts object and the sampling_dict.\n", "Moreover, a sampling_dict (generated in a previous run) can be provided as optional input and the user can decide whether a correction factor shall be applied (the default is applying the correction factor).\n", "Reapplying the same sampling_dict does not only allow to reproduce the generated annual_impacts object, but also for a physically consistent way of sampling impacts caused by different hazards. \n", "The correction factor that is applied when the optional input `correction_fac`= True is a scaling of the computed annual_impacts that assures that the eai(annual_events) = eai(events_impacts).\n", "\n", "To make the process more transparent, this tutorial shows the single computations that are performed when generating an annual_impacts object for a dummy event_impacts object. " ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "2021-04-01 11:47:04,148 - climada.util.yearsets - INFO - The correction factor amounts to -25.170068027210878\n", "The annual_impacts.at_event values equal our step-by-step computed impacts_per year:\n", "annual_impacts.at_event = [390. 90. 300. 190. 100. 0. 0. 240. 60. 100.]\n", "impact_per_year = [390. 90. 300. 190. 100. 0. 0. 240. 60. 100.]\n", "2021-04-01 11:47:04,154 - climada.util.yearsets - INFO - The correction factor amounts to -25.170068027210878\n", "The same can be used for the case of applying the correction factor.The annual_impacts.at_event values equal our step-by-step computed ipacts_per year:\n", "annual_impacts.at_event = [521.18181818 120.27272727 400.90909091 253.90909091 133.63636364\n", " 0. 0. 320.72727273 80.18181818 133.63636364]\n", "impact_per_year = [521.18181818 120.27272727 400.90909091 253.90909091 133.63636364\n", " 0. 0. 320.72727273 80.18181818 133.63636364]\n" ] } ], "source": [ "import numpy as np\n", "\n", "import climada.util.yearsets as yearsets\n", "from climada.engine import Impact\n", "\n", "# dummy event_impacts object containing 10 event_impacts with the values 10-110 \n", "# and the frequency 0.2 (Return period of 5 years)\n", "event_impacts = Impact()\n", "event_impacts.at_event = np.arange(10,110,10)\n", "event_impacts.frequency = np.array(np.ones(10)*0.2)\n", "\n", "# the number of years to sample impacts for (length(annual_impacts.at_event) = sampled_years)\n", "sampled_years = 10\n", "\n", "n_annual_events = np.sum(event_impacts.frequency)\n", "n_input_events = len(event_impacts.at_event)\n", "sampling_dict = yearsets.create_sampling_dict(sampled_years, n_annual_events, n_input_events)\n", "\n", "impact_per_year = yearsets.compute_annual_impacts(event_impacts, sampling_dict)\n", "\n", "correction_factor = yearsets.calculate_correction_fac(impact_per_year, event_impacts)\n", "\n", "# compare the resulting annual_impacts with our step-by-step computation without applying the correction factor: \n", " \n", "annual_impacts, sampling_vect = yearsets.impact_yearset(event_impacts,\n", " sampling_dict=sampling_dict,\n", " correction_fac = False)\n", "\n", "print('The annual_impacts.at_event values equal our step-by-step computed impacts_per year:')\n", "print('annual_impacts.at_event = ', annual_impacts.at_event)\n", "print('impact_per_year = ', impact_per_year)\n", "\n", "# and here the same comparison with applying the correction factor (default settings):\n", "annual_impacts, sampling_vect = yearsets.impact_yearset(event_impacts,\n", " sampling_dict=sampling_dict)\n", "\n", "print('The same can be shown for the case of applying the correction factor.' \n", " 'The annual_impacts.at_event values equal our step-by-step computed impacts_per year:')\n", "print('annual_impacts.at_event = ', annual_impacts.at_event)\n", "print('impact_per_year = ', impact_per_year/correction_factor)\n", "\n", "\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.9" } }, "nbformat": 4, "nbformat_minor": 4 }