JPK files are zipped archives of data.
In [1]:
from zipfile import ZipFile
fname = "../examples/force-save-2016.06.15-13.17.08.jpk-force"
In [2]:
z = ZipFile(fname)
In [3]:
list_of_files = z.filelist
for f in list_of_files:
print f.filename
In [4]:
print list_of_files[0].filename
f = z.open(list_of_files[0].filename)
lines = f.readlines()
print lines[0]
print lines[1]
print lines[2]
To extract the time, one can use dateutil.parser
In [6]:
from dateutil import parser
In [7]:
t = parser.parse(lines[0][1:])
print t
The remainder of the lines should contain properties following the syntax mentioned above. They can easily be parsed to a dictionary.
In [8]:
_properties = {}
for line in lines[1:]:
key, value = line.split("=")
value.strip()
_properties[key] = value
In [9]:
for p in _properties:
print p," = ",_properties[p]
In [10]:
properties = {}
for line in lines[1:]:
key,value = line.split("=")
value = value.strip()
split_key = key.split(".")
d = properties
if len(split_key) > 1:
for s in split_key[:-1]:
if d.keys().count(s):
d = d[s]
else:
d[s] = {}
d = d[s]
d[split_key[-1]] = value
In [11]:
for p in properties:
print p, " = ",properties[p]
In [12]:
properties['force-scan-series']['header']['force-settings']['force-baseline-adjust-settings']
Out[12]:
In [13]:
fname = z.filelist[-6].filename
print fname
In [14]:
f = z.open(fname)
lines = f.readlines()
print(lines[0])
print(lines[1])
In [14]:
from struct import unpack
In [15]:
fname = z.filelist[-12].filename
print fname
In [16]:
f = z.open(fname)
content = f.read()
print(len(content))
According to the JPKay guys, every 4 items make one data point
In [17]:
content[0], content[1], content[2], content[3]
Out[17]:
In [18]:
data = unpack(">i", content[0:4])
print data
According to the struct.unpack documentation, however, every 2 items should make a data point in short format. I don't get why the header says format is short ...
In [19]:
fname = z.filelist[-13].filename
print fname
f = z.open(fname)
lines = f.readlines()
properties = {}
for line in lines[2:]:
key,value = line.split("=")
value = value.strip()
split_key = key.split(".")
d = properties
if len(split_key) > 1:
for s in split_key[:-1]:
if d.keys().count(s):
d = d[s]
else:
d[s] = {}
d = d[s]
d[split_key[-1]] = value
print properties['channel']['height']['data']['type']
... and they still use 4 items instead of 2.
In [20]:
data = unpack(">h", content[0:2])
print data
With 120000 items per data file, and a number of points apparently 60000 ...
In [21]:
properties['force-segment-header']['num-points']
Out[21]:
... 2 items has to be right, not 4.
In [ ]: