.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/tutorials/reading_well_data.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note Click :ref:`here ` to download the full example code .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_tutorials_reading_well_data.py: Reading Well Data into Subsurface ================================= .. GENERATED FROM PYTHON SOURCE LINES 7-8 Authors: Miguel de la Varga and Alexander Juestel .. GENERATED FROM PYTHON SOURCE LINES 8-14 .. code-block:: default # This example will get into detail about how we are using `welly` and `striplog` to # import borehole data. # We start by using pooch to download the dataset into a temp file; .. GENERATED FROM PYTHON SOURCE LINES 15-31 .. code-block:: default import pooch from dataclasses import asdict import matplotlib.pyplot as plt from striplog import Component import subsurface as sb from subsurface.reader import ReaderFilesHelper from subsurface.reader.wells import read_collar, read_survey, read_lith, WellyToSubsurfaceHelper, welly_to_subsurface from subsurface.structs.base_structures.common_data_utils import to_netcdf base_url = "https://raw.githubusercontent.com/softwareunderground/subsurface/main/tests/data/borehole/" data_hash = "55d58e1e1ed22509579d46f736fa5f07f4428c6744bd16dbd919242d14348da7" raw_borehole_data_csv = pooch.retrieve(url=base_url + 'kim_ready.csv', known_hash=data_hash) .. GENERATED FROM PYTHON SOURCE LINES 32-35 This dataset consist on a csv file containing the following columns: x, y, name, num, z, year, 7,8,9, altitude, base, formation, top, _top_abs and md. This is a good example of how varied borehole data can be provided. We will need to be able to extract specific information to construct the `subsurface` object. .. GENERATED FROM PYTHON SOURCE LINES 35-43 .. code-block:: default # To read csv we are using `pandas` but since `pandas.read_csv` has a lot of arguments, we have created some # helper classes to facilitate the reading of the data for this specific context. These *Helpers* are just a python # data class with a bit of funcitonality for setter and getter. # Also since well data sometimes is given in multiple files - for collars, asseys and surveys - we will read those # subset of the data into its own `pandas.Dataframe`. Let's start: .. GENERATED FROM PYTHON SOURCE LINES 44-54 .. code-block:: default reading_collars = ReaderFilesHelper( file_or_buffer=raw_borehole_data_csv, # Path to file index_col="name", # Column used as index usecols=['x', 'y', 'altitude', "name"] # Specific columns for collar ) # We can see the fields from the class easily converting it to a dict asdict(reading_collars) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none {'file_or_buffer': '/home/runner/.cache/pooch/7c2d6aa7551f31216f7236d3f9fb70a6-kim_ready.csv', 'usecols': ['x', 'y', 'altitude', 'name'], 'col_names': None, 'drop_cols': None, 'format': '.csv', 'index_map': None, 'columns_map': None, 'additional_reader_kwargs': {}, 'file_or_buffer_type': , 'index_col': 'name', 'header': 'infer'} .. GENERATED FROM PYTHON SOURCE LINES 55-57 The rest of fields of ReaderFilesHelper would be used for different .csv configurations. With a `ReaderFilesHelper` we can use it for specific functions to read the file into pandas: .. GENERATED FROM PYTHON SOURCE LINES 59-62 .. code-block:: default collar = read_collar(reading_collars) collar .. raw:: html
x y altitude
name
KCL12 303412 3913997 108.713287
KCL12 303412 3913997 108.713287
KCL12 303412 3913997 108.713287
KCL12 303412 3913997 108.713287
KCL12 303412 3913997 108.713287
... ... ... ...
USLXX 318982 3935253 227.418152
USLXX 318982 3935253 227.418152
USLXX 318982 3935253 227.418152
USLXX 318982 3935253 227.418152
USLXX 318982 3935253 227.418152

721 rows × 3 columns



