bedrock-ge 0.2.0__py3-none-any.whl → 0.2.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bedrock_ge/gi/write.py ADDED
@@ -0,0 +1,105 @@
1
+ from pathlib import Path
2
+ from typing import Dict, Union
3
+
4
+ import geopandas as gpd
5
+ import pandas as pd
6
+
7
+
8
+ def write_gi_db_to_gpkg(
9
+ brgi_db: Dict[str, gpd.GeoDataFrame],
10
+ gpkg_path: Union[str, Path],
11
+ ) -> None:
12
+ """
13
+ Write a database, i.e. a dictionary of DataFrames, with Bedrock Ground Investigation data to a GeoPackage file.
14
+
15
+ Each DataFrame will be saved in a separate table named after the keys of the dictionary.
16
+
17
+ Args:
18
+ brgi_dfs (dict): A dictionary where keys are brgi table names and values are DataFrames with brgi data.
19
+ gpkg_path (str): The name of the output GeoPackage file.
20
+
21
+ Returns:
22
+ None: This function does not return any value. It writes the DataFrames to a GeoPackage file.
23
+ """
24
+
25
+ # Create a GeoDataFrame from the dictionary of DataFrames
26
+ for sheet_name, brgi_table in brgi_db.items():
27
+ sanitized_table_name = sanitize_table_name(sheet_name)
28
+
29
+ if isinstance(brgi_table, pd.DataFrame):
30
+ brgi_table = gpd.GeoDataFrame(brgi_table)
31
+
32
+ if isinstance(brgi_table, gpd.GeoDataFrame):
33
+ brgi_table.to_file(
34
+ gpkg_path, driver="GPKG", layer=sanitized_table_name, overwrite=True
35
+ )
36
+
37
+ print(f"Ground Investigation data has been written to '{gpkg_path}'.")
38
+
39
+
40
+ def write_gi_db_to_excel(
41
+ gi_db: Dict[str, Union[pd.DataFrame, gpd.GeoDataFrame]],
42
+ excel_path: Union[str, Path],
43
+ ) -> None:
44
+ """
45
+ Write a database, i.e. a dictionary of DataFrames, with Ground Investigation data to an Excel file.
46
+
47
+ Each DataFrame will be saved in a separate sheet named after the keys of the dictionary.
48
+ Function can be used on any GI database, whether in AGS, Bedrock, or another format.
49
+
50
+ Args:
51
+ gi_dfs (dict): A dictionary where keys are GI table names and values are DataFrames with GI data.
52
+ excel_path (str): The name of the output Excel file.
53
+
54
+ Returns:
55
+ None: This function does not return any value. It writes the DataFrames to an Excel file.
56
+ """
57
+
58
+ # Create an Excel writer object
59
+ with pd.ExcelWriter(excel_path, engine="openpyxl") as writer:
60
+ for sheet_name, df in gi_db.items():
61
+ sanitized_sheet_name = sanitize_table_name(sheet_name)
62
+ if isinstance(df, pd.DataFrame) or isinstance(df, gpd.GeoDataFrame):
63
+ df.to_excel(writer, sheet_name=sanitized_sheet_name, index=False)
64
+
65
+ print(f"Ground Investigation data has been written to '{excel_path}'.")
66
+
67
+
68
+ def sanitize_table_name(sheet_name):
69
+ """
70
+ Replace invalid characters and spaces in GI table names with underscores,
71
+ such that the name is consistent with SQL, GeoPackage and Excel naming conventions.
72
+
73
+ Args:
74
+ sheet_name (str): The original sheet name.
75
+
76
+ Returns:
77
+ str: A sanitized sheet name with invalid characters and spaces replaced.
78
+ """
79
+ # Trim to a maximum length of 31 characters
80
+ trimmed_name = sheet_name.strip()[:31]
81
+
82
+ # Define invalid characters and replace with underscores
83
+ invalid_chars = [":", "/", "\\", "?", "*", "[", "]"]
84
+ sanitized_name = trimmed_name
85
+ for char in invalid_chars:
86
+ sanitized_name = sanitized_name.replace(char, "_")
87
+
88
+ # Replace spaces with underscores
89
+ sanitized_name = sanitized_name.replace(" ", "_")
90
+
91
+ # Collapse multiple underscores to one
92
+ sanitized_name = "_".join(filter(None, sanitized_name.split("_")))
93
+
94
+ if trimmed_name != sanitized_name:
95
+ print(
96
+ f"Table names shouldn't contain {invalid_chars} or spaces and shouldn't be longer than 31 characters.\n",
97
+ f"Replaced '{sheet_name}' with '{sanitized_name}'.",
98
+ )
99
+
100
+ # Ensure name isn't empty after sanitization
101
+ if not sanitized_name:
102
+ sanitized_name = "Table1"
103
+ print("The table name was completely invalid or empty. Replaced with 'Table1'.")
104
+
105
+ return sanitized_name
bedrock_ge/plot.py ADDED
@@ -0,0 +1,2 @@
1
+ def hello_plt() -> None:
2
+ print("Hello from src/bedrock/plot.py!")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: bedrock-ge
3
- Version: 0.2.0
3
+ Version: 0.2.1
4
4
  Summary: Bedrock, the Open Source Foundation for Ground Engineering
