PyGSLIB

Introduction

This is a simple example on adding coordinates to a GSLIB grid. Note that the function addcord is a Fortran modified copy of the standalone GSLIB program addcoord.


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

#make the plots inline
%matplotlib inline


Getting the data ready for work

You can use Pandas to import your data from csv, execel, sql database, json, html, among others. If the data is in GSLIB format you can use the function gslib.read_gslib_file(filename) to import the data into a Pandas DataFrame.


In [3]:
# To put the GSLIB file into a Pandas DataFrame
mydata= pygslib.gslib.read_gslib_file(u'../datasets/true.dat')

In [5]:
# This is a 2D grid file with two variables
# To add a dummy variable BHID = 1 use this code
mydata['bhid']=1

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


 
 **** 5 first rows in my datafile **** 

         Primary  Secondary  bhid
2495     7.11       8.82     1
2496     9.26       7.97     1
2497     1.86       8.62     1
2498     1.12       6.59     1
2499     1.65       5.83     1

In [6]:
# GSLIB grids have not coordinates
# To add coordinates use addcoord function

#first prepare a parameter file
par= {  'nx'  : 50,
        'ny'  : 50,
        'nz'  : 1,
        'xmn' : 0.5,
        'ymn' : 0.5,
        'zmn' : 1,
        'xsiz': 1,
        'ysiz': 1,
        'zsiz': 10,
        'grid': mydata }

# then run the function
mydataxyz=pygslib.gslib.addcoord(**par)

# this is to see the output
mydataxyz


Out[6]:
x y z Primary Secondary bhid
0 0.5 0.5 1.0 2.26 3.26 1
1 1.5 0.5 1.0 3.28 2.64 1
2 2.5 0.5 1.0 2.80 2.15 1
3 3.5 0.5 1.0 0.95 1.69 1
4 4.5 0.5 1.0 0.12 0.51 1
5 5.5 0.5 1.0 0.13 0.27 1
6 6.5 0.5 1.0 0.39 0.16 1
7 7.5 0.5 1.0 0.24 0.31 1
8 8.5 0.5 1.0 0.30 0.39 1
9 9.5 0.5 1.0 0.22 0.40 1
10 10.5 0.5 1.0 0.18 0.42 1
11 11.5 0.5 1.0 0.26 0.42 1
12 12.5 0.5 1.0 0.55 0.30 1
13 13.5 0.5 1.0 0.12 0.25 1
14 14.5 0.5 1.0 0.44 0.32 1
15 15.5 0.5 1.0 0.14 0.57 1
16 16.5 0.5 1.0 0.50 0.61 1
17 17.5 0.5 1.0 0.82 0.64 1
18 18.5 0.5 1.0 0.51 0.69 1
19 19.5 0.5 1.0 0.73 0.65 1
20 20.5 0.5 1.0 0.36 0.46 1
21 21.5 0.5 1.0 0.16 0.42 1
22 22.5 0.5 1.0 0.10 0.47 1
23 23.5 0.5 1.0 0.47 0.49 1
24 24.5 0.5 1.0 0.52 0.60 1
25 25.5 0.5 1.0 0.29 0.66 1
26 26.5 0.5 1.0 0.98 0.94 1
27 27.5 0.5 1.0 2.14 1.44 1
28 28.5 0.5 1.0 1.31 1.85 1
29 29.5 0.5 1.0 1.97 2.22 1
... ... ... ... ... ... ...
2470 20.5 49.5 1.0 0.03 0.54 1
2471 21.5 49.5 1.0 0.05 0.42 1
2472 22.5 49.5 1.0 0.36 0.31 1
2473 23.5 49.5 1.0 0.13 0.35 1
2474 24.5 49.5 1.0 0.03 0.41 1
2475 25.5 49.5 1.0 0.36 0.61 1
2476 26.5 49.5 1.0 1.52 1.52 1
2477 27.5 49.5 1.0 2.32 3.60 1
2478 28.5 49.5 1.0 2.91 6.03 1
2479 29.5 49.5 1.0 8.13 8.36 1
2480 30.5 49.5 1.0 12.08 13.96 1
2481 31.5 49.5 1.0 5.49 16.22 1
2482 32.5 49.5 1.0 27.14 17.93 1
2483 33.5 49.5 1.0 29.36 17.08 1
2484 34.5 49.5 1.0 35.38 15.32 1
2485 35.5 49.5 1.0 14.50 10.40 1
2486 36.5 49.5 1.0 1.96 8.04 1
2487 37.5 49.5 1.0 7.88 7.10 1
2488 38.5 49.5 1.0 9.68 6.10 1
2489 39.5 49.5 1.0 13.57 6.68 1
2490 40.5 49.5 1.0 34.58 7.22 1
2491 41.5 49.5 1.0 13.59 8.03 1
2492 42.5 49.5 1.0 4.26 5.70 1
2493 43.5 49.5 1.0 3.73 8.36 1
2494 44.5 49.5 1.0 1.43 8.84 1
2495 45.5 49.5 1.0 7.11 8.82 1
2496 46.5 49.5 1.0 9.26 7.97 1
2497 47.5 49.5 1.0 1.86 8.62 1
2498 48.5 49.5 1.0 1.12 6.59 1
2499 49.5 49.5 1.0 1.65 5.83 1

2500 rows × 6 columns


In [7]:
# Now we can plot the centroids of the cells
plt.plot(mydataxyz['x'],mydataxyz['y'], '+')


Out[7]:
[<matplotlib.lines.Line2D at 0x2ee7eb5e390>]

In [ ]: