Monday, November 7, 2022
HomeData ScienceMaking a Multi-Properly Built-in Properly Log and Formation Tops Dataframe in Python...

Making a Multi-Properly Built-in Properly Log and Formation Tops Dataframe in Python | by Andy McDonald | Nov, 2022


Combining formation information and properly log measurements for a number of wells in Python

Picture by Quintin Gellar: https://www.pexels.com/picture/rock-formation-wallpaper-612893/

When working with properly log measurements and subsurface information we are sometimes coping with totally different file codecs and pattern charges. As an illustration, properly log measurements are sometimes saved and transferred inside .las recordsdata or dlis recordsdata and sampled each 0.1m or 0.5ft. Geological formation tops then again are single discrete depth factors. This requires interpolation of the formation information to match the pattern charges of properly log measurements.

In my earlier tutorial, we noticed methods to merge properly log information and formation information for a single properly. Inside this tutorial, we’re going to see how we will do that for a number of wells.

Step one within the course of is to import the libraries we will likely be working with.

For this tutorial we will likely be utilizing lasio to load in .las recordsdata, os to learn recordsdata from a listing, pandas to allow us to work with dataframes, and csv to load formation information saved inside csv recordsdata.

Subsequent, we’ll start importing the info.

The info used inside this tutorial was downloaded from NLOG.nl, which is a web site that accommodates properly logging information for all the Dutch sector of the North Sea. The info is free to obtain and use. Full particulars of the info licence will be discovered right here, however a abstract of the utilization is offered right here from the Mental Property Rights part:

NLOG.NL doesn’t declare any rights (besides domains, trademark rights, patents and different mental property rights) in respect of data offered on or by means of this web site. Customers are permitted to repeat, to obtain and to reveal in any method, to distribute or to simplify the data offered on this web site with out the prior written permission of NLOG.NL or the lawful consent of the entitled celebration. Customers are additionally permitted to repeat, duplicate, course of or edit the data and/or format, offered NLOG.NL is quoted because the supply.

From the NLOG.nl web site, we will likely be utilizing information from three wells: L07–01, L07–05 and L07–04.

When loading in single recordsdata, we will simply cross the file location into the lasio.learn() operate. Nonetheless, as we’re working with a number of .las recordsdata, we have to learn them individually and append them collectively inside an inventory.

The dataframes saved inside that checklist are then joined collectively utilizing pd.concat() .

The next code will learn all recordsdata ending in .las inside a listing named Information/Pocket book 36.

As soon as the total file title has been obtained (line 8) it is going to be mixed with the listing path it’s saved in. The las file is then learn (line 11) and transformed to a pandas dataframe (line 12).

In an effort to distinguish which properly the info got here from, we will add a brand new column known as WELL to the dataframe. Its worth will likely be set to the properly title (line 15–16) contained inside the properly header part of the las file.

When loading recordsdata with LASIO and changing them to dataframes, the index of the dataframe will likely be set to the depth curve. We will change this in order that now we have a easy integer index and depth as an precise column inside the dataframe. That is achieved through the use of the .reset_index() operate inside pandas (line 19).

Subsequent, we have to type the dataframe in order that it goes from the shallowest depth measurement to the deepest (line 20). Doing this can put the index out of order, so we have to reset the index once more, however this time, we don’t want the index reworked right into a column (line 20) so we have to set the drop parameter to True.

As soon as the dataframe has been sorted, we will then append it to our dataframe checklist: df_list (line 21).

This course of repeats till all out there .las recordsdata have been learn inside the specified listing.

Lastly, the dataframes saved inside the checklist are joined collectively utilizing pd.concat() (line 24).

Once we name upon the well_df dataframe, we get again the next view of the primary 5 and final 5 rows.

Dataframe contents after loading in a number of .las recordsdata with lasio and becoming a member of them collectively right into a single dataframe. Picture by the creator.

Loading Formation Tops Information from CSV

Formation prime information is commonly saved inside tabular kind, mostly inside .csv recordsdata. These recordsdata will comprise the title of the geological formation, and the related prime and backside depth.

Instance of formation information saved inside a csv file. Picture by the creator.

