SWC-Advanced-Microscopy / BakingTray

Serial-section automated anatomy extension for ScanImage
https://bakingtray.mouse.vision/
GNU Lesser General Public License v3.0
11 stars 5 forks source link

Last tile in preview scan doesn't get laid down #7

Closed raacampbell closed 4 years ago

raacampbell commented 7 years ago

This is a new bug. Although the stall may be due the MATLAB licence server being down. This is unusual.

raacampbell commented 7 years ago

Yes, the stall was because someone cut a cable outside. Novel failure mode.

raacampbell commented 7 years ago

This indeed happens during the fast preview. It's not important, we leave it for now.

raacampbell commented 7 years ago

Also doesn't get laid down during a full acquisition

raacampbell commented 7 years ago

This happens because after the final tile, tileAcq isn't run.

raacampbell commented 4 years ago

We need to fix this now because it's affecting the automatic brain finding in one out of a total of ten single brain samples.

raacampbell commented 4 years ago

The best solution is probably to move the code that extracts the tile data to a separate method. Then call that method once more after the acquisition has run.

raacampbell commented 4 years ago

With the dummyScanner now baking and saving properly (2ec5c344ad03ebc64d2ab777a5097e64abc5416c) also see the final preview tile not being laid down. So let's try to fix this and hopefully the same concept can be applied to SIBT.

raacampbell commented 4 years ago

Changes in this commit 54f5160f2aac420533bcfbb0e9239e9982f3dcd3 and this commit 5654ac741989f62250e8e1e97c45e136a5835bcf fix the last tile bug for the dummyScanner. It works in preview and bake. It saves the correct number of tiles. Can we implement a similar fix for SIBT?

raacampbell commented 4 years ago

SIBT.tileAcqDone should now coordinate the acquisition and display of the final preview tile: c4ba52445a564ab9b0afa56947151d0b283b84da

raacampbell commented 4 years ago

Ah... It's placing a tile but that tile is just a copy of the penultimate tile. Not fantastic, even though, TBH, 90% of the time the penultimate tile is empty. So the bug is not usually noticeable.

However, with samples that are not brains (i.e. not balls) it's fairly possible for this duplicate issue to cause an extra row or column of tiles to be imaged for no reason. That's a bit annoying.

raacampbell commented 4 years ago

I thought this was fixed: but right now on the autoROI branch I don't see the final tile being laid down.

raacampbell commented 4 years ago

If we examine the last stripe at the CLI at the end of a preview, the final tile is visible as it should be. Also, the following user function returns to screen a different sum after each z stack:

function BT_timer (src,event,varargin)
    % This is a test ScanImage UserFunction used to time events and debug the tiling cycle

    persistent nl;
    persistent n;

    switch event.EventName
        case 'acqModeStart'
            n=0;
            nl=0;

        case 'frameAcquired'
            n=n+1;

        case {'acqDone'}
            L=src.hSI.hDisplay.stripeDataBuffer{3};
            Lf=L.roiData{1}.imageData{1}{1};
            if src.hSI.active
                pause(0.2) %Simulate x/y motion
                src.hSI.hScan2D.trigIssueSoftwareAcq
            end
            nl = nl+1;
            sum(Lf(:))

        case {'acqModeDone'}
            fprintf('Acquired %d frames over %d loops\n',n,nl);

    end
end

This leads to me to believe that I'm doing something really silly in SIBT.tileAcqDone. It really should just work with no duplicate tiles and no failure to place the last tile.

raacampbell commented 4 years ago

Also we don't miss the final tile with stressTestTilePreviewBuffer, a class included in the repo's diagnostic code.

raacampbell commented 4 years ago

Ah! The reason it wasn't entering for the final tile was because of the second armedListener in SIBT:

 obj.armedListeners{end+1}=addlistener(obj.hC.hUserFunctions, 'acqAbort', @obj.tileScanAbortedInScanImage);

This is the one that's supposed to disarm the scanner if the user presses abort. If I disable that listener in takeRapidPreview then I get tileAcqDone running for all the tiles. It's still not placing the final, tile, but this should be fixable now, as it was before...

raacampbell commented 4 years ago

All tiles placed in grid! a8cd2f298fde3f4f68e4dc4b99918ea72bfde30d However, for this to happen we have to disable the acq abort listener. This seems to have no ill effects, but I will investigate a bit more.

raacampbell commented 4 years ago

remove the scan abort callback: 0585cda16ccb17c072c0e28d11f8da0bb04b589c