Roger setup class¶
- class roger.RogerSetup(override=None)[source]¶
Bases:
object
Main class for roger, used for building a model and running it.
Note
This class is meant to be subclassed. Subclasses need to implement the methods
set_parameters()
,set_topography()
,set_grid()
,set_coriolis()
,set_initial_conditions()
,set_forcing()
, andset_diagnostics()
.Example
>>> import matplotlib.pyplot as plt >>> from roger import RogerSetup >>> >>> class MyModel(RogerSetup): >>> ... >>> >>> model = MyModel() >>> model.run() >>> plt.imshow(model.state.variables.theta[..., 1]) >>> plt.show()
- abstract set_settings(state)[source]¶
To be implemented by subclass.
First function to be called during setup. Use this functions to set the model settings and define physical constants.
Example
>>> def set_settings(self, state): >>> settings = state.settings >>> settings.nx, settings.ny, settings.nz = (360, 120, 2)
- abstract set_look_up_tables(state)[source]¶
To be implemented by subclass.
Use this function to set the look-up tables.
Example
>>> def set_look_up_tables(self, state): >>> vs = state.variables >>> vs.lut_ilu = update(vs.lut_ilu, at[:, :], lut.ARR_ILU)
- abstract set_parameters_setup(state)[source]¶
To be implemented by subclass.
Use this function to set initial or constant model parameters.
Example
>>> def set_parameters_setup(self, state): >>> vs = state.variables >>> vs.dmpv = update(vs.dmpv, at[:, :, :, vs.tau], npx.random.rand(vs.dmpv.shape[:-1]))
- abstract set_parameters(state)[source]¶
To be implemented by subclass.
Use this function to modify the model parameters.
Example
>>> def set_parameters(self, state): >>> vs = state.variables >>> vs.dmpv = update(vs.dmpv, at[:, :, :, vs.tau], npx.random.rand(vs.dmpv.shape[:-1]))
- abstract set_initial_conditions_setup(state)[source]¶
To be implemented by subclass.
Use this function to set the initial conditions.
Example
>>> @roger_method >>> def set_initial_conditions_setup(self, state): >>> vs = state.variables >>> vs.theta_rz = update(vs.theta_rz, at[:, :, :, vs.tau], 0.4)
- abstract set_initial_conditions(state)[source]¶
To be implemented by subclass.
May be used to set initial conditions.
Example
>>> @roger_method >>> def set_initial_conditions(self, state): >>> vs = state.variables >>> vs.theta_rz = update(vs.theta_rz, at[:, :, :, vs.tau], 0.4)
- abstract set_boundary_conditions_setup(state)[source]¶
To be implemented by subclass.
Use this function to set the boundary conditions.
Example
>>> @roger_method >>> def set_boundary_conditions_setup(self, state): >>> vs = state.variables >>> vs.z_gw = update(vs.z_gw, at[:, :, :, :vs.taup1], 5)
- abstract set_boundary_conditions(state)[source]¶
To be implemented by subclass.
May be used to set boundary conditions.
Example
>>> @roger_method >>> def set_boundary_conditions(self, state): >>> vs = state.variables >>> vs.z_gw = update(vs.z_gw, at[:, :, :, :vs.taup1], 5)
- abstract set_grid(state)[source]¶
To be implemented by subclass.
Has to set the grid spacings
x
andy
, along with the coordinates of the grid origin,x_origin
andy_origin
.Example
>>> @roger_method >>> def set_grid(self, state): >>> vs = state.variables >>> vs.x_origin, vs.y_origin = 0, 0 >>> vs.x = 1. >>> vs.y = 1.
- abstract set_topography(state)[source]¶
To be implemented by subclass.
Must specify the model topography by setting
slope
.Example
>>> @roger_method >>> def set_topography(self, state): >>> vs = state.variables >>> vs.slope = update(vs.slope, at[...], 10)
- abstract set_forcing_setup(state)[source]¶
To be implemented by subclass.
Called within setup, e.g. through
PREC
,TA
,PET
.Example
>>> @roger_method >>> def set_forcing_setup(self, state): >>> vs = state.variables >>> vs.TA = vs._ta_data
- abstract set_forcing(state)[source]¶
To be implemented by subclass.
Called before every time step to update the external forcing, e.g. through
prec
,ta
,pet
.Example
>>> @roger_method >>> def set_forcing(self, state): >>> vs = state.variables >>> vs.ta = vs.TA[:, :, vs.itt]
- abstract set_diagnostics(vs, base_path=None)[source]¶
To be implemented by subclass.
Called before setting up the diagnostics. Use this method e.g. to mark additional variables for output.
Example
>>> @roger_method >>> def set_diagnostics(self, state): >>> state.diagnostics['snapshot'].output_variables += ['drho', 'dsalt', 'dtemp']
- abstract after_timestep(state)[source]¶
Called at the end of each time step. Can be used to define custom, setup-specific events.
- warmup(repeat=1)[source]¶
Warmup routine of the simulation.
- Parameters:
repeat (int, optional) – Number of warmup runs. Default is 1.
Note
Make sure to call
setup()
prior to this function.
- run(show_progress_bar=None)[source]¶
Main routine of the simulation.
:param show_progress_bar (
bool
: By default, only show if stdout is a terminal and roger is running on a single process. :type show_progress_bar (bool
: Whether to show fancy progress bar via tqdm. :param optional): By default, only show if stdout is a terminal and roger is running on a single process. :type optional): Whether to show fancy progress bar via tqdm.Note
Make sure to call
setup()
(andwarmup()
if offline transport) prior to this function.