Source code for pycif.plugins.models.lagrangian.ini_periods

import pandas as pd
import numpy as np
import itertools
from ....utils.dates import date_range


[docs] def ini_periods(self, **kwargs): """Compute temporal discretisation for the Lagrangian model. Splits the full simulation window into sub-simulation periods and defines the footprint input date windows that extend backward by ``self.backward_trajdays`` from each period start. Sets the following attributes on *self*: * ``subsimu_dates`` — boundary dates of sub-simulation windows (length = n_periods + 1). * ``tstep_dates`` — dict mapping each period start to its 1-hourly time-step array. * ``input_dates`` — dict mapping each period start to the backward- shifted flux input dates needed by the footprints. * ``input_background`` — same but shifted for background concentration read windows. * ``tstep_all`` — sorted unique merge of all time steps. * ``iniobs`` / ``reset_obs`` — per-period flags controlling obs dumping. Args: self: Lagrangian model plugin instance with ``datei``, ``datef``, ``period``, ``subperiod``, and ``backward_trajdays`` set. **kwargs: unused. """ # Hardcoded 1h for now datei = self.datei datef = self.datef period = self.period subperiod = self.subperiod # List of sub-simulation windows self.subsimu_dates = date_range(datei, datef, period=period, close="right") # Time steps per day freq = f'{3600:.0f}s' # List of time steps self.tstep_dates = { ddi: date_range(ddi, ddf, period=freq) for ddi, ddf in zip(self.subsimu_dates[:-1], self.subsimu_dates[1:]) } # List of input dates self.input_dates = { ddi: date_range(ddi - pd.to_timedelta(self.backward_trajdays), ddf, period=period, subperiod=subperiod) for ddi, ddf in zip(self.subsimu_dates[:-1], self.subsimu_dates[1:]) } self.input_background = { ddi: date_range(ddi - pd.to_timedelta(self.backward_trajdays), ddf - pd.to_timedelta(self.backward_trajdays), period=period, subperiod=subperiod) for ddi, ddf in zip(self.subsimu_dates[:-1], self.subsimu_dates[1:]) } # Merged list of time steps self.tstep_all = np.sort(np.unique( np.concatenate(list(self.tstep_dates.values())))) # Initializes dictionary to keep in memory whether observations were # already dumped for a given period self.iniobs = {ddi: False for ddi in self.subsimu_dates} self.reset_obs = {ddi: True for ddi in self.subsimu_dates}