Metadata-Version: 2.4
Name: pta-learn
Version: 1.0.4
Summary: A Python library for automated Pressure Transient Analysis (PTA) workflows. It provides tools for PTA flow regime feature extraction, time-lapse pattern recognition, pressure transient identification, and Bourdet derivative calculation.
Project-URL: Homepage, https://github.com/vitaliistarr/pta-learn
Project-URL: Repository, https://github.com/vitaliistarr/pta-learn.git
Project-URL: Bug Tracker, https://github.com/vitaliistarr/pta-learn/issues
Author-email: "V. Starikov" <starikovv98@gmail.com>, "B. Cui" <boyu.cui@qq.com>
License: Apache License
        Version 2.0, January 2004
        http://www.apache.org/licenses/
        
        TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
        1. Definitions.
        
        "License" shall mean the terms and conditions for use, reproduction,
         and distribution as defined by Sections 1 through 9 of this document.
        
        "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
        
        "Legal Entity" shall mean the union of the acting entity and all other entities that control,
         are controlled by, or are under common control with that entity. For the purposes of this definition,
         "control" means (i) the power, direct or indirect, to cause the direction or management of such entity,
         whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares,
         or (iii) beneficial ownership of such entity.
        
        "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
        
        "Source" form shall mean the preferred form for making modifications, including but not limited to software source code,
         documentation source, and configuration files.
        
        "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form,
         including but not limited to compiled object code, generated documentation, and conversions to other media types.
        
        "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License,
         as indicated by a copyright notice that is included in or attached to the work
         (an example is provided in the Appendix below).
        
        "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from)
         the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent,
         as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not
         include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work
         and Derivative Works thereof.
        
        "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications
         or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion
         in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of
         the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal,
         or written communication sent to the Licensor or its representatives, including but not limited to communication
         on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or
         on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication
         that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
        
        "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been
         received by Licensor and subsequently incorporated within the Work.
        
        2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants
         to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce,
         prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such
         Derivative Works in Source or Object form.
        
        3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants
         to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section)
         patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such
         license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their
         Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s)
         was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim
         in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory
         patent infringement, then any patent licenses granted to You under this License for that Work shall terminate
         as of the date such litigation is filed.
        
        4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium,
         with or without modifications, and in Source or Object form, provided that You meet the following conditions:
        
            (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
            (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
            (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent,
                trademark, and attribution notices from the Source form of the Work, excluding those notices that do not
                pertain to any part of the Derivative Works; and
            (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that
                You distribute must include a readable copy of the attribution notices contained within such NOTICE file,
                 excluding those notices that do not pertain to any part of the Derivative Works, in at least one of
                 the following places: within a NOTICE text file distributed as part of the Derivative Works;
                 within the Source form or documentation, if provided along with the Derivative Works; or, within a display
                 generated by the Derivative Works, if and wherever such third-party notices normally appear.
                 The contents of the NOTICE file are for informational purposes only and do not modify the License.
                 You may add Your own attribution notices within Derivative Works that You distribute, alongside or
                 as an addendum to the NOTICE text from the Work, provided that such additional attribution notices
                 cannot be construed as modifying the License.
        
        You may add Your own copyright statement to Your modifications and may provide additional or different license terms
         and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works
         as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions
         stated in this License.
        
        5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for
         inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any
         additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of
         any separate license agreement you may have executed with Licensor regarding such Contributions.
        
        6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks,
         or product names of the Licensor, except as required for reasonable and customary use in describing
         the origin of the Work and reproducing the content of the NOTICE file.
        
        7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing,
         Licensor provides the Work (and each Contributor provides its Contributions)
         on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including,
         without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY,
         or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of
         using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
        
        8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence),
         contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts)
         or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect,
         special, incidental, or consequential damages of any character arising as a result of this License or out of
         the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage,
         computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor
         has been advised of the possibility of such damages.
        
        9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof,
         You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability
         obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only
         on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree
         to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against,
         such Contributor by reason of your accepting any such warranty or additional liability.
        
        END OF TERMS AND CONDITIONS
        
        Copyright 2025-2026 AutoWell project team
        (https://www.norceresearch.no/en/projects/autowell-automated-well-monitoring-and-control),
        including Vitaly Starikov (https://www.linkedin.com/in/vitalystarikov/)
        and Boyu Cui (https://www.linkedin.com/in/boyu-cui-58878477/).
        
        Licensed under the Apache License, Version 2.0 (the "License");
        you may not use this file except in compliance with the License.
        You may obtain a copy of the License at
        
            http://www.apache.org/licenses/LICENSE-2.0
        
        Unless required by applicable law or agreed to in writing, software
        distributed under the License is distributed on an "AS IS" BASIS,
        WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
        See the License for the specific language governing permissions and
        limitations under the License.
License-File: LICENSE
License-File: NOTICE
Keywords: Bourdet-derivative,feature-extraction,loglog-plot,pattern-recognition,pressure-transient-analysis,transient-identification,well-testing
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Scientific/Engineering
Requires-Python: >=3.12
Requires-Dist: kneebow==1.0.1
Requires-Dist: matplotlib==3.10.1
Requires-Dist: numba>=0.61.0
Requires-Dist: numpy==2.1.3
Requires-Dist: pandas==2.2.3
Requires-Dist: plotly>=5.24.1
Requires-Dist: scikit-learn==1.6.1
Requires-Dist: scikit-optimize==0.10.2
Requires-Dist: scipy==1.15.0
Provides-Extra: dev
Requires-Dist: black>=22.0; extra == 'dev'
Requires-Dist: isort>=5.0; extra == 'dev'
Requires-Dist: pytest-cov>=2.0; extra == 'dev'
Requires-Dist: pytest>=6.0; extra == 'dev'
Requires-Dist: requests>=2.31.0; extra == 'dev'
Description-Content-Type: text/markdown

# pta-learn

A Python library for automated Pressure Transient Analysis (PTA) workflows. The library provides tools to identify shut-in and flowing transients, detect PTA flow regime features and recognize stable patterns in time-lapse pressure transient responses. 
Feature extraction and pattern recognition modules are based on the methodology described in the peer-reviewed paper: [Feature extraction and pattern recognition in time-lapse pressure transient responses](https://doi.org/10.1016/j.geoen.2024.213160).
Shut-in pressure transient identification module is implemented using the methodology detailed in the conference paper: [TPMR - A Novel Method for Automated Identification of Well Pressure Transients](https://doi.org/10.3997/2214-4609.202310910). 
Similarly, the flowing transient identification module employs the approach described in the conference paper: [LMIR - A New Method for Automated Identification of Multi-Rate Pressure Transients](https://doi.org/10.3997/2214-4609.202410313).

Usage examples provided in:

<a href="https://colab.research.google.com/drive/1ioJiNM5xpNyP1NoVpBrQp1qr1u94Knlz?usp=sharing"> PTA flow regime feature extraction example <img src="https://colab.research.google.com/assets/colab-badge.svg" height=16px></a> <br>
<a href="https://colab.research.google.com/drive/1_ASQ8nmRewhCZmNSMPcs3WBmBFFGiSs6?usp=sharing"> Time-lapse PTA pattern recognition example <img src="https://colab.research.google.com/assets/colab-badge.svg" height=16px></a> <br>
<a href="https://colab.research.google.com/drive/1z9B7RzGkWfQEpRWUygTIJvKtjnSeexE4?usp=sharing"> Shutin Transient Identification by TPMR method example <img src="https://colab.research.google.com/assets/colab-badge.svg" height=16px></a> <br>
<a href="https://colab.research.google.com/drive/1WFA9hKydEoxk1Z60_NFCQQJwhT9QwMEw?usp=sharing"> Flowing Transient Identification by LMIR method <img src="https://colab.research.google.com/assets/colab-badge.svg" height=16px></a> <br>
<a href="https://colab.research.google.com/drive/1SsXoKafnEJWafGUk8FHa_d7oF6ODljHI?usp=sharing"> Integrated Transient Identification Workflow example <img src="https://colab.research.google.com/assets/colab-badge.svg" height=16px></a> <br>
<a href="https://colab.research.google.com/drive/1lVzSIklC-51Nzqehp4lOFctKCjhEbX3Z?usp=sharing"> Loglog family ploting Workflow example <img src="https://colab.research.google.com/assets/colab-badge.svg" height=16px></a>

## Installation

Install the package using pip:

```bash
pip install pta-learn
```


## Usage

### Feature Extraction

- Automated flow regime feature detection
- Parameter optimization
- Visualization tools
- Multiple export formats (Excel, CSV)


The `PTAClassifier` class provides automated flow regime detection for single pressure transient analysis:

```python
from pta_learn import PTAClassifier
import numpy as np

# Prepare your data as a 2D numpy array with columns: [time, pressure, pressure_derivative]
data = np.array([
    [time_values],
    [pressure_values],
    [pressure_derivative_values]
]).T

# Initialize classifier
clf = PTAClassifier()

# Option 1: Fit and predict separately
clf.fit(data)
output, distance = clf.predict()

# Option 2: Fit and predict in one step
output, distance = clf.fit_predict(data)

# Option 3: Optimize parameters and predict
output, distance, optimization_result = clf.predict_optimize()

# Plot results
fig = clf.plot(industry_chart=True)

# Export results
clf.to_excel("results")  # or
clf.to_csv("results")
```

### Pattern Recognition
- Multi-transient analysis
- Stable pattern recognition
- Confidence estimation
- Result visualization

The `PatternRecognition` class enables multi-transient analysis to identify stable patterns:

```python
from pta_learn import PatternRecognition
import pandas as pd

# Prepare list of dataframes, each containing [time, pressure, pressure_derivative]
transient1 = pd.DataFrame({
    'time': time_values1,
    'pressure': pressure_values1,
    'pressure_derivative': pressure_derivative_values1
})
transient2 = pd.DataFrame({...})
data = [transient1, transient2]

# Initialize pattern recognition
pr = PatternRecognition()

# Fit data
pr.fit(data)

# Detect features
pr.detect_features()

# Get stable pattern
fig = pr.get_stable_pattern()

# Export results
pr.to_excel("pattern_results")
```

### TPMR method
- Shutin Transient Identification
- Result visualization

The `TPMR` function enables shut-in transient identication in time series sensors.
eg downhole pressure gauges. Please refer to `TPMR` and `plot_target` functions input/output description in the `pta_learn` module.

```python
from pta_learn import TPMR
from pta_learn.ti_misc import plot_target
import pandas as pd

# Prepare pressure and rate dataframes, pressure data is the one used by the method, and rate data is to verify the result.
pressure = pd.DataFrame({
    'Timestamp': timestamp_values,
    'Pressure': pressure_values,
    'Time': time_values
})
rate = pd.DataFrame({
    'Timestamp': timestamp_values,
    'Rate': rate_values,
    'Time': time_values
})

# Set parameters in the function
# p(float) stands for prominence, and it can be understood as the relative pressure drop in a shut-in transient
p = 10

# interval(float) is the minimum time duration in a shut-in transient
interval_shutin = 20

# run the function
shutin_bp_all, shutin_bp_interval, shutin_transient_all, shutin_transient_interval = TPMR(df_bhp, p, interval_shutin)

# plot the result
plot_target(df_bhp, df_rate ,shutin_transient_interval, TI_empty)
```

### LMIR method
- Flowing Transient Identification
- Result visualization

The `LMIR` function enables flowing transient identification in time series sensors, eg Step Rate Tests in downhole pressure gauges. Please refer to `LMIR` and `plot_target` functions input/output description in the `pta_learn` module. 

```python
from pta_learn import LMIR
from pta_learn.ti_misc import plot_target
import pandas as pd

# Prepare pressure and rate dataframes, pressure data is the one used by the method, and rate data is to verify the result.
pressure = pd.DataFrame({
    'Timestamp': timestamp_values,
    'Pressure': pressure_values,
    'Time': time_values
})
rate = pd.DataFrame({
    'Timestamp': timestamp_values,
    'Rate': rate_values,
    'Time': time_values
})

# Set parameters in the function
# order (int, optional): The number of adjacent points on each side of a data point to compare when identifying local minima.
order = 10
# - start_filter_hours (int, optional): Filters out breakpoints detected within the specified number of hours from the start of the transient.
# Example: If start_filter_hours = 5, any breakpoint detected within the first 5 hours will be removed.

# - end_filter_hours (int, optional): Filters out breakpoints detected within the specified number of hours from the end of the transient.
# Example: If end_filter_hours = 5, any breakpoint detected within the last 5 hours will be removed.

# run the function
flowing_period, multirate_bp_period,filtered_minima_df,para = LMIR(df_bhp,order = order)

# plot the result
plot_target(df_bhp, df_rate,TI_empty,flowing_period)
```

### Integrated transient identification workflow
- Identify both shut-in transients and flowing transient
- Result visualization

The Integrated transient identification workflow `ti_worflow` function enables shut-in and flowing transients identication in time series sensors, eg downhole pressure gauges. Please refer to `ti_workflow` and `plot_target` functions input/output description in the `pta_learn` module.

```python
from pta_learn import ti_workflow
from pta_learn.ti_misc import plot_target
import pandas as pd

# Prepare pressure and rate dataframes, pressure data is the one used by the method, and rate data is to verify the result.
pressure = pd.DataFrame({
    'Timestamp': timestamp_values,
    'Pressure': pressure_values,
    'Time': time_values
})
rate = pd.DataFrame({
    'Timestamp': timestamp_values,
    'Rate': rate_values,
    'Time': time_values
})

# Set parameters in the function

# parameters for TPMR method (p)
p = 10
# parameters for LMIR method (order, start_filter_hours , end_filter_hours)
order = 10
# paremeters for workflow (interval_shutin, interval_flowing)
interval_shutin = 10
interval_flowing = 10


# run the function
shutin,flowing,TI,TI_ft,all_breakpoints,w_rate,para = ti_workflow(df_bhp, df_rate, p, interval_shutin, interval_flowing, order = order)

# plot the result
plot_target(df_bhp, df_rate,shutin,flowing)
```

### Loglog family ploting Workflow
- Identify both shut-in transients and flowing transient in PTA
- Rate rebuilt based on breakpoints detected by transient idenfication.
- Superposition time calculation in PTA
- Bourdet derivative calculation in PTA
- Normalization calculation in PTA
- Result visualization

The `Loglog family ploting Workflow` function enables plotting loglog family of Bourdet derivatives from identified transients. Please refer to `cal_loglog_shut`, `cal_loglog_inj` and `plot_TI_family` functions input/output description in the `pta_learn` module.

```python
from pta_learn import ti_workflow
from pta_learn.bourdet_derivative import cal_loglog_shut, cal_loglog_inj
from pta_learn.normalization import normal_calc
from pta_learn.ti_misc import plot_TI_family
import pandas as pd

# Prepare pressure and rate dataframes, pressure data is the one used by the method, and rate data is to verify the result.
pressure = pd.DataFrame({
    'Timestamp': timestamp_values,
    'Pressure': pressure_values,
    'Time': time_values
})
rate = pd.DataFrame({
    'Timestamp': timestamp_values,
    'Rate': rate_values,
    'Time': time_values
})

# Transient identification workflow

# parameters for TPMR method (p)
p = 10
# parameters for LMIR method (order, start_filter_hours , end_filter_hours)
order = 10
# paremeters for workflow (interval_shutin, interval_flowing)
interval_shutin = 10
interval_flowing = 10

# run the function
shutin,flowing,TI,TI_ft,all_breakpoints,w_rate,para = ti_workflow(df_bhp, df_rate, p, interval_shutin, interval_flowing, order = order)


# Call the cal_loglog_shutin function
# L is the smoothing factor by default.
L = 0.1
log, rate_ave, all_bps = cal_loglog_shut(df_bhp, df_rate, Sel_shutin, all_breakpoints,w_rate,index,L)
log, rate_ave, all_bps = cal_loglog_inj(df_bhp, df_rate, Sel_flowing, all_breakpoints,w_rate,index,L)

# normalize the derivative
# ref is the index of transient used as the reference for normalization
ref = 0
loglog_normalized = []
for i in range(len(loglogs)):
    loglog_nor = normal_calc(loglogs[i],rate_lists[i],ref,rate_lists)
    loglog_normalized.append(loglog_nor)

# plot the loglog family
fig = plot_TI_family(*loglog_normalized)
```

## Citation

If you use this library in your research, please cite:

```
@article{starikov2024feature,
  title={Feature extraction and pattern recognition in time-lapse pressure transient responses},
  author={Starikov, V. and Shchipanov, A. and Demyanov, V. and Muradov, K.},
  journal={Geoenergy Science and Engineering},
  volume={242},
  pages={213160},
  year={2024},
  publisher={Elsevier},
  doi={10.1016/j.geoen.2024.213160},
  url={https://www.sciencedirect.com/science/article/pii/S294989102400530X}
}

@conference{starikov2023unsupervised,
  title={Unsupervised Classification of Flow Regime Features in Pressure Transient Responses},
  author={Starikov, V. and Demyanov, V. and Muradov, K. and Shchipanov, A.},
  booktitle={Fifth EAGE Conference on Petroleum Geostatistics},
  year={2023},
  month={Nov},
  pages={1-5},
  publisher={European Association of Geoscientists & Engineers},
  doi={10.3997/2214-4609.202335019}
}

@conference{Boyu2023tpmr,
  title={TPMR - A Novel Method for Automated Identification of Well Pressure Transients},
  author={Cui,B. and Zhang,N. and Shchipanov,A. and Rong,C. and Demyanov,V.},
  booktitle={84th EAGE Annual Conference & Exhibition},
  year={2023},
  month={Jun},
  pages={1-5},
  publisher={European Association of Geoscientists & Engineers},
  doi={https://doi.org/10.3997/2214-4609.202310910}
}

@conference{Boyu2024lmir,
  title={LMIR - A New Method for Automated Identification of Multi-Rate Pressure Transients},
  author={Cui,B. and Shchipanov,A. and Zhang,N. and Demyanov,V. and Rong,C.},
  booktitle={85th EAGE Annual Conference & Exhibition},
  year={2024},
  month={Jun},
  pages={1-5},
  publisher={European Association of Geoscientists & Engineers},
  doi={https://doi.org/10.3997/2214-4609.202410313}
}



```
## Acknowledgements

This research code was developed within the AutoWell research and development project funded by the Research Council of Norway and the industry partners including ConocoPhillips Skandinavia AS, Sumitomo Corporation Europe Norway Branch, Harbour Energy Norge AS and Aker BP ASA (grant no. 326580, PETROMAKS2 programme).

## Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

