# load some modules
import pandas as pd
import matplotlib.pylab as plt
import numpy as np
import pygslib

# see block model help
help(pygslib.blockmodel)

# Create an empty block model
mymodel=pygslib.blockmodel.Blockmodel(nx=5,ny=5,nz=5,xorg=-6,yorg=-6,zorg=-6,dx=3,dy=3,dz=3)

# there is no data, it is empty
print mymodel.bmtable

# Create a model from external DataFrame. 
# In this case IJK or IX, IY, IZ or XC, YC, ZC are required
bmtable=pd.DataFrame({'IJK':np.array([1,2,3,4], dtype=np.int32)})
mymodel.set_blocks(bmtable)
print mymodel.bmtable

bmtable.dtypes

# Calculate row, column and level indices from IJK 
mymodel.calc_ixyz_fromijk(overwrite=False)
mymodel.calc_ixyz_fromijk(overwrite=True)   # if IX, IY, IZ exist we need to overwrite
print mymodel.bmtable

# Removing data from block model
mymodel.delete_blocks()
print mymodel.bmtable

# Creating a full block model with IJK
mymodel.create_IJK(overwrite=True)
print mymodel.bmtable.tail()

# Calculate row, column and level indices from IJK  
mymodel.calc_ixyz_fromijk(overwrite=True)
print mymodel.bmtable.tail()

# Calculate coordinates from indices  
mymodel.calc_xyz_fromixyz(overwrite=True)
print mymodel.bmtable.tail()

"""
Explanation: Block model test
End of explanation
"""


mymodel.blocks2vtkRectilinearGrid('blocks')

"""
Explanation: Export blocks to a VTK file
End of explanation
"""


mymodel.

"""
Explanation: The results can be ploted in an external viewer, for example mayavi or paraview:
<img src="figures/Fig_paraview2.png">
End of explanation
"""


