def test_group_equal_layers(self): df_group = pd.DataFrame({ "depth": [0, 1, 2, 3, 4, 5, 6], "soil_type": [ "Peat", "Peat", "Peat", "Silt mixtures - clayey silt to silty clay", "Silt mixtures - clayey silt to silty clay", "Silt mixtures - clayey silt to silty clay", "Sand", ], "elevation_with_respect_to_NAP": [2, 1, 0, -1, -2, -3, -4], }) group = GroupClassification(2, df_group, 0.2) v = group.group_equal_layers(df_group, "soil_type", "depth", 0) df = pd.DataFrame({ "layer": ["Peat", "Silt mixtures - clayey silt to silty clay", "Sand"], "z_in": [0.0, 2.0, 5.0], "zf": [2, 5, 6], "thickness": [2.0, 3.0, 1.0], "z_centr": [1.0, 3.5, 5.5], "z_in_NAP": [2.0, 0.0, -3.0], "zf_NAP": [0, -3, -4], "z_centr_NAP": [1.0, -1.5, -3.5], }) assert_frame_equal(v, df)
def group_classification(self, min_thickness, classification, water_level_NAP, new=True, p_a=0.1): if classification == 'robertson': df = self.classify_robertson(water_level_NAP, new, p_a=p_a) return GroupClassification(df, min_thickness).df_group elif classification == 'been_jeffrey': df = self.classify_been_jeffrey(water_level_NAP) return GroupClassification(df, min_thickness).df_group else: return logging.error( f'Could not find {classification}. Check the spelling or classification not defined ' f'in the library')
def test_group_equal_layers(self): df_group = pd.DataFrame({ 'depth': [0, 1, 2, 3, 4, 5, 6], 'soil_type': [ 'Peat', 'Peat', 'Peat', 'Silt mixtures - clayey silt to silty clay', 'Silt mixtures - clayey silt to silty clay', 'Silt mixtures - clayey silt to silty clay', 'Sand' ], 'elevation_with_respect_to_NAP': [2, 1, 0, -1, -2, -3, -4] }) group = GroupClassification(df_group, 0.2) v = group.group_equal_layers(df_group, 'soil_type', 'depth') df = pd.DataFrame({ 'layer': ['Peat', 'Silt mixtures - clayey silt to silty clay', 'Sand'], 'z_in': [0., 2., 5.], 'zf': [2, 5, 6], 'thickness': [2., 3., 1.], 'z_centr': [1., 3.5, 5.5], 'zf_NAP': [0, -3, -4] }) assert_frame_equal(v, df)
def classify( self, classification, water_level_NAP=None, water_level_wrt_depth=None, p_a=0.1, new=True, do_grouping=False, min_thickness=None, ): """ Classify each row of the cpt type. Parameters ---------- classification: str Specify the classification, possible choices : "robertson", "been_jefferies". water_level_NAP: float, only for cpt type, necessary for the classification: give this or water_level_wrt_depth Water level with respect to NAP water_level_wrt_depth: float, only for cpt type, necessary for the classification: give this or water_level_NAP Water level with respect to the ground_level [0], it should be a negative value. p_a: float Atmospheric pressure. Default: 0.1 MPa. new: bool, default:True If True and the classification is robertson, the new(2016) implementation of robertson is used. do_grouping: bool, optional for the classification If True a group classification is added to the plot. min_thickness: float, optional for the classification [m] If specified together with the do_grouping set to True, a group classification is added to the plot. The grouping is a simple algorithm that merge all the layers < min_thickness with the last above one > min_thickness. In order to not make a big error do not use a value bigger then 0.2 m Returns ------- df: pd.DataFrame If do_grouping is True a pandas.DataFrame with the grouped layer is returned otherwise a pandas.DataFrame with a classification for each row is returned. """ # todo: refactor arguments, the arguments connected to each other should be given as a dict or tuple, check order water_level_and_zid_NAP = dict(water_level_NAP=water_level_NAP, zid=self.zid) if water_level_NAP is None and water_level_wrt_depth is None: water_level_wrt_depth = -1 logger.warning( f"You did not input the water level, a default value of -1 m respect to the ground is used." f" Change it using the kwagr water_level_NAP or water_level_wrt_depth." ) if min_thickness is None: min_thickness = 0.2 logger.warning( f"You did not input the accepted minimum thickness, a default value of 0.2 m is used." f" Change it using th kwarg min_thickness" ) if classification == "robertson": df = robertson.classify( self.df, water_level_and_zid_NAP=water_level_and_zid_NAP, water_level_wrt_depth=water_level_wrt_depth, new=new, area_quotient_cone_tip=self.net_surface_area_quotient_of_the_cone_tip, pre_excavated_depth=self.pre_excavated_depth, p_a=p_a, ) if do_grouping: return GroupClassification(self.zid, df, min_thickness).df_group return df elif classification == "been_jefferies": df = been_jefferies.classify( self.df, water_level_and_zid_NAP=water_level_and_zid_NAP, water_level_wrt_depth=water_level_wrt_depth, area_quotient_cone_tip=self.net_surface_area_quotient_of_the_cone_tip, pre_excavated_depth=self.pre_excavated_depth, ) if do_grouping: return GroupClassification(self.zid, df, min_thickness).df_group return df else: raise ValueError( f"Could not find {classification}. Check the spelling or classification not defined in the library" )
def classify( self, classification, water_level_NAP=None, water_level_wrt_depth=None, p_a=0.1, new=True, do_grouping=False, min_thickness=None, ): """ Classify function, classify gef files and return a dataframe with the classified gef. :param classification: (str) Specify the classification, possible choice : "robertson", "been_jefferies". :param water_level_NAP:(float) :param water_level_wrt_depth: (float) :param p_a: (float) Atmospheric pressure at ground level in MPa. :param new: (bool) Old(1990) or New(2016) implementation of Robertson. :param do_grouping: (bool) Do grouping if True. :param min_thickness: (float) Minimum accepted thickness for layers. :return: (DataFrame) DataFrame with classification. """ water_level_and_zid_NAP = dict(water_level_NAP=water_level_NAP, zid=self.zid) if water_level_NAP is None and water_level_wrt_depth is None: water_level_wrt_depth = -1 logging.warn( f"You did not input the water level, a default value of -1 m respect to the ground is used." f" Change it using the kwagr water_level_NAP or water_level_wrt_depth." ) if min_thickness is None: min_thickness = 0.2 logging.warn( f"You did not input the accepted minimum thickness, a default value of 0.2 m is used." f" Change it using th kwarg min_thickness") if classification == "robertson": df = robertson.classify( self.df, water_level_and_zid_NAP=water_level_and_zid_NAP, water_level_wrt_depth=water_level_wrt_depth, new=new, area_quotient_cone_tip=self. net_surface_area_quotient_of_the_cone_tip, pre_excavated_depth=self.pre_excavated_depth, p_a=p_a, ) if do_grouping: return GroupClassification(df, min_thickness).df_group return df elif classification == "been_jefferies": df = been_jefferies.classify( self.df, water_level_and_zid_NAP=water_level_and_zid_NAP, water_level_wrt_depth=water_level_wrt_depth, area_quotient_cone_tip=self. net_surface_area_quotient_of_the_cone_tip, pre_excavated_depth=self.pre_excavated_depth, ) if do_grouping: return GroupClassification(df, min_thickness).df_group return df else: return logging.error( f"Could not find {classification}. Check the spelling or classification not defined " f"in the library")