1.
Prepare data with time-pressure values
2. The code will automatically detect and annotate:
• Flow regimes (Radial/Linear/Spherical)
• Reservoir boundaries
• Fracture types
• Fault systems
Phase transitions
Import pandas as pd
Import numpy as np
Import [Link] as plt
From [Link] import find_peaks
Def load_pressure_data(filepath):
“””Load pressure-time data from CSV file”””
Df = pd.read_csv(filepath)
If {‘Time’, ‘Pressure’}.issubset([Link]):
Return df[‘Time’], df[‘Pressure’]
Else:
Raise ValueError(“CSV file must contain ‘Time’ and ‘Pressure’ columns”)
Def calculate_derivative(time, pressure):
“””Calculate pressure derivative using Bourdet method”””
Dp = [Link](pressure, time)
Tdp = time * dp
Return tdp
Def detect_classed_system(derivative, time):
“””Detect classed system features”””
Features = []
# Detect U-Fault (doubling of derivative)
If any(derivative[i] > 1.8*derivative[i-1] for i in range(1, len(derivative))):
[Link](‘U-Fault’)
# Detect Partial/Fault (plateau detection)
Slope = [Link](derivative)
If len(slope[abs(slope) < 0.01]) > 0.1*len(slope):
[Link](‘Partial/Fault’)
Return features
Def detect_vertical_features(time, pressure, derivative):
“””Detect vertical fracture/horizontal well features”””
Features = []
# Detect Dual Porosity (V-shape pattern)
Peaks, _ = find_peaks(-derivative, prominence=0.1)
If len(peaks) > 1:
[Link](‘Dual Porosity’)
# Detect Radial Composite (slope change)
Slopes = [Link]([Link](derivative))/[Link]([Link](time))
If any(slopes > 0.5):
[Link](‘Radial Composite’)
# Detect Constant Pressure (zero slope)
If [Link]([Link]([Link](pressure[-10:]))) < 0.1:
[Link](‘Constant Pressure’)
Return features
Def analyze_reservoir_signatures(time, pressure, derivative):
“””Analyze all reservoir signatures”””
Features = {
‘Classed System’: detect_classed_system(derivative, time),
‘Vertical Fracture/Horizontal Well’: detect_vertical_features(time, pressure, derivative),
‘Flow Phases’: [],
‘Phase Markers’: []
# Phase detection
Phase_boundaries = [0.01, 0.1]
Features[‘Phase Markers’] = [f”Phase boundary at {t}” for t in phase_boundaries]
# Flow regime detection
Log_deriv = [Link](derivative)
Dlog_deriv = [Link](log_deriv)/[Link]([Link](time))
If any(dlog_deriv < -0.2):
Features[‘Flow Phases’].append(‘Spherical Flow’)
If any(abs(dlog_deriv) < 0.1):
Features[‘Flow Phases’].append(‘Radial Flow’)
If any(dlog_deriv > 0.5):
Features[‘Flow Phases’].append(‘Linear Flow’)
Return features
Def plot_analysis(time, pressure, derivative, features):
“””Create enhanced log-log plot with annotations”””
[Link](figsize=(12, 8))
# Main plot
[Link](time, pressure, ‘b-‘, label=’Pressure’)
[Link](time, derivative, ‘r—‘, label=’Derivative’)
# Add phase markers
For marker in [0.01, 0.1]:
[Link](marker, color=’gray’, linestyle=’:’, alpha=0.7)
[Link](marker, [Link]()[0]*1.5, f’t={marker}’, rotation=90, ha=’right’, va=’bottom’)
# Add feature annotations
Annotation_y = max(derivative)*0.8
For i, (category, items) in enumerate([Link]()):
If items:
[Link](0.95, 0.85 – i*0.05, f”{category}: {‘, ‘.join(items)}”,
Transform=[Link]().transAxes, ha=’right’, va=’top’,
Bbox=dict(facecolor=’white’, alpha=0.8))
# Add slope markers
Slope_markers = {
‘Radial Flow’: (0.0, ‘green’),
‘Linear Flow’: (0.5, ‘purple’),
‘Spherical Flow’: (-0.5, ‘orange’)
}
For regime, (slope, color) in slope_markers.items():
X_ref = 0.1
Y_ref = derivative[[Link](abs(time – x_ref))]
Dx = [Link](-1, 1, 10)
Dy = y_ref * (dx/x_ref)**slope
[Link](dx, dy, color=color, linestyle=’:’, alpha=0.7)
[Link](dx[-1], dy[-1], regime, color=color, ha=’left’, va=’center’)
[Link](‘Time (log scale)’)
[Link](‘Pressure and Derivative (log scale)’)
[Link](‘Advanced Pressure Transient Analysis’)
[Link]()
[Link](True, which=’both’, linestyle=’—‘)
Plt.tight_layout()
[Link]()
Def main():
Time, pressure = load_pressure_data(‘pressure_data.csv’)
Derivative = calculate_derivative(time, pressure)
Features = analyze_reservoir_signatures(time, pressure, derivative)
Print(“Reservoir Analysis Results:”)
For category, items in [Link]():
Print(f”\n{category}:”)
For item in items:
Print(f” - {item}”)
Plot_analysis(time, pressure, derivative, features)
If __name__ == “__main__”:
Main()