Skip to content

Instantly share code, notes, and snippets.

@akirayou
Created October 1, 2024 04:06
Show Gist options
  • Save akirayou/16362e28f946dd0c75b21c9933329f15 to your computer and use it in GitHub Desktop.
Save akirayou/16362e28f946dd0c75b21c9933329f15 to your computer and use it in GitHub Desktop.
import numpy as np
from mocca2.classes import Data2D
import re
def parse_labsolutions(file, encoding="ShiftJIS"):
"""Reads the .txt Lab Solutions file"""
f = open(file, "r", encoding=encoding)
for line in f:
if "[PDA 3D" == line[:7]:
break
for line in f:
if "R.Time" == line[:6]:
break
waveLen = np.array([float(s) for s in re.split(r'[\t,]',f.readline())[1:] ])
N = len(waveLen)
rt = []
inten = []
for line in f:
d = re.split(r'[\t,]',line)
if len(d) != N + 1:
break
d = [float(s) for s in d]
rt.append(d[0])
inten.append(d[1:])
rt = np.array(rt)
inten = np.array(inten)
return Data2D(rt, waveLen/100, inten.T/100)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment