|
| 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)) |
0 commit comments