API Reference
This section provides comprehensive documentation for the Rompy API, organized by functional modules. Rompy is structured around a modular architecture that supports various ocean and wave models with consistent interfaces for configuration, data handling, execution, and post-processing.
Core Modules
Model Execution
The main entry point for running models in Rompy:
ModelRun
Bases: RompyBaseModel
A model run.
It is intented to be model agnostic. It deals primarily with how the model is to be run, i.e. the period of the run and where the output is going. The actual configuration of the run is provided by the config object.
Further explanation is given in the rompy.core.Baseconfig docstring.
Source code in rompy/model.py
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 | |
Functions
generate
Generate the model input files
returns
staging_dir : str
Source code in rompy/model.py
139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 | |
run
Run the model using the specified backend configuration.
This method uses Pydantic configuration objects that provide type safety and validation for all backend parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
backend
|
BackendConfig
|
Pydantic configuration object (LocalConfig, DockerConfig, etc.) |
required |
workspace_dir
|
Optional[str]
|
Path to generated workspace directory (optional) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if execution was successful, False otherwise |
Raises:
| Type | Description |
|---|---|
TypeError
|
If backend is not a BackendConfig instance |
Examples:
from rompy.backends import LocalConfig, DockerConfig
Local execution
model.run(LocalConfig(timeout=3600, command="python run.py"))
Docker execution
model.run(DockerConfig(image="swan:latest", cpu=4, memory="2g"))
Source code in rompy/model.py
postprocess
Postprocess the model outputs using the specified processor.
This method uses entry points to load and execute the appropriate postprocessor. Available processors are automatically discovered from the rompy.postprocess entry point group.
Built-in processors: - "noop": A placeholder processor that does nothing but returns success
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processor
|
str
|
Name of the postprocessor to use (default: "noop") |
'noop'
|
**kwargs
|
Additional processor-specific parameters |
{}
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with results from the postprocessing |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the specified processor is not available |
Source code in rompy/model.py
Core Configuration
Base configuration classes that provide validation and type safety:
BaseConfig
Bases: RompyBaseModel
Base class for model templates.
The template class provides the object that is used to set up the model configuration. When implemented for a given model, can move along a scale of complexity to suit the application.
In its most basic form, as implemented in this base object, it consists of path to a cookiecutter template with the class providing the context for the {{config}} values in that template. Note that any {{runtime}} values are filled from the ModelRun object.
If the template is a git repo, the checkout parameter can be used to specify a branch or tag and it will be cloned and used.
If the object is callable, it will be colled prior to rendering the template. This mechanism can be used to perform tasks such as fetching exteral data, or providing additional context to the template beyond the arguments provided by the user..
Source code in rompy/core/config.py
Time Management
Time range and interval handling:
TimeRange
Bases: BaseModel
A time range object
Examples
from rompy import TimeRange tr = TimeRange(start="2020-01-01", end="2020-01-02") tr TimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=datetime.datetime(2020, 1, 2, 0, 0), duration=None, interval=None, include_end=True) tr = TimeRange(start="2020-01-01", duration="1d") tr TimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=datetime.datetime(2020, 1, 2, 0, 0), duration=timedelta(days=1), interval=None, include_end=True) tr = TimeRange(start="2020-01-01", duration="1d", interval="1h") tr TimeRange(start=datetime.datetime(2020, 1, 1, 0, 0), end=None, duration=timedelta(days=1), interval=timedelta(hours=1), include_end=True)
Source code in rompy/core/time.py
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 | |
Grid Systems
Grid definition and management:
BaseGrid
Bases: RompyBaseModel
Representation of a grid in geographic space.
This is the base class for all Grid objects. The minimum representation of a grid are two NumPy array's representing the vertices or nodes of some structured or unstructured grid, its bounding box and a boundary polygon. No knowledge of the grid connectivity is expected.
Source code in rompy/core/grid.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | |
RegularGrid
Bases: BaseGrid
Regular grid in geographic space.
This object provides an abstract representation of a regular grid in some geographic space.
Source code in rompy/core/grid.py
188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 | |
Data Handling
Data source and handling components:
DataBase
Bases: ABC, RompyBaseModel
Base class for data objects.
Source code in rompy/core/data.py
SourceBase
Bases: RompyBaseModel, ABC
Abstract base class for a source dataset.
Source code in rompy/core/source.py
Boundary Conditions
Boundary condition management:
DataBoundary
Bases: DataGrid
Source code in rompy/core/boundary.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 | |
Functions
get
get(destdir: str | Path, grid: RegularGrid, time: Optional[TimeRange] = None) -> str
Write the selected boundary data to a netcdf file.
Parameters
destdir : str | Path
Destination directory for the netcdf file.
grid : RegularGrid
Grid instance to use for selecting the boundary points.
time: TimeRange, optional
The times to filter the data to, only used if self.crop_data is True.
Returns
outfile : Path Path to the netcdf file.
Source code in rompy/core/boundary.py
BoundaryWaveStation
Bases: DataBoundary
Wave boundary data from station datasets.
Note
The tolerance behaves differently with sel_methods idw and nearest; in idw
sites with no enough neighbours within tolerance are masked whereas in nearest
an exception is raised (see wavespectra documentation for more details).
Note
Be aware that when using idw missing values will be returned for sites with less
than 2 neighbours within tolerance in the original dataset. This is okay for land
mask areas but could cause boundary issues when on an open boundary location. To
avoid this either use nearest or increase tolerance to include more neighbours.
Source code in rompy/core/boundary.py
202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |
Functions
get
get(destdir: str | Path, grid: RegularGrid, time: Optional[TimeRange] = None) -> str
Write the selected boundary data to a netcdf file.
Parameters
destdir : str | Path
Destination directory for the netcdf file.
grid : RegularGrid
Grid instance to use for selecting the boundary points.
time: TimeRange, optional
The times to filter the data to, only used if self.crop_data is True.
Returns
outfile : Path Path to the netcdf file.
Source code in rompy/core/boundary.py
Backend Systems
Backend Configuration
Base and specific backend configurations:
BaseBackendConfig
Bases: BaseModel, ABC
Base class for all backend configurations.
This class defines common configuration parameters that apply to all backend types, such as timeouts and environment variables.
Source code in rompy/backends/config.py
Functions
get_backend_class
abstractmethod
Return the backend class that should handle this configuration.
Returns:
| Type | Description |
|---|---|
|
The backend class to use for execution |
LocalConfig
Bases: BaseBackendConfig
Configuration for local execution backend.
This configuration is used when running models directly on the local system using the system's Python interpreter or shell commands.
Source code in rompy/backends/config.py
DockerConfig
Bases: BaseBackendConfig
Configuration for Docker execution backend.
This configuration is used when running models inside Docker containers with appropriate resource limits and volume mounts.
Source code in rompy/backends/config.py
125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 | |
Backend Execution
Backend execution implementations:
DockerRunBackend
Execute models inside Docker containers.
This backend builds Docker images if needed and runs models inside containers with appropriate volume mounts.
Source code in rompy/run/docker.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 | |
Functions
run
run(model_run, config: DockerConfig, workspace_dir: Optional[str] = None) -> bool
Run the model inside a Docker container.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_run
|
The ModelRun instance to execute |
required | |
config
|
DockerConfig
|
DockerConfig instance with execution parameters |
required |
workspace_dir
|
Optional[str]
|
Path to the generated workspace directory (if None, will generate) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if execution was successful, False otherwise |
Source code in rompy/run/docker.py
LocalRunBackend
Execute models locally using the system's Python interpreter.
This is the simplest backend that just runs the model directly on the local system.
Source code in rompy/run/__init__.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
Functions
run
run(model_run, config: LocalConfig, workspace_dir: Optional[str] = None) -> bool
Run the model locally.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_run
|
The ModelRun instance to execute |
required | |
config
|
LocalConfig
|
LocalConfig instance with execution parameters |
required |
workspace_dir
|
Optional[str]
|
Path to the generated workspace directory (if None, will generate) |
None
|
Returns:
| Type | Description |
|---|---|
bool
|
True if execution was successful, False otherwise |
Raises:
| Type | Description |
|---|---|
ValueError
|
If model_run is invalid |
TimeoutError
|
If execution exceeds timeout |
Source code in rompy/run/__init__.py
CLI Interface
Command-line interface components:
cli
ROMPY Command Line Interface
This module provides the command-line interface for ROMPY.
Functions
main
run
run(config, backend_config, dry_run, verbose, log_dir, show_warnings, ascii_only, simple_logs, config_from_env)
Run a model configuration using Pydantic backend configuration.
Examples:
Run with local backend configuration
rompy run config.yml --backend-config unified_local_single.yml
Run with Docker backend configuration
rompy run config.yml --backend-config unified_docker_single.yml
Run with config from environment variable
rompy run --config-from-env --backend-config unified_local_single.yml
Source code in rompy/cli.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 | |
generate
generate(config, output_dir, verbose, log_dir, show_warnings, ascii_only, simple_logs, config_from_env)
Generate model input files only.
Source code in rompy/cli.py
Formatting and Utilities
Formatting and utility functions:
formatting
Formatting utilities for ROMPY.
This module provides various formatting utilities for creating consistent and visually appealing output in the ROMPY codebase.
utils
Utility functions for ROMPY.
This module provides various utility functions used throughout the ROMPY codebase.
Functions
load_config
Load configuration from file, string, or environment variable.
This is a lazy import wrapper to avoid circular imports.
Source code in rompy/utils.py
Post-processing
Post-processing utilities:
postprocess
No-op postprocessor for model outputs.
This module provides a basic postprocessor that does nothing.
Pipeline Management
Pipeline execution components:
LocalPipelineBackend
Local pipeline backend that executes the full workflow locally.
This backend uses the existing generate(), run() and postprocess() methods to execute the complete pipeline locally.
Source code in rompy/pipeline/__init__.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | |
Spectrum Handling
Spectral data handling:
Frequency
Bases: RompyBaseModel
Wave frequency.
Source code in rompy/core/spectrum.py
LogFrequency
Bases: RompyBaseModel
Logarithmic wave frequencies.
Frequencies are defined according to:
:math:f_{i+1} = \gamma * f_{i}
Note
The number of frequency bins nbin is always kept unchanged when provided. This
implies other parameters may be adjusted so nbin bins can be defined. Specify
f0, f1 and finc and let nbin be calculated to avoid those values changing.
Note
Choose finc=0.1 for a 10% increment between frequencies that satisfies the DIA.
Examples
.. ipython:: python :okwarning:
from rompy.core.spectrum import LogFrequency
LogFrequency(f0=0.04, f1=1.0, nbin=34)
LogFrequency(f0=0.04, f1=1.0, finc=0.1)
LogFrequency(f0=0.04, nbin=34, finc=0.1)
LogFrequency(f1=1.0, nbin=34, finc=0.1)
Source code in rompy/core/spectrum.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 | |
Type Definitions
Common type definitions:
types
Rompy types.