In [1]:
import pygslib
from matplotlib import pyplot as plt
import pandas as pd
%matplotlib inline



In [2]:
# read surpac string
surpac = pygslib.surpac.Surpac('surpac_strings.txt')

In [3]:
# print string properties
print ('location: {}'.format(surpac.location))
print ('date: {}'.format(surpac.date))
print ('purpose: {}'.format(surpac.purpose))
print ('memo: {}'.format(surpac.memo))
print ('axis: {}'.format(surpac.axis.string))
print ('axis1: {} {} {}'.format(surpac.axis.x_1,surpac.axis.y_1,surpac.axis.z_1))
print ('axis2: {} {} {}'.format(surpac.axis.x_2,surpac.axis.y_2,surpac.axis.z_2))


location: smp
date: 8-Feb-94
purpose: 
memo: Sample string file
axis: 0.0
axis1: 2440.0 6740.0 152.541
axis2: 2440.0 6830.0 152.541

In [4]:
# Iterate on data
 for r in surpac.records:
        # record ID
        print(r.number, len(r.string_record))


1 18
2 15
2 15
93 3

In [5]:
# access data
print('string ID: ',surpac.records[0].number)
print('x, y, z: ',surpac.records[0].string_record[5].x, surpac.records[0].string_record[5].y, surpac.records[0].string_record[5].z)
print('num of variables: ',surpac.records[0].string_record[5].length_d)
n=surpac.records[0].string_record[5].length_d
print('variables values: ', surpac.records[0].string_record[5].d[:n])


string ID:  1
x, y, z:  2420.0 6755.85 155.398
num of variables:  3
variables values:  ['point2', 'second description field', 'third']

In [6]:
# get point data
x = []
y = []
z = []
pid = []
strn = []
line = []
l = -1
for r in surpac.records:
    # record ID
    l=l+1
    for i in range(len(r.string_record)):
        pid.append(i)
        strn.append(r.number)
        line.append(l)
        x.append(r.string_record[i].x)
        y.append(r.string_record[i].y)
        z.append(r.string_record[i].z)

In [7]:
data = pd.DataFrame({'x':x,'y':y,'z':z,'p':pid,'s':strn, 'l':line})
data


Out[7]:
x y z p s l
0 2443.66 6749.12 155.249 0 1 0
1 2440.60 6747.52 155.184 1 1 0
2 2431.75 6746.43 155.173 2 1 0
3 2428.57 6747.60 155.174 3 1 0
4 2421.92 6751.69 155.245 4 1 0
5 2420.00 6755.85 155.398 5 1 0
6 2418.62 6762.34 155.593 6 1 0
7 2417.38 6774.82 155.708 7 1 0
8 2417.74 6823.88 155.566 8 1 0
9 2438.58 6822.65 156.611 9 1 0
10 2458.52 6819.25 157.692 10 1 0
11 2458.81 6803.57 156.966 11 1 0
12 2458.67 6777.96 156.229 12 1 0
13 2457.77 6771.68 156.034 13 1 0
14 2455.93 6765.55 155.823 14 1 0
15 2452.75 6759.21 155.598 15 1 0
16 2448.61 6753.24 155.391 16 1 0
17 2443.66 6749.12 155.249 17 1 0
18 2458.52 6819.25 157.692 0 2 1
19 2457.26 6805.61 156.590 1 2 1
20 2456.67 6798.67 155.920 2 2 1
21 2455.95 6792.24 155.630 3 2 1
22 2455.22 6785.94 155.330 4 2 1
23 2454.76 6779.90 154.590 5 2 1
24 2453.29 6772.95 153.640 6 2 1
25 2451.95 6767.39 153.090 7 2 1
26 2449.30 6761.96 152.890 8 2 1
27 2445.58 6758.68 152.090 9 2 1
28 2441.95 6756.05 151.790 10 2 1
29 2436.10 6755.43 151.490 11 2 1
30 2432.44 6756.08 151.390 12 2 1
31 2429.18 6757.69 151.190 13 2 1
32 2427.46 6759.26 150.990 14 2 1
33 2454.83 6819.73 157.580 0 2 2
34 2454.04 6806.68 156.580 1 2 2
35 2453.52 6800.61 156.290 2 2 2
36 2453.16 6796.49 155.930 3 2 2
37 2452.79 6792.61 155.620 4 2 2
38 2452.56 6789.91 155.330 5 2 2
39 2451.01 6777.24 154.090 6 2 2
40 2449.37 6772.13 153.290 7 2 2
41 2446.87 6767.10 152.890 8 2 2
42 2444.83 6763.58 152.490 9 2 2
43 2442.81 6760.96 152.090 10 2 2
44 2439.61 6759.46 151.730 11 2 2
45 2436.73 6759.18 151.490 12 2 2
46 2434.50 6759.62 151.390 13 2 2
47 2432.11 6760.90 151.200 14 2 2
48 2428.57 6747.60 155.174 0 93 3
49 2436.10 6755.43 151.490 1 93 3
50 2440.60 6747.52 155.184 2 93 3

In [8]:
fig, axis = plt.subplots()
# plot points
data.plot.scatter(x='x',y='y', c = 'k', ax = axis)
#plot lines
for l in data['l'].unique():
    data.loc[data['l']==l].plot.line(x='x', y='y', ax = axis)

axis.legend(data['l'].unique())


Out[8]:
<matplotlib.legend.Legend at 0x245f6e1b198>

In [ ]: