-
Notifications
You must be signed in to change notification settings - Fork 13
ENH: implemented arbitrary data separator, for now supported Tab and Comma. #15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
LabVIEW Measurement, | ||
Writer_Version,2 | ||
Reader_Version,2 | ||
Separator,Comma | ||
Decimal_Separator,. | ||
Multi_Headings,No | ||
X_Columns,One | ||
Time_Pref,Absolute | ||
Operator,photron | ||
Date,2024/04/10 | ||
Time,13:06:46.2639230999998221435 | ||
***End_of_Header***, | ||
, | ||
Channels,4,,,, | ||
Samples,4,4,4,4, | ||
Date,2024/04/10,2024/04/10,2024/04/10,2024/04/10, | ||
Time,13:06:46.2639230999998221435,13:06:46.2639230999998221435,13:06:46.2639230999998221435,13:06:46.2639230999998221435, | ||
Y_Unit_Label,Volts,Volts,Volts,Volts, | ||
X_Dimension,Time,Time,Time,Time, | ||
X0,0.0000000000000000E+0,0.0000000000000000E+0,0.0000000000000000E+0,0.0000000000000000E+0, | ||
Delta_X,2.000000E-6,2.000000E-6,2.000000E-6,2.000000E-6, | ||
***End_of_Header***,,,,, | ||
X_Value,p_st1,p_st2,p_plate,TC1,Comment | ||
0.000000,-0.000424,-0.002187,-0.002505,0.163976 | ||
2.000000E-6,-0.000424,-0.002827,-0.002185,0.163337 | ||
4.000000E-6,-0.000744,-0.003147,-0.003144,0.163657 | ||
6.000000E-6,-0.000424,-0.002827,-0.002505,0.163657 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,7 +7,7 @@ | |
import pickle | ||
import numpy as np | ||
|
||
__version__ = '1.21' | ||
__version__ = '1.22' | ||
|
||
def _lvm_pickle(filename): | ||
""" Reads pickle file (for local use) | ||
|
@@ -42,6 +42,21 @@ def _lvm_dump(lvm_data, filename, protocol=-1): | |
pickle.dump(lvm_data, output, protocol=protocol) | ||
output.close() | ||
|
||
def get_separator(file): | ||
separators = {'Tab': '\t', | ||
'Comma': ',' | ||
} | ||
for line in file: | ||
if line.startswith('Separator'): | ||
separator = line.strip()[10:] | ||
break | ||
file.seek(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using |
||
if separator in separators.keys(): | ||
return separators[separator] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From the specification: "To find out what the separator character(s) is, read the entire header block and search for the keyword Separator. The character(s) that follows the keyword is the separator." Any separator can be supported by just using the character following 'Separator'. |
||
else: | ||
raise Warning('No separator defined, using tabulator!') | ||
return '\t' | ||
|
||
|
||
def _read_lvm_base(filename): | ||
""" Base lvm reader. Should be called from ``read``, only | ||
|
@@ -50,11 +65,12 @@ def _read_lvm_base(filename): | |
:return lvm_data: lvm dict | ||
""" | ||
with open(filename, 'r', encoding="utf8", errors='ignore') as f: | ||
lvm_data = read_lines(f) | ||
separator = get_separator(f) | ||
lvm_data = read_lines(f, separator=separator) | ||
return lvm_data | ||
|
||
|
||
def read_lines(lines): | ||
def read_lines(lines, separator='\t'): | ||
""" Read lines of strings. | ||
|
||
:param lines: lines of the lvm file | ||
|
@@ -76,10 +92,10 @@ def to_float(a): | |
return np.nan | ||
for line in lines: | ||
line = line.replace('\r', '') | ||
line_sp = line.replace('\n', '').split('\t') | ||
line_sp = line.replace('\n', '').split(separator) | ||
if line_sp[0] in ['***End_of_Header***', 'LabVIEW Measurement']: | ||
continue | ||
elif line in ['\n', '\t\n']: | ||
elif line in ['\n', separator+'\n']: | ||
# segment finished, new segment follows | ||
segment = dict() | ||
lvm_data[segment_nr] = segment | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could cause an Indexation error if a writer decides to write a header like:
Separator;