AI4S2S / s2spy

A high-level python package integrating expert knowledge and artificial intelligence to boost (sub) seasonal forecasting
https://ai4s2s.readthedocs.io/
Apache License 2.0
20 stars 7 forks source link

Change to `allow_overlap`/`skip_n_years` in calendars (CustomCalendar) #112

Closed BSchilperoort closed 1 year ago

BSchilperoort commented 2 years ago

I had the idea to make allow_overlap=False work differently internally. Why don't we first generate the intervals, and then throw out anchor years if there is overlap. This avoids having to do complex calculations when working with non-day Timedeltas. For the plotting utilities we already require a get_overlapping_periods method on the calendar anyway (to display which intervals overlap).

Some pseudocode:

intervals = self.get_intervals()
overlap, overlapping_intervals = assert_overlap(intervals)
while overlap:
    self.skip_years = 1
    intervals = self.get_intervals()
    overlap, _ = assert_overlap(intervals)

Of course this makes generating the calendar a bit slower, but I don't think the calendar generation will ever be a bottleneck. On the upside; it makes our code a lot simpler.

Peter9192 commented 2 years ago

What about

intervals = self.get_intervals()
self.skip_years = discard_overlap(intervals, tolerance=5)