cvai-roig-lab / Net2Brain

BSD 3-Clause "New" or "Revised" License
71 stars 12 forks source link

Bug: .DS_Store file causes error when running RSA evaluation #25

Closed Eliulm closed 1 year ago

Eliulm commented 1 year ago

When I run an evaluation on my machine (macOS), I get the following error:

No fmri/meg found in ROI-name. Error!

This persists even when the brain scans and DRMs are properly named.

Upon further investigation, I found that the folderlookup() function does not filter for .DS_Store files which are automatically created by the macOS operating system. This will later on cause issues, since the self.RSA property will not be set.

Full error log:

ValueError                                Traceback (most recent call last)
Cell In[50], line 10
      7 evaluation = RSA(model_rdms, predictor_matrix, save_path=os.getcwd(), model_name="resnet50_c4_Instance_seg")
      9 # Evaluation - Returns a pandas dataframe
---> 10 dataframe1 = evaluation.evaluate() 
     11 print(dataframe1)
     13 ## plotting_results = Plotting([dataframe1])
     14 ## results_dataframe = plotting_results.plot(variant="best_layer")

File /opt/homebrew/Caskroom/miniconda/base/envs/N2B/lib/python3.8/site-packages/net2brain/evaluations/rsa.py:215, in RSA.evaluate(self)
    212 self.this_nc = NoiseCeiling(roi, op.join(self.brain_rdms_path, roi)).noise_ceiling()
    214 # Return Correlation Values for this ROI to all model layers
--> 215 all_layers_dict = self.evaluate_layer(roi)
    217 # Create dict with these results
    218 scan_key = "(" + str(counter) + ") " + roi[:-4]

File /opt/homebrew/Caskroom/miniconda/base/envs/N2B/lib/python3.8/site-packages/net2brain/evaluations/rsa.py:171, in RSA.evaluate_layer(self, roi)
    167 # For each layer to RSA with the current ROI
    168 for counter, layer in enumerate(self.model_rdms):
    169 
    170     # Load RDMS
--> 171     roi_rdm = load(op.join(self.brain_rdms_path, roi))
    172     model_rdm = load(op.join(self.model_rdms_path, layer))
    175     # Calculate Correlations
File /opt/homebrew/Caskroom/miniconda/base/envs/N2B/lib/python3.8/site-packages/net2brain/evaluations/eval_helper.py:87, in load(data_file)
     78 """organizing loading functions
     79 
     80 Args:
   (...)
     84     numpy array: loaded file
     85 """
     86 root, ext = os.path.splitext(data_file)
---> 87 return {'.npy': loadnpy,
     88         '.mat': loadmat,
     89         '.npz': loadnpz
     90         }.get(ext, loadnpy)(data_file)

File /opt/homebrew/Caskroom/miniconda/base/envs/N2B/lib/python3.8/site-packages/net2brain/evaluations/eval_helper.py:62, in loadnpy(npyfile)
     53 def loadnpy(npyfile):
     54     """load in npy format
     55 
     56     Args:
   (...)
     60          numpy array: loaded file
     61     """
---> 62     return np.load(npyfile)

File /opt/homebrew/Caskroom/miniconda/base/envs/N2B/lib/python3.8/site-packages/numpy/lib/npyio.py:438, in load(file, mmap_mode, allow_pickle, fix_imports, encoding, max_header_size)
    435 else:
    436     # Try a pickle
    437     if not allow_pickle:
--> 438         raise ValueError("Cannot load file containing pickled data "
    439                          "when allow_pickle=False")
    440     try:
    441         return pickle.load(fid, **pickle_kwargs)

ValueError: Cannot load file containing pickled data when allow_pickle=False
ToastyDom commented 1 year ago

Wow thank you so much!!! I accepted your PR! Thanks for noticing and fixing right away :)