resqpy.model.ModelContext¶
- class resqpy.model.ModelContext(epc_file, mode='r')¶
Bases:
object
Context manager for easy opening and closing of resqpy models.
When a model is opened this way, any open file handles are safely closed when the “with” clause exits. Optionally, the epc can be written back to disk upon exit.
Example:
with ModelContext("my_model.epc", mode="rw") as model: print(model.uuids())
Note
The “write_hdf5” and “create_xml” methods of individual resqpy objects still need to be invoked as usual.
Methods:
__init__
(epc_file[, mode])Open a resqml file, safely closing file handles upon exit.
__enter__
()Enter the runtime context, return a model.
__exit__
(exc_type, exc_value, exc_tb)Exit the runtime context, close the model.
- __init__(epc_file, mode='r') None [source]¶
Open a resqml file, safely closing file handles upon exit.
The modes operate as follows:
In “read” mode, an existing epc file is opened. Any changes are not
saved to disk automatically, but can still be saved by calling model.store_epc(). - In “read/write” mode, changes are written to disk when the context exists. - In “create” mode, a new model is created and saved upon exit. Any existing
model will be deleted.
- Parameters
epc_file (str) – path to existing resqml file
mode (str) – one of “read”, “read/write”, “create”, or shorthands
"r" –
"rw" –
"c". –