TNO Intern

Commit c23a55e5 authored by Zanne Korevaar's avatar Zanne Korevaar
Browse files

Merge branch '13-fix-bug-lithology_properties-table' into 'main'

Resolve "fix bug lithology_properties table"

Closes #13

See merge request !14
parents a08e080b 516acf7d
Loading
Loading
Loading
Loading
Loading
+21 −19
Original line number Diff line number Diff line
@@ -14,9 +14,10 @@ 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 |
| 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         | —                                                                                       |
@@ -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:

+20 −0
Original line number Diff line number Diff line
@@ -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


+0 −5
Original line number Diff line number Diff line
@@ -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",
+15 −5
Original line number Diff line number Diff line
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,
+0 −0

Empty file added.

Loading