OpenWF package¶
Submodules¶
OpenWF.aux_functions module¶
- OpenWF.aux_functions.log_progress(sequence, every=None, size=None, name='Items')¶
Ipywidget for displaying a progress bar. Developed by Elisa Heim
OpenWF.db_access module¶
db_access is a compendium of high-level python functions to mess around with a database.
- OpenWF.db_access.close(conn, commit='Yes')¶
Close connection to the database, commit or dont.
- OpenWF.db_access.connect(db_file)¶
Connect to an existing sqlite database file.
- Parameters
db_file – string - path to database file
- Returns
connection object or None
- OpenWF.db_access.get_columns(c, table, verbose=False)¶
Get all columns in a specified table.
- OpenWF.db_access.get_tables(c, verbose=False)¶
Get all table names in the database.
Examples using OpenWF.db_access.connect
¶
OpenWF.shemat_preprocessing module¶
This file contains preprocessing methods for creating SHEMAT-Suite models, created using the 2-step-conditioning workflow developed in the project Pilot Study Geothermics Aargau.
Methods comprise masking the geological model with topography and calculation of parameters, such as the heatflow.
- OpenWF.shemat_preprocessing.conc_lithblocks(path: str = '.')¶
Concatenate multiple lith block files (npy files) in a folder into one numpy array
- Parameters
path (str, optional) – Path to the numpy array files. Defaults to ‘.’.
- Returns
concatenated lith blocks in a numpy array
- Return type
np.array
- OpenWF.shemat_preprocessing.export_shemat_suite_input_file(geo_model, lithology_block, output: str = 'vtk hdf', units: Optional[pandas.core.frame.DataFrame] = None, head_bcs_file: Optional[str] = None, top_temp_bcs_file: Optional[str] = None, hf_bcs_file: Optional[str] = None, hf_value: float = 0.07, conduction_only: bool = True, data_file: Optional[str] = None, borehole_logs: Optional[numpy.array] = None, lateral_boundaries: str = 'noflow', path: Optional[str] = None, filename: str = 'geo_model_SHEMAT_input_erode')¶
Method to export a 3D geological model as SHEMAT-Suite input-file for a conductive HT-simulation.
- Parameters
geo_model (gp model) – gempy model
lithology_block (numpy array) – array containing the lithology IDs for the regular grid of the model
output (str, optional) – declare which output files should be generated hdf=HDF5, vtk=VTK, plt=PLT (tecplot)
units (pd.DataFrame, optional) – unit petrophysical parameters for SHEMAT-Suite model. Defaults to None.
head_bcs_file (str, optional) – boundary condition file for spatially varying boundary conditions (e.g. head by topography). Defaults to None.
top_temp_bcs_file (str, optional) – boundary condition file for spatially varying boundary conditions (e.g. temperature due to topography). Defaults to None.
data_file (str, optional) – data for calibrating the model, e.g. temperatures from boreholes. Defaults to None.
borehole_logs (np.array, optional) – coordinates for synthetic borehole logs, will write parameters such as pressure and temperature. Defaults to None.
path (str, optional) – save path for the SHEMAT-Suite input file. Defaults to None.
filename (str, optional) – name of the SHEMAt-Suite input file. Defaults to ‘geo_model_SHEMAT_input_erode’.
- OpenWF.shemat_preprocessing.normalize(df)¶
Normalize a df-column
- OpenWF.shemat_preprocessing.topomask(geo_model, lith_block)¶
Method to mask the GemPy model with topography and change masked IDs to a new one for air.
- Parameters
geo_model (gp model) – gempy geomodel
lith_block (np.array) – numpy array with the lith_block solution of a gempy model in a defined regular grid
- Returns
lith_block masked with topography, so including cell IDs representing topography.
- Return type
np.array
Examples using OpenWF.shemat_preprocessing.export_shemat_suite_input_file
¶
OpenWF.postprocessing module¶
This file contains postprocessing methods for the SHEMAT-Suite models, created using the 2-step-conditioning workflow developed in the project Pilot Study Geothermics Aargau.
Methods comprise plotting and calculation of parameters, such as the heatflow.
- OpenWF.postprocessing.add_dataset_to_hdf(f: h5py._hl.files.File, name: str = 'parameter', values=None)¶
Add data to an existing h5py file, which has to be loaded with ‘r+’, or ‘a’
- OpenWF.postprocessing.available_parameters(file: h5py._hl.files.File)¶
Return a summary of available parameters in the simulation file
- Parameters
file (h5py.File) – loaded HDF5 file
- Returns
dictionary with available parameters and short definition
- Return type
available parameters [dict]
- OpenWF.postprocessing.c_rmse(predicted, target)¶
- OpenWF.postprocessing.calc_adv_hf(data: h5py._hl.files.File, direction: str = 'full')¶
Calculate advective heat flow
- OpenWF.postprocessing.calc_cond_hf(data: h5py._hl.files.File, direction: str = 'full')¶
Calculate the conductive heat flow for the whole model cube in x, y, z direction
- Parameters
data (h5py.File) – HDF5 file with simulated variables
direction (str, optional) – string to return either full (x,y,z) heat flow, or just one direction. x returns just in x-direction, y just in y-direction, z just in z-direction. Defaults to ‘full’.
- Returns
- array with the heat flow in the specified direction, or the full. then the method returns three variables,
one for each direction.
- Return type
[np.ndarray]
- OpenWF.postprocessing.calc_cond_hf_over_interval(data: h5py._hl.files.File, depth_interval: list, model_depth: float = 6000.0, direction: bool = False)¶
calculate the vertical heatflow over a certain depth interval.
- Parameters
data (h5py.File) – HDF5 file with simulated variables
depth_interval (list) – list of depth interval with [deeper, shallower] values
model_depth (float, optional) – vertical extent of the model in meter. Defaults to 6000..
direction (boolean, optional) – if set to True, direction of heatflow will be included, i.e. negative heat flows for outward ones
- Returns
average heat flow over the defined depth interval
- Return type
hf [array]
- OpenWF.postprocessing.calc_tgradient(data, direction=True)¶
Return the temperature gradient in z-direction
- Parameters
data (HDF5) – HDF5 File with simulation results
direction (bool, optional) – direction considered (positive downward, negative upward). Defaults to True.
- Returns
array of the temperature gradient
- Return type
gradT (np.array)
- OpenWF.postprocessing.extract_parameters(datafile, parameters: list = ['temp', 'uindex'], dimension: int = 3, direction: str = 'x')¶
extract single parameter fields from an HDF5 file for postprocessing.
- OpenWF.postprocessing.fahrenheit_to_celsius(temp_fahrenheit, difference=False)¶
Transform Fahrenheit temperatures to Celsius
- OpenWF.postprocessing.find_nearest(array, value)¶
Find nearest cell index to given value
- OpenWF.postprocessing.heatcapacity(data: h5py._hl.files.File)¶
Calculate the specific, isobaric heat capacity of water based on Zyvoloski 1997.
- Parameters
data (h5py.File) – HDF5 file with the heat transport simulation
- Returns
3D array of the specific heat capacity of water
- Return type
cpf
Zyvoloski, G.A., Robinson, B.A., Dash, Z.V., & Trease, L.L. Summary of the models and methods for the FEHM application - a finite-element heat- and mass-transfer code. United States. doi:10.2172/565545.
- OpenWF.postprocessing.load_inv(filepath: str = '.')¶
Load SHEMAT-Suite simulation data files
- Parameters
filepath (str, optional) – path to shemat-suite datafile. Files include simulated and observed values for #data nodes in the shemat-suite model. Defaults to ‘.’.
- Returns
Dataframe with loaded values
- Return type
[Pandas Dataframe]
- OpenWF.postprocessing.plot_apriori_aposteriori(parameter_data, parameter, borehole, save=False, interval=[0, 100])¶
- OpenWF.postprocessing.plot_log_inv(inv_data, forw_data, parameter_data, borehole, delz, z_extent: float, col_dict: dict, reduction: int = 1, apa=0.7, save=False)¶
Plot the simulated and measured temperature log of a borehole in front of borehole stratigraphy
- Parameters
inv_data (pandas dataframe) – dataframe with simulated data from shemat-suite
forw_data (pandas dataframe) – dataframe with observed data
parameter_data (dictionary) – dictionary with arrays from parameter files, read in with read2dict method
borehole (int) – borehole ID
delz (float) – vertical cell size of the model in meters (assuming regular grid)
z_extent (float) – vertical model extent in meters
col_dict (dictionary) – dictionary pairing lithology IDs to colors
reduction (int) – data reduction for plotting (in case you have so many points in your log)
apa (float, optional) – alpha value. Defaults to 0.7.
save (bool, optional) – save option for plot. Defaults to False.
- OpenWF.postprocessing.plot_logs(data, delz, borehole: int = 0, apa=0.7, z_extent: float = 6000.0, col_dict: dict = {})¶
Plot temperature logs of simulated and observed temperatures with lithologies as background
- Parameters
data (pandas Dataframe)) – dataframe with borehole temperature data and cell values, i.e. i,j,k
delz (float) – cell size in z direction
borehole (int, optional) – borehole ID. Defaults to 0.
apa (float, optional) – alpha value. Defaults to 0.7.
z_extent (float, optional) – vertical model dimension. Defaults to 6000..
- OpenWF.postprocessing.plot_slice(file, parameter: str = 'temp', direction: str = 'x', cell_number: int = 0, model_depth: Optional[float] = None)¶
Plot a slice of available parameters through the model in x, y, or z direction.
- Parameters
file (HDF5) – hdf5 file of SHEMAT-Suite results
parameter (str, optional) – parameter to be plotted. . Defaults to ‘temp’.
direction (str, optional) – direction in which the slice is plotted. Defaults to ‘x’.
cell_number (int, optional) – cell number at which the slice is plotted. Defaults to 0.
model_depth (float, optional) – model depth in meter above sea level. So if it extends 3 km below sea lvl, enter 3000. Defaults to None.
- OpenWF.postprocessing.read2dict(file: str = '.')¶
Read a parameter file and store it as a dictionary
- Parameters
file (string) – path to file loaded. These are the parameter files generated by SHEMAT-Suite in gradient based inversion
- Returns
dictionary with parameter blocks as arrays for different sections in the parameter file.
- Return type
data_dict [dictionary]
- OpenWF.postprocessing.read_hdf_file(filepath: str = '.', write: bool = False)¶
Short method to load an hdf5 file.
- Parameters
filepath (string) – path to the stored .h5 file