Generalize moving window indexing for other reference index than day of year 1
In the current code, the time step indices are constructet in a numpy array with 365 rows (day of year) and nyears*31 columns. The indices are constructed in a way that they indicate the timesteps with reference timestep January 1 of the first year in the reference period. See code snippet from _build_indices:
for c in time.cells():
tt = c.point.timetuple()
year = tt[0]
day_of_year = tt[7] - 1
if day_of_year >= self.max_doy:
continue
idx_y = year - first_year
days = np.arange(
day_of_year - self.window_width, day_of_year + self.window_width + 1
)
# day_of_year, idx_y * self.window_size : (idx_y + 1) * self.window_size]))
#print(np.shape((idx_y * self.max_doy + days)))
np_indices[
day_of_year, idx_y * self.window_size : (idx_y + 1) * self.window_size<
] = (idx_y * self.max_doy + days)
As seen in the code, the day_of_year is always relative to the first day in the year as expressed by tt[7]-1. This works well if the reference period also starts on January 1, which is most often the case in climate model bias-correction. However, the current code also has a limitation to select the reference period from January 2 if full years are indicated to define the reference period. For e.g., a reference period indicated as 1981-2011 will extract data for the period 1981-01-02 to 2010-12-31. In that case, the indices built in _build_indices are off by one day.