From 62bbb617226d5bb1f06a4ebc0ef389192a588ab7 Mon Sep 17 00:00:00 2001 From: Ezequiel Valencia Date: Mon, 18 Nov 2024 13:00:51 -0500 Subject: [PATCH] Refactor Data Reduction Manager into It's Own Class --- .../N5/reduction/DataReductionManager.java | 200 +++++++++++++ .../N5/reduction/DataReductionWriter.java | 278 +++--------------- .../N5/reduction/ReductionCalculations.java | 7 +- .../vcell/N5/retrieving/LoadingManager.java | 5 +- .../reduction/ReductionCalculationsTest.java | 5 +- 5 files changed, 255 insertions(+), 240 deletions(-) create mode 100644 view-simulation-results/src/main/java/org/vcell/N5/reduction/DataReductionManager.java diff --git a/view-simulation-results/src/main/java/org/vcell/N5/reduction/DataReductionManager.java b/view-simulation-results/src/main/java/org/vcell/N5/reduction/DataReductionManager.java new file mode 100644 index 0000000..70385e6 --- /dev/null +++ b/view-simulation-results/src/main/java/org/vcell/N5/reduction/DataReductionManager.java @@ -0,0 +1,200 @@ +package org.vcell.N5.reduction; + +import com.google.gson.internal.LinkedTreeMap; +import ij.ImagePlus; +import ij.WindowManager; +import ij.gui.Roi; +import org.vcell.N5.N5ImageHandler; +import org.vcell.N5.UI.ControlButtonsPanel; +import org.vcell.N5.UI.MainPanel; +import org.vcell.N5.reduction.DTO.RangeOfImage; +import org.vcell.N5.retrieving.SimLoadingListener; +import org.vcell.N5.retrieving.SimResultsLoader; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.atomic.AtomicBoolean; + +public class DataReductionManager implements SimLoadingListener { + private final ArrayList arrayOfSimRois; + private final Object csvMatrixLock = new Object(); + + private int numOfCalculationsTimesNumImages; + private final ReductionCalculations calculations; + + public final DataReductionGUI.DataReductionSubmission submission; + + private final ConcurrentHashMap threadPool = new ConcurrentHashMap<>(); + private final Object threadPoolLock = new Object(); + + private DataReductionWriter dataReductionWriter; + + + // Per Image + public static class ReducedData{ + public final double[][] data; + public final ArrayList columnHeaders; + public final SelectMeasurements.AvailableMeasurements measurementType; + public final RangeOfImage rangeOfImage; + public final int colLen; + public ReducedData(RangeOfImage rangeOfImage, int colLen, SelectMeasurements.AvailableMeasurements measurementType){ + int nFrames = rangeOfImage.timeEnd - rangeOfImage.timeStart + 1; + int nSlices = rangeOfImage.zEnd - rangeOfImage.zStart + 1; + data = new double[nFrames * nSlices][colLen]; // row - col + columnHeaders = new ArrayList<>(); + this.measurementType = measurementType; + this.colLen = colLen; + this.rangeOfImage = rangeOfImage; + } + } + + public DataReductionManager(DataReductionGUI.DataReductionSubmission submission){ + N5ImageHandler.loadingManager.addSimLoadingListener(this); + this.submission = submission; + + this.arrayOfSimRois = submission.arrayOfSimRois; + this.numOfCalculationsTimesNumImages = (submission.numOfSimImages + 1) * submission.selectedMeasurements.size(); // Plus one for the lab image + this.calculations = new ReductionCalculations(submission.normalizeMeasurementsBool); + + Thread processLabResults = new Thread(() -> { + calculateAndAddResults(submission.labResults, submission.experiementNormRange, submission.experimentImageRange, + submission.arrayOfLabRois, null, "Lab"); + synchronized (threadPoolLock){ + threadPool.remove("Lab"); + } + }, "Processing Lab Image"); + ThreadStruct threadStruct = new ThreadStruct(submission.labResults, new AtomicBoolean(true), processLabResults); + synchronized (threadPoolLock){ + threadPool.put("Lab", threadStruct); + } + } + + //////////////////////// + // General Functions // + ////////////////////// + + private void calculateAndAddResults(ImagePlus imagePlus, RangeOfImage normRange, + RangeOfImage imageRange, ArrayList rois, + LinkedTreeMap> channelInfo, + String threadName){ + HashMap normValue = null; + if (submission.normalizeMeasurementsBool){ + normValue = calculations.calculateNormalValue(imagePlus, normRange, rois, imageRange); + } + + int nChannels = imageRange.channelEnd - imageRange.channelStart + 1; + + ArrayList reducedDataArrayList = new ArrayList<>(); + for (SelectMeasurements.AvailableMeasurements measurement : submission.selectedMeasurements){ + ReducedData reducedData = new ReducedData(imageRange, nChannels * arrayOfSimRois.size(), measurement); + reducedDataArrayList.add(reducedData); + calculations.addAppropriateHeaders(imagePlus, rois, imageRange, reducedData, channelInfo); + } + AtomicBoolean continueOperation = threadPool.get(threadName).continueOperation; + calculations.calculateStatistics(imagePlus, rois, normValue, reducedDataArrayList, imageRange, continueOperation); + for (ReducedData reducedData: reducedDataArrayList){ + if (continueOperation.get()){ + synchronized (csvMatrixLock){ + dataReductionWriter.addValuesToWideCSVMatrix(reducedData); + numOfCalculationsTimesNumImages -= 1; + } + } + } + if (numOfCalculationsTimesNumImages == 0){ + try{ + dataReductionWriter.writeCSVMatrix(); + } catch (IOException ioException){ + throw new RuntimeException(ioException); + } finally { + N5ImageHandler.loadingManager.removeFromSimLoadingListener(this); + MainPanel.controlButtonsPanel.updateButtonsToMatchState(false, ControlButtonsPanel.PanelState.NOTHING_OR_LOADING_IMAGE); + } + } + } + + public void stopAllThreads(){ + synchronized (threadPoolLock){ + for (String threadName: threadPool.keySet()){ + ThreadStruct threadStruct = threadPool.get(threadName); + threadStruct.continueOperation.set(false); + // Experiment image is in thread pool, so trying to retrieve a results loader for it would not work + if (threadStruct.simResultsLoader != null){ + SimResultsLoader loadedResults = threadStruct.simResultsLoader; + MainPanel.n5ExportTable.removeSpecificRowFromLoadingRows(loadedResults.rowNumber); + ImagePlus openImage = WindowManager.getImage(loadedResults.getImagePlus().getID()); + if (openImage != null){ + openImage.close(); + } + } + threadPool.remove(threadName); + } + } + N5ImageHandler.loadingManager.removeFromSimLoadingListener(this); + MainPanel.controlButtonsPanel.updateButtonsToMatchState(false, ControlButtonsPanel.PanelState.NOTHING_OR_LOADING_IMAGE); + } + + + @Override + public void simIsLoading(int itemRow, String exportID) { + + } + + @Override + public void simFinishedLoading(SimResultsLoader loadedResults) { + if (loadedResults.openTag == SimResultsLoader.OpenTag.DATA_REDUCTION){ + Thread imageProcessingThread = new Thread(() -> { + ImagePlus imagePlus = loadedResults.getImagePlus(); + imagePlus.show(); + dataReductionWriter.addMetaData(loadedResults); + calculateAndAddResults(imagePlus, submission.simNormRange, submission.simImageRange, + submission.arrayOfSimRois, loadedResults.getChannelInfo(), loadedResults.exportID); + MainPanel.n5ExportTable.removeSpecificRowFromLoadingRows(loadedResults.rowNumber); + imagePlus.close(); + synchronized (threadPoolLock){ + threadPool.remove(loadedResults.exportID); + } + }, "Processing Image: " + loadedResults.userSetFileName); + ThreadStruct threadStruct = new ThreadStruct(loadedResults, new AtomicBoolean(true), imageProcessingThread); + synchronized (threadPoolLock){ + threadPool.put(loadedResults.exportID, threadStruct); + if (threadPool.size() == (submission.numOfSimImages + 1)){ + int maxZ = 0; + int maxT = 0; + for (String threadName : threadPool.keySet()){ + int curZ = threadPool.get(threadName).imagePlus.getNSlices(); + int curT = threadPool.get(threadName).imagePlus.getNFrames(); + maxZ = Math.max(curZ, maxZ); + maxT = Math.max(curT, maxT); + } + dataReductionWriter = new DataReductionWriter(submission, maxT, maxZ); + dataReductionWriter.initializeDataSheets(); + for (String threadName : threadPool.keySet()){ + threadPool.get(threadName).thread.start(); + } + } + } + } + } + + static class ThreadStruct { + public final SimResultsLoader simResultsLoader; + public final ImagePlus imagePlus; + public final AtomicBoolean continueOperation; + public final Thread thread; + public ThreadStruct(SimResultsLoader simResultsLoader, AtomicBoolean continueOperation, Thread thread){ + this.simResultsLoader = simResultsLoader; + this.continueOperation = continueOperation; + this.thread = thread; + this.imagePlus = simResultsLoader.getImagePlus(); + } + + public ThreadStruct(ImagePlus imagePlus, AtomicBoolean continueOperation, Thread thread){ + this.imagePlus = imagePlus; + this.simResultsLoader = null; + this.continueOperation = continueOperation; + this.thread = thread; + } + } +} diff --git a/view-simulation-results/src/main/java/org/vcell/N5/reduction/DataReductionWriter.java b/view-simulation-results/src/main/java/org/vcell/N5/reduction/DataReductionWriter.java index 4279b5c..1d92edb 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/reduction/DataReductionWriter.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/reduction/DataReductionWriter.java @@ -1,17 +1,11 @@ package org.vcell.N5.reduction; -import com.google.gson.internal.LinkedTreeMap; import com.opencsv.CSVWriter; -import ij.ImagePlus; -import ij.WindowManager; -import ij.gui.Roi; import org.vcell.N5.ExportDataRepresentation; -import org.vcell.N5.N5ImageHandler; -import org.vcell.N5.UI.ControlButtonsPanel; import org.vcell.N5.UI.MainPanel; import org.vcell.N5.UI.N5ExportTable; import org.vcell.N5.reduction.DTO.RangeOfImage; -import org.vcell.N5.retrieving.SimLoadingListener; +import org.vcell.N5.reduction.DataReductionManager.ReducedData; import org.vcell.N5.retrieving.SimResultsLoader; import java.io.File; @@ -19,27 +13,17 @@ import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.atomic.AtomicBoolean; -public class DataReductionWriter implements SimLoadingListener { - private final ArrayList arrayOfSimRois; - - private final Object csvMatrixLock = new Object(); +public class DataReductionWriter{ private final Object metaDataLock = new Object(); private final File file; - private int numOfCalculationsTimesNumImages; - private final ReductionCalculations calculations; - public final DataReductionGUI.DataReductionSubmission submission; private final ArrayList> averageMatrix = new ArrayList<>(); private final ArrayList> standardDivMatrix = new ArrayList<>(); private final ArrayList> metaDataSheet = new ArrayList<>(); - private final ConcurrentHashMap threadPool = new ConcurrentHashMap<>(); - private final Object threadPoolLock = new Object(); private final HashMap>> sheetsAvailable = new HashMap>>(){{ put(SelectMeasurements.AvailableMeasurements.AVERAGE, averageMatrix); @@ -52,57 +36,22 @@ public class DataReductionWriter implements SimLoadingListener { private final ArrayList selectedMeasurements; - private int maxZ; - private int maxT; - - // Per Image - static class ReducedData{ - public final double[][] data; - public final ArrayList columnHeaders; - public final SelectMeasurements.AvailableMeasurements measurementType; - public final RangeOfImage rangeOfImage; - public final int colLen; - public ReducedData(RangeOfImage rangeOfImage, int colLen, SelectMeasurements.AvailableMeasurements measurementType){ - int nFrames = rangeOfImage.timeEnd - rangeOfImage.timeStart + 1; - int nSlices = rangeOfImage.zEnd - rangeOfImage.zStart + 1; - data = new double[nFrames * nSlices][colLen]; // row - col - columnHeaders = new ArrayList<>(); - this.measurementType = measurementType; - this.colLen = colLen; - this.rangeOfImage = rangeOfImage; - } - } + private final int maxZ; + private final int maxT; /////////////////////////////////////// // Initialize Sheet and Lab results // ///////////////////////////////////// - public DataReductionWriter(DataReductionGUI.DataReductionSubmission submission){ - N5ImageHandler.loadingManager.addSimLoadingListener(this); + public DataReductionWriter(DataReductionGUI.DataReductionSubmission submission, int maxT, int maxZ){ this.submission = submission; this.selectedMeasurements = submission.selectedMeasurements; - - this.arrayOfSimRois = submission.arrayOfSimRois; - this.numOfCalculationsTimesNumImages = (submission.numOfSimImages + 1) * submission.selectedMeasurements.size(); // Plus one for the lab image this.file = submission.fileToSaveResultsTo; - this.calculations = new ReductionCalculations(submission.normalizeMeasurementsBool); - - - - Thread processLabResults = new Thread(() -> { - calculateAndAddResults(submission.labResults, submission.experiementNormRange, submission.experimentImageRange, - submission.arrayOfLabRois, null, "Lab"); - synchronized (threadPoolLock){ - threadPool.remove("Lab"); - } - }, "Processing Lab Image"); - ThreadStruct threadStruct = new ThreadStruct(submission.labResults, new AtomicBoolean(true), processLabResults); - synchronized (threadPoolLock){ - threadPool.put("Lab", threadStruct); - } + this.maxZ = maxZ; + this.maxT = maxT; } - private void initializeDataSheets(){ + public void initializeDataSheets(){ ArrayList headers = new ArrayList(){{add("Time Frame");}}; boolean is3D = maxZ > 1; if (is3D){ @@ -149,69 +98,37 @@ private void initializeDataSheets(){ // General Functions // ////////////////////// - private void calculateAndAddResults(ImagePlus imagePlus, RangeOfImage normRange, - RangeOfImage imageRange, ArrayList rois, - LinkedTreeMap> channelInfo, - String threadName){ - HashMap normValue = null; - if (submission.normalizeMeasurementsBool){ - normValue = calculations.calculateNormalValue(imagePlus, normRange, rois, imageRange); - } - - int nChannels = imageRange.channelEnd - imageRange.channelStart + 1; - - ArrayList reducedDataArrayList = new ArrayList<>(); - for (SelectMeasurements.AvailableMeasurements measurement : submission.selectedMeasurements){ - ReducedData reducedData = new ReducedData(imageRange, nChannels * arrayOfSimRois.size(), measurement); - reducedDataArrayList.add(reducedData); - calculations.addAppropriateHeaders(imagePlus, rois, imageRange, reducedData, channelInfo); - } - AtomicBoolean continueOperation = threadPool.get(threadName).continueOperation; - calculations.calculateStatistics(imagePlus, rois, normValue, reducedDataArrayList, imageRange, continueOperation); - for (ReducedData reducedData: reducedDataArrayList){ - if (continueOperation.get()){ - addValuesToWideCSVMatrix(reducedData); - } - } - } - - private void addValuesToWideCSVMatrix(ReducedData reducedData){ - synchronized (csvMatrixLock){ - ArrayList> dataSheet = sheetsAvailable.get(reducedData.measurementType); - int colIndex = columnsForSheets.get(reducedData.measurementType); - fillWithEmptySpace(dataSheet.get(0), colIndex); - for (int c = 0; c < reducedData.columnHeaders.size(); c++){ - dataSheet.get(0).add(colIndex, reducedData.columnHeaders.get(c)); - } - RangeOfImage rangeOfImage = reducedData.rangeOfImage; - int tzCounter = 1; - for (int t = 1; t <= maxT; t++){ - for (int z = 1; z <= maxZ; z++){ - boolean inBetweenTime = t <= rangeOfImage.timeEnd && rangeOfImage.timeStart <= t; - boolean inBetweenZ = z <= rangeOfImage.zEnd && rangeOfImage.zStart <= z; - ArrayList row = dataSheet.get(tzCounter); - fillWithEmptySpace(row, colIndex); - for (int c = 0; c < reducedData.colLen; c++){ - if (inBetweenTime && inBetweenZ){ - int dataRow = ((t - rangeOfImage.timeStart) * (z - rangeOfImage.zStart)) + (z - rangeOfImage.zStart); - double mean = reducedData.data[dataRow][c]; - row.add(String.valueOf(mean)); - } + public void addValuesToWideCSVMatrix(ReducedData reducedData){ + ArrayList> dataSheet = sheetsAvailable.get(reducedData.measurementType); + int colIndex = columnsForSheets.get(reducedData.measurementType); + fillWithEmptySpace(dataSheet.get(0), colIndex); + for (int c = 0; c < reducedData.columnHeaders.size(); c++){ + dataSheet.get(0).add(colIndex, reducedData.columnHeaders.get(c)); + } + RangeOfImage rangeOfImage = reducedData.rangeOfImage; + int tzCounter = 1; + for (int t = 1; t <= maxT; t++){ + for (int z = 1; z <= maxZ; z++){ + boolean inBetweenTime = t <= rangeOfImage.timeEnd && rangeOfImage.timeStart <= t; + boolean inBetweenZ = z <= rangeOfImage.zEnd && rangeOfImage.zStart <= z; + ArrayList row = dataSheet.get(tzCounter); + fillWithEmptySpace(row, colIndex); + for (int c = 0; c < reducedData.colLen; c++){ + if (inBetweenTime && inBetweenZ){ + int dataRow = ((t - rangeOfImage.timeStart) * (z - rangeOfImage.zStart)) + (z - rangeOfImage.zStart); + double mean = reducedData.data[dataRow][c]; + row.add(String.valueOf(mean)); } - tzCounter += 1; } - } - numOfCalculationsTimesNumImages -= 1; - colIndex += 1 + reducedData.data[0].length; - columnsForSheets.replace(reducedData.measurementType, colIndex); - if (numOfCalculationsTimesNumImages == 0){ - writeCSVMatrix(); + tzCounter += 1; } } + colIndex += 1 + reducedData.data[0].length; + columnsForSheets.replace(reducedData.measurementType, colIndex); } // If parameter is not in list of parameters, add new column. If simulation does not have parameter say "not-present" - private void addMetaData(SimResultsLoader loadedResults){ + public void addMetaData(SimResultsLoader loadedResults){ synchronized (metaDataLock){ N5ExportTable n5ExportTable = MainPanel.n5ExportTable; ExportDataRepresentation.SimulationExportDataRepresentation data = n5ExportTable.n5ExportTableModel.getRowData(loadedResults.rowNumber); @@ -248,132 +165,27 @@ private void fillWithEmptySpace(ArrayList arrayList, int col){ } } -// // Z changes the fastest -// private ArrayList> fillWithEmptySpace(ReducedData reducedData){ -// int t = 1; -// int z = 1; -// ArrayList> paddedInfo = new ArrayList<>(); -// while (reducedData.numFrames != t){ -// while (reducedData.numSlices != z){ -// -// } -// t += 1; -// } -// } - - private void writeCSVMatrix(){ - try { - for (SelectMeasurements.AvailableMeasurements measurements : sheetsAvailable.keySet()){ - if (!sheetsAvailable.get(measurements).isEmpty()){ - File currentFile = new File(file.getAbsolutePath() + "-" + measurements.publicName + ".csv"); - try (FileWriter fileWriter = new FileWriter(currentFile)){ - CSVWriter csvWriter = new CSVWriter(fileWriter); - for (ArrayList row : sheetsAvailable.get(measurements)){ - csvWriter.writeNext(row.toArray(new String[0])); - } + public void writeCSVMatrix() throws IOException { + for (SelectMeasurements.AvailableMeasurements measurements : sheetsAvailable.keySet()){ + if (!sheetsAvailable.get(measurements).isEmpty()){ + File currentFile = new File(file.getAbsolutePath() + "-" + measurements.publicName + ".csv"); + try (FileWriter fileWriter = new FileWriter(currentFile)){ + CSVWriter csvWriter = new CSVWriter(fileWriter); + for (ArrayList row : sheetsAvailable.get(measurements)){ + csvWriter.writeNext(row.toArray(new String[0])); } } } - File currentFile = new File(file.getAbsolutePath() + "-Metadata.csv"); - try (FileWriter fileWriter = new FileWriter(currentFile)){ - CSVWriter csvWriter = new CSVWriter(fileWriter); - for (ArrayList row : metaDataSheet){ - csvWriter.writeNext(row.toArray(new String[0])); - } - } - - } catch (IOException e) { - throw new RuntimeException(e); - } finally { - N5ImageHandler.loadingManager.removeFromSimLoadingListener(this); - MainPanel.controlButtonsPanel.updateButtonsToMatchState(false, ControlButtonsPanel.PanelState.NOTHING_OR_LOADING_IMAGE); - } - } - - public void stopAllThreads(){ - synchronized (threadPoolLock){ - for (String threadName: threadPool.keySet()){ - ThreadStruct threadStruct = threadPool.get(threadName); - threadStruct.continueOperation.set(false); - // Experiment image is in thread pool, so trying to retrieve a results loader for it would not work - if (threadStruct.simResultsLoader != null){ - SimResultsLoader loadedResults = threadStruct.simResultsLoader; - MainPanel.n5ExportTable.removeSpecificRowFromLoadingRows(loadedResults.rowNumber); - ImagePlus openImage = WindowManager.getImage(loadedResults.getImagePlus().getID()); - if (openImage != null){ - openImage.close(); - } - } - threadPool.remove(threadName); - } } - N5ImageHandler.loadingManager.removeFromSimLoadingListener(this); - MainPanel.controlButtonsPanel.updateButtonsToMatchState(false, ControlButtonsPanel.PanelState.NOTHING_OR_LOADING_IMAGE); - } - - - @Override - public void simIsLoading(int itemRow, String exportID) { - - } - - @Override - public void simFinishedLoading(SimResultsLoader loadedResults) { - 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(), loadedResults.exportID); - MainPanel.n5ExportTable.removeSpecificRowFromLoadingRows(loadedResults.rowNumber); - imagePlus.close(); - synchronized (threadPoolLock){ - threadPool.remove(loadedResults.exportID); - } - }, "Processing Image: " + loadedResults.userSetFileName); - ThreadStruct threadStruct = new ThreadStruct(loadedResults, new AtomicBoolean(true), imageProcessingThread); - synchronized (threadPoolLock){ - threadPool.put(loadedResults.exportID, threadStruct); - if (threadPool.size() == (submission.numOfSimImages + 1)){ - maxZ = 0; - maxT = 0; - for (String threadName : threadPool.keySet()){ - int curZ = threadPool.get(threadName).imagePlus.getNSlices(); - int curT = threadPool.get(threadName).imagePlus.getNFrames(); - maxZ = Math.max(curZ, maxZ); - maxT = Math.max(curT, maxT); - } - initializeDataSheets(); - for (String threadName : threadPool.keySet()){ - threadPool.get(threadName).thread.start(); - } - } + File currentFile = new File(file.getAbsolutePath() + "-Metadata.csv"); + try (FileWriter fileWriter = new FileWriter(currentFile)){ + CSVWriter csvWriter = new CSVWriter(fileWriter); + for (ArrayList row : metaDataSheet){ + csvWriter.writeNext(row.toArray(new String[0])); } } } - - static class ThreadStruct { - public final SimResultsLoader simResultsLoader; - public final ImagePlus imagePlus; - public final AtomicBoolean continueOperation; - public final Thread thread; - public ThreadStruct(SimResultsLoader simResultsLoader, AtomicBoolean continueOperation, Thread thread){ - this.simResultsLoader = simResultsLoader; - this.continueOperation = continueOperation; - this.thread = thread; - this.imagePlus = simResultsLoader.getImagePlus(); - } - - public ThreadStruct(ImagePlus imagePlus, AtomicBoolean continueOperation, Thread thread){ - this.imagePlus = imagePlus; - this.simResultsLoader = null; - this.continueOperation = continueOperation; - this.thread = thread; - } - } - } diff --git a/view-simulation-results/src/main/java/org/vcell/N5/reduction/ReductionCalculations.java b/view-simulation-results/src/main/java/org/vcell/N5/reduction/ReductionCalculations.java index dd6e57d..5b66008 100644 --- a/view-simulation-results/src/main/java/org/vcell/N5/reduction/ReductionCalculations.java +++ b/view-simulation-results/src/main/java/org/vcell/N5/reduction/ReductionCalculations.java @@ -4,6 +4,7 @@ import ij.ImagePlus; import ij.gui.Roi; import org.vcell.N5.reduction.DTO.RangeOfImage; +import org.vcell.N5.reduction.DataReductionManager.ReducedData; import java.util.ArrayList; import java.util.HashMap; @@ -17,7 +18,7 @@ public ReductionCalculations(boolean normalize){ } public void addAppropriateHeaders(ImagePlus imagePlus, ArrayList roiList, RangeOfImage rangeOfImage, - DataReductionWriter.ReducedData reducedData, + ReducedData reducedData, LinkedTreeMap> channelInfo){ for (Roi roi: roiList){ for (int c = rangeOfImage.channelStart; c <= rangeOfImage.channelEnd; c++){ //Last channel is domain channel, not variable @@ -39,7 +40,7 @@ public void addAppropriateHeaders(ImagePlus imagePlus, ArrayList roiList, R */ void calculateStatistics(ImagePlus imagePlus, ArrayList roiList, HashMap normalizationValue, - ArrayList reducedDataArrayList, + ArrayList reducedDataArrayList, RangeOfImage rangeOfImage, AtomicBoolean continueOperation){ int roiCounter = 0; for (Roi roi: roiList) { @@ -54,7 +55,7 @@ void calculateStatistics(ImagePlus imagePlus, ArrayList roiList, } imagePlus.setPosition(c, z, t); double calculatedValue; - for (DataReductionWriter.ReducedData reducedData : reducedDataArrayList){ + for (ReducedData reducedData : reducedDataArrayList){ switch (reducedData.measurementType){ case AVERAGE: calculatedValue = imagePlus.getStatistics().mean; 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 52ec335..6ee6990 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 @@ -8,6 +8,7 @@ import org.vcell.N5.UI.RangeSelector; import org.vcell.N5.UI.MainPanel; import org.vcell.N5.reduction.DataReductionGUI; +import org.vcell.N5.reduction.DataReductionManager; import org.vcell.N5.reduction.DataReductionWriter; import javax.swing.*; @@ -25,7 +26,7 @@ public class LoadingManager implements SimLoadingEventCreator { private final HashMap openingSimulations = new HashMap<>(); private final Object openSimulationsLock = new Object(); - private DataReductionWriter dataReductionWriter = null; + private DataReductionManager dataReductionWriter = null; private static final Logger logger = N5ImageHandler.getLogger(RangeSelector.class); @@ -38,7 +39,7 @@ public void openN5FileDataset(ArrayList filesToOpen, boolean o ArrayList dimensions = firstSim.getN5Dimensions(); if (dataReduction){ dataReductionGUI = new DataReductionGUI(filesToOpen, dimensions.get(2), dimensions.get(3), dimensions.get(4)); - dataReductionWriter = dataReductionGUI.shouldContinueWithProcess() ? new DataReductionWriter(dataReductionGUI.createSubmission()) : null; + dataReductionWriter = dataReductionGUI.shouldContinueWithProcess() ? new DataReductionManager(dataReductionGUI.createSubmission()) : null; } else { rangeSelector.displayRangeMenu(dimensions.get(2), dimensions.get(3), dimensions.get(4)); } diff --git a/view-simulation-results/src/test/java/org/vcell/N5/reduction/ReductionCalculationsTest.java b/view-simulation-results/src/test/java/org/vcell/N5/reduction/ReductionCalculationsTest.java index 68c4fbf..6c1ff2f 100644 --- a/view-simulation-results/src/test/java/org/vcell/N5/reduction/ReductionCalculationsTest.java +++ b/view-simulation-results/src/test/java/org/vcell/N5/reduction/ReductionCalculationsTest.java @@ -11,6 +11,7 @@ import org.vcell.N5.reduction.DTO.RangeOfImage; import org.vcell.N5.retrieving.LoadingManager; import org.vcell.N5.retrieving.SimResultsLoader; +import org.vcell.N5.reduction.DataReductionManager.ReducedData; import java.io.File; import java.net.URISyntaxException; @@ -51,8 +52,8 @@ private void compareExpectedCalculations(ImagePlus imagePlus, ArrayList roi RangeOfImage entireRange = new RangeOfImage(1, imagePlus.getNFrames(), 1, imagePlus.getNSlices(), 1, imagePlus.getNChannels()); RangeOfImage normRange = new RangeOfImage(1, 1); - DataReductionWriter.ReducedData reducedData = new DataReductionWriter.ReducedData(entireRange, imagePlus.getNChannels() * roiList.size(), SelectMeasurements.AvailableMeasurements.AVERAGE); - ArrayList reducedDataArrayList = new ArrayList<>(); + ReducedData reducedData = new ReducedData(entireRange, imagePlus.getNChannels() * roiList.size(), SelectMeasurements.AvailableMeasurements.AVERAGE); + ArrayList reducedDataArrayList = new ArrayList<>(); reducedDataArrayList.add(reducedData); HashMap norms = reductionCalculations.calculateNormalValue(imagePlus, normRange, roiList, entireRange);