Cara menggunakan 3d cube in python

This article is meant to continue previously posted article: Depositional Facies Belt Mapping With Python. I really recommend you to read previously article before you continue.

The focus of this article is to show How simple is it to work on Facies model using Python using only some basic packages, such as Pandas, Numpy, Scikit-learn, and some visualization tool.

Disclaimer: The data that we’re using is a “toy data” that I think very relatable with real case data according to my experience. You can download the toy data here.

From Previous Article

Previous article shows the processes of making a simple 2d facies belt. The output are: Discrette Facies class, Probability Map for each Facies, and Randomized Discrette Facies Class. In this article we’re going to replicate this processes in order to make 3d facies model.

General Workflow in Making 3d facies model with SVM
  1. Data loading
  2. 2d facies and Probability map generation.
  3. Create 3d cube template
  4. Probability 3d interpolation
  5. Randomize the Facies using generated Probability Cube
  6. Facies Visualization
Into Python

1 Data Loading

I will trying my best to use as simple library as possible, to ease the operation and make it general and easier to understand. I use pandas, numpy, matplotlib, and sklearn.

import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from sklearn.svm import SVC, LinearSVC
from sklearn.model_selection import train_test_split

The data that I provide consist of XY coordinate that stored in X and Y column respectively, and Z position that stored in Zone column. The Facies column is the label that store the Depositional Environment information where 0 is backshore facies, 1 is foreshore facies, and 2 is offshore transition facies.

df = pd.read_csv(‘svm_data_3d_2.csv’, sep=’\t’)df.head()

To visualize the data, I use simple 3d plot using matplotlib with adding “projection = ‘3d’ “ projection arguments. With this, the figure will be able to show simple 3d plots using matplotlib.

2 2d facies and Probability map generation.

This steps actually mimic the facies mapping on previous post, but instead doing it on single layer we will do it in multiple zone.

First we need to provide the 2d grid geometry for the facies map, by using meshgrid. We use the value range from 0 to 1 with number 100 grid number.

We will store the facies label and probability map on a pred and prob list container.

pred = []
prob = []

and for each zone we will do facies prediction using SVM. We use append method to put each prediction and probability on pred and prob list container. Therefore we will be able to call the result for later.

To visualize the result, we can use subplots and iteration:

3 Create 3d Cube Template

This might be wrong and didn’t fit on your purpose, but at least it is easy and still geologically make sense, and most importantly it really solve my problem.

Firstly we need to create 3d grid using meshgrid, but instead passing only two arguments, we pass three arguments now which are grid_xy, grid_xy, and grid_zz.

grid_xy = np.linspace(0,1,100)
grid_zz = np.linspace(0,99,100)
xx,yy,zz = np.meshgrid(grid_xy,grid_xy,grid_zz)

4 Probability 3d interpolation

From this part onward will be a little bit confusing.

So i’m creating 3d probability cube from 3 2d maps by interpolate one each other map using np.linspace (see..!! its easy!). Fortunately numpy are capable to do the interpolation for 2d matrix.

We will create probability cube for each facies, and for each facies cube will be divided into two part:

  • The upper part (part1) is probability cube between zone 0 to zone 49
  • the lower part (part2) is probability cube between zone 50 to zone 100

Once each part created, we will combine both part with “np.append” method.

Here’s the code to create and stack each part on every facies code.

Once the probability cube for each facies done, we will stack the cube with np.c_ and have it stored in “prob_stack”, resulting a numpy array with the shape of n x 3.

prob_stack = np.c_[prob_fac00.flatten(), prob_fac01.flatten(), prob_fac02.flatten()]

5 Randomize Facies Label using Generated Probability Cube

Now we have probability cube in n x 3 numpy array. Finally we will randomize the facies label using the probability cube that we has been created in order to achieve “the “Geological Look”.

fac_transsitional = np.array([np.random.choice(a=(0,1,2),p=(i)) for i in prob_stack]).reshape(100,100,100)

6 Visualize the Result

3d Visualization using on 3d gridded data in Matplotlib will be very tricky. Unfortunately, i can’t find easier way to visualize the result in 3d.

Using matplotlib, we need to define the “plane”, and put the value on each plane.

To define the plane, we use xx, yy, xz, and yz array that stores 3d coordinate for plane that we’re about use for visualizing the cube. Later we use the value in the grid to visualize the color.

Conclusion

This simple workflow demonstrates the potential of using SVM in order to make 3d facies model using python. However, there are a lot of things to improve, i’m afraid it will make the code more complicated if I have it written in this article. The improvisation that can be done with this are: