Notebook to optimize code

This notebook is a series of independent cells showing how to create a simple model from the beginning to the end using GeMpy

Importing dependencies


In [1]:
# Importing
import theano.tensor as T
import sys, os
sys.path.append("../GeMpy")

# Importing GeMpy modules
import GeMpy

# Reloading (only for development purposes)
import importlib
importlib.reload(GeMpy)

# Usuful packages
import numpy as np
import pandas as pn

import matplotlib.pyplot as plt

# This was to choose the gpu
os.environ['CUDA_LAUNCH_BLOCKING'] = '1'

# Default options of printin
np.set_printoptions(precision = 6, linewidth= 130, suppress =  True)

%matplotlib inline
#%matplotlib notebook

## Visualize data

# Setting the extent
geo_data = GeMpy.import_data([0,10,0,10,0,10], [10,4,10])


# =========================
# DATA GENERATION IN PYTHON
# =========================
# Layers coordinates
layer_1 = np.array([[0.5,4,7], [2,4,6.5], [4,4,7], [5,4,6]])#-np.array([5,5,4]))/8+0.5
layer_2 = np.array([[3,4,5], [6,4,4],[8,4,4], [7,4,3], [1,4,6]])
layers = np.asarray([layer_1,layer_2])

# Foliations coordinates
dip_pos_1 = np.array([7,4,7])#- np.array([5,5,4]))/8+0.5
dip_pos_2 = np.array([2.,4,4])

# Dips
dip_angle_1 = float(15)
dip_angle_2 = float(340)
dips_angles = np.asarray([dip_angle_1, dip_angle_2], dtype="float64")

# Azimuths
azimuths = np.asarray([90,90], dtype="float64")

# Polarity
polarity = np.asarray([1,1], dtype="float64")

# Setting foliations and interfaces values
GeMpy.set_interfaces(geo_data, pn.DataFrame(
    data = {"X" :np.append(layer_1[:, 0],layer_2[:,0]),
            "Y" :np.append(layer_1[:, 1],layer_2[:,1]),
            "Z" :np.append(layer_1[:, 2],layer_2[:,2]),
            "formation" : np.append(
               np.tile("Layer 1", len(layer_1)), 
               np.tile("Layer 2", len(layer_2))),
            "labels" : [r'${\bf{x}}_{\alpha \, 0}^1$',
               r'${\bf{x}}_{\alpha \, 1}^1$',
               r'${\bf{x}}_{\alpha \, 2}^1$',
               r'${\bf{x}}_{\alpha \, 3}^1$',
               r'${\bf{x}}_{\alpha \, 0}^2$',
               r'${\bf{x}}_{\alpha \, 1}^2$',
               r'${\bf{x}}_{\alpha \, 2}^2$',
               r'${\bf{x}}_{\alpha \, 3}^2$',
               r'${\bf{x}}_{\alpha \, 4}^2$'] }))

GeMpy.set_foliations(geo_data,  pn.DataFrame(
    data = {"X" :np.append(dip_pos_1[0],dip_pos_2[0]),
            "Y" :np.append(dip_pos_1[ 1],dip_pos_2[1]),
            "Z" :np.append(dip_pos_1[ 2],dip_pos_2[2]),
            "azimuth" : azimuths,
            "dip" : dips_angles,
            "polarity" : polarity,
            "formation" : ["Layer 1", "Layer 2"],
            "labels" : [r'${\bf{x}}_{\beta \,{0}}$',
              r'${\bf{x}}_{\beta \,{1}}$'] })) 



layer_3 = np.array([[2,4,3], [8,4,2], [9,4,3]])
dip_pos_3 = np.array([1,4,1])
dip_angle_3 = float(80)
azimuth_3 = 90
polarity_3 = 1



GeMpy.set_interfaces(geo_data, pn.DataFrame(
    data = {"X" :layer_3[:, 0],
            "Y" :layer_3[:, 1],
            "Z" :layer_3[:, 2],
            "formation" : np.tile("Layer 3", len(layer_3)), 
            "labels" : [  r'${\bf{x}}_{\alpha \, 0}^3$',
                           r'${\bf{x}}_{\alpha \, 1}^3$',
                           r'${\bf{x}}_{\alpha \, 2}^3$'] }), append = True)
GeMpy.get_raw_data(geo_data,"interfaces")

 
GeMpy.set_foliations(geo_data, pn.DataFrame(data = {
                     "X" : dip_pos_3[0],
                     "Y" : dip_pos_3[1],
                     "Z" : dip_pos_3[2],
                     "azimuth" : azimuth_3,
                     "dip" : dip_angle_3,
                     "polarity" : polarity_3,
                     "formation" : [ 'Layer 3'],
                     "labels" : r'${\bf{x}}_{\beta \,{2}}$'}), append = True)


GeMpy.set_data_series(geo_data, {'younger': ('Layer 1', 'Layer 2'),
                      'older': 'Layer 3'}, order_series = ['younger', 'older'])


GeMpy.set_interpolator(geo_data, u_grade = 0)


Using gpu device 0: GeForce GTX 970 (CNMeM is disabled, cuDNN not available)
---------------------------------------------------------------------------
MissingInputError                         Traceback (most recent call last)
<ipython-input-1-2bf6a9c52a5a> in <module>()
    120 
    121 
--> 122 GeMpy.set_interpolator(geo_data, u_grade = 0)

/home/miguel/PycharmProjects/GeMpy/GeMpy/GeMpy.py in set_interpolator(geo_data, compile_theano, *args, **kwargs)
    171     if not getattr(geo_data, 'interpolator', None) or compile_theano:
    172         geo_data.interpolator = geo_data.InterpolatorClass(geo_data, geo_data.grid, compile_theano=True,
--> 173                                                            *args, **kwargs)
    174     else:
    175         geo_data.interpolator._data = geo_data

