JingyiGF / HERBS

MIT License
18 stars 15 forks source link

Simple question: 'Can not find the image' when loading projects #48

Open fergil-mills opened 1 year ago

fergil-mills commented 1 year ago

First, thank you for making HERBS - seems like an excellent tool with a lot of potential.

I have a simple question that I can't find an answer to:

I have some projects in HERBS that we have moved to a different location, now saved locally instead of a server. All the project files and relevant images have been copied over. However, when we go to 'Load Project' there is the error message in the info bar "Can not find the image. Image file may be deleted or moved to another location."

Presumably this is because, now that we have moved the project data, the old paths pointing to the images are no longer valid. However, how can we resolve this issue? Is a way to open project files when they have been moved, or update the paths to the images? How should I approach this?

Apologies for this very basic question, esp. if it is covered in documentation and I haven't found it yet Cheers F

JingyiGF commented 1 year ago

Hi, thanks for asking. As you might seen that all projects/objects are saved in .pkl (pickle) format. That means you can use pickle.load to load it. After you load it, you will see everything is saving as a dictionary with key names. Find the image path and change it and save it again. This trick should save your previous projects (if you use the same version of HERBS.) I did not try myself, so please do not hesitate to ask again if it does not work. Then I will try to do something.

laurelrr commented 1 year ago

This last suggestion worked for our group. Here are the specific steps we used to update the pathnames for other python newbies:

import pickle

# give the file path and open and read the pickle file
file_path = '/path/to/pickle/NPX1_Slide2_FullProject.pkl'
with open(file_path, 'rb') as f:
    dict1=pickle.load(f)

# you can read different parts in the dictionary 
dict1.keys() # shows you all the keynames
dict1.get('img_path') # reports the value of the key called 'img_path'
dict1.get('atlas_path') # reports the value of the key called 'atlas_path'

# now update those values using the WINDOWS format.  
# **Note the letter r before the string when using backslash
dict1.update({'img_path':r'\\win\path\to\pickle\NPX1_Slide2\NPX1_Slide2_ProbeSlice_4.png'})
dict1.update({'atlas_path':r'\\win\path\to\pickle\Allen Mouse Atlas 50um'})

# lastly write the file to a new filename
output_file_path = '/path/to/pickle/NPX1_Slide2_FullProject_WIN.pkl'
with open(output_file_path,'wb') as h:
   pickle.dump(dict1,h)
JingyiGF commented 1 year ago

@laurelrr Thank you so much for testing this and crystal clear code for python newbies ❤️