-
Notifications
You must be signed in to change notification settings - Fork 17
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
Labspec 1D Raman compatibility #477
Conversation
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.
Thanks for this @elbee99! One minor comment below:
@@ -30,8 +30,10 @@ def load(self, location: str | Path) -> Tuple[pd.DataFrame, List[str]]: | |||
ext = os.path.splitext(location)[-1].lower() | |||
|
|||
if ext == ".txt": | |||
df = pd.read_csv(location, sep=r"\s+") | |||
df = df.rename(columns={"#Wave": "wavenumber", "#Intensity": "intensity"}) | |||
try: |
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.
It would be nice to have some additional expected features of the Raman txt format specifically, as at the moment you could upload any two columns of numbers in a txt file and they would be successfully plotted as Raman data.
Looking at the example data, we could also parse the headers and check for various keys, e.g.,
vendor = None # try to detect vendor first
header = []
with open(location, "r") as f:
while header_line := f.readline().startswith("#"):
header.append(header_line)
if "#Wave" in header[0] and "#Intensity" in header[0]:
vendor = "renishaw"
# otherwise try to parse the Labstep header
else:
metadata = {key: value for key, value in line.split("=") for line in header}
if metadata.get("AxisType[0]") == "Intens" and metadata.get("AxisType[1]") == "Spectr":
vendor = "labstep"
self.data["metadata"] = metadata
if not vendor:
raise RuntimeError("Could not detect Raman data vendor -- this file type is not supported by this block.")
Let me know if you want to have a go at this, otherwise I can do it!
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.
That's fair, will give this a go, should be straightforward
0e0aa4a
to
edc92f9
Compare
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.
LGTM, thanks again @elbee99!
Related to #411 |
Modified Raman block to make Labspec Raman data exported to .txt compatible and added example data file