88from ngi_calculations .cpt_correlations .definitions .geo import GEO
99from ngi_calculations .cpt_correlations .definitions .physics import PhysicParameters as PHY
1010from ngi_calculations .cpt_correlations .methods .cpt_process .options import CptProcessOptions
11+ from ngi_calculations .cpt_correlations .models .cpt_cone import CptCone
1112from ngi_calculations .cpt_correlations .models .cpt_raw import RawCPT
1213from ngi_calculations .cpt_correlations .models .lab_data import LabData
1314from ngi_calculations .cpt_correlations .utils .interpolation import interpolate_missing_values
@@ -30,7 +31,6 @@ def __init__(self, raw_cpt: RawCPT, lab_data: LabData, options: CptProcessOption
3031 self .raw_cpt = raw_cpt
3132 self .lab_data = lab_data
3233 self .options = options
33- # self.calculate()
3434
3535 @measure ("ProcessCPT_Calculation" , log_time = False , log_child = False )
3636 @track_execution
@@ -50,6 +50,7 @@ def calculate(self):
5050 self ._differential_pressure ()
5151 self ._normalized_differential_pressure ()
5252 self ._elevation ()
53+ self ._set_cone_info ()
5354 self ._total_cone_resistance ()
5455 self ._net_cone_resistance ()
5556 self ._normalized_cone_resistance ()
@@ -63,7 +64,7 @@ def calculate(self):
6364 self ._filter_data ()
6465
6566 def _set_initial_data (self ):
66- self .data = self .raw_cpt .data [ self . raw_cpt . columns . all ] .copy ()
67+ self .data = self .raw_cpt .data .copy ()
6768 self .data [GEO .u2_raw .key ] = self .data [GEO .u2 .key ]
6869 self .data [GEO .depth_raw .key ] = self .data [GEO .depth .key ]
6970 self .depth_raw = self .data [GEO .depth .key ].values
@@ -164,7 +165,14 @@ def _integrate_lab_profile(self):
164165 _df = _df .drop ([x for x in lab_cols if x in _df .columns ], axis = 1 )
165166
166167 # Merge the two Dataframes
167- _df .astype (np .float64 , copy = False )
168+ # Create a type dictionary for all columns
169+ types_dict = {col : np .float64 for col in _df .columns if col != self .options .cpt_identifier and col != depth }
170+ # Add depth type if needed
171+ types_dict [depth ] = np .float64
172+ # Apply types
173+ _df = _df .astype (types_dict )
174+
175+ # _df.astype(np.float64, copy=False)
168176 _df = pd .merge (_df , lab_df , on = depth , how = "outer" )
169177 _df .sort_values (by = depth , inplace = True )
170178 _df .set_index (depth , drop = False , inplace = True )
@@ -231,16 +239,36 @@ def _elevation(self):
231239 # TODO: Where to make available the self.options.elevation?
232240 self .data [GEO .elevation .key ] = self .options .elevation - self .data [GEO .depth .key ]
233241
242+ def _set_cone_info (self ):
243+ if self .options .cpt_identifier in self .data .columns :
244+ # Create a function to map each identifier to the corresponding cone area ratio value
245+ def get_cone_area_ratio (identifier ):
246+ cone = self .raw_cpt .cone .get (identifier )
247+ # Return the numeric cone_area_ratio attribute, not the entire CptCone object
248+ return cone .cone_area_ratio if cone else CptCone ().cone_area_ratio
249+
250+ # Apply the function to each row's identifier
251+ self .data [GEO .cone_area_ratio .key ] = self .data [self .options .cpt_identifier ].apply (get_cone_area_ratio )
252+ else :
253+ # If the identifier column doesn't exist, use the default value
254+ self .data [GEO .cone_area_ratio .key ] = CptCone ().cone_area_ratio
255+
256+ # Do the same for sleeve_area_ratio
257+ if self .options .cpt_identifier in self .data .columns :
258+
259+ def get_sleeve_area_ratio (identifier ):
260+ cone = self .raw_cpt .cone .get (identifier )
261+ # Return the numeric sleeve_area_ratio attribute, not the entire CptCone object
262+ return cone .sleeve_area_ratio if cone else CptCone ().sleeve_area_ratio
263+
264+ self .data [GEO .sleeve_area_ratio .key ] = self .data [self .options .cpt_identifier ].apply (get_sleeve_area_ratio )
265+ else :
266+ self .data [GEO .sleeve_area_ratio .key ] = CptCone ().sleeve_area_ratio
267+
234268 def _total_cone_resistance (self ):
235- self .data [GEO .cone_area_ratio .key ] = self .raw_cpt .cone .cone_area_ratio
236- self .data [GEO .sleeve_area_ratio .key ] = self .raw_cpt .cone .sleeve_area_ratio
237269 self .data [GEO .qt .key ] = (
238270 1000 * self .data [GEO .qc .key ] + self .data [GEO .u2 .key ] * (1 - self .data [GEO .cone_area_ratio .key ])
239271 ) / 1000
240- # self.df[GEO.qt.key] = (
241- # 1000 * self.df[GEO.qc.key]
242- # + self.df[GEO.u2.key] * (1 - self.df[GEO.cone_area_ratio.key]) * self.df[GEO.sleeve_area_ratio.key]
243- # ) / 1000
244272
245273 def _net_cone_resistance (self ):
246274 self .data [GEO .qn .key ] = self .data [GEO .qt .key ] - self .data [GEO .sigVtTotal .key ] / 1000
0 commit comments