struct_post 0.1.4__tar.gz → 0.1.4.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {struct_post-0.1.4 → struct_post-0.1.4.2}/PKG-INFO +1 -1
- {struct_post-0.1.4 → struct_post-0.1.4.2}/pyproject.toml +1 -1
- {struct_post-0.1.4 → struct_post-0.1.4.2}/struct_post/__init__.py +1 -1
- struct_post-0.1.4.2/struct_post/read_lvm_file.py +70 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/struct_post.egg-info/PKG-INFO +1 -1
- {struct_post-0.1.4 → struct_post-0.1.4.2}/struct_post.egg-info/SOURCES.txt +1 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/LICENSE +0 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/README.md +0 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/setup.cfg +0 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/struct_post/beam.py +0 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/struct_post/coupon.py +0 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/struct_post.egg-info/dependency_links.txt +0 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/struct_post.egg-info/requires.txt +0 -0
- {struct_post-0.1.4 → struct_post-0.1.4.2}/struct_post.egg-info/top_level.txt +0 -0
@@ -0,0 +1,70 @@
|
|
1
|
+
def read_lvm_file(file_name: str):
|
2
|
+
'''
|
3
|
+
Reads a LabVIEW .lvm file and returns a pandas DataFrame.
|
4
|
+
|
5
|
+
Processing steps:
|
6
|
+
- Reads the raw .lvm file as CSV text.
|
7
|
+
- Finds the last "***End_of_Header***" marker to skip metadata.
|
8
|
+
- Uses the first row after the header as column names.
|
9
|
+
- Ensures each row has the same number of entries as the header.
|
10
|
+
- Converts numeric values where possible.
|
11
|
+
- Sets the "X_Value" column as the index.
|
12
|
+
|
13
|
+
Returns:
|
14
|
+
pd.DataFrame:
|
15
|
+
DataFrame with:
|
16
|
+
- Index: "X_Value" (numeric, usually time or sample number).
|
17
|
+
- Columns: measurement channels from the .lvm file.
|
18
|
+
- Values: floats (where conversion is possible), otherwise strings.
|
19
|
+
'''
|
20
|
+
import csv
|
21
|
+
import pandas as pd
|
22
|
+
#Read the lvm file
|
23
|
+
with open(file_name, 'r') as csv_file:
|
24
|
+
csv_reader = csv.reader(csv_file)
|
25
|
+
raw_data = list(csv_reader)
|
26
|
+
# -------------------------------
|
27
|
+
# Step 1: Flatten into a list of strings
|
28
|
+
# -------------------------------
|
29
|
+
lines = []
|
30
|
+
for item in raw_data:
|
31
|
+
if item: # make sure it's not empty
|
32
|
+
lines.append(item[0]) # take the string inside
|
33
|
+
# -------------------------------
|
34
|
+
# Step 2: Find the line with the last End_of_Header
|
35
|
+
# -------------------------------
|
36
|
+
end_header_indices = []
|
37
|
+
for i, line in enumerate(lines):
|
38
|
+
if "***End_of_Header***" in line:
|
39
|
+
end_header_indices.append(i)
|
40
|
+
start_idx = end_header_indices[-1] + 1 # the line after header
|
41
|
+
|
42
|
+
# -------------------------------
|
43
|
+
# Step 3: Extract header and data
|
44
|
+
# -------------------------------
|
45
|
+
header_line = lines[start_idx]
|
46
|
+
header = header_line.split("\t")
|
47
|
+
|
48
|
+
data_lines = []
|
49
|
+
for line in lines[start_idx + 1:]:
|
50
|
+
if line.strip(): # skip empty lines
|
51
|
+
values = line.split("\t")
|
52
|
+
# Pad with empty values if too short
|
53
|
+
while len(values) < len(header):
|
54
|
+
values.append("")
|
55
|
+
data_lines.append(values)
|
56
|
+
|
57
|
+
# -------------------------------
|
58
|
+
# Step 4: Build DataFrame
|
59
|
+
# -------------------------------
|
60
|
+
df = pd.DataFrame(data_lines, columns=header)
|
61
|
+
|
62
|
+
# Convert to numeric where possible
|
63
|
+
for col in df.columns:
|
64
|
+
try:
|
65
|
+
df[col] = pd.to_numeric(df[col])
|
66
|
+
except:
|
67
|
+
pass
|
68
|
+
|
69
|
+
df = df.set_index("X_Value").iloc[:, :-1]
|
70
|
+
return df, file_name[:-4]
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|