Skip to content

Commit

Permalink
Functional GUI For Data Reduction
Browse files Browse the repository at this point in the history
You can now go through the entire process of data reduction through the GUI.
  • Loading branch information
AvocadoMoon committed Oct 24, 2024
1 parent 9d2d4b9 commit ce35f52
Show file tree
Hide file tree
Showing 9 changed files with 202 additions and 188 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,15 +155,17 @@ private void automaticRefresh(){
refreshTableThread.start();
}

public void openSelectedRows(boolean inMemory){
public void openSelectedRows(){
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);
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(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ public String getS3URL(){
@Override
public void actionPerformed(ActionEvent e) {
SimResultsLoader simResultsLoader = new SimResultsLoader(getS3URL(), "", -1, "");
N5ImageHandler.loadingManager.openN5FileDataset(new ArrayList<SimResultsLoader>(){{add(simResultsLoader);}}, false);
AdvancedFeatures advancedFeatures = MainPanel.controlButtonsPanel.advancedFeatures;
N5ImageHandler.loadingManager.openN5FileDataset(new ArrayList<SimResultsLoader>(){{add(simResultsLoader);}},
advancedFeatures.inMemory.isSelected(), advancedFeatures.rangeSelection.isSelected(),
advancedFeatures.dataReduction.isSelected());
this.setVisible(false);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,10 @@ public class DataReduction implements SimLoadingListener {

private final ArrayList<ArrayList<String>> 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).
Expand All @@ -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<Roi> arrayOfSimRois, ArrayList<Roi> 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<String> headers = new ArrayList<String>(){{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<String, ArrayList<Double>> reducedData = calculateMean(labResults, arrayOfLabRois);
HashMap<String, ArrayList<Double>> 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<String> rowForTime = new ArrayList<>();
rowForTime.add(String.valueOf(t));
csvMatrix.add(rowForTime);
}

}
addValuesToCSVMatrix(labResults, reducedData);
addValuesToCSVMatrix(submission.labResults, reducedData);

}

private void addValuesToCSVMatrix(ImagePlus imagePlus, HashMap<String, ArrayList<Double>> 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<String, ArrayList<Double>> calculateMean(ImagePlus imagePlus, ArrayList<Roi> roiList){
private HashMap<String, ArrayList<Double>> calculateMean(ImagePlus imagePlus, ArrayList<Roi> roiList,
double normalizationValue){
// ResultsTable resultsTable = new ResultsTable();

HashMap<String,ArrayList<Double>> roiListOfMeans = new HashMap<>();
Expand All @@ -116,11 +118,8 @@ private HashMap<String, ArrayList<Double>> 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);
}
Expand All @@ -135,6 +134,7 @@ private void writeCSVMatrix(){
for (ArrayList<String> row: csvMatrix){
csvWriter.writeNext(row.toArray(new String[0]));
}
csvWriter.close();
} catch (IOException e) {
throw new RuntimeException(e);
}
Expand All @@ -148,8 +148,8 @@ public void simIsLoading(int itemRow, String exportID) {

@Override
public void simFinishedLoading(int itemRow, String exportID, ImagePlus imagePlus) {

HashMap<String, ArrayList<Double>> calculations = calculateMean(imagePlus, arrayOfSimRois);
double normValue = calculateNormalValue(imagePlus, submission.simStartPointNorm, submission.simEndPointNorm);
HashMap<String, ArrayList<Double>> calculations = calculateMean(imagePlus, arrayOfSimRois, normValue);
addValuesToCSVMatrix(imagePlus, calculations);
}
}
Expand Down
Loading

0 comments on commit ce35f52

Please sign in to comment.