API reference
Here you find the code reference for the main components of PyStemmusScope.
Run the model:
PyStemmusScope wrapper around Stemmus_Scope model.
PyStemmusScope wrapper around Stemmus_Scope model.
For a detailed model description, look at this publication.
Configures the model and prepares forcing and soil data for the model run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
Union[str, Path]
|
Path to Stemmus_Scope configuration file. An example config_file can be found in tests/test_data in STEMMUS_SCOPE_Processing repository. |
required |
model_src_path
|
Union[str, Path]
|
Path to Stemmus_Scope executable file or to a directory containing model source codes. |
required |
interpreter
|
optional
|
Use |
None
|
Example
See notebooks/run_model_in_notebook.ipynb at the STEMMUS_SCOPE_Processing repository
Source code in PyStemmusScope/stemmus_scope.py
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 | |
config
property
Return the configurations for this model.
setup(WorkDir=None, Location=None, StartTime=None, EndTime=None)
Configure the model run.
- Creates config file and input/output directories based on the config template
- Prepare forcing and soil data
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
WorkDir
|
Optional[str]
|
path to a directory where input/output directories should be created. |
None
|
Location
|
Optional[str]
|
Location of the model run. Can be a site ("FI-Hyy") or lat/lon, e.g., "(52.0, 4.05)". |
None
|
ForcingFileName
|
forcing file name. Forcing file should be in netcdf format. |
required | |
StartTime
|
Optional[str]
|
Start time of the model run. It must be in ISO format (e.g. 2007-01-01T00:00). |
None
|
EndTime
|
Optional[str]
|
End time of the model run. It must be in ISO format (e.g. 2007-01-01T00:00). |
None
|
Returns:
| Type | Description |
|---|---|
str
|
Path to the config file |
Source code in PyStemmusScope/stemmus_scope.py
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 | |
run()
Run model using executable.
Returns:
| Type | Description |
|---|---|
str
|
The model log. |
Source code in PyStemmusScope/stemmus_scope.py
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 | |
Post processing:
PyStemmusScope.save
PyStemmusScope save module.
Module designed to create a netcdf file following the ALMA convention from csv files following the SCOPE format in the output directory.
The file
required_netcf_variables.csv
lists required variable names and their attributes based on the
ALMA+CF convention table.
Note
See notebooks/run_model_in_notebook.ipynb in the STEMMUS_SCOPE_Processing repository.
to_netcdf(config_file, cf_filename)
Save csv files generated by STEMMUS_SCOPE to a ALMA compliant netCDF file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
str
|
Path to the config file. |
required |
cf_filename
|
str
|
Path to a csv file for ALMA conventions. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Path to a csv file under the output directory. |
Source code in PyStemmusScope/save.py
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 | |
BMI interface:
PyStemmusScope.bmi.StemmusScopeBmi
Bases: InapplicableBmiMethods, Bmi
STEMMUS_SCOPE Basic Model Interface.
initialize(config_file)
Perform startup tasks for the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_file
|
str
|
Path to the configuration file. |
required |
Source code in PyStemmusScope/bmi/implementation.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 | |
update()
Advance the model state by one time step.
Source code in PyStemmusScope/bmi/implementation.py
243 244 245 246 247 248 249 250 251 252 253 254 | |
update_until(time)
Advance model state until the given time.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
time
|
float
|
A model time later than the current model time. |
required |
Source code in PyStemmusScope/bmi/implementation.py
256 257 258 259 260 261 262 263 | |
finalize()
Finalize the STEMMUS_SCOPE model.
Source code in PyStemmusScope/bmi/implementation.py
265 266 267 268 269 270 271 | |
get_component_name()
Name of the component.
Returns:
| Type | Description |
|---|---|
str
|
Name of the component (STEMMUS_SCOPE). |
Source code in PyStemmusScope/bmi/implementation.py
273 274 275 276 277 278 279 | |
get_input_item_count()
Get the number of model input variables.
Returns:
| Type | Description |
|---|---|
int
|
The number of input variables. |
Source code in PyStemmusScope/bmi/implementation.py
282 283 284 285 286 287 288 | |
get_output_item_count()
Get the number of model output variables.
Returns:
| Type | Description |
|---|---|
int
|
The number of output variables. |
Source code in PyStemmusScope/bmi/implementation.py
290 291 292 293 294 295 296 | |
get_input_var_names()
List of the model's input variables (as CSDMS Standard Names).
Source code in PyStemmusScope/bmi/implementation.py
300 301 302 | |
get_output_var_names()
List of the model's output variables (as CSDMS Standard Names).
Source code in PyStemmusScope/bmi/implementation.py
304 305 306 | |
get_var_grid(name)
Get grid identifier for the given variable.
Source code in PyStemmusScope/bmi/implementation.py
308 309 310 | |
get_var_type(name)
Get data type of the given variable.
Source code in PyStemmusScope/bmi/implementation.py
312 313 314 | |
get_var_units(name)
Get units of the given variable.
Source code in PyStemmusScope/bmi/implementation.py
316 317 318 | |
get_var_itemsize(name)
Get memory use for each array element in bytes.
Source code in PyStemmusScope/bmi/implementation.py
320 321 322 | |
get_var_nbytes(name)
Get size, in bytes, of the given variable.
Source code in PyStemmusScope/bmi/implementation.py
324 325 326 | |
get_current_time()
Get the current time of the model.
Source code in PyStemmusScope/bmi/implementation.py
329 330 331 332 333 334 | |
get_start_time()
Start time of the model.
Source code in PyStemmusScope/bmi/implementation.py
336 337 338 339 340 341 342 343 344 345 | |
get_end_time()
End time of the model.
Source code in PyStemmusScope/bmi/implementation.py
347 348 349 350 351 352 353 354 355 356 | |
get_time_units()
Time units of the model.
Source code in PyStemmusScope/bmi/implementation.py
358 359 360 | |
get_time_step()
Return the current time step of the model.
Source code in PyStemmusScope/bmi/implementation.py
362 363 364 365 366 | |
get_value(name, dest)
Get a copy of values of the given variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
input or output variable name, a CSDMS Standard Name. |
required |
dest
|
ndarray
|
numpy array into which to place the values. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The same numpy array that was passed as an input buffer. |
Source code in PyStemmusScope/bmi/implementation.py
369 370 371 372 373 374 375 376 377 378 379 380 381 382 | |
get_value_ptr(name)
Get a reference to values of the given variable.
Note: not possible due to the Matlab<>Python coupling.
Source code in PyStemmusScope/bmi/implementation.py
384 385 386 387 388 389 | |
get_value_at_indices(name, dest, inds)
Get values at particular indices.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Input or output variable name, a CSDMS Standard Name. |
required |
dest
|
ndarray
|
numpy array into which to place the values. |
required |
inds
|
ndarray
|
The indices into the variable array. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
Value of the model variable at the given location. |
Source code in PyStemmusScope/bmi/implementation.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 | |
set_value(name, src)
Specify a new value for a model variable.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Input or output variable name, a CSDMS Standard Name. |
required |
src
|
ndarray
|
The new value for the specified variable. |
required |
Source code in PyStemmusScope/bmi/implementation.py
409 410 411 412 413 414 415 416 417 418 419 420 421 | |
set_value_at_indices(name, inds, src)
Specify a new value for a model variable at particular indices.
Parameters
name : str An input or output variable name, a CSDMS Standard Name. inds : array_like The indices into the variable array. src : array_like The new value for the specified variable.
Source code in PyStemmusScope/bmi/implementation.py
423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 | |
get_grid_rank(grid)
Get number of dimensions of the computational grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
int
|
A grid identifier. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Rank of the grid. |
Source code in PyStemmusScope/bmi/implementation.py
445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 | |
get_grid_size(grid)
Get the total number of elements in the computational grid.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
int
|
A grid identifier. |
required |
Returns:
| Type | Description |
|---|---|
int
|
Size of the grid. |
Source code in PyStemmusScope/bmi/implementation.py
461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 | |
get_grid_type(grid)
Get the grid type as a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
int
|
A grid identifier. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Type of grid as a string. |
Source code in PyStemmusScope/bmi/implementation.py
481 482 483 484 485 486 487 488 489 490 | |
get_grid_x(grid, x)
Get coordinates of grid nodes in the x direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
int
|
grid identifier. |
required |
x
|
ndarray
|
numpy array to hold the x-coordinates of the grid node columns. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The input numpy array that holds the grid's column x-coordinates. |
Source code in PyStemmusScope/bmi/implementation.py
492 493 494 495 496 497 498 499 500 501 502 503 504 505 | |
get_grid_y(grid, y)
Get coordinates of grid nodes in the y direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
int
|
grid identifier. |
required |
y
|
ndarray
|
numpy array to hold the y-coordinates of the grid node columns. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The input numpy array that holds the grid's column y-coordinates. |
Source code in PyStemmusScope/bmi/implementation.py
507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
get_grid_z(grid, z)
Get coordinates of grid nodes in the z direction.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grid
|
int
|
grid identifier. |
required |
z
|
ndarray
|
numpy array to hold the z-coordinates of the grid node columns. |
required |
Returns:
| Type | Description |
|---|---|
ndarray
|
The input numpy array that holds the grid's column z-coordinates. |
Source code in PyStemmusScope/bmi/implementation.py
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 | |
get_grid_shape(grid, shape)
Get dimensions of the computational grid.
Source code in PyStemmusScope/bmi/implementation.py
548 549 550 551 552 553 554 555 556 557 558 | |