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

import datetime

import numpy as np
import pandas as pd
import xarray as xr
from netCDF4 import Dataset

from logging import info, debug

from ....utils.dates import date_range
from ....utils.netcdf import readnc

[docs]def ini_periods(self, **kwargs): """ The function :bash:`ini_periods` is optional but very recommended. It is used to define the temporal variables ``subsimu_dates``, ``input_dates``, ``tstep_dates`` and ``tstep_all``. The function is automatically called at the initialization of the :bash:`model` class if available. If not available, the temporal variables should be defined manually in the :bash:`ini_data` function (not recommended). :bash:`ini_periods` is a class method that applies to the :bash:`model` plugin itself. Therefore, the only expected argument is :bash:`self`. .. code-block:: python def ini_periods(self, **kwargs): self.subsimu_dates = XXXX self.tstep_dates = XXXXX self.input_dates = XXXXX self.tstep_all = XXXXX """ # Define sub-simu dates info("Sub-simulations are initialized as one sub-simulation " "covering the full simulation window") self.subsimu_dates = [self.datei, self.datef] # Define modelling time steps for outputs self.tstep_dates = {} self.input_dates = {} for dd0, dd1 in zip(self.subsimu_dates[:-1], self.subsimu_dates[1:]): self.tstep_dates[dd0] = pd.date_range( dd0, dd1, freq=self.output_resolution).to_pydatetime() self.input_dates[dd0] = pd.date_range( dd0, dd1, freq=self.input_resolution).to_pydatetime()