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

number of spectrum is different for each sample #41

Open
hadas-equinom opened this issue Dec 29, 2024 · 5 comments
Open

number of spectrum is different for each sample #41

hadas-equinom opened this issue Dec 29, 2024 · 5 comments

Comments

@hadas-equinom
Copy link

Hi @nzhagen

First, thank you for this much needed package.

I have been trying to run it, but I got different headers [x] values for each samples. not only different on value, but also different in size. instead of getting 1400 spectrum points I get a different number for each samples.

Can you please check this issue? or if there is already an existing solution, please let me know,

Thank you,
Hadas

@nzhagen
Copy link
Owner

nzhagen commented Jan 2, 2025

@hadas-equinom,
Actually, that behavior sounds correct to me. The code is designed to read a JCAMP format file, so if two files sample spectra at different wavelengths, then the code will exactly reflect that. Or am I possibly misreading the issue that you are seeing? If so, please send some example code so I can try to replicate the issue...

@hadas-equinom
Copy link
Author

@nzhagen thank you for your response.
Unfortunately I cannot send an example of the data I have, but the only code I ran is:
file = jcamp.jcamp_readfile('\\Data\\iqx_file.dx')

as you can see the data was not extracted correctly. you can see the npoints is not matching the length of x and y [see figure below] . After some debugging it seems that it might be related to how you interpret the duplicates of the data [by taking only one letter] . somewhere in here:

jcamp/jcamp.py

Line 515 in 86daf5b

mul = DUP_digits[c]

image

@hadas-equinom
Copy link
Author

in addition the version I get after pip install --upgrade jcamp , is different from what I see in git.
here is what I see in my pycharm:
image

@nzhagen
Copy link
Owner

nzhagen commented Jan 6, 2025

Ah, now I see what you mean -- that difference in the number of points is definitely an issue. And, yeah, it looks like the PyPI version of the package has fallen behind the GitHub version -- I must have forgotten to do an update. I will make an update soon. But first, could you send to me the JCAMP file you are using? I don't have a good example file that uses the DUP codes, so my ability to test without that is limited.

@hadas-equinom
Copy link
Author

hadas-equinom commented Jan 7, 2025

@nzhagen well, I cannot share the files, but someone from my work was able to fix it. see the following code:

if any(c in DUP_set for c in line):
        ## Split the line into individual characters so that you can check for coded characters one-by-one.
        newline = ''
        mul_str = ''
        cont = 0
        for (i,c) in enumerate(line):
            while cont > 0:
                cont -= 1
                continue
            if (c in DUP_digits):
                ## Check for last DIF_digit which is start of last y-value by default, so that all
                ## characters belonging to last value is fully decompressed by DUP compression.
                back = 1
                while line[i-back] not in DIF_digits:
                    back += 1
                prev_c = line[i-back:i]
                fwd = 1
                cont = 0
                mul_str = ''
                while line[i+fwd] not in DIF_digits:
                    mul_str += line[i+fwd]
                    cont += 1
                    fwd += 1
                if mul_str:
                    mul = (DUP_digits[c] * (10 ** cont)) + int(mul_str)
                else:
                    mul = DUP_digits[c]
                newline += prev_c * (mul-1)
            else:
                mul = ''
                newline += c
        line = "".join(newline)


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

No branches or pull requests

2 participants