/home/miguel/PycharmProjects/GeMpy/GeMpy/DataManagement.py in __init__(self, _data, _grid, *args, **kwargs)
    309             self._set_constant_parameteres(_data, _grid, **kwargs)
    310 
--> 311             self.theano_compilation_3D()
    312             # -------------------------
    313             self.potential_fields = [self.compute_potential_field(i, verbose=verbose)

/home/miguel/PycharmProjects/GeMpy/GeMpy/DataManagement.py in theano_compilation_3D(self)
   1077                                                   ref_layer_points, n_formation, yet_simulated], grad,
   1078                                                  updates=[(self.block, potential_field_contribution)],
-> 1079                                                  on_unused_input="warn", profile=True, allow_input_downcast=True,)
   1080                                              #   mode=theano.compile.MonitorMode(
   1081                                              #       post_func=detect_nan))

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/compile/function.py in function(inputs, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input)
    318                    on_unused_input=on_unused_input,
    319                    profile=profile,
--> 320                    output_keys=output_keys)
    321     # We need to add the flag check_aliased inputs if we have any mutable or
    322     # borrowed used defined inputs

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/compile/pfunc.py in pfunc(params, outputs, mode, updates, givens, no_default_updates, accept_inplace, name, rebuild_strict, allow_input_downcast, profile, on_unused_input, output_keys)
    477                          accept_inplace=accept_inplace, name=name,
    478                          profile=profile, on_unused_input=on_unused_input,
--> 479                          output_keys=output_keys)
    480 
    481 

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py in orig_function(inputs, outputs, mode, accept_inplace, name, profile, on_unused_input, output_keys)
   1774                    profile=profile,
   1775                    on_unused_input=on_unused_input,
-> 1776                    output_keys=output_keys).create(
   1777             defaults)
   1778 

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py in __init__(self, inputs, outputs, mode, accept_inplace, function_builder, profile, on_unused_input, fgraph, output_keys)
   1426             # OUTPUT VARIABLES)
   1427             fgraph, additional_outputs = std_fgraph(inputs, outputs,
-> 1428                                                     accept_inplace)
   1429             fgraph.profile = profile
   1430         else:

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/compile/function_module.py in std_fgraph(input_specs, output_specs, accept_inplace)
    175 
    176     fgraph = gof.fg.FunctionGraph(orig_inputs, orig_outputs,
--> 177                                   update_mapping=update_mapping)
    178 
    179     for node in fgraph.apply_nodes:

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/gof/fg.py in __init__(self, inputs, outputs, features, clone, update_mapping)
    169 
    170         for output in outputs:
--> 171             self.__import_r__(output, reason="init")
    172         for i, output in enumerate(outputs):
    173             output.clients.append(('output', i))

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/gof/fg.py in __import_r__(self, variable, reason)
    358         # Imports the owners of the variables
    359         if variable.owner and variable.owner not in self.apply_nodes:
--> 360                 self.__import__(variable.owner, reason=reason)
    361         if (variable.owner is None and
    362                 not isinstance(variable, graph.Constant) and

/home/miguel/anaconda3/lib/python3.5/site-packages/theano/gof/fg.py in __import__(self, apply_node, check, reason)
    463                                 'leading from this input to an output is %s. '
    464                                 'This chain may not be unique' % str(path) +
--> 465                                 detailed_err_msg)
    466 
    467                         # Standard error message

MissingInputError: A variable that is an input to the graph was neither provided as an input to the function nor given a value. A chain of variables leading from this input to an output is [Reference points for every layer, for{cpu,scan_fn}.0]. This chain may not be unique
Backtrace when the variable is created:
  File "/home/miguel/anaconda3/lib/python3.5/site-packages/ipykernel/ipkernel.py", line 199, in do_execute
    shell.run_cell(code, store_history=store_history, silent=silent)
  File "/home/miguel/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2723, in run_cell
    interactivity=interactivity, compiler=compiler, result=result)
  File "/home/miguel/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2831, in run_ast_nodes
    if self.run_code(code, result):
  File "/home/miguel/anaconda3/lib/python3.5/site-packages/IPython/core/interactiveshell.py", line 2885, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-1-2bf6a9c52a5a>", line 122, in <module>
    GeMpy.set_interpolator(geo_data, u_grade = 0)
  File "../GeMpy/GeMpy.py", line 173, in set_interpolator
    *args, **kwargs)
  File "../GeMpy/DataManagement.py", line 311, in __init__
    self.theano_compilation_3D()
  File "../GeMpy/DataManagement.py", line 591, in theano_compilation_3D
    ref_layer_points = T.matrix("Reference points for every layer")

In [ ]:


In [ ]:
GeMpy.compute_block_model(geo_data, series_number= [1], verbose = 0)

In [ ]:
geo_data.interpolator.grad

In [1]:
GeMpy.plot_section(geo_data, 12)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-1-f681715638c6> in <module>()
----> 1 GeMpy.plot_section(geo_data, 12)

NameError: name 'GeMpy' is not defined

In [2]:
GeMpy.compute_block_model(geo_data, series_number= 'all', verbose = 0)


---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-2-74a69dac30c6> in <module>()
----> 1 GeMpy.compute_block_model(geo_data, series_number= 'all', verbose = 0)

NameError: name 'GeMpy' is not defined

In [ ]:


In [ ]:
geo_data.interpolator.C

In [ ]:
geo_data.interpolator.C

In [ ]:
GeMpy.compute_block_model(geo_data, series_number= 'all', verbose = 0)

In [ ]:
25/34

In [ ]:
geo_data.interpolator._interpolate.profile.summary()

In [ ]: