Schroeder-Lab / Data

For pre-processing raw data (two-photon, ephys, bonsai, ...) and loading/saving data.
0 stars 3 forks source link

Z stack correlation with frame: correlation threshold #28

Closed mariacozan closed 1 year ago

mariacozan commented 1 year ago

I ran the preprocessing code on some retinal boutons experiments which had some substantial bleaching (2023-02-07, Io). Because the Z stack was taken as usual at the end of the experiment, the Z stack was also quite dark.

When I checked through the code, I noticed the correlation values for the Z stack with the frames of the recordings were quite low with the max value in zcorr (obtained by running np.max(zcorr) ) being 0.032962244 and the median value 0.0047376594 (obtained by running np.median(zcorr) ).

When checking the actual zStack (already corrected) and comparing it to the binary, the plane that it thought the frame should be at looked nothing like it (Image Brightness enhanced through ImageJ): image

I chose the 24rd plane because in the Z trace this is the plane it shows the frame is at (value given when running this zTrace[2759]) and see here: image

In any case, none of the Z stack planes matches this FOV.

As a safety measure and to warn the user, it would be good if the correlation values between Z stack and the frame (given by the suite2p function compute_zpos which is used in runners process_s2p_singlePlane, variable zcorr) would have to be above a certain threshold and if it is below that, a User warning or error could be given.

Although this problem is hopefully rare and the Z stack should resemble the actual frames, this is an important safety measure to make sure the z correlation actually makes sense as the z correction heavily relies on the true location of the imaging plane.

However, just as a positive control I also wanted to check if this is in fact a valid metric using data where the z stack plane does in fact correspond to the imaged plane.

For this I used the data from 2022-08-18 (Glaucus). image

As you can see here, the plane that is supposed to correspond to the imaging plane (zTrace[45795]=18), does in fact look like it. However, the zcorr values that were given in this case, are in fact lower than for the boutons (np.max(zcorr) = 0.025701549)

Therefore, the only potential measure (that I can think of) which could be used as a confidence metric is in fact meaningless. Alternatively, a user warning should be given nonetheless to manually check how well the imaging plane matches with the suggested plane in the z stack.

liadJB commented 1 year ago

The boutons data is preprocessed differently.