PyGSLIB

Probplot


In [1]:
#general imports
import matplotlib.pyplot as plt   
import pygslib
import numpy as np

#make the plots inline
%matplotlib inline


Getting the data ready for work

If the data is in GSLIB format you can use the function pygslib.gslib.read_gslib_file(filename) to import the data into a Pandas DataFrame.


In [2]:
#get the data in gslib format into a pandas Dataframe
mydata= pygslib.gslib.read_gslib_file('../datasets/cluster.dat')  
true= pygslib.gslib.read_gslib_file('../datasets/true.dat')

In [3]:
# This is a 2D file, in this GSLIB version we require 3D data and drillhole name or domain code
# so, we are adding constant elevation = 0 and a dummy BHID = 1 
mydata['Zlocation']=0
mydata['bhid']=1

true['Declustering Weight']=1

# printing to verify results
print ' \n **** 5 first rows in my datafile \n\n  ', mydata.head(n=5)

print ' \n **** 5 first rows in my datafile \n\n  ', true.head(n=5)


 
 **** 5 first rows in my datafile 

      Xlocation  Ylocation  Primary  Secondary  Declustering Weight  Zlocation  \
0       39.5       18.5     0.06       0.22                1.619          0   
1        5.5        1.5     0.06       0.27                1.619          0   
2       38.5        5.5     0.08       0.40                1.416          0   
3       20.5        1.5     0.09       0.39                1.821          0   
4       27.5       14.5     0.09       0.24                1.349          0   

   bhid  
0     1  
1     1  
2     1  
3     1  
4     1  
 
 **** 5 first rows in my datafile 

      Primary  Secondary  Declustering Weight
0     2.26       3.26                    1
1     3.28       2.64                    1
2     2.80       2.15                    1
3     0.95       1.69                    1
4     0.12       0.51                    1

In [4]:
#view data in a 2D projection
plt.scatter(mydata['Xlocation'],mydata['Ylocation'], c=mydata['Primary'])
plt.colorbar()
plt.grid(True)
plt.show()


Testing probplot

This is not plotting results but is handy to get declustered bins for plots


In [5]:
print pygslib.gslib.__plot.probplt.__doc__


binval,cl,xpt025,xlqt,xmed,xuqt,xpt975,xmin,xmax,xcvr,xmen,xvar,error = probplt(iwt,va,wt,[nd])

Wrapper for ``probplt``.

Parameters
----------
iwt : input int
va : input rank-1 array('d') with bounds (nd)
wt : input rank-1 array('d') with bounds (nd)

Other Parameters
----------------
nd : input int, optional
    Default: len(va)

Returns
-------
binval : rank-1 array('d') with bounds (nd)
cl : rank-1 array('d') with bounds (nd)
xpt025 : float
xlqt : float
xmed : float
xuqt : float
xpt975 : float
xmin : float
xmax : float
xcvr : float
xmen : float
xvar : float
error : int


In [6]:
mydata['Declustering Weight'].sum()


Out[6]:
140.00299999999996

In [7]:
parameters_probplt = {
        'iwt'  : 0,                             #int, 1 use declustering weight
        'va'   : mydata['Primary'],             # array('d') with bounds (nd)
        'wt'   : mydata['Declustering Weight']} # array('d') with bounds (nd), wight variable (obtained with declust?)

parameters_probpltl =  {
        'iwt'  : 1,                             #int, 1 use declustering weight
        'va'   : mydata['Primary'],             # array('d') with bounds (nd)
        'wt'   : mydata['Declustering Weight']} # array('d') with bounds (nd), wight variable (obtained with declust?)

parameters_probpltt =  {
        'iwt'  : 0,                             #int, 1 use declustering weight
        'va'   : true['Primary'],             # array('d') with bounds (nd)
        'wt'   : true['Declustering Weight']} # array('d') with bounds (nd), wight variable (obtained with declust?)


binval,cl,xpt025,xlqt,xmed,xuqt,xpt975,xmin,xmax, \
xcvr,xmen,xvar,error = pygslib.gslib.__plot.probplt(**parameters_probplt)

binvall,cll,xpt025l,xlqtl,xmedl,xuqtl,xpt975l,xminl, \
xmaxl,xcvrl,xmenl,xvarl,errorl = pygslib.gslib.__plot.probplt(**parameters_probpltl)

binvalt,clt,xpt025t,xlqtt,xmedt,xuqtt,xpt975t,xmint, \
xmaxt,xcvrt,xment,xvart,errort = pygslib.gslib.__plot.probplt(**parameters_probpltt)

In [8]:
print cl
print binvall


