Closed samuelbray32 closed 7 months ago
One solution is to catch this error and move the downloaded file to the correct location if so. Here's an example:
import os
import shutil
table = IntervalLinearizedPosition & lin_pos_key
try:
(table).fetch_nwb()
except FileNotFoundError as e:
# get the location stored as a datajoint filepath
dj_path = str(e).split(': ')[1].replace("'","")
print(dj_path)
# get the location where AnalysisNwbfile.kachery would have stored it
analysis_file = (table).fetch1('analysis_file_name')
current_path = AnalysisNwbfile().get_abs_path(analysis_file)
assert os.path.exists(current_path)
# move the file to the datajoint location
# this will change the output of future calls to AnalysisNwbfile().get_abs_path(analysis_file)
shutil.move(current_path,dj_path)
table.fetch_nwb()
Once this has executed once, future calls of fetch_nwb
for the analysis file will work fine. One option would to put a version of this check in AnalysisNwbfileKachery
to solve it in the background when the file is downloaded.
@edeno, do you have a sense if this will show up often enough that we should put this into spyglass or should this issue just be the solution for people on a case-by-case basis?
I think it would be okay to have in AnalysisNwbfileKachery
for now. It would be good to have it pretty well documented in the code why the check is happening.
Came up with a cleaner solution in the PR above. Fixing the abs_path returned by AnalysisNwb.get_abs_path()
to agree with datajoint entries. Since this is what's used to define where kachery saves the file to in the first place it fixes the issue before it happens
Describe the bug
When sharing with kachery in spyglass the receiving client downloads analysis nwb files in the location returned by
AnalysisNwbfile.get_abs_path()
.Problem: Older analysis files not stored in a subdirectory have a datajoint filepath in the database without the subdirectory as well
filepath
used to find the file duringfetch_nwb
does not have the subdirectory in itSolution? @CBroz1, do you know if the datajoint filepath for an entry can be determined without raising a file not found error? If so we can use this to define where the files should be saved to when downloading from kachery to ensure consistency with the source database.
To Reproduce On a remote clien connected to the franklab databaset:
Additional context Add any other context about the problem here.
Note that the file is downloaded in a subdirectory. After running the above this statement executes