# Importing gempy
import gempy as gp

# Embedding matplotlib figures into the notebooks
#%matplotlib inline


# Aux imports
import numpy as np
import pandas as pn
import matplotlib.pyplot as plt
import theano
import qgrid

geo_model = gp.create_model('Tutorial_ch1-6_CreatingModels')
gp.init_data(geo_model, [0, 1000, 0, 1000, -1000, 0], [50, 50, 50])
geo_model.set_default_surfaces()
geo_model.set_default_orientation()
geo_model.add_surface_points(400, 300, -500, 'surface1')
geo_model.add_surface_points(600, 300, -500, 'surface1')


"""
Explanation: Chapter 1.6: Creating models from scratch

So far we have shown the basics to create geological models by importing data from an external source (in especial GeoModeller 3D). In this chapter, we will explore the option available in GemPy to create the data directly in GemPy or to modify existing one. In this respect we will delve into the pandas DataFrames that contain the necessary data.
In this example we will make use of the library qgrid. From its documentation :

Qgrid is a Jupyter notebook widget which uses SlickGrid to render pandas DataFrames within a Jupyter notebook. This allows you to explore your DataFrames with intuitive scrolling, sorting, and filtering controls, as well as edit your DataFrames by double clicking cells.

In practice these library allows us to use pandas.DataFrames in Jupyter Notebooks as an excel table. Be aware that Qgrid requires of enabling nbextensions so it is important to test that the installation (https://github.com/quantopian/qgrid) was successful before trying to execute the rest of the notebook.
Let's create a bit of default data:
Let's start as always by importing the necessary dependencies:
End of explanation
"""


gp.set_interpolator(geo_model, theano_optimizer='fast_run',  verbose=[])

geo_model.additional_data

gp.compute_model(geo_model, debug=False,compute_mesh=False, sort_surfaces=False)

gp.plot_2d(geo_model, cell_number=25,
           direction='y', show_data=True)


gp.plot_2d(geo_model, cell_number= 25, direction='y', series_n=0, show_scalar=True)

vtk_object = gp.plot_3d(geo_model, plotter_type='background')

vtk_object.toggle_live_updating()

geo_model.surfaces

geo_model.modify_surface_points(0, Z=-300, plot_object=vtk_object)

geo_model.add_orientations(1,1,1, 'surface1', pole_vector=(1,1,1), plot_object=vtk_object)

"""
Explanation: Some default values but to make the model a bit faster but they are not necessary:
End of explanation
"""


gp.activate_interactive_df(geo_model, vtk_object)

"""
Explanation: Passing the vtk object to qgrid
End of explanation
"""


geo_model.qi.get('orientations')

geo_model.qi.get('surface_points')

geo_model.qi.get('surfaces')

geo_model.qi.get('series')

geo_model.qi.get('faults')

geo_model.qi.get('faults_relations')

geo_model.stack

gp.compute_model(geo_model)

geo_model.surface_points

"""
Explanation: It is important to get df with get to update the models sinde the activate_interactive method is called
End of explanation
"""


geo_model.interpolator.theano_graph.not_l.set_value(1.)
vtk_object.update_model()

geo_model.interpolator.theano_graph.ellipse_factor_exponent.set_value(50)

vtk_object.update_model()

"""
Explanation: Finite Fault parameters
End of explanation
"""


