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

Issue with opening files on the IBL ENV GUI #309

Open
antaramaj16 opened this issue May 19, 2022 · 9 comments
Open

Issue with opening files on the IBL ENV GUI #309

antaramaj16 opened this issue May 19, 2022 · 9 comments
Assignees

Comments

@antaramaj16
Copy link

I was able to prepare files for the IBLenv GUI but then I run into issues with loading it in and I get these error messages:

(iblenv) C:\Users\Antara\int-brain-lab\iblapps\atlaselectrophysiology>python ephys_atlas_gui.py -o True
Failed to load the remote cache file
Traceback (most recent call last):
File "C:\Users\Antara\int-brain-lab\iblapps\atlaselectrophysiology\ephys_atlas_gui.py", line 1240, in data_button_pressed
self.ephysalign = EphysAlignment(self.xyz_picks, self.chn_depths,
File "C:\Users\Antara\int-brain-lab\ibllib-repo\ibllib\pipes\ephys_alignment.py", line 47, in init
= self.get_histology_regions(self.xyz_samples, self.sampling_trk, self.brain_atlas)
File "C:\Users\Antara\int-brain-lab\ibllib-repo\ibllib\pipes\ephys_alignment.py", line 229, in get_histology_regions
region_ids = brain_atlas.get_labels(xyz_coords, mapping=mapping)
File "C:\Users\Antara\int-brain-lab\ibllib-repo\ibllib\atlas\atlas.py", line 250, in get_labels
regions_indices = self._get_mapping(mapping=mapping)[self.label.flat[self._lookup(xyz)]]
File "C:\Users\Antara\int-brain-lab\ibllib-repo\ibllib\atlas\atlas.py", line 240, in _lookup
return self._lookup_inds(self.bc.xyz2i(xyz))
File "C:\Users\Antara\int-brain-lab\ibllib-repo\ibllib\atlas\atlas.py", line 230, in _lookup_inds
inds = np.ravel_multi_index(idims, self.bc.nxyz[self.xyz2dims])
File "<array_function internals>", line 180, in ravel_multi_index
ValueError: invalid entry in coordinates array

Could you let me know how to resolve this? Thank you!

@mayofaulkner
Copy link
Contributor

Hi, could you briefly describe the method you used to get the xyz_picks.json file and also send me the file that you are getting this problem for.

Thanks

@antaramaj16
Copy link
Author

Here are the xyz picks:
{"xyz_picks":[[-880,2550,-2770],[-1050,2430,-3270],[-850,2310,-3090],[-890,2310,-3560],[-930,2220,-3460],[-960,2220,-3860],[-870,2100,-3850],[-940,2100,-4410],[-930,1980,-4270],[-1000,1980,-4660],[-860,1860,-5060],[-940,1860,-5560],[-640,1740,-6520],[-850,1620,-6810],[-940,1620,-7300],[-810,1500,-6140],[-870,1500,-6620],[-800,1410,-7720],[-1000,1320,-7570]]}

@antaramaj16
Copy link
Author

I use the SHARP track script to get the probe points file and then I use this code to convert it into useable xyz picks files:

POINTLISTFILE = "\QNAP-AL001.dpag.ox.ac.uk\Data\AMR013\histology\probe_pointselectrodetrack.mat";

folder = dir(POINTLISTFILE);
jsonOutputFolder = folder.folder;

probePoints = load(POINTLISTFILE);

numProbes = size(probePoints.pointList.pointList,1);

for p = 1:numProbes

thisProbe = probePoints.pointList.pointList{p,1}; %get first probe coords

% Convert probe coordinates (in pixels) to mm relative to bregma
ML = (thisProbe(:,1) - 570)*0.01;
DV = thisProbe(:,2)*0.01;
AP = (thisProbe(:,3) - 540)*0.01;

% Convert to um and the correct sign
ML = 1000*ML;
DV = -1000*DV;
AP = -1000*AP;

%Ouput should be ML AP DV
out = jsonencode( struct('xyz_picks', round([ML AP DV])) );
fid = fopen( fullfile(jsonOutputFolder, ['Probe' num2str(p) '_xyz_picks.json']) , 'w');
fprintf(fid, out);
fclose(fid);

end

@mayofaulkner
Copy link
Contributor

Hello, sorry for the delay. Could you also give the original .mat file and let me know which columns relates to ML, AP, DV in this original mat file and in what coordinate system they are in (are they in Allen CCF)?

Thanks

@antaramaj16
Copy link
Author

antaramaj16 commented Jun 3, 2022 via email

@mayofaulkner
Copy link
Contributor

Hey, the files don't seem to be attached. Could you try sending again. Thanks

@antaramaj16
Copy link
Author

antaramaj16 commented Jun 3, 2022 via email

@antaramaj16
Copy link
Author

@mayofaulkner
Copy link
Contributor

Hi Antara,

I've had a look into this and the problem occurs because the dv position of the second from last point (-7720) falls outside of the ccf atlas. This is happening because in the script above when converting you are assuming that there is no offset from bregma in the dv axis when in reality there is ~ 330um difference. The quickest fix will be to add this in before saving to json

DV = DV + 330

There is, however, also a function that converts from ccf coordinates to the bregma ones used in the alignment gui that you can also use. Here I have written an example of how you would convert your points. It requires saving the points you have in matlab to an npy file and then reading them in in python to do the conversion

In matlab you can do the following (FYI here is the writeNPY function https://github.com/kwikteam/npy-matlab)

# In matlab save the picks as a .npy file
thisProbe = probePoints.pointList.pointList{6,1}
writeNPY(thisProbe, 'picks_ccf.npy')

and then in python

# In python load in the same file
# Load in the pixel for tracing for single probe
import numpy as np
picks_mldvap = np.load('picks_ccf.npy')

# Switch axis so that array is in order mlapdv
picks_mlapdv = np.copy(picks_mldvap)
picks_mlapdv[:, 1] = picks_mldvap[:, 2]
picks_mlapdv[:, 2] = picks_mldvap[:, 1]

# Convert from pixels to um (assumes pixels have been taken from 10um allen atlas)
picks_mlapdv = picks_mlapdv * 10

# Convert from ccf to IBL bregma coordinates
from ibllib.atlas import AllenAtlas
ba = AllenAtlas()
xyz_mlapdv = ba.ccf2xyz(picks_mlapdv, ccf_order='mlapdv') * 1e6
xyz_picks = {'xyz_picks': xyz_mlapdv.tolist()}

# Write to json
import json
output_path = Path(r'C:/Users/Mayo/Downloads/FlatIron/SWC_023/alf')
with open(Path(output_path, 'xyz_picks.json'), "w") as f:
    json.dump(xyz_picks, f, indent=2)

Two things that I noticed when looking at your tracing (see images for coronal and sagittal slice)

image
image

  1. A lot of the traced points are outside the brain. I wonder if this is because the ml and ap coordinates above have been switched. From your experiment do you have an idea of where the ml and ap coordinates should be in the brain and if so does the location in the slices above seem correct?

  2. It may be worth seeing if you can get a smoother tracing as those sharp edges between points will lead to strange behaviour when doing alignments as points are interpolated along the line between the points. I would also definitely recommend sorting the values by dv value to make sure the points are decreasing.

I hope that all makes sense. Please let me know if you need any other help.

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

No branches or pull requests

3 participants