<jupyter_start><jupyter_text>Load the moduleIf you added the folder in which `jpkfile.py` is to you site-packages, you should be able to import the module.<jupyter_code>import jpkfile<jupyter_output><empty_output><jupyter_text>Create a JPKFile object<jupyter_code>jpk = jpkfile.JPKFile("../examples/force-save-2016.06.15-13.17.08.jpk-force")<jupyter_output><empty_output><jupyter_text>Structure of JPKFile objects * Data is separated in segments in jpk archives. Thus, it is separated in JPKFile objects as well. The member JPKFile.segments is a list of JPKSegment objects.<jupyter_code>jpk.segments<jupyter_output><empty_output><jupyter_text>* To get some basic information on the jpk archive behind the JPKFile object, you can use the JPKFile.get_info function. Note that 'segments' is currently the only working keyword here ...<jupyter_code>print(jpk.get_info('segments'))<jupyter_output>======================================================================
SEGMENT	TYPE	NUM POINTS	DURATION
-------	----	----------	--------
0	extend	60000		10.0
1	pause	30000		5.0
2	retract	60000		10.0
3	pause	2		5.0
======================================================================<jupyter_text>Data of segmentsThe JPKSegment objects contain some information and parameters as well. Additionaly, they contain the segment's data.  JPKSegment.data is a dictionary, where keys are different channels and values are data arrays and parameters on how to convert the raw data to physical values.  To figure out what the names of valid channels are, print JPKSegment.data.keys().<jupyter_code>s0 = jpk.segments[0]
print(s0.data.keys())<jupyter_output>['hDeflection', 'vDeflection', 'height', 'strainGaugeHeight', 't', 'error']<jupyter_text>Extract data converted to physical valuesUse the function get_array() to get the physical data of channels.  Let's say you want data of channel 'height' and 'vDeflection' (which makes sense for the example file, it looks like all the other channels are not relevant, since there are no parameters on conversion to physical values defined; jpk appears to always store all channels that could be used for the method of recording) you need to provide these channel names as first parameter in a list.<jupyter_code>s0_data, s0_units = s0.get_array(['height','vDeflection'])
print(s0_data)<jupyter_output>[[(4.882270801632857e-05, -2.2291090247982416e-09)]
 [(4.882172935038292e-05, -2.227681939448722e-09)]
 [(4.882075068443725e-05, -2.2229249882836574e-09)]
 ..., 
 [(1.752986440377226e-05, -1.7957507736608136e-09)]
 [(1.752986440377226e-05, -1.7971778590103334e-09)]
 [(1.7528885737826602e-05, -1.7819556152821252e-09)]]<jupyter_text>The function returns a tuple with a labeled numpy array as first item, a dictionary specifying the physical units for each channel.<jupyter_code>print(s0_units)<jupyter_output>{'vDeflection': 'N', 'height': 'm'}<jupyter_text>Data of all segmentsYou can also retrieve the data of all segments in a similar way, by using JPKFile's get_array function.<jupyter_code>data,units = jpk.get_array(['height','vDeflection'])<jupyter_output><empty_output><jupyter_text>But for plotting ...it is probably more useful to extract them separately, to be able to plot them separately.<jupyter_code>s1_data = jpk.segments[1].get_array(['height','vDeflection'])[0]
s2_data = jpk.segments[2].get_array(['height','vDeflection'])[0]
# I actually don't know what the last segment is, it contains only 2 data points<jupyter_output><empty_output><jupyter_text>Plot the data<jupyter_code>import matplotlib.pyplot as plt
%matplotlib notebook
f,ax = plt.subplots(1,1)
ax.plot(s0_data['height'],s0_data['vDeflection'], label = jpk.segments[0].get_info('type'))
ax.plot(s1_data['height'],s1_data['vDeflection'], label = jpk.segments[1].get_info('type'))
ax.plot(s2_data['height'],s2_data['vDeflection'], label = jpk.segments[2].get_info('type'))
ax.legend()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14799693799438632, 'fraction_numerical': 0.07450880326613932, 'mean_word_length': 6.438330170777989, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '139385', 'license': 'MIT', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1291, 'n_words': 366, 'path': 'examples/read_data_from_jpk_archive.ipynb', 'repo_name': 'JelleWestra/jpkfile', 'size': '3919'}