From ce35f5287e171cbf12fba18767e08dc6746d4213 Mon Sep 17 00:00:00 2001 From: Ezequiel Valencia Date: Thu, 24 Oct 2024 09:07:22 -0400 Subject: [PATCH] Functional GUI For Data Reduction You can now go through the entire process of data reduction through the GUI. --- .../org/vcell/N5/UI/AdvancedFeatures.java | 4 +- .../org/vcell/N5/UI/ControlButtonsPanel.java | 4 +- .../java/org/vcell/N5/UI/N5ExportTable.java | 6 +- .../java/org/vcell/N5/UI/RangeSelector.java | 37 ++--- .../org/vcell/N5/UI/RemoteFileSelection.java | 5 +- .../org/vcell/N5/analysis/DataReduction.java | 70 ++++----- ...AnalysisGUI.java => DataReductionGUI.java} | 141 +++++++++--------- .../vcell/N5/retrieving/LoadingManager.java | 105 +++++++------ .../vcell/N5/retrieving/SimResultsLoader.java | 18 ++- 9 files changed, 202 insertions(+), 188 deletions(-) rename view-simulation-results/src/main/java/org/vcell/N5/analysis/{TemporalAnalysisGUI.java => DataReductionGUI.java} (53%) diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/AdvancedFeatures.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/AdvancedFeatures.java index 16c5a97..31d1834 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/AdvancedFeatures.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/AdvancedFeatures.java @@ -6,8 +6,8 @@ public class AdvancedFeatures extends JPanel { public final JCheckBox inMemory; - private JCheckBox dataReduction; - private JCheckBox rangeSelection; + public final JCheckBox dataReduction; + public final JCheckBox rangeSelection; public AdvancedFeatures(){ diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/ControlButtonsPanel.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/ControlButtonsPanel.java index bcc14cc..83b2d52 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/ControlButtonsPanel.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/ControlButtonsPanel.java @@ -22,7 +22,7 @@ public class ControlButtonsPanel extends JPanel implements ActionListener { private N5ExportTable n5ExportTable; private RemoteFileSelection remoteFileSelection; - private final AdvancedFeatures advancedFeatures = new AdvancedFeatures(); + public final AdvancedFeatures advancedFeatures = new AdvancedFeatures(); public ControlButtonsPanel(){ includeExampleExports = new JCheckBox("Show Example Exports"); @@ -107,7 +107,7 @@ public void actionPerformed(ActionEvent e) { if (openOrCancel.getText().equals("Cancel")){ n5ExportTable.removeFromLoadingRows(); } else { - n5ExportTable.openSelectedRows(advancedFeatures.inMemory.isSelected()); + n5ExportTable.openSelectedRows(); } } else if (e.getSource().equals(copyLink)) { n5ExportTable.copySelectedRowLink(); diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/N5ExportTable.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/N5ExportTable.java index e6b9253..cf21e7f 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/N5ExportTable.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/N5ExportTable.java @@ -155,7 +155,7 @@ private void automaticRefresh(){ refreshTableThread.start(); } - public void openSelectedRows(boolean inMemory){ + public void openSelectedRows(){ ArrayList filesToOpen = new ArrayList<>(); for(int row: exportListTable.getSelectedRows()){ String uri = n5ExportTableModel.getRowData(row).uri; @@ -163,7 +163,9 @@ public void openSelectedRows(boolean inMemory){ SimResultsLoader simResultsLoader = new SimResultsLoader(uri, rowData.savedFileName, row, rowData.jobID); filesToOpen.add(simResultsLoader); } - N5ImageHandler.loadingManager.openN5FileDataset(filesToOpen, inMemory); + AdvancedFeatures advancedFeatures = MainPanel.controlButtonsPanel.advancedFeatures; + N5ImageHandler.loadingManager.openN5FileDataset(filesToOpen, advancedFeatures.inMemory.isSelected(), + advancedFeatures.rangeSelection.isSelected(), advancedFeatures.dataReduction.isSelected()); } public void copySelectedRowLink(){ diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/RangeSelector.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/RangeSelector.java index feb47c8..d5ed49d 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/RangeSelector.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/RangeSelector.java @@ -19,35 +19,39 @@ public class RangeSelector extends JDialog implements ActionListener { public int startZ; public int endZ; - private final JTextField channelStartTextField; - private final JTextField channelEndTextField; - private final JTextField timeStartTextField; - private final JTextField timeEndTextField; - private final JTextField zStartTextField; - private final JTextField zEndTextField; + private JTextField channelStartTextField; + private JTextField channelEndTextField; + private JTextField timeStartTextField; + private JTextField timeEndTextField; + private JTextField zStartTextField; + private JTextField zEndTextField; public boolean cancel; private static final String okayButtonText = "Okay"; private static final String cancelButtonText = "Cancel"; - public final JButton okayButton; - public final JButton cancelButton; - private final JFrame frame; + public JButton okayButton; + public JButton cancelButton; + private JFrame frame; - private static final Logger logger = N5ImageHandler.getLogger(RangeSelector.class); private static final EventListenerList eventListenerList = new EventListenerList(); private final ControlButtonsPanel controlButtonsPanel = MainPanel.controlButtonsPanel; - public RangeSelector(double cDim, double zDim, double tDim, String userSetFileName){ - channelStartTextField = new HintTextField("1"); + public RangeSelector(){ + + } + + public void displayRangeMenu(double cDim, double zDim, double tDim){ channelEndTextField = new HintTextField("" + (int) cDim); + zEndTextField = new HintTextField("" + (int) zDim); + timeEndTextField = new HintTextField("" + (int) tDim); + String userSetFileName = "Range for All Images Used"; + channelStartTextField = new HintTextField("1"); zStartTextField = new HintTextField("1"); - zEndTextField = new HintTextField("" + (int) zDim); timeStartTextField = new HintTextField("1"); - timeEndTextField = new HintTextField("" + (int) tDim); // Create the frame frame = new JFrame("Select " + userSetFileName + " Dimensions"); @@ -93,15 +97,12 @@ public RangeSelector(double cDim, double zDim, double tDim, String userSetFileNa frame.add(panel); this.setContentPane(panel); this.setModal(true); - } - - public void displayRangeMenu(){ // Make the window visible this.setVisible(true); } public static void main(String[] args) { - RangeSelector inMemoryPopUp = new RangeSelector(1, 2, 3, null); + RangeSelector inMemoryPopUp = new RangeSelector(); } @Override diff --git a/view-simulation-results/src/main/java/org/vcell/N5/UI/RemoteFileSelection.java b/view-simulation-results/src/main/java/org/vcell/N5/UI/RemoteFileSelection.java index ec9c518..374adae 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/UI/RemoteFileSelection.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/UI/RemoteFileSelection.java @@ -96,7 +96,10 @@ public String getS3URL(){ @Override public void actionPerformed(ActionEvent e) { SimResultsLoader simResultsLoader = new SimResultsLoader(getS3URL(), "", -1, ""); - N5ImageHandler.loadingManager.openN5FileDataset(new ArrayList(){{add(simResultsLoader);}}, false); + AdvancedFeatures advancedFeatures = MainPanel.controlButtonsPanel.advancedFeatures; + N5ImageHandler.loadingManager.openN5FileDataset(new ArrayList(){{add(simResultsLoader);}}, + advancedFeatures.inMemory.isSelected(), advancedFeatures.rangeSelection.isSelected(), + advancedFeatures.dataReduction.isSelected()); this.setVisible(false); } } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReduction.java b/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReduction.java index 4d37fd2..67b0d0e 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReduction.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReduction.java @@ -19,11 +19,10 @@ public class DataReduction implements SimLoadingListener { private final ArrayList> csvMatrix = new ArrayList<>(); - private final double normalPreChange; - private final double normalPostChange; - private final int timeWhenChangeOccurs; + private int numOfImagesToBeOpened; + private final boolean normalize; - private int numOfSimImages; + public final DataReductionGUI.DataReductionSubmission submission; /* Open an image from file (assume 2D for now). @@ -46,64 +45,67 @@ Save to cvs file of some kind (something that can be imported into excel). // Take results and place them within a spreadsheet // Create a graph from that spreadsheet - public DataReduction(boolean normalizePostChange, boolean normalizeWithPreChangeValues, - ArrayList arrayOfSimRois, ArrayList arrayOfLabRois, - ImagePlus labResults, int startPreChange, int endPreChange, - int timeWhenChangeOccurs, int numOfSimImages, File fileToSaveResultsTo){ - this.arrayOfSimRois = arrayOfSimRois; - this.timeWhenChangeOccurs = timeWhenChangeOccurs; - this.numOfSimImages = numOfSimImages; - this.file = fileToSaveResultsTo; + public DataReduction(DataReductionGUI.DataReductionSubmission submission){ + this.submission = submission; + this.arrayOfSimRois = submission.arrayOfSimRois; + this.numOfImagesToBeOpened = submission.numOfSimImages + 1; // Plus one for the lab image + this.file = submission.fileToSaveResultsTo; + this.normalize = submission.normalizeMeasurementsBool; ArrayList headers = new ArrayList(){{add("Time Frame");}}; csvMatrix.add(headers); - normalPreChange = normalizeWithPreChangeValues ? calculateNormalValue(labResults, startPreChange, endPreChange) : Double.MIN_NORMAL; - normalPostChange = normalizePostChange ? calculateNormalValue(labResults, timeWhenChangeOccurs, timeWhenChangeOccurs) : Double.MIN_NORMAL; + double normValue = calculateNormalValue(submission.labResults, submission.imageStartPointNorm, submission.imageEndPointNorm); - HashMap> reducedData = calculateMean(labResults, arrayOfLabRois); + HashMap> reducedData = calculateMean(submission.labResults, submission.arrayOfLabRois, normValue); synchronized (csvMatrixLock){ - for (int t = 0; t < labResults.getNFrames(); t++){ + for (int t = 0; t < submission.labResults.getNFrames(); t++){ ArrayList rowForTime = new ArrayList<>(); rowForTime.add(String.valueOf(t)); csvMatrix.add(rowForTime); } } - addValuesToCSVMatrix(labResults, reducedData); + addValuesToCSVMatrix(submission.labResults, reducedData); } private void addValuesToCSVMatrix(ImagePlus imagePlus, HashMap> reducedData){ synchronized (csvMatrixLock){ csvMatrix.get(0).add(""); - csvMatrix.get(0).add(imagePlus.getTitle()); for (String roiName: reducedData.keySet()){ - csvMatrix.get(0).add(roiName); + csvMatrix.get(0).add(imagePlus.getTitle()+" : " + roiName); for(int t = 0; t < imagePlus.getNFrames(); t++){ double mean = reducedData.get(roiName).get(t); + csvMatrix.get(t + 1).add(""); csvMatrix.get(t + 1).add(String.valueOf(mean)); } } - numOfSimImages -= 1; - if (numOfSimImages == 0){ + numOfImagesToBeOpened -= 1; + if (numOfImagesToBeOpened == 0){ writeCSVMatrix(); } } } private double calculateNormalValue(ImagePlus imagePlus, int startT, int endT){ - double normal = 0; - for (int k = startT; k <= endT; k++){ - imagePlus.setT(k); - normal += imagePlus.getProcessor().getStatistics().mean; + if (normalize){ + double normal = 0; + for (int k = startT; k <= endT; k++){ + imagePlus.setT(k); + normal += imagePlus.getProcessor().getStatistics().mean; + } + normal = normal / (endT - startT); + return normal; + } else { + return Double.MIN_NORMAL; } - normal = normal / (endT - startT); - return normal; + } - private HashMap> calculateMean(ImagePlus imagePlus, ArrayList roiList){ + private HashMap> calculateMean(ImagePlus imagePlus, ArrayList roiList, + double normalizationValue){ // ResultsTable resultsTable = new ResultsTable(); HashMap> roiListOfMeans = new HashMap<>(); @@ -116,11 +118,8 @@ private HashMap> calculateMean(ImagePlus imagePlus, Ar // // double meanValue = resultsTable.getValueAsDouble(resultsTable.getColumnIndex("Mean"), 0); double meanValue = imagePlus.getProcessor().getStatistics().mean; - if (normalPreChange != Double.MIN_NORMAL){ - meanValue = meanValue / normalPreChange; - } - if (normalPostChange != Double.MIN_NORMAL && t >= timeWhenChangeOccurs){ - meanValue = meanValue / normalPostChange; + if (normalizationValue != Double.MIN_NORMAL){ + meanValue = meanValue / normalizationValue; } meanValues.add(meanValue); } @@ -135,6 +134,7 @@ private void writeCSVMatrix(){ for (ArrayList row: csvMatrix){ csvWriter.writeNext(row.toArray(new String[0])); } + csvWriter.close(); } catch (IOException e) { throw new RuntimeException(e); } @@ -148,8 +148,8 @@ public void simIsLoading(int itemRow, String exportID) { @Override public void simFinishedLoading(int itemRow, String exportID, ImagePlus imagePlus) { - - HashMap> calculations = calculateMean(imagePlus, arrayOfSimRois); + double normValue = calculateNormalValue(imagePlus, submission.simStartPointNorm, submission.simEndPointNorm); + HashMap> calculations = calculateMean(imagePlus, arrayOfSimRois, normValue); addValuesToCSVMatrix(imagePlus, calculations); } } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/analysis/TemporalAnalysisGUI.java b/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReductionGUI.java similarity index 53% rename from view-simulation-results/src/main/java/org/vcell/N5/analysis/TemporalAnalysisGUI.java rename to view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReductionGUI.java index f673a79..9ea4a93 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/analysis/TemporalAnalysisGUI.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/analysis/DataReductionGUI.java @@ -1,5 +1,6 @@ package org.vcell.N5.analysis; +import ij.ImagePlus; import ij.WindowManager; import ij.gui.Roi; import ij.io.RoiDecoder; @@ -12,24 +13,17 @@ import java.io.File; import java.util.ArrayList; -public class TemporalAnalysisGUI extends JPanel implements ActionListener { +public class DataReductionGUI extends JPanel implements ActionListener { private JComboBox chosenImage; private JComboBox chosenMeasurement; - private JCheckBox normalizeEntireImage = new JCheckBox("Normalize Entire Image"); - private JCheckBox normalizeROI = new JCheckBox("Normalize ROI"); + private final JCheckBox normalizeMeasurement = new JCheckBox("Normalize Measurement: "); - private JTextField entireImageFramesFromImageStart; - private JTextField entireImageFramesFromImageEnd; - private JTextField entireImageFramesFromSimStart; - private JTextField entireImageFramesFromSimEnd; + private JTextField createNormFromImageStart; + private JTextField createNormFromImageEnd; + private JTextField createNormFromSimStart; + private JTextField createNormFromSimEnd; private JPanel entireImageFramesJPanel; - private JTextField roiFramesFromImageStart; - private JTextField roiFramesFromImageEnd; - private JTextField roiFramesFromSimStart; - private JTextField roiFramesFromSimEnd; - private JPanel roiFramesJPanel; - private JButton imageROIFileButton; private JButton simROIFileButton; @@ -43,16 +37,47 @@ public class TemporalAnalysisGUI extends JPanel implements ActionListener { private final JDialog jDialog; private final JOptionPane pane; + private File chosenFile; + + private int numSimsToOpen; + + public int mainGUIReturnValue; + public int fileChooserReturnValue; // private TemporalAnalysis temporalAnalysis = new TemporalAnalysis(); - public TemporalAnalysisGUI(){ + public class DataReductionSubmission{ + public final boolean normalizeMeasurementsBool; + public final ArrayList arrayOfSimRois; + public final ArrayList arrayOfLabRois; + public final ImagePlus labResults; + public final int simStartPointNorm; + public final int simEndPointNorm; + public final int imageStartPointNorm; + public final int imageEndPointNorm; + public final int numOfSimImages; + public final File fileToSaveResultsTo; + public DataReductionSubmission(){ + normalizeMeasurementsBool = normalizeMeasurement.isSelected(); + arrayOfSimRois = simROIList; + arrayOfLabRois = imageROIList; + labResults = WindowManager.getImage((String) chosenImage.getSelectedItem()); + simStartPointNorm = createNormFromSimStart.getText().isEmpty() ? Integer.MIN_VALUE : Integer.parseInt(createNormFromSimStart.getText()); + simEndPointNorm = createNormFromSimEnd.getText().isEmpty() ? Integer.MIN_VALUE: Integer.parseInt(createNormFromSimEnd.getText()); + imageStartPointNorm = createNormFromImageStart.getText().isEmpty() ? Integer.MIN_VALUE: Integer.parseInt(createNormFromImageStart.getText()); + imageEndPointNorm = createNormFromImageEnd.getText().isEmpty() ? Integer.MIN_VALUE: Integer.parseInt(createNormFromImageEnd.getText()); + numOfSimImages = numSimsToOpen; + fileToSaveResultsTo = chosenFile; + } + } + + public DataReductionGUI(int numSimsToOpen){ + this.numSimsToOpen = numSimsToOpen; setLayout(new GridLayout(4, 1)); add(imageAndAnalysisType()); add(roisSelectedGUI()); - add(normalizeEntireImageGUI()); - add(normalizeROIGUI()); + add(normalizeGUI()); setSize(400, 400); setVisible(true); @@ -62,19 +87,15 @@ public TemporalAnalysisGUI(){ public void displayGUI(){ jDialog.setVisible(true); - Integer returnValue = (Integer) pane.getValue(); - if (returnValue.equals(JOptionPane.OK_OPTION)){ + mainGUIReturnValue = (Integer) pane.getValue(); + if (mainGUIReturnValue == JOptionPane.OK_OPTION){ JFileChooser saveToFile = new JFileChooser(); saveToFile.setFileSelectionMode(JFileChooser.FILES_ONLY); - int response = saveToFile.showDialog(this, "Save Results To File"); - if (response == JFileChooser.APPROVE_OPTION){ + fileChooserReturnValue = saveToFile.showDialog(this, "Save Results To File"); + if (fileChooserReturnValue == JFileChooser.APPROVE_OPTION){ + chosenFile = saveToFile.getSelectedFile(); Thread thread = new Thread(() -> { - DataReduction dataReduction = new DataReduction( - normalizeROI.isSelected(), normalizeEntireImage.isSelected(), simROIList, - imageROIList, WindowManager.getImage((String) chosenImage.getSelectedItem()), - 0, 0, 0, - 5, saveToFile.getSelectedFile() - ); + DataReduction dataReduction = new DataReduction(new DataReductionSubmission()); N5ImageHandler.loadingManager.addSimLoadingListener(dataReduction); }); thread.start(); @@ -82,59 +103,33 @@ public void displayGUI(){ } } - private JPanel normalizeROIGUI(){ - JPanel jPanel = new JPanel(new GridLayout()); - normalizeROI.addActionListener(this); - - JPanel fromImage = new JPanel(new GridLayout()); - roiFramesFromImageStart = new JTextField(); - roiFramesFromImageEnd = new JTextField(); - fromImage.add(roiFramesFromImageStart); - fromImage.add(new JLabel("to")); - fromImage.add(roiFramesFromImageEnd); - - JPanel fromSim = new JPanel(new GridLayout()); - roiFramesFromSimStart = new JTextField(); - roiFramesFromSimEnd = new JTextField(); - fromSim.add(roiFramesFromSimStart); - fromSim.add(new JLabel("to")); - fromSim.add(roiFramesFromSimEnd); - - roiFramesJPanel = new JPanel(new GridLayout()); - roiFramesJPanel.add(fromImage); - roiFramesJPanel.add(fromSim); - roiFramesJPanel.setVisible(false); - - jPanel.add(normalizeROI); - jPanel.add(roiFramesJPanel); - - return jPanel; - } - - private JPanel normalizeEntireImageGUI(){ - JPanel jPanel = new JPanel(new GridLayout()); - normalizeEntireImage.addActionListener(this); + private JPanel normalizeGUI(){ + JPanel jPanel = new JPanel(new GridLayout(2, 1)); + normalizeMeasurement.addActionListener(this); + JLabel explainInput = new JLabel("Timeline Range to Create Norm"); JPanel fromImage = new JPanel(new GridLayout()); - entireImageFramesFromImageStart = new JTextField(); - entireImageFramesFromImageEnd = new JTextField(); - fromImage.add(entireImageFramesFromImageStart); + createNormFromImageStart = new JTextField(); + createNormFromImageEnd = new JTextField(); + fromImage.add(new JLabel("Exp. Timeline: ")); + fromImage.add(createNormFromImageStart); fromImage.add(new JLabel("to")); - fromImage.add(entireImageFramesFromImageEnd); + fromImage.add(createNormFromImageEnd); JPanel fromSim = new JPanel(new GridLayout()); - entireImageFramesFromSimStart = new JTextField(); - entireImageFramesFromSimEnd = new JTextField(); - fromSim.add(entireImageFramesFromSimStart); + createNormFromSimStart = new JTextField(); + createNormFromSimEnd = new JTextField(); + fromSim.add(new JLabel("Sim Timeline: ")); + fromSim.add(createNormFromSimStart); fromSim.add(new JLabel("to")); - fromSim.add(entireImageFramesFromSimEnd); + fromSim.add(createNormFromSimEnd); - entireImageFramesJPanel = new JPanel(new GridLayout()); + entireImageFramesJPanel = new JPanel(new GridLayout(2, 1)); entireImageFramesJPanel.add(fromImage); entireImageFramesJPanel.add(fromSim); entireImageFramesJPanel.setVisible(false); - jPanel.add(normalizeEntireImage); + jPanel.add(normalizeMeasurement); jPanel.add(entireImageFramesJPanel); return jPanel; } @@ -172,10 +167,8 @@ public void actionPerformed(ActionEvent e) { imageROIList = fillROIList(imageROIFileChooser); } else if (e.getSource().equals(simROIFileButton)) { simROIList = fillROIList(simROIFileChooser); - } else if (e.getSource().equals(normalizeEntireImage)) { - entireImageFramesJPanel.setVisible(normalizeEntireImage.isSelected()); - } else if (e.getSource().equals(normalizeROI)) { - roiFramesJPanel.setVisible(normalizeROI.isSelected()); + } else if (e.getSource().equals(normalizeMeasurement)) { + entireImageFramesJPanel.setVisible(normalizeMeasurement.isSelected()); } } @@ -201,8 +194,8 @@ enum AvailableMeasurements{ } public static void main(String[] args) { - TemporalAnalysisGUI temporalAnalysisGUI = new TemporalAnalysisGUI(); - temporalAnalysisGUI.displayGUI(); + DataReductionGUI dataReductionGUI = new DataReductionGUI(0); + dataReductionGUI.displayGUI(); } } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/retrieving/LoadingManager.java b/view-simulation-results/src/main/java/org/vcell/N5/retrieving/LoadingManager.java index 63a75d9..8e83d88 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/retrieving/LoadingManager.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/retrieving/LoadingManager.java @@ -9,6 +9,7 @@ import org.vcell.N5.UI.ControlButtonsPanel; import org.vcell.N5.UI.RangeSelector; import org.vcell.N5.UI.MainPanel; +import org.vcell.N5.analysis.DataReductionGUI; import javax.swing.*; import javax.swing.event.EventListenerList; @@ -28,68 +29,66 @@ public class LoadingManager implements SimLoadingEventCreator { private static final Logger logger = N5ImageHandler.getLogger(RangeSelector.class); - public void openN5FileDataset(ArrayList filesToOpen, boolean openInMemory){ - controlButtonsPanel.allowCancel(true); - MainPanel.changeCursor(new Cursor(Cursor.WAIT_CURSOR)); - - for (int i = 0; i < filesToOpen.size(); i++){ - SimResultsLoader simResultsLoader = filesToOpen.get(i); - Thread openThread = new Thread(() -> { - ImagePlus imagePlus = null; - try{ - simResultsLoader.createS3ClientAndReader(); - notifySimIsLoading(simResultsLoader); - RangeSelector rangeSelector; - if (openInMemory){ - ArrayList dimensions = simResultsLoader.getN5Dimensions(); - rangeSelector = new RangeSelector(dimensions.get(2), dimensions.get(3), dimensions.get(4), simResultsLoader.userSetFileName); - rangeSelector.displayRangeMenu(); - if (!rangeSelector.cancel){ - imagePlus = openInMemory(simResultsLoader, rangeSelector); + public void openN5FileDataset(ArrayList filesToOpen, boolean openInMemory, + boolean selectRange, boolean dataReduction){ + RangeSelector rangeSelector = new RangeSelector(); + if (selectRange){ + SimResultsLoader firstSim = filesToOpen.get(0); + firstSim.createS3ClientAndReader(); + ArrayList dimensions = firstSim.getN5Dimensions(); + rangeSelector.displayRangeMenu(dimensions.get(2), dimensions.get(3), dimensions.get(4)); + } + DataReductionGUI dataReductionGUI = new DataReductionGUI(filesToOpen.size()); + if (dataReduction){ + dataReductionGUI.displayGUI(); + } + boolean dataReductionOkay = dataReduction && dataReductionGUI.mainGUIReturnValue == JOptionPane.OK_OPTION && dataReductionGUI.fileChooserReturnValue == JFileChooser.APPROVE_OPTION; + if (dataReductionOkay || !dataReduction){ + controlButtonsPanel.allowCancel(true); + MainPanel.changeCursor(new Cursor(Cursor.WAIT_CURSOR)); + for (int i = 0; i < filesToOpen.size(); i++){ + SimResultsLoader simResultsLoader = filesToOpen.get(i); + Thread openThread = new Thread(() -> { + ImagePlus imagePlus = null; + try{ + simResultsLoader.createS3ClientAndReader(); + notifySimIsLoading(simResultsLoader); + if (openInMemory){ + if (!rangeSelector.cancel){ + imagePlus = simResultsLoader.openInMemory(rangeSelector); + } + } else{ + imagePlus = simResultsLoader.getImgPlusFromN5File(); } - rangeSelector.dispose(); - } else{ - imagePlus = simResultsLoader.getImgPlusFromN5File(); } - } - catch (RuntimeException e) { - if (e.getCause().getCause().getCause() instanceof SdkInterruptedException || - e.getCause().getCause() instanceof AbortedException){ - logger.debug("Simulation stopped loading"); - } else { - throw new RuntimeException(e); + catch (RuntimeException e) { + if (e.getCause().getCause().getCause() instanceof SdkInterruptedException || + e.getCause().getCause() instanceof AbortedException){ + logger.debug("Simulation stopped loading"); + } else { + throw new RuntimeException(e); + } } - } - catch (Exception e){ - throw new RuntimeException(e); - } finally { - MainPanel.changeCursor(new Cursor(Cursor.DEFAULT_CURSOR)); - controlButtonsPanel.enableCriticalButtons(true); - notifySimIsDoneLoading(simResultsLoader, imagePlus); - synchronized (openSimulationsLock){ - openingSimulations.remove(simResultsLoader.exportID); + catch (Exception e){ + throw new RuntimeException(e); + } finally { + MainPanel.changeCursor(new Cursor(Cursor.DEFAULT_CURSOR)); + controlButtonsPanel.enableCriticalButtons(true); + notifySimIsDoneLoading(simResultsLoader, imagePlus); + synchronized (openSimulationsLock){ + openingSimulations.remove(simResultsLoader.exportID); + } } + }); + openThread.setName("Opening sim number: " + i + ". With id: " + simResultsLoader.exportID); + synchronized (openSimulationsLock){ + openingSimulations.put(simResultsLoader.exportID, openThread); } - }); - openThread.setName("Opening sim number: " + i + ". With id: " + simResultsLoader.exportID); - synchronized (openSimulationsLock){ - openingSimulations.put(simResultsLoader.exportID, openThread); + openThread.start(); } - openThread.start(); } } - private ImagePlus openInMemory(SimResultsLoader simResultsLoader, RangeSelector rangeSelector) throws IOException { - ImagePlus imagePlus = simResultsLoader.getImgPlusFromN5File(); - long start = System.currentTimeMillis(); - logger.debug("Loading Virtual N5 File " + simResultsLoader.userSetFileName + " Into Memory"); - imagePlus = new Duplicator().run(imagePlus, rangeSelector.startC, rangeSelector.endC, rangeSelector.startZ, - rangeSelector.endZ, rangeSelector.startT, rangeSelector.endT); - long end = System.currentTimeMillis(); - logger.debug("Loaded Virtual N5 File " + simResultsLoader.userSetFileName + " Into Memory taking: " + ((end - start)/ 1000) + "s"); - return imagePlus; - } - public void stopOpeningSimulation(String exportID){ Thread stopOtherThread = new Thread(() -> { synchronized (openSimulationsLock){ diff --git a/view-simulation-results/src/main/java/org/vcell/N5/retrieving/SimResultsLoader.java b/view-simulation-results/src/main/java/org/vcell/N5/retrieving/SimResultsLoader.java index a3e9495..159fc9f 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/retrieving/SimResultsLoader.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/retrieving/SimResultsLoader.java @@ -9,9 +9,12 @@ import com.amazonaws.services.s3.AmazonS3ClientBuilder; import com.google.gson.GsonBuilder; import ij.ImagePlus; +import ij.VirtualStack; import ij.plugin.ContrastEnhancer; +import ij.plugin.Duplicator; import net.imglib2.cache.img.CachedCellImg; import net.imglib2.img.display.imagej.ImageJFunctions; +import net.imglib2.img.display.imagej.ImageJVirtualStackFloat; import net.imglib2.type.numeric.real.DoubleType; import org.apache.http.conn.socket.ConnectionSocketFactory; import org.apache.http.conn.ssl.TrustSelfSignedStrategy; @@ -24,6 +27,7 @@ import org.janelia.saalfeldlab.n5.s3.N5AmazonS3Reader; import org.scijava.log.Logger; import org.vcell.N5.N5ImageHandler; +import org.vcell.N5.UI.RangeSelector; import org.vcell.N5.library.extensions.S3KeyValueAccess; import org.vcell.N5.library.extensions.SimCacheLoader; @@ -121,7 +125,8 @@ public boolean verify(String hostname, SSLSession session) { don't originate from amazon this is not a format we can possibly mimic, so we have to use path based buckets because it's the fallback style chosen by the N5 libraries if standard format is unavailable. */ - public ImagePlus getImgPlusFromN5File() throws IOException { + + public ImagePlus getImgPlusFromN5File() { // N5AmazonS3Reader n5AmazonS3Reader = new N5AmazonS3Reader(s3Client, bucketName, "/" + s3ObjectKey); long start = System.currentTimeMillis(); @@ -148,6 +153,17 @@ public ImagePlus getImgPlusFromN5File() throws IOException { return imagePlus; } + public ImagePlus openInMemory(RangeSelector rangeSelector){ + ImagePlus imagePlus = this.getImgPlusFromN5File(); + long start = System.currentTimeMillis(); + logger.debug("Loading Virtual N5 File " + userSetFileName + " Into Memory"); + imagePlus = new Duplicator().run(imagePlus, rangeSelector.startC, rangeSelector.endC, rangeSelector.startZ, + rangeSelector.endZ, rangeSelector.startT, rangeSelector.endT); + long end = System.currentTimeMillis(); + logger.debug("Loaded Virtual N5 File " + userSetFileName + " Into Memory taking: " + ((end - start)/ 1000) + "s"); + return imagePlus; + } + private void setUnits(N5Reader n5Reader, ImagePlus imagePlus){ try{ double pixelWidth = n5Reader.getAttribute(dataSetChosen, "pixelWidth", double.class);