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))
In [4]:
# Iterate on data
for r in surpac.records:
# record ID
print(r.number, len(r.string_record))
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])
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]:
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]:
In [ ]: