-
Notifications
You must be signed in to change notification settings - Fork 33
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
improve error reporting when stimulus file cannot be found #81
Comments
@sgratiy thanks for reporting this! If you send me the ABF I can look further into it this weekend |
Interestingly, I do get an exception on Windows 10. I'm using Python 3.6.8 and Numpy 1.13.3. Without worrying about the Windows/Linux difference for now, I'll try to fix command waveform synthesis for this ABF. https://github.com/swharden/pyABF/tree/master/data#h19_29_150_11_21_01_0011abf def assertNanIsNotInSweepC(abf):
for sweep in range(abf.sweepCount):
for channel in range(abf.channelCount):
abf.setSweep(sweep, channel=channel)
if not abf._dacSection.nWaveformEnable[channel]:
continue
print(F"sweep {abf.sweepC}")
if np.isnan(abf.sweepC).any():
raise ValueError(f"Found at least one 'Not a Number' "
f"entry in stimulus channel {channel} of sweep {sweep} "
f"in file {abf.abfFilePath} using protocol {abf.protocol}.")
if __name__ == "__main__":
abf = pyabf.ABF(PATH_DATA+"/H19_29_150_11_21_01_0011.abf")
assertNanIsNotInSweepC(abf)
|
@sgratiy I think I figured this one out and made a fix that improves it. My guess is that on your Linux system the stimulus file is not being found in the path you gave. Note that the case sensitivity of Linux files may also contribute to this. According to your file header it's looking for a file with the case When pyABF can't find the stimulus file it returns a @sgratiy I'm looking forward to hearing if you were able to figure out the issue based on these notes! Also if you think the fix is good (a warning), I'll release it on pypi this weekend. Lines 101 to 110 in eb7656a
|
@sgratiy I haven't heard back in about a week so I'll assume you got it working again. If it turns out this is not the case let me know! Either way, the new error message that got added when stimulus files cannot be found is an improvement. I'll probably issue a pypi release this weekend. Thanks for posting the initial issue. |
@swharden, sorry I was not able to get back to you sooner. I appreciate your looking into this issue
Indeed, I do not have the path C:\Allen Institute\Allen Institute protocols with text attachment\IN0\C1NSD1SHORT. Thanks to you, now I know that it comes from the file header. The mystery: I am not familiar with this format. I thought that by providing the |
Hi @sgratiy, no worries about the delay. I'm happy to help you resolve this issue. What is the output of this program on your system? import numpy as np
import pyabf
pyabf.stimulus.Stimulus.protocolStorageDir = "/local1/ephys/abf_convertion/reference_atf"
def checkStorageDirectory(abf):
assert isinstance(abf, pyabf.ABF)
protocolDir = abf.stimulusByChannel[0].protocolStorageDir
protocolFilename = os.path.basename(abf.protocolPath)
protocolPath = os.path.join(protocolDir, protocolFilename)
print("Protocol storage directory:", protocolDir)
print("Protocol filename:", protocolFilename)
print("Looking for protocol:", protocolPath)
assert os.path.exists(protocolPath)
abf = pyabf.ABF("/local1/ephys/abf_convertion/H19_29_150_11_21_01_0011.abf", loadData=False)
checkStorageDirectory(abf) |
Thanks, here is the output:
|
lol @ that third line. That's obviously wrong, but I'm confused about how that can happen... perhaps |
This may fix your issue. It's a one-line edit so it should be easy for you to try out. Let me know how it goes! |
@swharden, How would be the best way to apply this change? Should I make same change in the source code of the installed package? I tried installing the latest pyABF from github into my environment |
I just pushed a new release on pypi (2.1.9). You can now
Let me know if this fixes your problem! |
Unfortunately, the fix did not work. I have updated the package as you instructed to: pyabf 2.1.9 But running your script I still get the same path issue:
|
Actually it may be working even though that test script fails. Can you try your original script from the first message? import numpy as np
import pyabf
def _check(abf):
for sweep in range(abf.sweepCount):
for channel in range(abf.channelCount):
abf.setSweep(sweep, channel=channel)
if not abf._dacSection.nWaveformEnable[channel]:
continue
print(F"sweep {abf.sweepC}")
if np.isnan(abf.sweepC).any():
raise ValueError(f"Found at least one 'Not a Number' "
f"entry in stimulus channel {channel} of sweep {sweep} "
f"in file {abf.abfFilePath} using protocol {abf.protocol}.")
protocolStorageDir = "/local1/ephys/abf_convertion/reference_atf"
inFile = "/local1/ephys/abf_convertion/H19_29_150_11_21_01_0011.abf"
pyabf.stimulus.Stimulus.protocolStorageDir = protocolStorageDir
abf = pyabf.ABF(inFile, loadData=False)
_check(abf) and keep an eye out for warnings or error messages about the protocol not being found |
Ok, here is the output of the original script. It issues an new warning, but still has the original error:
As I mentioned earlier, I do not have the path "C:\Allen Institute\Allen Institute protocols with text attachment\IN0\C1NSD1SHORT" either on Windows and Linux, but on Windows it does not seem to be a problem. |
@sgratiy thanks for your patience! I know the original windows path isn't on your system, but I'm pretty sure this is the path it's currently looking for. This file should exist, in this path, and in this case:
I made an updated test script to reflect what pyABF does as of the latest update (fd32943). Does this throw an exception on your system? import pyabf
def checkStorageDirectory(abf):
assert isinstance(abf, pyabf.ABF)
protocolDir = abf.stimulusByChannel[0].protocolStorageDir
protocolPath = abf.protocolPath.replace("\\", "/") # this is the new line
protocolFilename = os.path.basename(protocolPath)
protocolPath = os.path.join(protocolDir, protocolFilename)
print("Protocol storage directory:", protocolDir)
print("Protocol filename:", protocolFilename)
print("Looking for protocol:", protocolPath)
assert os.path.exists(protocolPath)
if __name__ == "__main__":
pyabf.stimulus.Stimulus.protocolStorageDir = "/local1/ephys/abf_convertion/reference_atf"
abf = pyabf.ABF(PATH_DATA+"/H19_29_150_11_21_01_0011.abf")
checkStorageDirectory(abf) |
@swharden Thank you for help, I really appreciate it. Below is the output of the script. As you can see, I do not have the .pro files but I do have the .atf files (with the same name). Sorry, but I do not understand the difference between the two.Is that the problem?
|
I think browser window programming has gotten the best of me! I started mixing up protocol files and stimulus files. Want to zip that folder (or at least the relevant files) and send those to me? (not just the ABF) - I can then test it on a linux machine, fix the issue, and publish the fix without so much back and forth. |
Here is the link to the zipped folder with atf files |
I got it working on my raspberry pi. This doesn't work: pyabf.stimulus.Stimulus.protocolStorageDir = "/local1/ephys/abf_convertion/reference_atf"
abf = pyabf.ABF(inFile, loadData=False)
print(abf.sweepC) This worked: abf = pyabf.ABF(inFile, loadData=False)
abf.stimulusFileFolder = "/local1/ephys/abf_convertion/reference_atf"
print(abf.sweepC) Does the second method work for you? |
Yes, the second example does work. Thanks. I am not familiar with the format. Is the path to the atf files cannot be written in pyabf.stimulus.Stimulus.protocolStorageDir? |
I'm glad you got this working! I'll add this example to the documentation page so people are less likely to get confused over this in the future. I don't remember all the ins and outs of this topic, but I did notice that a warning is thrown when you try to assign to Lines 81 to 83 in 0090854
I think Either way I'm glad this is resolved! Thanks again for sharing your issue! |
This is the new documentation for manually defining stimulus waveform folders: |
thank you. |
I get different behaviour when creating an ABF object using the same version of python (3.7.3) and pyabf (2.0.25) and numpy (1.16.4)
On Windows 10 the code below does not generate an exception, but Centos 7 does.
I would be happy to provide the abf file and protocols files
The text was updated successfully, but these errors were encountered: