Callbacks module
A callback is an object can perform a particular task at the end of the model time step. The following callbacks are available in pySPEEDY:
|
Base callback class. |
|
Callback used save selected variables of the model state at the current time step. |
|
Callback used to create an xarray dataset with selected variables a the current model time step. |
- class pyspeedy.callbacks.BaseCallback(*args, **kwargs)
Base callback class.
- __init__(*args, **kwargs)
Constructor.
- Parameters
- interval: int
Interval, in time steps, for which the callback should be applied.
- verbose: bool
If true, print debug and progress messages.
- spinup_date: datetime or None:
End date of the spinup period. During the spinup the callback is ignored.
- print_msg(msg)
Print debug message if verbose was set to True.
- skip_flag(model_instance)
Return True when the callback excecution is skipped for this time step if - model_date < spinup_date - current_step % interval !=0
- class pyspeedy.callbacks.ModelCheckpoint(interval=36, verbose=False, spinup_date=None, variables=None, output_dir='./', filename_fmt='%Y-%m-%d_%H%M.nc')
Callback used save selected variables of the model state at the current time step. Note that this is not the full model state, only a small subset of it. We will refer to this saved state as “Checkpoint”.
Each instance of this callback will keep internally a time series of the checkpoints saved during the the model run in an xarray DataFrame following CF conventions.
Notes
The variables are saved in the lat/lon grid space (not the spectral domain). Spectral variables are not supported by this callback.
- __init__(interval=36, verbose=False, spinup_date=None, variables=None, output_dir='./', filename_fmt='%Y-%m-%d_%H%M.nc')
- Parameters
- interval: int
Interval, in time steps, for which the model variables are saved.
- verbose: bool
If true, print debug and progress messages.
- spinup_date: datetime or None:
End date of the spinup period. During the spinup the output files are not saved.
- variables: list, tuple
List of variables to save
- output_dir: str
Path to folder where the output files are stored.
- filename_fmt: str
Format string used to generate the output filename. The format string is passed to the strftime method for the current model datetime.
- interval: int
History interval in timesteps every which the output files are saved.
- spinup_date: datetime or None
Model spinup date. From start_date to spinup_date the callbacks functions are not called.
- print_msg(msg)
Print debug message if verbose was set to True.
- skip_flag(model_instance)
Return True when the callback excecution is skipped for this time step if - model_date < spinup_date - current_step % interval !=0
- class pyspeedy.callbacks.XarrayExporter(interval=36, verbose=False, spinup_date=None, variables=None, output_dir='./', filename_fmt='%Y-%m-%d_%H%M.nc')
Callback used to create an xarray dataset with selected variables a the current model time step.
The variables are saved in the lat/lon grid space (not the spectral domain). Spectral variables are not supported by this callback.
- __init__(interval=36, verbose=False, spinup_date=None, variables=None, output_dir='./', filename_fmt='%Y-%m-%d_%H%M.nc')
- Parameters
- interval: int
Interval, in time steps, for which the model variables are saved.
- verbose: bool
If true, print debug and progress messages.
- spinup_date: datetime or None:
End date of the spinup period. During the spinup the model checkpoints are not saved.
- variables: list, tuple
List of variables to save
- output_dir: str
Path to folder where the output files are stored.
- filename_fmt: str
Format string used to generate the output filename. The format string is passed to the strftime method for the current model datetime.
- interval: int
History interval in timesteps every which the output files are saved.
- spinup_date: datetime or None
Model spinup date. From start_date to spinup_date the callbacks functions are not called.
- print_msg(msg)
Print debug message if verbose was set to True.
- skip_flag(model_instance)
Return True when the callback excecution is skipped for this time step if - model_date < spinup_date - current_step % interval !=0