.. GENERATED FROM PYTHON SOURCE LINES 63-64 We do the same for survey and lithologies: .. GENERATED FROM PYTHON SOURCE LINES 66-75 .. code-block:: default survey = read_survey( ReaderFilesHelper( file_or_buffer=raw_borehole_data_csv, index_col="name", usecols=["name", "md"] ) ) survey .. rst-class:: sphx-glr-script-out Out: .. code-block:: none /home/runner/work/subsurface/subsurface/subsurface/reader/wells/well_files_reader.py:140: UserWarning: inc and/or azi columns are not present in the file. The boreholes will be straight. warnings.warn('inc and/or azi columns are not present in the file.' .. raw:: html
md inc azi
name
KCL12 0.000000 0 0
KCL12 1035.597077 0 0
KCL12 1652.245636 0 0
KCL12 2109.993683 0 0
KCL12 2109.984893 0 0
... ... ... ...
USLXX 308.885376 0 0
USLXX 601.202972 0 0
USLXX 753.114075 0 0
USLXX 1197.413513 0 0
USLXX 1623.969910 0 0

721 rows × 3 columns



.. GENERATED FROM PYTHON SOURCE LINES 76-89 .. code-block:: default lith = read_lith( ReaderFilesHelper( file_or_buffer=raw_borehole_data_csv, usecols=['name', 'top', 'base', 'formation'], columns_map={'top': 'top', 'base': 'base', 'formation': 'component lith', } ) ) lith .. raw:: html
top base component lith
name
KCL12 0.000000 1035.597077 topo
KCL12 1035.597077 1652.245636 etchegoin
KCL12 1652.245636 2109.993683 macoma
KCL12 2109.993683 2110.003683 mclure
KCL12 2109.984893 2799.027984 fruitvale
... ... ... ...
USLXX 308.885376 601.202972 freeman_jewett
USLXX 601.202972 753.114075 vedder
USLXX 753.114075 1197.413513 cretaceous
USLXX 1197.413513 1623.969910 basement
USLXX 1623.969910 1623.979910 NaN

721 rows × 3 columns



.. GENERATED FROM PYTHON SOURCE LINES 90-98 At this point we have all the necessary data in `pandas.Dataframe`. However, to construct a `subsurface.UnstructuredData` object we are going to need to convert the data to the usual scheme of: *vertex*, *cells*, *vertex_attr* and *cells_attr*. To do this we will use `welly` and `striplog` Welly is a family of classes to facilitate the loading, processing, and analysis of subsurface wells and well data, such as striplogs, formation tops, well log curves, and synthetic seismograms. The class WellyToSubsurfaceHelper contains the methods to create a welly project and export it to a subsurface data class. .. GENERATED FROM PYTHON SOURCE LINES 100-102 .. code-block:: default wts = WellyToSubsurfaceHelper(collar_df=collar, survey_df=survey, lith_df=lith) .. rst-class:: sphx-glr-script-out Out: .. code-block:: none The following striplog failed being processed: [] .. GENERATED FROM PYTHON SOURCE LINES 103-106 In the field p is stored a welly project (https://github.com/agile-geoscience/welly/blob/master/tutorial/04_Project.ipynb) and we can use it to explore and visualize properties of each well. .. GENERATED FROM PYTHON SOURCE LINES 108-110 .. code-block:: default wts.p .. raw:: html
IndexUWIDataCurves
0KerrXX2 curveslith, lith_log
1Steele_Petroleum_Co4_12 curveslith, lith_log
2PACIFIC_STATESXX2 curveslith, lith_log
3Russell12 curveslith, lith_log
4XX32_152 curveslith, lith_log
5St._Anthony12 curveslith, lith_log
6Kuhn81_152 curveslith, lith_log
7Bellevue_Deep12 curveslith, lith_log
8RoeXX2 curveslith, lith_log
9SUPERIOR_TENNECO_GAUTXX2 curveslith, lith_log
10Union_Tribe_BXX2 curveslith, lith_log
11MARQUIS12 curveslith, lith_log
12S_&_D_Killingwoth_EPM12 curveslith, lith_log
13West_Rio_Bravo12 curveslith, lith_log
14Ingram13_732 curveslith, lith_log
15KCL_G12 curveslith, lith_log
16Tidewater_Capital_Co.XX2 curveslith, lith_log
17Mobil_Pan_Pet_KCL86_352 curveslith, lith_log
18HayesXX2 curveslith, lith_log
19TennecoXX2 curveslith, lith_log
20Golden_State_VintnersXX2 curveslith, lith_log
21Gow12 curveslith, lith_log
22Westates442 curveslith, lith_log
23Bergman_Trust12 curveslith, lith_log
24Del_Fortuna12 curveslith, lith_log
25Amalgamated_Happold22 curveslith, lith_log
26TWIXX2 curveslith, lith_log
27BALD_EAGLE742 curveslith, lith_log
28Kramer12 curveslith, lith_log
29Kern_AXX2 curveslith, lith_log
30Tenneco_Ladd_Rio_Bravo_North872 curveslith, lith_log
31112 curveslith, lith_log
32Roe32 curveslith, lith_log
33KCL152 curveslith, lith_log
34Tenneco_Rio_Bravo322 curveslith, lith_log
35KCL122 curveslith, lith_log
36KCL_A58_82 curveslith, lith_log
37Mobil_Pan_Petroleum_KCL31_152 curveslith, lith_log
38KCL_B452 curveslith, lith_log
39Roberts_Cox23_12 curveslith, lith_log
40RUSSELLXX2 curveslith, lith_log
41KerncoXX2 curveslith, lith_log
42Davies12 curveslith, lith_log
43KCL_11442 curveslith, lith_log
44Arkelian23_262 curveslith, lith_log
45Cities_Service_TennecoXX2 curveslith, lith_log
46KCL87_252 curveslith, lith_log
4733XX2 curveslith, lith_log
48CURRY12 curveslith, lith_log
49JewettaXX2 curveslith, lith_log
50DearingerXX2 curveslith, lith_log
51McCulloch_Camp_et_al1_362 curveslith, lith_log
52Shell_Magee_GlideXX2 curveslith, lith_log
53Wright_Bloemer742 curveslith, lith_log
54Sharples_Marathon_BillingtonXX2 curveslith, lith_log
55Kimberlina12 curveslith, lith_log
56CallowayXX2 curveslith, lith_log
57Helbling12 curveslith, lith_log
58API_BartellXX2 curveslith, lith_log
59Famosa12_12 curveslith, lith_log
60Bishop_FeeXX2 curveslith, lith_log
61Wiedman55_262 curveslith, lith_log
62USLXX2 curveslith, lith_log
63Tenneco_Sun11x_312 curveslith, lith_log
64Law_et_alXX2 curveslith, lith_log
65XXXX2 curveslith, lith_log
66R.A._Shafter_A12 curveslith, lith_log


.. GENERATED FROM PYTHON SOURCE LINES 111-114 .. code-block:: default stripLog = wts.p[0].data['lith'] stripLog .. rst-class:: sphx-glr-script-out Out: .. code-block:: none Striplog(11 Intervals, start=0.0, stop=4604.7157137) .. GENERATED FROM PYTHON SOURCE LINES 115-118 .. code-block:: default stripLog.plot() plt.gcf() .. image-sg:: /examples/tutorials/images/sphx_glr_reading_well_data_001.png :alt: reading well data :srcset: /examples/tutorials/images/sphx_glr_reading_well_data_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out Out: .. code-block:: none
.. GENERATED FROM PYTHON SOURCE LINES 119-121 Once we have the `WellyToSubsurfaceHelper` the function `welly_to_subsurface` will directly convert the objet to `subsurface.UnstructuredData` -- using the trajectory module of `welly`. .. GENERATED FROM PYTHON SOURCE LINES 123-135 .. code-block:: default formations = ["topo", "etchegoin", "macoma", "chanac", "mclure", "santa_margarita", "fruitvale", "round_mountain", "olcese", "freeman_jewett", "vedder", "eocene", "cretaceous", "basement", "null"] unstruct = welly_to_subsurface( wts, table=[Component({'lith': l}) for l in formations] # This is to keep the lithology ids constant across all the wells ) unstruct .. rst-class:: sphx-glr-script-out Out: .. code-block:: none The following boreholes failed being processed: [] Dimensions: (points: 3350, XYZ: 3, cell: 3283, nodes: 2, cell_attr: 1, vertex_attr: 0) Coordinates: * points (points) int64 0 1 2 3 4 5 6 ... 3344 3345 3346 3347 3348 3349 * XYZ (XYZ) ` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: reading_well_data.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_