Updates to impact yearset module and review of tutorial by ValentinGebhart · Pull Request #1075 · CLIMADA-project/climada_python
This is an example for which the earlier sampling without replacement was not reasonable. One of the impact events has a significantly larger frequency. Once it was drawn in the sampling, the other events were drawn until no events were left. With replacement, the high-frequency event would be drawn more often.
import numpy as np import climada.util.yearsets as yearsets from climada.engine import Impact imp = Impact() imp.at_event = np.arange(10, 110, 10) imp.frequency = np.concatenate([np.array([1.]), np.ones(9) * 0.01]) # highly unbalanced frequencies, first event 100 times more likely # the number of years to sample impacts for (length(yimp.at_event) = sampled_years) sampled_years = 10 # sample number of events per sampled year lam = np.sum(imp.frequency) events_per_year = yearsets.sample_from_poisson(sampled_years, lam, seed=123) sampling_vect = yearsets.sample_events(events_per_year, imp.frequency, seed=123) sampling_vect
Result when setting the optional parameter with_replacement=False, similar to the old version
2025-07-22 16:59:12,925 - climada.util.yearsets - WARNING - The frequencies of the different events are not equal. This can lead to distorted sampling if the frequencies vary significantly. To avoid this, please set with_replacement=True to sample with replacement instead.
[array([0]),
array([], dtype=int64),
array([7, 1]),
array([6, 2]),
array([8]),
array([5]),
array([], dtype=int64),
array([9]),
array([], dtype=int64),
array([], dtype=int64)]
Result in the new version
[array([0]),
array([], dtype=int64),
array([0, 0]),
array([0, 0]),
array([0]),
array([1]),
array([], dtype=int64),
array([0]),
array([], dtype=int64),
array([], dtype=int64)]