5
5
  Project-URL: Homepage, https://bedrock.engineer/
6
6
  Project-URL: Source, https://github.com/bedrock-engineer/bedrock-ge
@@ -0,0 +1,21 @@
1
+ bedrock_ge/__init__.py,sha256=TiCwiii4nnwQ5cVDKNEfUCwTzspLkydhtOtFuHA68yw,89
2
+ bedrock_ge/plot.py,sha256=hUxpZXWlUmf2Ec5CKkGkOBJ_TfC1KM8yUeuMtsqk7A0,70
3
+ bedrock_ge/gi/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ bedrock_ge/gi/bedrock-gi-schema.json,sha256=XaumYqouiflu4Nc8ChyFSHpmpJW4YPG0hsyeSxkuIWQ,850
5
+ bedrock_ge/gi/concatenate.py,sha256=kdK6TRu6dzUKeRALAqP3Az75PDTROe3rXfUaMXrCu-c,1462
6
+ bedrock_ge/gi/gis_geometry.py,sha256=f-J0OYQoi-ZXGslbo5qSXaBYphIpDB_igtUVMKi3Rzw,9316
7
+ bedrock_ge/gi/schemas.py,sha256=ZA2wFQOevXtN57XglY-M70TzbZY2RyLHJDRUkmz47_M,2871
8
+ bedrock_ge/gi/sqlmodels.py,sha256=_h3H9UP91I_1Ya_SZuL6gZbqL7uNCd5Y-u-yTf7CNto,2253
9
+ bedrock_ge/gi/validate.py,sha256=km5PeAUDRQr_RhwUG606I0SAdNrHmMA0RYpg7TU95Dc,4664
10
+ bedrock_ge/gi/write.py,sha256=vSHcj3xfWTyFJCa065Xfu4PBZddCPrYZ7MeW9M8PoUM,3863
11
+ bedrock_ge/gi/ags/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
12
+ bedrock_ge/gi/ags/ags3_data_dictionary.json,sha256=Wx20_oJRdAlzEo-cKD6FgN9B9zOMDTcsp5dgc8QWofI,188588
13
+ bedrock_ge/gi/ags/ags4_data_dictionary.json,sha256=XE5XJNo8GBPZTUPgvVr3QgO1UfEIAxzlSeXi-P1VLTs,609670
14
+ bedrock_ge/gi/ags/read.py,sha256=ebBHfU-w0BkjvcfmmmBxJx-PyziBRNm_4Okzvvqime8,7078
15
+ bedrock_ge/gi/ags/schemas.py,sha256=y36n9SCKqFfoIQ_7-MTEdfArA5vAqZdRpY3wC4fdjy4,7451
16
+ bedrock_ge/gi/ags/transform.py,sha256=EFCVnxRkLUT4mpmG5y_Bz4rNeTAAgolVfGGANMf29-E,8015
17
+ bedrock_ge/gi/ags/validate.py,sha256=Wghxm0dFGQB-6qrsbxOf68YalnPdJ6oeCXZJ7xrYVHI,703
18
+ bedrock_ge-0.2.1.dist-info/METADATA,sha256=PInDVd89ZxniGjAgO3Na0AUp9UaDP4ZJKFkgE268_FU,13712
19
+ bedrock_ge-0.2.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
20
+ bedrock_ge-0.2.1.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
21
+ bedrock_ge-0.2.1.dist-info/RECORD,,
@@ -1,4 +0,0 @@
1
- bedrock_ge-0.2.0.dist-info/METADATA,sha256=D3sGpuyeQc2RhQeAYUTPFROyZRhBlKkdIMkv6dB1hnY,13712
2
- bedrock_ge-0.2.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
3
- bedrock_ge-0.2.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
4
- bedrock_ge-0.2.0.dist-info/RECORD,,