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()

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()

Compute the sand fraction as a continous updating data field.

finalize_timestep()

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, verbosity=0)

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()

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, timestep)

Create a figure.

Parameters

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

Returns

fig – The created figure object.

Return type

matplotlib.figure

output_checkpoint()

Output checkpoint if needed.

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

output_data()

Output grids and figures if needed.

run_one_timestep()

Run the timestep once.

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

Note

Will print the current time to stdout, if verbose > 0.

save_figure(fig, directory, filename_root, timestep, ext='.png', close=True)

Save a figure.

Parameters
  • path (str) – The path (and filename without extension) to save the figure to.

  • 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, var, ts)

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.

  • ts (int) – The current timestep (+1, so human readable)

save_grids_and_figs()

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()

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.