Mapas de ubicación
1. Extraer los datos del survey de un pozo
1.1 Importar librerías
from mpl_toolkits.mplot3d import Axes3D
from pathlib import Path
import contextily as ctx
import geopandas as gpd
import glob
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import plotly.express as px
import re
1.2 Importar ubicación de archivos
data_path = Path("Survey_wells")
files_survey = list(data_path.glob("*.txt"))
files_survey
1.3 Extracción de datos desde archivo *.txt
# Función modificada para extraer todos los datos de coordenadas más survey
def read_survey_data(file_name):
template_numeric = {
"surf_x": "Surface EW:",
"surf_y": "Surface NS:",
"KB": "KB-WH:",
"bot_x":"Bottom Hole EW:",
"bot_y":"Bottom Hole NS:"
}
template_strings = {
"well_name": "WELL NAME:",
"survey_name": "Survey Name:",
"wellbore_name": "WELLBORE NAME:",
"field": "FIELD:"
}
other_survey_information = []
well_dict = {}
count = 0
with open(file_name, "r", encoding = "ISO-8859-1") as f:
has_started_survey_cols = False
has_finished_header = False
for line in f:
count += 1
#print(f'getting line {count}')
#if line.startswith('HEADER'):
for key_num, pattern_num in template_numeric.items():
if line.startswith(pattern_num):
value_num = re.findall(r'-?\d+\.?\d*', line)
well_dict[key_num] = value_num[0]
#print(well_dict)
# print(f'found numeric pattern in line {count}')
for key_str, pattern_str in template_strings.items():
if line.startswith(pattern_str):
value_str = line.replace(pattern_str, "").strip()
well_dict[key_str] = value_str
#print(f'found string pattern in line {count}')
if line.startswith('MD'):
line = line.replace('X-Offset (E/W)', 'X-Offset(E/W)')
line = line.replace('Y-Offset (N/S)', 'Y-Offset(N/S)')
line = line.replace('UTM E/W', 'UTM(E/W)')
line = line.replace('UTM N/S', 'UTM(N/S)')
survey_columns = line.split()
indexes_of_cols = [x for x in range(len(survey_columns))]
helper_cols = dict(zip(survey_columns, indexes_of_cols))
survey_dict = {k: [] for k in survey_columns}
well_dict["survey"] = survey_dict
elif line.startswith('m RKB'):
continue
elif line.startswith(('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')):
survey_values = re.findall(r'-?\d+\.?\d*', line)
for survey_col, values_list in well_dict['survey'].items():
well_dict['survey'][survey_col].append(survey_values[helper_cols[survey_col]]
)
return well_dict
survey1 = r'Survey_wells/Volve F_159-19_19 A_19 A_ACTUAL.txt'
survey1 = read_survey_data(survey1)
print(survey1)
survey2 = r'Survey_wells/Volve F_159-19_19 A_19 A_ACTUAL.txt'
survey2 = read_survey_data(survey2)
print(survey2)
2. Extracción de coordenadas del survey
def coor_proc(well_dict):
coor_dict = {}
well = well_dict['well_name']
botx = well_dict['bot_x']
botx = float(botx)
boty = well_dict['bot_y']
boty = float(boty)
survname = well_dict['survey_name']
wellbore = well_dict['wellbore_name']
coor_dict = {'well': well, 'survey_name': survname, 'wellbore_name': wellbore, 'bottom_x': botx, 'bottom_y': boty}
return coor_dict
# Prueba de función para filtrar coordenadas
test = coor_proc(survey1)
test
3. Automatización de la extracción de survey de cada pozo
# Lectura de las coordenadas de cada pozo
coordenadas_df = pd.DataFrame()
for file in files_survey:
datos = read_survey_data(file)
coordenadas = coor_proc(datos)
df = pd.DataFrame([coordenadas])
coordenadas_df = coordenadas_df.append(coordenadas, ignore_index=True)
# Datafram final con toda la información consolidada
coordenadas_df.columns
4. Mapa 2D con Geopandas
4.1 Cargar ubicaciones de pozos con geopandas
# Obtener geometría x y y
geometry_wgs84 = gpd.points_from_xy(coordenadas_df['bottom_x'], coordenadas_df['bottom_y'])
# Convertir estructura dataframe en geodataframe
gdf = gpd.GeoDataFrame(coordenadas_df,
crs="epsg:32631",
geometry=geometry_wgs84)
# Mostrar geodataframe
display(gdf.head())
4.2 Visualización de datos interactiva
# Mapa interactivo con geopandas
gdf.explore()
4.3 Creación de mapa 2D
# Delimitar el área geográfica de Noruega
extent = (-500000, 1300000, 7600000, 8500000)
# Ubicación del campo Volve
ax = gdf.to_crs(epsg=3857).plot(figsize=(15, 12), markersize=30, color="green")
ax.axis(extent)
ctx.add_basemap(ax, source=ctx.providers.OpenTopoMap.url, zoom=6)
plt.title("Ubicación del campo Volve", fontsize=20)
plt.show()
# Zoom al mapa para visualizar mejor la ubicación de los pozos
ax = gdf.to_crs(epsg=3857).plot(figsize=(15, 12), markersize=50, color="green")
ctx.add_basemap(ax, source=ctx.providers.OpenTopoMap.url, zoom=5)
plt.title("Ubicación de los pozos del campo Volve", fontsize=20)
plt.show()