diff --git a/pyborehole/borehole.py b/pyborehole/borehole.py index e326ddd..f32f0d7 100644 --- a/pyborehole/borehole.py +++ b/pyborehole/borehole.py @@ -94,6 +94,21 @@ def create_df(self): df : pd.DataFrame DataFrame containing the Borehole Metadata. + Examples + ________ + >>> borehole.create_df() + >>> borehole.df + Value + Name RWE EB1 + Address Am Kraftwerk 17, 52249 Eschweiler, Germany + Location POINT (6.313031 50.835676) + X 6.313031 + Y 50.835676 + Coordinate Reference System EPSG:4326 + Coordinate Reference System PyProj EPSG:4326 + Altitude above sea level 136 + Altitude above KB None + """ # Create dict from attributes df_dict = {'Name': self.name, @@ -133,9 +148,12 @@ def update_df(self, data_dict: dict): df]) def add_deviation(self, - path: str, - delimiter: str, - step: float): + path: Union[str, pd.DataFrame], + delimiter: str = '', + step: float = 1, + md_column: str = 'MD', + dip_column: str = 'DIP', + azimuth_column: str = 'AZI'): """Add deviation to the Borehole Object. Parameters @@ -153,7 +171,10 @@ def add_deviation(self, self.deviation = Deviation(self, path=path, delimiter=delimiter, - step=step) + step=step, + md_column=md_column, + dip_column=dip_column, + azimuth_column=azimuth_column) # Updating DataFrame self.update_df(self.deviation.data_dict) @@ -206,9 +227,12 @@ class Deviation(Borehole): def __init__(self, borehole, - path: str, + path: Union[str, pd.DataFrame], delimiter: str, - step: float = 5): + step: float = 5, + md_column: str = 'MD', + dip_column: str = 'DIP', + azimuth_column: str = 'AZI'): # Importing wellpathpy try: @@ -217,8 +241,16 @@ def __init__(self, ModuleNotFoundError('wellpathpy package not installed') # Opening deviation file - md, inc, azi = wp.read_csv(fname=path, - delimiter=delimiter) + if isinstance(path, str): + md, inc, azi = wp.read_csv(fname=path, + delimiter=delimiter) + + # Opening Pandas DataFrame + if isinstance(path, pd.DataFrame): + md = path[md_column].values + inc = path[dip_column].values + azi = path[azimuth_column].values + # Creating deviation dev = wp.deviation( @@ -561,15 +593,15 @@ def plot_well_logs(self, else: j = 0 + if not colors: + colors = [None] * len(tracks) + # Creating plot fig, ax = plt.subplots(1, len(tracks) + j, figsize=(len(tracks) * 1.8, 8), sharey=True) - if not colors: - colors = [None] * len(tracks) - # Helping variable for adding well tops if add_well_tops: for index, row in self.well_tops.df.iterrows(): @@ -607,6 +639,8 @@ def plot_well_logs(self, ax[fill_between+j].fill_betweenx(df[depth_column], df[tracks[fill_between]], left_col_value, where=df[tracks[fill_between]] >= index, color=color) + plt.tight_layout() + return fig, ax def plot_well_log_along_path(self, diff --git a/test/test_borehole.py b/test/test_borehole.py index 93b5a04..ce5bebc 100644 --- a/test/test_borehole.py +++ b/test/test_borehole.py @@ -31,6 +31,22 @@ def test_borehole_class(): assert borehole.deviation is None assert borehole.logs is None assert isinstance(borehole.df, pd.DataFrame) + assert borehole.__str__() == 'Weisweiler R1' + + borehole.update_df({'newname': 'Weisweiler R2'}) + assert borehole.df.T['newname'].iloc[0] == 'Weisweiler R2' + + data = {'MD': [0, 50, 100], + 'DIP': [2, 2, 2], + 'AZI': [5, 5, 5]} + + df_dev = pd.DataFrame.from_dict(data) + + borehole.add_deviation(path=df_dev, + step=25, + md_column='MD', + dip_column='DIP', + azimuth_column='AZI') def test_borehole_class_error():