|
4 | 4 | import pandas as pd |
5 | 5 |
|
6 | 6 | from bedrock_ge.gi.schemas import ( |
7 | | - InSituTestSchema, |
8 | | - LocationSchema, |
9 | | - ProjectSchema, |
10 | | - SampleSchema, |
| 7 | + BedrockGIDatabase, |
| 8 | + BedrockGIGeospatialDatabase, |
11 | 9 | ) |
12 | 10 |
|
13 | 11 |
|
14 | | -# TODO: rename to check_brgi_geodb |
15 | | -# TODO: make this check actually work... |
16 | | -def check_brgi_database(brgi_db: Dict[str, Union[pd.DataFrame, gpd.GeoDataFrame]]): |
17 | | - """Validates the structure and relationships of a 'Bedrock Ground Investigation' (BRGI) database (which is a dictionary of DataFrames). |
| 12 | +def check_brgi_geospatial_database( |
| 13 | + brgi_geodb: BedrockGIGeospatialDatabase, |
| 14 | +): |
| 15 | + """Validates the structure and relationships of a 'Bedrock Ground Investigation' (BrGI) geospatial database. |
18 | 16 |
|
19 | | - This function checks that all tables in the BRGI database conform to their respective schemas |
| 17 | + This function checks that all tables in the BrGI geospatialdatabase conform to their respective schemas |
20 | 18 | and that all foreign key relationships are properly maintained. It validates the following tables: |
21 | 19 | - Project |
22 | 20 | - Location |
| 21 | + - LonLatHeight |
| 22 | + - All In-Situ test tables |
23 | 23 | - Sample |
24 | | - - InSitu_TESTX |
25 | | - - Lab_TESTY (not yet implemented) |
| 24 | + - All Lab test tables |
26 | 25 |
|
27 | 26 | Args: |
28 | | - brgi_db (Dict[str, Union[pd.DataFrame, gpd.GeoDataFrame]]): A dictionary |
29 | | - containing the BRGI database tables, where keys are table names and |
30 | | - values are the corresponding data tables (DataFrame or GeoDataFrame). |
| 27 | + brgi_geodb (BedrockGIGeospatialDatabase): Bedrock GI geospatial database object. |
31 | 28 |
|
32 | 29 | Returns: |
33 | 30 | is_valid (bool): True if all tables are valid and relationships are properly maintained. |
34 | 31 |
|
35 | 32 | Example: |
36 | 33 | ```python |
37 | | - brgi_db = { |
38 | | - "Project": project_df, |
39 | | - "Location": location_gdf, |
40 | | - "Sample": sample_gdf, |
41 | | - "InSitu_ISPT": in_situ_ispt_gdf, |
42 | | - } |
43 | | - check_brgi_database(brgi_db) |
| 34 | + brgi_geodb = BedrockGIGeospatialDatabase( |
| 35 | + Project=project_df, |
| 36 | + Location=location_geodf, |
| 37 | + LonLatHeight=lon_lat_height_geodf, |
| 38 | + InSituTests={"ISPT": ispt_geodf}, |
| 39 | + Sample=sample_geodf, |
| 40 | + LabTests={"LLPL": llpl_df}, |
| 41 | + ) |
| 42 | + check_brgi_geospatial_database(brgi_db) |
44 | 43 | ``` |
45 | 44 | """ |
46 | | - for table_name, table in brgi_db.items(): |
47 | | - if table_name == "Project": |
48 | | - ProjectSchema.validate(table) |
49 | | - print("'Project' table aligns with Bedrock's 'Project' table schema.") |
50 | | - elif table_name == "Location": |
51 | | - LocationSchema.validate(table) |
52 | | - check_foreign_key("project_uid", brgi_db["Project"], table) |
53 | | - print("'Location' table aligns with Bedrock's 'Location' table schema.") |
54 | | - elif table_name == "Sample": |
55 | | - SampleSchema.validate(table) |
56 | | - check_foreign_key("project_uid", brgi_db["Project"], table) |
57 | | - check_foreign_key("location_uid", brgi_db["Location"], table) |
58 | | - print("'Sample' table aligns with Bedrock's 'Sample' table schema.") |
59 | | - # ! JG is pretty sure that this doesn't work |
60 | | - # ! The line below should be: |
61 | | - # ! elif table_name.startswith("InSitu_"): |
62 | | - elif table_name == "InSitu": |
63 | | - InSituTestSchema.validate(table) |
64 | | - check_foreign_key("project_uid", brgi_db["Project"], table) |
65 | | - check_foreign_key("location_uid", brgi_db["Location"], table) |
66 | | - print( |
67 | | - f"'{table_name}' table aligns with Bedrock's table schema for In-Situ measurements." |
68 | | - ) |
69 | | - elif table_name.startswith("Lab_"): |
70 | | - print( |
71 | | - "🚨 !NOT IMPLEMENTED! We haven't come across Lab data yet. !NOT IMPLEMENTED!" |
72 | | - ) |
73 | | - |
| 45 | + # TODO: implement this |
74 | 46 | return True |
75 | 47 |
|
76 | 48 |
|
77 | | -# TODO: rename to check_brgi_db |
78 | | -def check_no_gis_brgi_database( |
79 | | - brgi_db: Dict[str, Union[pd.DataFrame, gpd.GeoDataFrame]], |
| 49 | +def check_brgi_database( |
| 50 | + brgi_db: BedrockGIDatabase, |
80 | 51 | ): |
81 | | - """Validates the structure and relationships of a 'Bedrock Ground Investigation' (BGI) database without GIS geometry. |
| 52 | + """Validates the structure and relationships of a 'Bedrock Ground Investigation' (BrGI) database. |
82 | 53 |
|
83 | | - This function performs the same validation as `check_brgi_database` but uses schemas |
84 | | - that don't require GIS geometry. It validates the following tables: |
85 | | - - Project (never has GIS geometry) |
86 | | - - Location (without GIS geometry) |
87 | | - - Sample (without GIS geometry) |
88 | | - - InSitu_TESTX (without GIS geometry) |
89 | | - - Lab_TESTY (not yet implemented) |
| 54 | + This function performs the same validation as `check_brgi_geospatial_database`, but uses schemas |
| 55 | + that don't require geospatial geometry. It validates the following tables: |
| 56 | + - Project (never has geospatial geometry) |
| 57 | + - Location (without geospatial geometry) |
| 58 | + - All In-Situ test tables (without geospatial geometry) |
| 59 | + - Sample (without geospatial geometry) |
| 60 | + - All Lab test tables (never has geospatial geometry) |
90 | 61 |
|
91 | 62 | Args: |
92 | | - brgi_db (Dict[str, Union[pd.DataFrame, gpd.GeoDataFrame]]): A dictionary |
93 | | - containing the Bedrock GI database tables, where keys are table names |
94 | | - and values are the corresponding data tables (DataFrame or GeoDataFrame). |
| 63 | + brgi_db (BedrockGIDatabase): A Bedrock GI database object. |
95 | 64 |
|
96 | 65 | Returns: |
97 | 66 | bool: True if all tables are valid and relationships are properly maintained. |
98 | 67 |
|
99 | 68 | Example: |
100 | 69 | ```python |
101 | | - brgi_db = { |
102 | | - "Project": projects_df, |
103 | | - "Location": locations_df, |
104 | | - "Sample": samples_df, |
105 | | - "InSitu_measurements": insitu_df, |
106 | | - } |
107 | | - check_no_gis_brgi_database(brgi_db) |
| 70 | + brgi_db = BedrockGIDatabase( |
| 71 | + Project=project_df, |
| 72 | + Location=location_df, |
| 73 | + InSituTests={"ISPT": ispt_df}, |
| 74 | + Sample=sample_df, |
| 75 | + LabTests={"LLPL": llpl_df}, |
| 76 | + ) |
| 77 | + check_brgi_database(brgi_db) |
108 | 78 | ``` |
109 | 79 | """ |
110 | | - for table_name, table in brgi_db.items(): |
111 | | - if table_name == "Project": |
112 | | - ProjectSchema.validate(table) |
113 | | - print("'Project' table aligns with Bedrock's 'Project' table schema.") |
114 | | - elif table_name == "Location": |
115 | | - LocationSchema.validate(table) |
116 | | - check_foreign_key("project_uid", brgi_db["Project"], table) |
117 | | - print( |
118 | | - "'Location' table aligns with Bedrock's 'Location' table schema without GIS geometry." |
119 | | - ) |
120 | | - elif table_name == "Sample": |
121 | | - SampleSchema.validate(table) |
122 | | - check_foreign_key("project_uid", brgi_db["Project"], table) |
123 | | - check_foreign_key("location_uid", brgi_db["Location"], table) |
124 | | - print( |
125 | | - "'Sample' table aligns with Bedrock's 'Sample' table schema without GIS geometry." |
126 | | - ) |
127 | | - elif table_name.startswith("InSitu_"): |
128 | | - InSituTestSchema.validate(table) |
129 | | - check_foreign_key("project_uid", brgi_db["Project"], table) |
130 | | - check_foreign_key("location_uid", brgi_db["Location"], table) |
131 | | - print( |
132 | | - f"'{table_name}' table aligns with Bedrock's '{table_name}' table schema without GIS geometry." |
133 | | - ) |
134 | | - elif table_name.startswith("Lab_"): |
135 | | - print( |
136 | | - "🚨 !NOT IMPLEMENTED! We haven't come across Lab data yet. !NOT IMPLEMENTED!" |
137 | | - ) |
138 | | - |
| 80 | + # TODO: implement this |
139 | 81 | return True |
140 | 82 |
|
141 | 83 |
|
|
0 commit comments