The csv recordsdata for this instance have already got a column known as Properly, which accommodates the properly title. Doing this upfront previous to loading them into Python is useful, however not important. Should you don’t do that although, you will have to extract the properly title from the file title, which will be extra time-consuming.

Within the code instance beneath, we once more create a clean checklist (line 2) to retailer the dataframes in.

Subsequent, we loop over all recordsdata ending with .csv inside the specified listing and skim them utilizing pd.read_csv(), after which append them to the checklist known as df_formation_list

As soon as all recordsdata have been learn, we will then name upon pd.concat() to affix the dataframes collectively.

Once we name upon the formations_df dataframe we get again the next view:

Formation information saved inside a pandas dataframe for a number of wells. Picture by the creator.

Making a Dictionary of Formation Information

Now that now we have the formations inside a easy pandas dataframe, we now must convert this dataframe to a nested dictionary.

This makes the method of mixing the 2 datasets a lot simpler and permits us to create a steady column with the formation title at every depth stage.

We will do that through the use of a dictionary comprehension.

As soon as now we have run the above code, we will name upon formations_dict and we get again the next outcome.

Nested dictionary of formation names and depths. Picture by the creator.

From it, we will see that the primary secret’s the properly title, and inside every properly now we have a sub-dictionary with the depth as the important thing and the formation title as the worth.

You could surprise why we’re utilizing depth as the important thing slightly than the formation title. Doing it this fashion will enable us to verify if the depth we’re presently at (within the loop we’ll cowl within the subsequent part) is between two of the keys. Whether it is, then we will merely get the formation title.

If we need to view the tops for a selected properly, we will name upon particular wells inside the name to the dictionary like so:

formations_dict['L07-01']

Which can return the formation information for that particular properly:

Formation depths and names for a selected properly. Picture by the creator.

Now that the processing and setup have been accomplished, we will transfer on to integrating the formation tops dictionary with the properly log dataframe.

For this, we’ll use the next operate.

The operate first will get the depths (keys from formations_dict) for the formations of the properly (well_name ) that’s handed in.

We then must catch a couple of edge instances.

First, we have to see if we’re on the final formation inside the formations dictionary. If we’re then we’ll set a flag at_last_formation to True, in any other case, we’ll create a brand new variable known as beneath which would be the closest formation depth beneath the present depth (depth).

Subsequent, we have to see if we’re on the first formation inside the dictionary (traces 12–17). On this state of affairs, we’re checking if now we have any depth values above the primary formation listed. This will happen if we solely have formations from a selected depth as an alternative of from the floor. If the present depth is above (shallower) the primary formation depth, then we’ll set the formation title to a clean string (traces 19–20). In any other case, we’ll get the depth worth for the formation from above the present depth.

Lastly, we have to verify the place the present depth worth sits inside the formation depths. If we don’t do that, then the proper formation title is not going to be set. If the present depth is the same as one contained inside the formation dictionary then we’ll set it to the formation title on the depth listed.

As soon as the operate has been written, we will name upon it utilizing the apply methodology inside pandas. This permits us to iterate over every row inside the dataframe.

Once we name upon well_df we get again the next view of the dataframe:

Mixed dataframe outcomes containing each properly log information and formation information. Picture by the creator.

When doing something like this, it’s important you verify the outcomes shut up. For instance, we will verify the outcomes inside one of many wells, between the depths the place we anticipate a formation change.

We will try this as follows.

Shut-up of formation information inside pandas dataframe and authentic information inside the csv file. Picture by the creator.

Within the authentic formation tops csv file above, we will see that the transition between the Brussels Marl Member and the Ieper Member happens at 930 ft. This happens on the identical level inside the mixed dataframe.

This helps us achieve confidence that the method has labored.

To make sure, it’s at all times smart to verify a number of wells and intervals on this method, or by producing a properly log plot.

Integrating properly log information and formation information for a number of wells could be a problem inside Python. Inside this quick article, now we have seen methods to load a number of las recordsdata and formation information recordsdata and mix them collectively right into a single dataframe.

It will enable us to combine formation information and properly log information into machine studying fashions or properly log shows.

You should definitely try the next article in case you are trying to cope with a single properly:

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments