Skip to content

Commit

Permalink
- working on fancy plot section
Browse files Browse the repository at this point in the history
  • Loading branch information
Leguark committed Feb 21, 2019
1 parent 03beb48 commit 924cff0
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 35 deletions.
72 changes: 41 additions & 31 deletions gempy/plotting/visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,8 @@ def _slice(self, direction, cell_number=25):
raise AttributeError(str(direction) + "must be a cartesian direction, i.e. xyz")
return _a, _b, _c, extent_val, x, y, Gx, Gy

def plot_block_section(self, cell_number=13, block=None, direction="y", interpolation='none',
plot_data=False, topography = None, ve=1, **kwargs):
def plot_block_section(self, cell_number=13, block=None, direction="y", scalar_field_at_interfaces=None,
interpolation='none', plot_data=False, topography = None, ve=1, **kwargs):
"""
Plot a section of the block model
Expand All @@ -248,28 +248,25 @@ def plot_block_section(self, cell_number=13, block=None, direction="y", interpol
Returns:
Block plot
"""
if block is not None:
import theano
import numpy
assert (type(block) is theano.tensor.sharedvar.TensorSharedVariable or
type(block) is numpy.ndarray), \
'Block has to be a theano shared object or numpy array.'
if type(block) is numpy.ndarray:
_block = block
else:
_block = block.get_value()
else:
try:
_block = self._data.interpolator.tg.final_block.get_value()
except AttributeError:
raise AttributeError('There is no block to plot')

plot_block = _block.reshape(self._data.resolution[0], self._data.resolution[1], self._data.resolution[2])
_a, _b, _c, extent_val, x, y = self._slice(direction, cell_number)[:-2]

if plot_data:
self.plot_data(direction, 'all')
# TODO: plot_topo option - need fault_block for that
#if block is not None:
# import theano
# import numpy
# assert (type(block) is theano.tensor.sharedvar.TensorSharedVariable or
# type(block) is numpy.ndarray), \
# 'Block has to be a theano shared object or numpy array.'
# if type(block) is numpy.ndarray:
# _block = block
# else:
# _block = block.get_value()
# else:
# try:
# _block = self._data.interpolator.tg.final_block.get_value()
# except AttributeError:
# raise AttributeError('There is no block to plot')


_block = block

# apply vertical exaggeration
if direction == 'x' or direction == 'y':
Expand All @@ -278,23 +275,36 @@ def plot_block_section(self, cell_number=13, block=None, direction="y", interpol
aspect = 1

if 'cmap' not in kwargs:
kwargs['cmap'] = self._cmap #
kwargs['cmap'] = self._cmap #
if 'norm' not in kwargs:
kwargs['norm'] = self._norm

if plot_data:
self.plot_data(direction, 'all')

plot_block = _block.reshape(self._data.resolution[0], self._data.resolution[1], self._data.resolution[2])
_a, _b, _c, extent_val, x, y = self._slice(direction, cell_number)[:-2]
# TODO: plot_topo option - need fault_block for that
if scalar_field_at_interfaces is not None:
sfai = scalar_field_at_interfaces[self._data.n_faults:].sum(axis=0)
no_idx = np.nonzero(sfai)[0]
sfai.sort()
im = plt.contourf(plot_block[_a, _b, _c].T, levels=sfai[no_idx], extend='both',
extent=extent_val, **kwargs)

else:
im = plt.imshow(plot_block[_a, _b, _c].T, origin="bottom",
extent=extent_val,
interpolation=interpolation,
aspect=aspect,
**kwargs)

im = plt.imshow(plot_block[_a, _b, _c].T, origin="bottom",
extent=extent_val,
interpolation=interpolation,
aspect=aspect,
**kwargs)
if direction == 'x' or direction=='y':
if direction == 'x' or direction == 'y':
if topography:
# TODO: apply vertical exaggeration to topography
topoline = topography._slice(direction = direction, extent = extent_val, cell_number = cell_number)
plt.fill(topoline[:, 0], topoline[:, 1], color='k')


import matplotlib.patches as mpatches
colors = [im.cmap(im.norm(value)) for value in self.formation_numbers]
patches = [mpatches.Patch(color=colors[i], label=self.formation_names[i]) for i in range(len(self.formation_names))]
Expand Down
10 changes: 6 additions & 4 deletions gempy/theano_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,17 +1298,17 @@ def compare(self, a, b, slice_init, Z_x, l, n_formation, drift):
b = theano.printing.Print("b")(b)
# l = 200/ (a - b)
slice_init = theano.printing.Print("slice_init")(slice_init)
n_formation_0 = theano.printing.Print("n_formation_0")(n_formation[slice_init:slice_init + 1])
n_formation_1 = theano.printing.Print("n_formation_1")(n_formation[slice_init + 1:slice_init + 2])
drift = theano.printing.Print("drift[slice_init:slice_init+1][0]")(drift[slice_init:slice_init + 1][0])
n_formation_0 = theano.printing.Print("n_formation_0")(n_formation_0)
n_formation_1 = theano.printing.Print("n_formation_1")(n_formation_1)
drift = theano.printing.Print("drift[slice_init:slice_init+1][0]")(drift)

# drift = T.switch(slice_init == 0, n_formation_1, n_formation_0)
# drift = T.set_subtensor(n_formation[0], n_formation[1])

# The 5 rules the slope of the function
sigm = (-n_formation_0[0] / (1 + T.exp(-l * (Z_x - a)))) - \
((n_formation_1[0] / (1 + T.exp(l * (Z_x - b))))) + drift
if False:
if 'sigm' in self.verbose:
sigm = theano.printing.Print("middle point")(sigm)
# n_formation = theano.printing.Print("n_formation")(n_formation)
return sigm
Expand Down Expand Up @@ -1383,6 +1383,8 @@ def block_series(self, slope=5000, weights=None):
n_formation_op_float_sigmoid = T.repeat(self.n_formation_op_float, 2)

# TODO: instead -1 at the border look for the average distance of the input!

# This -1 makes that after the last interfaces the gradient goes on upwards
n_formation_op_float_sigmoid = T.set_subtensor(n_formation_op_float_sigmoid[0], -1)
#- T.sqrt(T.square(n_formation_op_float_sigmoid[0] - n_formation_op_float_sigmoid[2])))

Expand Down

0 comments on commit 924cff0

Please sign in to comment.