[  0.06   0.06   0.08   0.09   0.09   0.1    0.1    0.11   0.11   0.16
   0.16   0.17   0.18   0.19   0.19   0.19   0.22   0.24   0.26   0.28
   0.28   0.31   0.32   0.33   0.34   0.34   0.34   0.4    0.45   0.46
   0.51   0.57   0.62   0.65   0.67   0.71   0.79   0.81   0.83   0.84
   0.89   0.92   0.93   0.94   0.96   0.99   0.99   1.01   1.02   1.1
   1.11   1.21   1.21   1.27   1.34   1.36   1.37   1.38   1.38   1.66
   1.7    1.71   1.78   1.81   1.82   1.89   1.96   1.98   2.13   2.17
   2.22   2.28   2.33   2.33   2.34   2.47   2.51   2.52   2.55   2.74
   2.75   2.76   2.82   2.84   2.96   2.97   2.99   3.04   3.21   3.33
   3.35   3.51   3.56   3.59   3.61   3.64   3.81   4.29   4.6    4.89
   4.92   5.05   5.15   5.26   5.31   5.38   5.54   5.54   6.26   6.41
   6.49   7.53   7.56   7.71   7.92   7.94   8.03   8.34   8.48   8.71
   8.9    9.01   9.08   9.08   9.27   9.42  10.2   10.27  11.08  12.74
  15.77  15.77  17.19  18.64  18.76  19.44  20.35  21.08  22.75  58.32]
[ 0.00578202  0.01734606  0.02818511  0.0380599   0.04938108  0.05925587
  0.06696285  0.07539124  0.08526603  0.09755148  0.10887267  0.11730463
  0.12429019  0.13127576  0.139947    0.14909681  0.15897159  0.17125704
  0.18233538  0.19244945  0.20256352  0.21436326  0.22495947  0.23411284
  0.2471197   0.25771591  0.26686928  0.27650479  0.2861403   0.29558295
  0.30309708  0.31081834  0.31926102  0.32889295  0.34045342  0.35249602
  0.36261009  0.37368842  0.38404534  0.39151304  0.40090927  0.4124733
  0.42331236  0.43415141  0.44426905  0.4551081   0.46594716  0.4746184
  0.48304679  0.49123233  0.50002143  0.51049978  0.52133883  0.5318136
  0.54373478  0.55602023  0.56589502  0.57335914  0.58178753  0.59069806
  0.5993693   0.60755841  0.61627608  0.62667943  0.63582923  0.64714685
  0.66159654  0.67086062  0.67747477  0.6871067   0.69388513  0.69682435
  0.7038242   0.71080263  0.71537038  0.72187382  0.72676657  0.73023792
  0.73305215  0.73697349  0.74557331  0.75340171  0.75641593  0.7624408
  0.7694478   0.77341914  0.7785476   0.78550817  0.79118305  0.79878645
  0.81107191  0.82099669  0.82636801  0.82947508  0.83240716  0.83529282
  0.84362835  0.85241745  0.85679235  0.86417791  0.87149918  0.87634194
  0.88566316  0.89378799  0.89592723  0.89825932  0.90196996  0.90579845
  0.90805197  0.91033764  0.91275187  0.91501611  0.91708035  0.91917673
  0.92188739  0.92499089  0.92809797  0.93090505  0.93361928  0.93634779
  0.93882274  0.94208696  0.94589045  0.9492618   0.95359742  0.95781876
  0.96057942  0.96339721  0.96634358  0.9701935   0.97500411  0.97835046
  0.98060756  0.98295751  0.98495389  0.98747527  0.99023592  0.99257159
  0.99526082  0.99839289]

In [9]:
fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plt.plot (clt, binvalt, label = 'true')
plt.plot (cl, binval, label = 'raw')
plt.plot (cll, binvall, label = 'declustered')
plt.grid(True)
plt.legend()
fig.show


fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plt.plot (clt, binvalt, label = 'true')
plt.plot (cl, binval, label = 'raw')
plt.plot (cll, binvall, label = 'declustered')
ax.set_xscale('log')
plt.grid(True)
plt.legend()
fig.show


fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plt.plot (clt, binvalt, label = 'true')
plt.plot (cl, binval, label = 'raw')
plt.plot (cll, binvall, label = 'declustered')
ax.set_yscale('log')
plt.grid(True)
plt.legend()
fig.show


fig = plt.figure()
ax = fig.add_subplot(1,1,1)
plt.plot (clt, binvalt, label = 'true')
plt.plot (cl, binval, label = 'raw')
plt.plot (cll, binvall, label = 'declustered')
ax.set_xscale('log')
ax.set_yscale('log')
plt.grid(True)
plt.legend()
fig.show


Out[9]:
<bound method Figure.show of <matplotlib.figure.Figure object at 0x0000000012A67EF0>>

In [10]:
print 'data min, max: ', xmin, xmax
print 'data quantile 2.5%, 25%, 50%, 75%, 97.75%: ' , xpt025,xlqt,xmed,xuqt,xpt975
print 'data cv, mean, variance : ',  xcvr,xmen,xvar
print 'error <> 0? Then all ok?' , error==0


data min, max:  0.06 58.32
data quantile 2.5%, 25%, 50%, 75%, 97.75%:  0.06 0.06 0.06 0.06 -48.3898812723
data cv, mean, variance :  1.54066617191 4.35042857143 44.9242855306
error <> 0? Then all ok? True

In [ ]:


In [ ]: