Skip to content

Commit

Permalink
Add Image Open Tagging
Browse files Browse the repository at this point in the history
Tag the images which are being opened to distinguish between "Viewing" and "Data Reduction".
  • Loading branch information
AvocadoMoon committed Nov 12, 2024
1 parent 5777315 commit 42ef820
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.vcell.N5.UI;

import org.vcell.N5.N5ImageHandler;
import org.vcell.N5.retrieving.SimResultsLoader;

import javax.swing.*;
import javax.swing.border.Border;
Expand Down Expand Up @@ -108,7 +109,8 @@ public void actionPerformed(ActionEvent e) {
if (openOrCancel.getText().equals("Cancel")){
n5ExportTable.removeFromLoadingRows();
} else {
n5ExportTable.openSelectedRows(inMemory, performDataReduction);
SimResultsLoader.OpenTag openTag = performDataReduction ? SimResultsLoader.OpenTag.DATA_REDUCTION : SimResultsLoader.OpenTag.VIEW;
n5ExportTable.openSelectedRows(inMemory, performDataReduction, openTag);
}
} else if (e.getSource().equals(advancedFeatures.copyLink)) {
n5ExportTable.copySelectedRowLink();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,12 +155,12 @@ private void automaticRefresh(){
refreshTableThread.start();
}

public void openSelectedRows(boolean openInMemory, boolean performDataReduction){
public void openSelectedRows(boolean openInMemory, boolean performDataReduction, SimResultsLoader.OpenTag openTag){
ArrayList<SimResultsLoader> filesToOpen = new ArrayList<>();
for(int row: exportListTable.getSelectedRows()){
String uri = n5ExportTableModel.getRowData(row).uri;
ExportDataRepresentation.SimulationExportDataRepresentation rowData = n5ExportTableModel.getRowData(row);
SimResultsLoader simResultsLoader = new SimResultsLoader(uri, rowData.savedFileName, row, rowData.jobID);
SimResultsLoader simResultsLoader = new SimResultsLoader(uri, rowData.savedFileName, row, rowData.jobID, openTag);
filesToOpen.add(simResultsLoader);
}
N5ImageHandler.loadingManager.openN5FileDataset(filesToOpen, openInMemory,
Expand Down Expand Up @@ -226,7 +226,9 @@ public void simFinishedLoading(SimResultsLoader loadedResults) {
loadingRowsJobID.remove(loadedResults.rowNumber);
exportListTable.repaint();
controlPanel.allowCancel(false);
loadedResults.getImagePlus().show();
if (loadedResults.openTag == SimResultsLoader.OpenTag.VIEW){
loadedResults.getImagePlus().show();
}
}

public static class N5ExportTableModel extends AbstractTableModel {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public String getS3URL(){

@Override
public void actionPerformed(ActionEvent e) {
SimResultsLoader simResultsLoader = new SimResultsLoader(getS3URL(), "", -1, "");
SimResultsLoader simResultsLoader = new SimResultsLoader(getS3URL(), "", -1, "", SimResultsLoader.OpenTag.VIEW);
N5ImageHandler.loadingManager.openN5FileDataset(new ArrayList<SimResultsLoader>(){{add(simResultsLoader);}},
false,
false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,14 +261,16 @@ public void simIsLoading(int itemRow, String exportID) {

@Override
public void simFinishedLoading(SimResultsLoader loadedResults) {
Thread imageProcessingThread = new Thread(() -> {
ImagePlus imagePlus = loadedResults.getImagePlus();
imagePlus.show();
addMetaData(loadedResults);
calculateAndAddResults(imagePlus, submission.simNormRange, submission.simImageRange,
submission.arrayOfSimRois, loadedResults.getChannelInfo());
}, "Processing Image: " + loadedResults.userSetFileName);
imageProcessingThread.start();
if (loadedResults.openTag == SimResultsLoader.OpenTag.DATA_REDUCTION){
Thread imageProcessingThread = new Thread(() -> {
ImagePlus imagePlus = loadedResults.getImagePlus();
imagePlus.show();
addMetaData(loadedResults);
calculateAndAddResults(imagePlus, submission.simNormRange, submission.simImageRange,
submission.arrayOfSimRois, loadedResults.getChannelInfo());
}, "Processing Image: " + loadedResults.userSetFileName);
imageProcessingThread.start();
}
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,22 @@ public class SimResultsLoader {
private static final Logger logger = N5ImageHandler.getLogger(SimResultsLoader.class);
public static AmazonS3ClientBuilder s3ClientBuilder;
private ImagePlus imagePlus = null;
public final OpenTag openTag;


public String userSetFileName = null;
public int rowNumber;
public String exportID;

public SimResultsLoader(){

openTag = OpenTag.NONE;
}
public SimResultsLoader(String stringURI, String userSetFileName, int rowNumber, String exportID){
this(stringURI, userSetFileName);
public SimResultsLoader(String stringURI, String userSetFileName, int rowNumber, String exportID, OpenTag openTag){
this(stringURI, userSetFileName, openTag);
this.rowNumber = rowNumber;
this.exportID = exportID;
}
public SimResultsLoader(String stringURI, String userSetFileName){
public SimResultsLoader(String stringURI, String userSetFileName, OpenTag openTag){
uri = URI.create(stringURI);
this.userSetFileName = userSetFileName;
if(!(uri.getQuery() == null)){
Expand All @@ -78,6 +79,7 @@ public SimResultsLoader(String stringURI, String userSetFileName){
throw new RuntimeException(e);
}
}
this.openTag = openTag;
}

/////////////////////////////////
Expand Down Expand Up @@ -225,4 +227,10 @@ ImagePlus getImgPlusFromLocalN5File() throws IOException {
N5Reader n5Reader = new N5FSReader(selectedLocalFile.getPath());
return ImageJFunctions.wrap((CachedCellImg<DoubleType, ?>) N5Utils.open(n5Reader, dataSetChosen), userSetFileName);
}

public enum OpenTag{
VIEW,
DATA_REDUCTION,
NONE
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void compareExpectedCalculations(ImagePlus imagePlus, ArrayList<Roi> roi
@Test
public void testMean2DCalculation(){
// Ensure the mean calculated for each ROI, and each time point is what's to be expected
SimResultsLoader simResultsLoader = new SimResultsLoader("https://vcell.cam.uchc.edu/n5Data/ezequiel23/ddf7f4f0c77dffd.n5?dataSetName=4864003788", "test1");
SimResultsLoader simResultsLoader = new SimResultsLoader("https://vcell.cam.uchc.edu/n5Data/ezequiel23/ddf7f4f0c77dffd.n5?dataSetName=4864003788", "test1", SimResultsLoader.OpenTag.NONE);
ImagePlus labResultImage2D = simResultsLoader.getImagePlus();

Roi labRoi = RoiDecoder.open(getTestResourceFiles("ROIs/Lab ROI.roi").getAbsolutePath());
Expand All @@ -85,7 +85,7 @@ public void testMean3DCalculation(){

@Test
public void testMeanAndNormalization2DCalculation(){
SimResultsLoader simResultsLoader = new SimResultsLoader("https://vcell.cam.uchc.edu/n5Data/ezequiel23/ddf7f4f0c77dffd.n5?dataSetName=4864003788", "test1");
SimResultsLoader simResultsLoader = new SimResultsLoader("https://vcell.cam.uchc.edu/n5Data/ezequiel23/ddf7f4f0c77dffd.n5?dataSetName=4864003788", "test1", SimResultsLoader.OpenTag.NONE);
ImagePlus labResultImage2D = simResultsLoader.getImagePlus();
Roi labRoi = RoiDecoder.open(getTestResourceFiles("ROIs/Lab ROI.roi").getAbsolutePath());
Roi simROI = RoiDecoder.open(getTestResourceFiles("ROIs/Sim ROI.roi").getAbsolutePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void testGettingImgPlus() throws IOException {
public void testS3AlphaInstance() throws IOException{
N5DataSetFile[] n5DataSetFiles = N5DataSetFile.alphaTestFiles();
for(N5DataSetFile n5DataSetFile : n5DataSetFiles) {
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri, "");
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri, "", SimResultsLoader.OpenTag.NONE);
simResultsLoader.createS3ClientAndReader();
simResultsLoader.loadImageFromN5File();
ImagePlus imagePlus = simResultsLoader.getImagePlus();
Expand All @@ -91,7 +91,7 @@ public void testS3AlphaInstance() throws IOException{
public void testS3AlphaInstanceLoadedIntoMemory() throws IOException {
N5DataSetFile[] n5DataSetFiles = N5DataSetFile.alphaTestFiles();
for(N5DataSetFile n5DataSetFile : n5DataSetFiles) {
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri, "");
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri, "", SimResultsLoader.OpenTag.NONE);
simResultsLoader.createS3ClientAndReader();
simResultsLoader.loadImageFromN5File();
ImagePlus imagePlus = simResultsLoader.getImagePlus();
Expand All @@ -113,7 +113,7 @@ interface PixelCalculations {
public void testUnits() throws IOException {
N5DataSetFile[] n5DataSetFiles = N5DataSetFile.alphaTestFiles();
for (N5DataSetFile n5DataSetFile: n5DataSetFiles){
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri, "");
SimResultsLoader simResultsLoader = new SimResultsLoader(n5DataSetFile.uri, "", SimResultsLoader.OpenTag.NONE);
simResultsLoader.createS3ClientAndReader();
simResultsLoader.loadImageFromN5File();
ImagePlus imagePlus = simResultsLoader.getImagePlus();
Expand Down

0 comments on commit 42ef820

Please sign in to comment.