Skip to content
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

added chemstation encoding options #16

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/mocca2/parsers/chemstation.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@

from mocca2.classes import Data2D

def parse_chemstation(path) -> Data2D:
def parse_chemstation(path, encoding='utf-16') -> Data2D:
"""
Chemstation read and processing function.
"""

if os.path.isfile(path):
raw = np.genfromtxt(path, delimiter=',', encoding='utf-16')
raw = np.genfromtxt(path, delimiter=',', encoding=encoding)
else:
raw = np.genfromtxt(os.path.join(path, 'DAD1.CSV'), delimiter=',', encoding='utf-16')
raw = np.genfromtxt(os.path.join(path, 'DAD1.CSV'), delimiter=',', encoding=encoding)


time = raw[1:,0]
Expand Down
6 changes: 3 additions & 3 deletions src/mocca2/parsers/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from mocca2.parsers.chemstation import parse_chemstation
from mocca2.parsers.labsolutions import parse_labsolutions

def load_data2d(path: str, format: Literal['auto', 'empower', 'chemstation', 'labsolutions'] = 'auto') -> Data2D:
def load_data2d(path: str, format: Literal['auto', 'empower', 'chemstation', 'labsolutions'] = 'auto', encoding = 'utf-16') -> Data2D:
"""
Loads empower/chemstation/labsolutions file, returns 2D data

Expand All @@ -31,15 +31,15 @@ def load_data2d(path: str, format: Literal['auto', 'empower', 'chemstation', 'la
if path.lower().endswith('.arw'):
data = parse_empower(path)
elif path.lower().endswith('.csv') or path.lower().endswith('.d'):
data = parse_chemstation(path)
data = parse_chemstation(path, encoding=encoding)
elif path.lower().endswith('.txt'):
data = parse_labsolutions(path)
else:
raise Exception("Unknown file format in load_data2D(), consider specifying the format instead of using `auto`")
elif format == 'empower':
data = parse_empower(path)
elif format == 'chemstation':
data = parse_chemstation(path)
data = parse_chemstation(path, encoding=encoding)
elif format == 'labsolutions':
data = parse_labsolutions(path)

Expand Down