In [1]:
from IPython.core.display import HTML
css_file = 'pynoddy.css'
HTML(open(css_file, "r").read())
Out[1]:
In [2]:
%matplotlib inline
In [3]:
# here the usual imports. If any of the imports fails, make sure that pynoddy is installed
# properly, ideally with 'python setup.py develop' or 'python setup.py install'
import sys, os
import matplotlib.pyplot as plt
import numpy as np
# adjust some settings for matplotlib
from matplotlib import rcParams
# print rcParams
rcParams['font.size'] = 15
# determine path of repository to set paths corretly below
repo_path = os.path.realpath('../..')
import pynoddy.history
import pynoddy.experiment
rcParams.update({'font.size': 15})
We are considering the following scenario: we defined a kinematic model of a prospective geological unit at depth. As we know that the estimates of the (kinematic) model parameters contain a high degree of uncertainty, we would like to represent this uncertainty with the model.
Our approach is here to perform a randomised uncertainty propagation analysis with a Monte Carlo sampling method. Results should be presented in several figures (2-D slice plots and a VTK representation in 3-D).
To perform this analysis, we need to perform the following steps (see main paper for more details):
It would be possible to write a Python script to perform all of these steps in one go. However, we will here take another path and use the implementation in a Pynoddy Experiment class. Initially, this requires more work and a careful definition of the experiment - but, finally, it will enable a higher level of flexibility, extensibility, and reproducibility.
As in the last example, we will use a model from the Virtual Explorer Atlas as an examlpe model for this simulation. We use a model for a fold interference structure. A discretised 3-D version of this model (from the Virtual Explorer website) is presented in the figure below. The model represents a fold interference pattern of "Type 1" according to the definition of Ramsey (1967).
Instead of loading the model into a history object, we are now directly creating an experiment object for the type of uncertainty analysis:
In [4]:
reload(pynoddy.history)
reload(pynoddy.experiment)
model_url = 'http://virtualexplorer.com.au/special/noddyatlas/ch3/ch3_7/his/typeb.his'
ue = pynoddy.experiment.UncertaintyAnalysis(url = model_url)
# ue = pynoddy.experiment.UncertaintyAnalysis(history = "typeb_tmp.his")
For simpler visualisation in this notebook, we will analyse the following steps in a section view of the model.
We consider a section in y-direction through the model:
In [5]:
ue.write_history("typeb_tmp3.his")
In [6]:
ue.write_history("typeb_tmp2.his")
In [7]:
ue.plot_section('y')
Before we start to draw random realisations of the model, we should first store the base state of the model for later reference. This is simply possibel with the freeze() method which stores the current state of the model as the "base-state":
In [19]:
ue.freeze()
We now intialise the random generator. We can directly assign a random seed to simplify reproducibility (note that this is not essential, as it would be for the definition in a script function: the random state is preserved within the model and could be retrieved at a later stage, as well!):
In [20]:
ue.set_random_seed(12345)
The next step is to define probability distributions to the relevant event parameters. Let's first look at the different events:
In [21]:
ue.info(events_only = True)
In [22]:
ev2 = ue.events[2]
In [23]:
ev2.properties
Out[23]:
Next, we define the probability distributions for the uncertain input parameters:
In [24]:
param_stats = [{'event' : 2,
'parameter': 'Amplitude',
'stdev': 100.0,
'type': 'normal'},
{'event' : 2,
'parameter': 'Wavelength',
'stdev': 500.0,
'type': 'normal'},
{'event' : 2,
'parameter': 'X',
'stdev': 500.0,
'type': 'normal'}]
ue.set_parameter_statistics(param_stats)
In [25]:
resolution = 50
ue.change_cube_size(resolution)
tmp = ue.get_section('y')
prob_4 = np.zeros_like(tmp.block[:,:,:])
for i in range(30):
ue.random_draw()
tmp = ue.get_section('y', resolution = resolution)
prob_4 += (tmp.block[:,:,:] == 4)
In [26]:
plt.imshow(prob_4.transpose()[:,0,:], origin = 'lower left', interpolation = 'none')
Out[26]:
In [27]:
reload(pynoddy.history)
reload(pynoddy.output)
reload(pynoddy.experiment)
model_url = 'http://virtualexplorer.com.au/special/noddyatlas/ch3/ch3_7/his/typeb.his'
# ue = pynoddy.experiment.UncertaintyAnalysis(url = model_url)
ue = pynoddy.experiment.UncertaintyAnalysis(history = "typeb_tmp.his")
ue.change_cube_size(100)
# tmp = ue.get_section('y')
# tmp.plot_section('y', position = 0, data = prob_4, cmap = 'jet')
In [28]:
ue.plot_section('y', position = 'center', data = prob_4, cmap = 'jet')
In [352]:
ue.plot_section('y')
In [356]:
ue.export_to_vtk(vtk_filename = "typeb")
In [349]:
ue.export_to_vtk(vtk_filename = "prob4", data = prob_4)
In [210]:
block = ue.get_section('y')
In [231]:
tmp = np.zeros_like(block.block)
tmp += (block.block[:,0,:] == 2)
In [232]:
plt.imshow(tmp[:,0,:].transpose())
Out[232]:
In [225]:
block.plot_section('y')
In [233]:
plt.imshow(block.block[:,0,:].transpose(), origin = 'lower left', interpolation = 'none')
plt.colorbar(orientation = "horizontal")
Out[233]:
In [237]:
# filter out unit 4:
test = np.zeros_like(block.block[:,0,:])
test += (block.block[:,0,:] == 4)
plt.imshow(test.transpose(), origin = 'lower left', interpolation = 'none')
Out[237]:
In [268]:
ue.write_history("typeb_tmp.his")
In [362]:
ue.events[2].event_lines[-1]
Out[362]:
In [386]:
for i,line in enumerate(ue.history_lines):
if 'BlockOptions' in line:
print ue.history_lines[i-1] == '\n'
In [378]:
list.insert??
In [382]:
a = ['a', 'b', 'c']
In [383]:
print a[2]
a.insert(2,'2')
In [381]:
a
Out[381]:
In [ ]: