diff --git a/docs/manual/lithology_configuration.md b/docs/manual/lithology_configuration.md index 5842af6f2eddf91068b5ef8efb630aadaa640e64..baa6f949222f09a8efad95a02066a2a6687f9bb6 100644 --- a/docs/manual/lithology_configuration.md +++ b/docs/manual/lithology_configuration.md @@ -13,22 +13,23 @@ except `config_file_path`. The input JSON file for the lithology module includes the following parameters: -| Parameter | Description | Unit | Type | Remark | -|-------------------------|---------------------------------------------------------------------------------------------|------|------|---------| -| input_dir_lithology | Path to folder with Excel file containing lithology properties for the borehole | — | string | — | -| out_dir_lithology | Path to folder where lithology output is stored | — | string | Output includes tables with bulk subsurface thermal conductivity over depth and figures | -| borehole_lithology_path | Path to Excel file with subsurface lithology data | — | string | — | -| borhole_litho_sheetname | Name of tab in Excel file with subsurface lithology data | — | string | — | -| out_table | Name of HDF5 (.h5) file to store lithology and thermal conductivity data | — | string | — | -| Tg | (Sub)surface temperature | °C | scalar or list | Represents surface temperature if scalar | -| Tgrad | Subsurface temperature gradient | °C/100m | scalar | Used only if Tg is scalar | -| z_Tg | End depths of `Tg` values | m | list | Used only if Tg is a list | -| phi_scale | Factor to scale porosity uniformly over depth | — | scalar | — | -| lithology_scale | Factor to scale fraction of lithology a uniformly over depth | — | scalar | — | -| lithology_error | Random variation factor for lithology fraction over depth | — | scalar | — | -| n_samples | Number of samples for generating subsurface thermal conductivity models | — | scalar | Used only if basecase is false | -| basecase | Flag to apply error/scaling factors in lithology and porosity sampling | — | boolean | — | -| read_from_table | Flag to read pre-calculated thermal conductivity data instead of calculating during runtime | — | boolean | — | +| Parameter | Description | Unit | Type | Remark | +|---------------------------|--------------------------------------------------------------------------------------------|---------|----------------|-----------------------------------------------------------------------------------------| +| input_dir_lithology | Path to folder with Excel file containing lithology properties for the borehole | — | string | — | +| out_dir_lithology | Path to folder where lithology output is stored | — | string | Output includes tables with bulk subsurface thermal conductivity over depth and figures | +| lithology_properties_path | Path to Excel file containing user-defined soil/rock properties | - | string | Optional; default table with properties is included in the lithology package | +| borehole_lithology_path | Path to Excel file with subsurface lithology data | — | string | — | +| borhole_litho_sheetname | Name of tab in Excel file with subsurface lithology data | — | string | — | +| out_table | Name of HDF5 (.h5) file to store lithology and thermal conductivity data | — | string | — | +| Tg | (Sub)surface temperature | °C | scalar or list | Represents surface temperature if scalar | +| Tgrad | Subsurface temperature gradient | °C/100m | scalar | Used only if Tg is scalar | +| z_Tg | End depths of `Tg` values | m | list | Used only if Tg is a list | +| phi_scale | Factor to scale porosity uniformly over depth | — | scalar | — | +| lithology_scale | Factor to scale fraction of lithology a uniformly over depth | — | scalar | — | +| lithology_error | Random variation factor for lithology fraction over depth | — | scalar | — | +| n_samples | Number of samples for generating subsurface thermal conductivity models | — | scalar | Used only if basecase is false | +| basecase | Flag to apply error/scaling factors in lithology and porosity sampling | — | boolean | — | +| read_from_table | Flag to read pre-calculated thermal conductivity data instead of calculating during runtime | — | boolean | — | ### Rules for Configuration of the Lithology Module @@ -78,10 +79,11 @@ The lithology types (for `Lithology_a` and `Lithology_b`) currently supported by ### Excel Format for Lithological Thermal Properties from Literature -The lithology module relies on an Excel file (`resources/lithology_properties/lithology_properties.xlsx`) that contains +The lithology module relies on an Excel file (`lithology/resources/lithology_properties.xlsx`) that contains physical and thermal parameters for each lithology type, from Hantschel & Kauerauf (2009). This table acts as the reference -database from which all lithology-dependent thermal-conductivity calculations draw their input values. This table -should be edited for additional lithologies and/or customization of the rock properties. +database from which all lithology-dependent thermal-conductivity calculations draw their input values. Optionally, +the path to a similar table is user-defined in the configuration of the lithology module, with additional or edited soil +and/or rock properties. The Excel file includes the following columns: diff --git a/src/geoloop/configuration.py b/src/geoloop/configuration.py index 248615ba0ec699f639e64ed912d38f091c844df6..5f339a1164163019fa8348b880986f2060ea86a8 100644 --- a/src/geoloop/configuration.py +++ b/src/geoloop/configuration.py @@ -19,6 +19,8 @@ class LithologyConfig(BaseModel): Path to the JSON configuration file that created this object. out_dir_lithology : str or Path Directory where lithology outputs will be written. + lithology_properties_path: str or Path + Path to the Excel table with lithology properties. borehole_lithology_path : str or Path Path to the Excel or CSV file containing lithology data. borehole_lithology_sheetname : str @@ -48,6 +50,7 @@ class LithologyConfig(BaseModel): config_file_path: str | Path out_dir_lithology: str | Path input_dir_lithology: str | Path + lithology_properties_path: str |Path | None = None borehole_lithology_path: str | Path borehole_lithology_sheetname: str out_table: str @@ -89,6 +92,23 @@ class LithologyConfig(BaseModel): if not isinstance(self.out_dir_lithology, Path): self.out_dir_lithology = base_dir_lithology / Path(self.out_dir_lithology) + # Lithology properties table + # Resolve user-supplied path + if self.lithology_properties_path is not None: + if not isinstance(self.lithology_properties_path, Path): + self.lithology_properties_path = Path(self.lithology_properties_path) + + if not self.lithology_properties_path.is_absolute(): + self.lithology_properties_path = ( + base_dir_lithology / self.lithology_properties_path + ).resolve() + + if not self.lithology_properties_path.exists(): + raise FileNotFoundError( + f"Lithology properties file not found: " + f"{self.lithology_properties_path}" + ) + return self diff --git a/src/geoloop/constants.py b/src/geoloop/constants.py index 1b4a225ac8a1c771e396e148d6e53556c320f850..e1e55cfa596741b33a51f021241e6eeb39f2a416 100644 --- a/src/geoloop/constants.py +++ b/src/geoloop/constants.py @@ -10,11 +10,6 @@ test_output_path = test_dir / "output" # Resources directory resources_path = repo_path / "resources" -# Lithology resources directory -lithology_properties_xlsx = ( - resources_path / "lithology_properties" / "lithology_properties.xlsx" -) - # Dictionary of units for various parameters in the model. units_dict = { "Q_b": "W", diff --git a/src/geoloop/lithology/process_lithology.py b/src/geoloop/lithology/process_lithology.py index 74e91c2198920834a4e61bae87abf067b84deb28..74b430bb74e4aae9267d551e00d6899bbbb88d20 100644 --- a/src/geoloop/lithology/process_lithology.py +++ b/src/geoloop/lithology/process_lithology.py @@ -1,12 +1,12 @@ import math from pathlib import Path +from importlib.resources import files import numpy as np import pandas as pd import xarray as xr from geoloop.configuration import LithologyConfig -from geoloop.constants import lithology_properties_xlsx from geoloop.geoloopcore.strat_interpolator import TgInterpolator @@ -257,6 +257,7 @@ class ProcessLithologyToThermalConductivity: def __init__( self, + lithology_properties_df: pd.DataFrame, borehole_df: pd.DataFrame, Tg: float, Tgrad: float, @@ -270,8 +271,7 @@ class ProcessLithologyToThermalConductivity: out_table: str, read_from_table: bool, ) -> None: - # Read lithology properties reference table (Excel) - self.lithology_props_df = pd.read_excel(lithology_properties_xlsx) + self.lithology_props_df = lithology_properties_df self.borehole_df = borehole_df self.lithology_props_dict = self.create_lithology_props_dict() @@ -385,12 +385,22 @@ class ProcessLithologyToThermalConductivity: Initialized instance. """ - borehole_path = config.borehole_lithology_path + # Read borehole lithology table (Excel) borehole_df = pd.read_excel( - borehole_path, sheet_name=config.borehole_lithology_sheetname + config.borehole_lithology_path, sheet_name=config.borehole_lithology_sheetname ) + # Read lithology properties reference table (Excel) + if config.lithology_properties_path is not None: + lithology_properties_df = pd.read_excel( + config.lithology_properties_path + ) + else: + lithology_properties_df = pd.read_excel( + files("geoloop.lithology.resources").joinpath("lithology_properties.xlsx") + ) return cls( + lithology_properties_df=lithology_properties_df, borehole_df=borehole_df, Tg=config.Tg, Tgrad=config.Tgrad, diff --git a/src/geoloop/lithology/resources/__init__.py b/src/geoloop/lithology/resources/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/resources/lithology_properties/lithology_properties.xlsx b/src/geoloop/lithology/resources/lithology_properties.xlsx similarity index 100% rename from resources/lithology_properties/lithology_properties.xlsx rename to src/geoloop/lithology/resources/lithology_properties.xlsx