iteration_tools

Todo

Add paragraph description of the module. What stages are defined here generally? Make a table with the main ones like in water tools?

Public API methods attached to model

The following methods are defined in the iteration_tools class, of the pyDeltaRCM.iteration_tools module.

iteration_tools()

Tools relating to the updating of the model and model I/O.

class pyDeltaRCM.iteration_tools.iteration_tools

Tools relating to the updating of the model and model I/O.

Tools defined in this class include steps to iterate for one timestep, finalize timesteps, and saving output figures, grids, and checkpoints. Additionally, most stratigraphy-related operations are defined here, since these operations largely occur when saving and updating the model.

apply_subsidence() None

Apply subsidence pattern.

Apply subsidence to domain if toggle_subsidence is True, and time is >= start_subsidence. Note, that the configuration of the update() method determines that the subsidence may be applied before the model time is incremented, such that subsidence will begin on the step following the time step that brings the model to time == start_subsidence.

compute_sand_frac() None

Compute the sand fraction as a continous updating data field.

finalize_timestep() None

Finalize timestep.

Clean up after sediment routing. This includes a correction for flooded cells that are not “wet” (via flooding_correction()).

Update sea level if baselevel changes between timesteps.

log_info(message: str, verbosity: int = 0) None

Log message dependent on verbosity settings.

Parameters:
  • message (str) – Message string to write to the log as info.

  • verbosity (int, optional) – Verbosity threshold, whether to write the message to the log or not. Default value is 0, or i.e. to always log.

log_model_time() None

Log the time of the model.

Reports the time to the log file, and depending on verbosity, will report it to stdout.

make_figure(var: str, time: float) None

Create a figure.

Parameters:
  • var (str) – Which variable to plot into the figure. Specified as a string and looked up via getattr.

  • time (float) – The current model time. Used as title in figure.

Returns:

fig – The created figure object.

Return type:

matplotlib.figure

output_checkpoint() None

Output checkpoint if needed.

Save checkpoint data (including rng state) so that the model can be resumed from this time.

output_data() None

Output grids and figures if needed.

run_one_timestep() None

Deprecated, since v1.3.1. Use solve_water_and_sediment_timestep.

save_figure(fig, directory: str, filename_root: str, save_iter: int, ext: str = '.png', close: bool = True) None

Save a figure.

Parameters:
  • fig (matplotlib.Figure) – The Figure instance to save out.

  • directory (str) – The directory to save the figure into.

  • filename_root (str) – A root name to save the file as (usually the variable name being plotted in the figure). This is the first part of the filename.

  • save_iter (int) – The saving iteration number of this figure.

  • ext (str, optional) – The file extension (default=’.png’). This must be supported by the active matplotlib backend (see matplotlib.backends module). Most backends support ‘.png’, ‘.pdf’, ‘.ps’, ‘.eps’, and ‘.svg’. Be sure to include the ‘.’ before the extension.

  • close (bool, optional) – Whether to close the file after saving.

save_grids(var_name: str, var: ndarray, save_idx: int) None

Save a grid into an existing netCDF file.

File should already be open (by init_output_grid()) as self.output_netcdf.

Parameters:
  • var_name (str) – The name of the variable to be saved

  • var (ndarray) – The numpy array to be saved.

  • save_idx (int) – The index to save the data into the NetCDF file.

save_grids_and_figs() None

Save grids and figures.

Save grids and/or plots of specified variables (eta, discharge, velocity, depth, and stage), depending on configuration of the relevant flags in the YAML configuration file.

save_the_checkpoint() None

Save checkpoint files.

Saves the grids to a .npz file so that the model can be initiated from this point. The timestep of the checkpoint is also saved. The values from the model that are saved to the checkpoint.npz are the following:

  • Model time

  • Flow velocity and its components

  • Water depth

  • Water stage

  • Topography

  • Surface sand fraction

  • Active layer values

  • Current random seed state

If save_checkpoint is turned on, checkpoints are re-written with either a frequency of checkpoint_dt or save_dt if checkpoint_dt has not been explicitly defined.

solve_water_and_sediment_timestep() None

Run water and sediment operations for one timestep.

The first operation called by update(), this method iterates the water surface calculation and sediment parcel routing routines.