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

Labspec 1D Raman compatibility #477

Merged
merged 7 commits into from
Nov 20, 2023
Merged

Conversation

elbee99
Copy link
Contributor

@elbee99 elbee99 commented Oct 27, 2023

Modified Raman block to make Labspec Raman data exported to .txt compatible and added example data file

  • Also loads metadata when provided in the Raman file

@elbee99 elbee99 requested a review from ml-evs as a code owner October 27, 2023 11:17
Copy link
Member

@ml-evs ml-evs left a 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:
Copy link
Member

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!

Copy link
Contributor Author

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

@ml-evs ml-evs added the enhancement New feature or request label Nov 14, 2023
Copy link
Member

@ml-evs ml-evs left a 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!

@ml-evs ml-evs merged commit 725f672 into datalab-org:main Nov 20, 2023
12 checks passed
@ml-evs
Copy link
Member

ml-evs commented Nov 20, 2023

Related to #411

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants