Skip to content

Commit e7cb2ee

Browse files
Julien76Julien
andauthored
add example (#8)
Co-authored-by: Julien <[email protected]>
1 parent bf5a0b2 commit e7cb2ee

File tree

4 files changed

+87
-1
lines changed

4 files changed

+87
-1
lines changed

CHANGES.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changes
22

3+
## Version 0.1.10:
4+
5+
**date: 2025-05-05**
6+
7+
- Add example on how to use the library
8+
39
## Version 0.1.7:
410

511
**date: 2024-09-26**

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@ This repository contains various correlations for CPTs.
44

55
# Getting Started
66

7+
## Installation
8+
9+
`pip install ngi-calculations`
10+
11+
## Usage
12+
13+
You can find a complete example in:
14+
`./examples/basic-cpt-process.py`
15+
716
## Development
817

918
### Dependencies

examples/basic-cpt-process.py

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import pandas as pd
2+
from tests.data.calculation_data import ExcelDataConfig
3+
from tests.data.excel_data_column_mapping import CptRawColumns
4+
5+
from ngi_calculations.cpt_correlations.methods.cpt_process.calculations import CPTProcessCalculation
6+
from ngi_calculations.cpt_correlations.methods.cpt_process.options import CptProcessOptions
7+
from ngi_calculations.cpt_correlations.models.cpt_cone import CptCone
8+
from ngi_calculations.cpt_correlations.models.cpt_raw import RawCPT
9+
from ngi_calculations.cpt_correlations.models.lab_data import LabData
10+
11+
12+
def import_raw_cpt_from_excel(file_path, file_config: ExcelDataConfig) -> pd.DataFrame:
13+
return pd.read_excel(
14+
file_path,
15+
sheet_name=file_config.sheetname,
16+
header=[file_config.header_row - 1],
17+
usecols=f"{file_config.start_column}:{file_config.end_column}",
18+
skiprows=[0, 2],
19+
nrows=file_config.data_end_row - file_config.data_start_row + 1,
20+
)
21+
22+
23+
if __name__ == "__main__":
24+
# ── raw cpt data ──────────────────────────────────────────────────────
25+
# import the raw cpt data from an excel file. You can provide directly the cpt as dataframe
26+
raw_cpt_config = ExcelDataConfig(
27+
sheetname="cpt_raw",
28+
start_column="A",
29+
end_column="I",
30+
header_row=1,
31+
data_start_row=5,
32+
data_end_row=439,
33+
column_mapping=CptRawColumns().columns,
34+
)
35+
36+
raw_cpt_df = import_raw_cpt_from_excel("tests/data/calculations/testA.xlsx", raw_cpt_config)
37+
raw_cpt = RawCPT(data=raw_cpt_df, cone={"a": CptCone()})
38+
39+
# ── lab profile data ──────────────────────────────────────────────────
40+
# 1. top and bottom of the lab profile in m, it does not need to be the cpt depths
41+
lab_profile_depths: list[float] = [0, 100]
42+
43+
# 2. list of uw in kN/m3, should have same length as lab_profile_depths
44+
lab_profile_uw: list[float] = [14, 18]
45+
if len(lab_profile_uw) != len(lab_profile_depths):
46+
raise ValueError("the length of uw and depth must be the same")
47+
48+
# 3. list of u0 in kPa, should have same length as lab_profile_depths
49+
lab_profile_u0: list[float] = [14, 18]
50+
if len(lab_profile_u0) != len(lab_profile_depths):
51+
raise ValueError("the length of u0 and depth must be the same")
52+
53+
lab_data_df = pd.DataFrame({"depth": lab_profile_depths, "uw": lab_profile_uw, "u0": lab_profile_u0})
54+
lab_data = LabData(data=lab_data_df)
55+
56+
# ── process the cpt ───────────────────────────────────────────────────
57+
processed_cpt = CPTProcessCalculation(
58+
raw_cpt=raw_cpt, lab_data=lab_data, options=CptProcessOptions(cpt_identifier="method_id")
59+
)
60+
# 1. choose how the lab profiles are spread over the raw cpt rows
61+
# this is needed to compute the vertical stress
62+
# by default the interpolation is a "linear" but if the uw is constant you can set it to "padding" or "linear"
63+
# note that u0 is always interpolated linearly
64+
processed_cpt.options.interpolation_mode = "linear" # "padding" or "linear"
65+
66+
# 2. Process the cpt data
67+
processed_cpt.calculate()
68+
69+
# 3. you can now access the processed cpt data via:
70+
print(processed_cpt.results.head(10))

pyproject.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "ngi-calculations"
3-
version = "0.1.9"
3+
version = "0.1.10"
44
description = "CPT correlations including commonly used empirical correlations"
55
authors = [
66
"Julien Hericher <[email protected]>",
@@ -9,6 +9,7 @@ authors = [
99
readme = "README.md"
1010
packages = [
1111
{ include = "ngi_calculations", from = "src"},
12+
{ include = "tests" }
1213
]
1314

1415
[tool.poetry.dependencies]

0 commit comments

Comments
 (0)