diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/AnalysisManagerController.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/AnalysisManagerController.java index d1b1e602..08a2c660 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/AnalysisManagerController.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/AnalysisManagerController.java @@ -31,7 +31,7 @@ import org.cirdles.tripoli.gui.dialogs.TripoliMessageDialog; import org.cirdles.tripoli.sessions.analysis.Analysis; import org.cirdles.tripoli.sessions.analysis.AnalysisInterface; -import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.AllBlockInitForOGTripoli; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.AllBlockInitForOGTripoli; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataSourceProcessors.MassSpecOutputSingleBlockRecord; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.detectorSetups.Detector; import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethod; diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/TripoliGUIController.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/TripoliGUIController.java index 7d11ebb2..555f1d91 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/TripoliGUIController.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/TripoliGUIController.java @@ -227,7 +227,7 @@ private void launchSessionManager() throws IOException, TripoliException { sessionManagerMenuItem.setDisable(false); saveSessionAsMenuItem.setDisable(false); closeSessionMenuItem.setDisable(false); - analysisMenu.setDisable(false); + analysisMenu.setDisable(true); } private void buildSessionMenuMRU() { diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/AbstractPlot.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/AbstractPlot.java index 305fd50d..713b958b 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/AbstractPlot.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/AbstractPlot.java @@ -355,17 +355,18 @@ private void drawAxes(GraphicsContext g2d) { public void showTitle(GraphicsContext g2d) { Paint savedPaint = g2d.getFill(); - Font titleFont = Font.font("Monospaced Bold", 12); + Font titleFont = Font.font("Courier Bold", 12); g2d.setFont(titleFont); g2d.setFill(Paint.valueOf("RED")); - g2d.fillText(plotTitle[0], leftMargin, 12); + double titleLeftX = 15; + g2d.fillText(plotTitle[0], titleLeftX, 12); if (2 == plotTitle.length) { Text textTitle1 = new Text(plotTitle[0].split("\\.")[0]); textTitle1.setFont(titleFont); Text textTitle2 = new Text(plotTitle[1].split("\\.")[0]); textTitle2.setFont(titleFont); double offset = textTitle1.getLayoutBounds().getWidth() - textTitle2.getLayoutBounds().getWidth(); - g2d.fillText(plotTitle[1], leftMargin + offset, 22); + g2d.fillText(plotTitle[1], titleLeftX + offset, 22); } g2d.setFill(savedPaint); } diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPane.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPane.java index 3021ab4f..ef99e67a 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPane.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPane.java @@ -47,7 +47,7 @@ public class PlotWallPane extends Pane implements PlotWallPaneInterface { private final String iD; private final boolean[] zoomFlagsXY = new boolean[2]; private final AnalysisInterface analysis; - private final MCMCPlotsControllerInterface mcmcPlotsControllerInterface; + private final MCMCPlotsControllerInterface mcmcPlotsController; AnalysisManagerCallbackI analysisManagerCallbackI; private double toolBarHeight; private int toolBarCount; @@ -55,12 +55,12 @@ public class PlotWallPane extends Pane implements PlotWallPaneInterface { private ConstantsTripoliApp.PlotLayoutStyle plotLayoutStyle; - private PlotWallPane(String iD, AnalysisInterface analysis, MCMCPlotsControllerInterface mcmcPlotsControllerInterface, AnalysisManagerCallbackI analysisManagerCallbackI) { + private PlotWallPane(String iD, AnalysisInterface analysis, MCMCPlotsControllerInterface mcmcPlotsController, AnalysisManagerCallbackI analysisManagerCallbackI) { this.iD = iD; zoomFlagsXY[0] = true; zoomFlagsXY[1] = true; this.analysis = analysis; - this.mcmcPlotsControllerInterface = mcmcPlotsControllerInterface; + this.mcmcPlotsController = mcmcPlotsController; this.analysisManagerCallbackI = analysisManagerCallbackI; plotLayoutStyle = ConstantsTripoliApp.PlotLayoutStyle.TILE; @@ -69,12 +69,12 @@ private PlotWallPane(String iD, AnalysisInterface analysis, MCMCPlotsControllerI public static PlotWallPaneInterface createPlotWallPane( String iD, AnalysisInterface analysis, - MCMCPlotsControllerInterface mcmcPlotsControllerInterface, + MCMCPlotsControllerInterface mcmcPlotsController, AnalysisManagerCallbackI analysisManagerCallbackI) { if (null == iD) { - return new PlotWallPane("NONE", analysis, mcmcPlotsControllerInterface, analysisManagerCallbackI); + return new PlotWallPane("NONE", analysis, mcmcPlotsController, analysisManagerCallbackI); } else { - return new PlotWallPane(iD, analysis, mcmcPlotsControllerInterface, analysisManagerCallbackI); + return new PlotWallPane(iD, analysis, mcmcPlotsController, analysisManagerCallbackI); } } @@ -223,12 +223,14 @@ public void toggleRatiosLogRatios() { } public void applyBurnIn() { - int burnIn = (int) analysis.getMapOfBlockIdToPlots().get(mcmcPlotsControllerInterface.getCurrentBlockID())[5][0].getShadeWidthForModelConvergence(); - int blockID = mcmcPlotsControllerInterface.getCurrentBlockID(); + int burnIn = (int) analysis.getMapOfBlockIdToPlots().get(mcmcPlotsController.getCurrentBlockID())[5][0].getShadeWidthForModelConvergence(); + int blockID = mcmcPlotsController.getCurrentBlockID(); analysis.getMapOfBlockIdToModelsBurnCount().put(blockID, burnIn); + blockEnsemblePlotEngine(blockID, analysis); - mcmcPlotsControllerInterface.plotEnsemblesEngine(analysis.getMapOfBlockIdToPlots().get(blockID)); - mcmcPlotsControllerInterface.plotRatioSessionEngine(); + mcmcPlotsController.plotEnsemblesEngine(analysis.getMapOfBlockIdToPlots().get(blockID)); + ((Analysis) analysis).analysisRatioEngine(); + mcmcPlotsController.plotAnalysisRatioEngine(); EnsemblesStore.produceSummaryModelFromEnsembleStore(blockID, analysis); // fire up OGTripoli style analysis plots @@ -238,18 +240,20 @@ public void applyBurnIn() { } public void applyBurnInAllBlocks() { - int burnIn = (int) analysis.getMapOfBlockIdToPlots().get(mcmcPlotsControllerInterface.getCurrentBlockID())[5][0].getShadeWidthForModelConvergence(); + int burnIn = (int) analysis.getMapOfBlockIdToPlots().get(mcmcPlotsController.getCurrentBlockID())[5][0].getShadeWidthForModelConvergence(); int blockIDCount = analysis.getMapOfBlockIdToPlots().keySet().size() + 1; + for (int blockID = 1; blockID < blockIDCount; blockID++) { ((Analysis) analysis).updateShadeWidthsForConvergenceLinePlots(blockID, burnIn); analysis.getMapOfBlockIdToModelsBurnCount().put(blockID, burnIn); blockEnsemblePlotEngine(blockID, analysis); - mcmcPlotsControllerInterface.plotEnsemblesEngine(analysis.getMapOfBlockIdToPlots().get(blockID)); -// mcmcPlotsControllerInterface.plotRatioSessionEngine(); + mcmcPlotsController.plotEnsemblesEngine(analysis.getMapOfBlockIdToPlots().get(blockID)); +// mcmcPlotsController.analysisRatioEngine(); EnsemblesStore.produceSummaryModelFromEnsembleStore(blockID, analysis); } - mcmcPlotsControllerInterface.plotRatioSessionEngine(); + ((Analysis) analysis).analysisRatioEngine(); + mcmcPlotsController.plotAnalysisRatioEngine(); // fire up OGTripoli style analysis plots if (null != analysisManagerCallbackI) { diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPaneInterface.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPaneInterface.java index cdffb401..3dd21acb 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPaneInterface.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPaneInterface.java @@ -15,4 +15,8 @@ public interface PlotWallPaneInterface { public void stackPlots(); + public void tilePlots(); + + public void toggleShowStatsAllPlots(); + } \ No newline at end of file diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPaneOGTripoli.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPaneOGTripoli.java index 5dc58e30..4f5688e4 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPaneOGTripoli.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/PlotWallPaneOGTripoli.java @@ -101,6 +101,22 @@ public void stackPlots() { } } + /** + * + */ + @Override + public void tilePlots() { + // not applicable + } + + /** + * + */ + @Override + public void toggleShowStatsAllPlots() { + // not used + } + public void buildOGTripoliToolBar(List species) { ToolBar toolBar = new ToolBar(); toolBar.setPrefHeight(toolBarHeight); diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/TripoliPlotPane.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/TripoliPlotPane.java index 0ae79763..901f897a 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/TripoliPlotPane.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/TripoliPlotPane.java @@ -27,6 +27,7 @@ import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.ogTripoliPlots.analysisPlots.BlockRatioCyclesAnalysisPlot; import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.ogTripoliPlots.analysisPlots.SpeciesIntensityAnalysisPlot; import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.tripoliPlots.RatioHistogramPlot; +import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.tripoliPlots.analysisPlots.AnalysisRatioPlot; import org.cirdles.tripoli.gui.utilities.TripoliColor; import static org.cirdles.tripoli.gui.dataViews.plots.PlotWallPane.gridCellDim; @@ -253,8 +254,13 @@ public void toggleShowStats() { public void toggleRatiosLogRatios() { if (!getChildren().isEmpty() && (getChildren().get(0) instanceof RatioHistogramPlot)) { ((RatioHistogramPlot) getChildren().get(0)).toggleRatiosLogRatios(); - ((RatioHistogramPlot) getChildren().get(0)).repaint(); +// ((RatioHistogramPlot) getChildren().get(0)).repaint(); } + if (!getChildren().isEmpty() && (getChildren().get(0) instanceof AnalysisRatioPlot)) { + ((AnalysisRatioPlot) getChildren().get(0)).toggleRatiosLogRatios(); +// ((AnalysisRatioPlot) getChildren().get(0)).repaint(); + } + } public void restorePlot() { diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotBuildersTask.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotBuildersTask.java index 8bd07bd5..06f3742d 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotBuildersTask.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotBuildersTask.java @@ -26,7 +26,7 @@ /** * @author James F. Bowring */ -public class MCMCPlotBuildersTask extends Task implements LoggingCallbackInterface, PlotBuildersTaskInterface { +public class MCMCPlotBuildersTask extends Task implements LoggingCallbackInterface, MCMCPlotBuildersTaskInterface { public static AnalysisInterface analysis; private final int blockID; // plotBuilders diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/PlotBuildersTaskInterface.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotBuildersTaskInterface.java similarity index 95% rename from TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/PlotBuildersTaskInterface.java rename to TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotBuildersTaskInterface.java index cc9ff1b6..e7946160 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/PlotBuildersTaskInterface.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotBuildersTaskInterface.java @@ -2,7 +2,7 @@ import org.cirdles.tripoli.plots.PlotBuilder; -public interface PlotBuildersTaskInterface { +public interface MCMCPlotBuildersTaskInterface { boolean healthyPlotbuilder(); PlotBuilder[] getPeakShapesBuilder(); diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotsController.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotsController.java index 8cc544cf..30b33ef8 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotsController.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotsController.java @@ -23,17 +23,18 @@ import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.ogTripoliPlots.OGTripoliPlotsWindow; import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.ogTripoliPlots.OGTripoliViewController; import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.tripoliPlots.*; -import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.tripoliPlots.analysisPlots.HistogramAnalysisPlot; +import org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.tripoliPlots.analysisPlots.AnalysisRatioPlot; import org.cirdles.tripoli.plots.PlotBuilder; -import org.cirdles.tripoli.plots.analysisPlotBuilders.HistogramAnalysisBuilder; +import org.cirdles.tripoli.plots.analysisPlotBuilders.AnalysisRatioRecord; import org.cirdles.tripoli.plots.analysisPlotBuilders.PeakCentreAnalysisBuilder; import org.cirdles.tripoli.plots.histograms.HistogramBuilder; import org.cirdles.tripoli.plots.histograms.HistogramRecord; import org.cirdles.tripoli.plots.histograms.RatioHistogramBuilder; import org.cirdles.tripoli.plots.linePlots.*; +import org.cirdles.tripoli.sessions.analysis.Analysis; import org.cirdles.tripoli.sessions.analysis.AnalysisInterface; -import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.AllBlockInitForOGTripoli; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.MCMCProcess; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.AllBlockInitForOGTripoli; import org.cirdles.tripoli.species.IsotopicRatio; import org.cirdles.tripoli.utilities.IntuitiveStringComparator; @@ -45,7 +46,6 @@ import static org.cirdles.tripoli.gui.dataViews.plots.TripoliPlotPane.minPlotWidth; import static org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.mcmcPlots.MCMCPlotsWindow.PLOT_WINDOW_HEIGHT; import static org.cirdles.tripoli.gui.dataViews.plots.plotsControllers.mcmcPlots.MCMCPlotsWindow.PLOT_WINDOW_WIDTH; -import static org.cirdles.tripoli.plots.analysisPlotBuilders.HistogramAnalysisBuilder.initializeHistogramAnalysis; import static org.cirdles.tripoli.plots.analysisPlotBuilders.PeakCentreAnalysisBuilder.initializeAnalysisPeakCentres; import static org.cirdles.tripoli.sessions.analysis.Analysis.*; @@ -60,12 +60,6 @@ public class MCMCPlotsController implements MCMCPlotsControllerInterface { private AnchorPane logAnchorPane; @FXML private ProgressBar progressBar; - @FXML - private Tab convergencesTab; - @FXML - private Tab convergeErrorTab; - @FXML - private Tab convergeIntensityTab; private Service[] services; @FXML private ResourceBundle resources; @@ -113,6 +107,7 @@ public int getCurrentBlockID() { public void plotIncomingAction() { processDataFileAndShowPlotsOfMCMC(analysis); + } @FXML @@ -218,10 +213,10 @@ public synchronized void processDataFileAndShowPlotsOfMCMC(AnalysisInterface ana showLogsEngine(finalBlockIndex); } if (activeServices.isEmpty()) { - //if (blocksToProcess.size() > 1) plotRatioSessionEngine(); listViewOfBlocks.setDisable(false); listViewOfBlocks.getSelectionModel().selectFirst(); progressBar.setProgress(1.0); + ((Analysis) analysis).analysisRatioEngine(); // fire up OGTripoli style session plots AllBlockInitForOGTripoli.PlottingData plottingData = analysis.assemblePostProcessPlottingData(); @@ -238,6 +233,8 @@ public synchronized void processDataFileAndShowPlotsOfMCMC(AnalysisInterface ana services[finalBlockIndex].setOnFailed(evt -> { listViewOfBlocks.setDisable(false); listViewOfBlocks.getSelectionModel().selectFirst(); + progressBar.setProgress(1.0); + ((Analysis) analysis).analysisRatioEngine(); }); } @@ -263,29 +260,7 @@ public synchronized void processDataFileAndShowPlotsOfMCMC(AnalysisInterface ana } @FXML - public void plotRatioSessionEngine() { - Map mapOfBlockIdToPlots = analysis.getMapOfBlockIdToPlots(); - Map> mapRatioNameToAnalysisRecords = new TreeMap<>(); - Iterator> iterator = mapOfBlockIdToPlots.entrySet().iterator(); - while (iterator.hasNext()) { - Map.Entry entry = iterator.next(); - if (analysis.getMapOfBlockIdToProcessStatus().get(entry.getKey()) == SHOW) { - PlotBuilder[] ratiosPlotBuilder = entry.getValue()[PLOT_INDEX_RATIOS]; - for (PlotBuilder ratioPlotBuilder : ratiosPlotBuilder) { - IsotopicRatio ratio = ((RatioHistogramBuilder) ratioPlotBuilder).getRatio(); - if (ratioPlotBuilder.isDisplayed()) { - String ratioName = ratioPlotBuilder.getTitle()[0]; - mapRatioNameToAnalysisRecords.computeIfAbsent(ratio, k -> new ArrayList<>()); - boolean useInvertedRatio = analysis.getAnalysisMethod().getMapOfRatioNamesToInvertedFlag().get(ratioName); - mapRatioNameToAnalysisRecords.get(ratio).add( - useInvertedRatio ? - ((RatioHistogramBuilder) ratioPlotBuilder).getInvertedRatioHistogramRecord() - : ((RatioHistogramBuilder) ratioPlotBuilder).getHistogramRecord()); - } - } - } - } - + public void plotAnalysisRatioEngine() { plotTabPane.widthProperty().addListener((observable, oldValue, newValue) -> { ratiosSessionPlotsWallPane.repeatLayoutStyle(); }); @@ -293,27 +268,28 @@ public void plotRatioSessionEngine() { ratiosSessionPlotsWallPane.repeatLayoutStyle(); }); - if (ratioSessionAnchorPane.getChildren().isEmpty()) { ratiosSessionPlotsWallPane = (PlotWallPane) PlotWallPane.createPlotWallPane(null, analysis, this, analysisManagerCallbackI); ratiosSessionPlotsWallPane.buildToolBar(); ratiosSessionPlotsWallPane.setBackground(new Background(new BackgroundFill(Paint.valueOf("LINEN"), null, null))); ratiosSessionPlotsWallPane.prefWidthProperty().bind(ratioSessionAnchorPane.widthProperty()); ratiosSessionPlotsWallPane.prefHeightProperty().bind(ratioSessionAnchorPane.heightProperty()); + ratiosSessionPlotsWallPane.setToolBarCount(2); + ratiosSessionPlotsWallPane.setToolBarHeight(35.0); ratioSessionAnchorPane.getChildren().add(ratiosSessionPlotsWallPane); } else { ratiosSessionPlotsWallPane = (PlotWallPane) ratioSessionAnchorPane.getChildren().get(0); ratiosSessionPlotsWallPane.clearTripoliPanes(); } - for (Map.Entry> entry : mapRatioNameToAnalysisRecords.entrySet()) { - HistogramAnalysisBuilder histogramAnalysisBuilder = initializeHistogramAnalysis( - analysis.getMapOfBlockIdToProcessStatus().size(), entry.getKey(), entry.getValue(), entry.getValue().get(0).title(), "Block ID", "Ratio"); + for (Map.Entry entry : ((Analysis) analysis).getMapOfRatioToAnalysisRatioRecord().entrySet()) { + AbstractPlot plot = AnalysisRatioPlot.generatePlot(new Rectangle(minPlotWidth, minPlotHeight), entry.getValue()); TripoliPlotPane tripoliPlotPane = TripoliPlotPane.makePlotPane(ratiosSessionPlotsWallPane); - AbstractPlot plot = HistogramAnalysisPlot.generatePlot(new Rectangle(minPlotWidth, minPlotHeight), histogramAnalysisBuilder.getHistogramAnalysisRecord()); tripoliPlotPane.addPlot(plot); } - ratiosSessionPlotsWallPane.stackPlots(); + + ratiosSessionPlotsWallPane.tilePlots(); + ratiosSessionPlotsWallPane.toggleShowStatsAllPlots(); } // plotting engine for peak sessions @@ -331,7 +307,6 @@ private void plotPeakSessionEngine() { String peakName = peakPlotBuilder.getTitle()[1]; mapPeakNameToAnalysisRecords.computeIfAbsent(peakName, k -> new ArrayList<>()); mapPeakNameToAnalysisRecords.get(peakName).add(((PeakShapesOverlayBuilder) peakPlotBuilder).getPeakShapesOverlayRecord()); - } } } @@ -342,12 +317,13 @@ private void plotPeakSessionEngine() { plotTabPane.heightProperty().addListener((observable, oldValue, newValue) -> { peakAnalysisPlotWallPlane.repeatLayoutStyle(); }); - // TODO add peak analysis pane to fxml and controller if (peakAnalysisAnchorPane.getChildren().isEmpty()) { peakAnalysisPlotWallPlane = (PlotWallPane) PlotWallPane.createPlotWallPane(null, analysis, this, null); peakAnalysisPlotWallPlane.buildToolBar(); peakAnalysisPlotWallPlane.setBackground(new Background(new BackgroundFill(Paint.valueOf("LINEN"), null, null))); + peakAnalysisPlotWallPlane.setToolBarCount(2); + peakAnalysisPlotWallPlane.setToolBarHeight(35.0); peakAnalysisAnchorPane.getChildren().add(peakAnalysisPlotWallPlane); } else { peakAnalysisPlotWallPlane = (PlotWallPane) peakAnalysisAnchorPane.getChildren().get(0); @@ -370,7 +346,7 @@ private void plotPeakSessionEngine() { private synchronized void plotBlockEngine(Task plotBuildersTaska) { analysisManagerCallbackI.callbackRefreshBlocksStatus(); - PlotBuildersTaskInterface plotBuildersTask = (PlotBuildersTaskInterface) plotBuildersTaska; + MCMCPlotBuildersTaskInterface plotBuildersTask = (MCMCPlotBuildersTaskInterface) plotBuildersTaska; PlotBuilder[] convergeRatioPlotBuilder = plotBuildersTask.getConvergeRatioLineBuilder(); PlotBuilder[] convergeBLFaradayLineBuilder = plotBuildersTask.getConvergeBLFaradayLineBuilder(); @@ -408,6 +384,8 @@ private synchronized void plotBlockEngine(Task plotBuildersTaska) { convergePlotsWallPane.setBackground(new Background(new BackgroundFill(Paint.valueOf("LINEN"), null, null))); convergePlotsWallPane.prefWidthProperty().bind(convergePlotsAnchorPane.widthProperty()); convergePlotsWallPane.prefHeightProperty().bind(convergePlotsAnchorPane.heightProperty()); + convergePlotsWallPane.setToolBarCount(2); + convergePlotsWallPane.setToolBarHeight(35.0); convergePlotsAnchorPane.getChildren().add(convergePlotsWallPane); } else { convergePlotsWallPane = (PlotWallPane) convergePlotsAnchorPane.getChildren().get(0); @@ -424,6 +402,8 @@ private synchronized void plotBlockEngine(Task plotBuildersTaska) { convergeErrorPlotsWallPane.setBackground(new Background(new BackgroundFill(Paint.valueOf("LINEN"), null, null))); convergeErrorPlotsWallPane.prefWidthProperty().bind(convergeErrorPlotsAnchorPane.widthProperty()); convergeErrorPlotsWallPane.prefHeightProperty().bind(convergeErrorPlotsAnchorPane.heightProperty()); + convergeErrorPlotsWallPane.setToolBarCount(2); + convergeErrorPlotsWallPane.setToolBarHeight(35.0); convergeErrorPlotsAnchorPane.getChildren().add(convergeErrorPlotsWallPane); } else { convergeErrorPlotsWallPane = (PlotWallPane) convergeErrorPlotsAnchorPane.getChildren().get(0); @@ -440,6 +420,8 @@ private synchronized void plotBlockEngine(Task plotBuildersTaska) { convergeIntensityPlotsWallPane.setBackground(new Background(new BackgroundFill(Paint.valueOf("LINEN"), null, null))); convergeIntensityPlotsWallPane.prefWidthProperty().bind(convergeIntensityAnchorPane.widthProperty()); convergeIntensityPlotsWallPane.prefHeightProperty().bind(convergeIntensityAnchorPane.heightProperty()); + convergeIntensityPlotsWallPane.setToolBarCount(2); + convergeIntensityPlotsWallPane.setToolBarHeight(35.0); convergeIntensityAnchorPane.getChildren().add(convergeIntensityPlotsWallPane); } else { convergeIntensityPlotsWallPane = (PlotWallPane) convergeIntensityAnchorPane.getChildren().get(0); @@ -458,6 +440,8 @@ private synchronized void plotBlockEngine(Task plotBuildersTaska) { dataFitPlotsWallPane.setBackground(new Background(new BackgroundFill(Paint.valueOf("LINEN"), null, null))); dataFitPlotsWallPane.prefWidthProperty().bind(dataFitPlotsAnchorPane.widthProperty()); dataFitPlotsWallPane.prefHeightProperty().bind(dataFitPlotsAnchorPane.heightProperty()); + dataFitPlotsWallPane.setToolBarCount(2); + dataFitPlotsWallPane.setToolBarHeight(35.0); dataFitPlotsAnchorPane.getChildren().add(dataFitPlotsWallPane); } else { dataFitPlotsWallPane = (PlotWallPane) dataFitPlotsAnchorPane.getChildren().get(0); @@ -474,6 +458,8 @@ private synchronized void plotBlockEngine(Task plotBuildersTaska) { peakShapeOverlayPlotWallPane.setBackground(new Background(new BackgroundFill(Paint.valueOf("LINEN"), null, null))); peakShapeOverlayPlotWallPane.prefWidthProperty().bind(beamShapeAnchorPane.widthProperty()); peakShapeOverlayPlotWallPane.prefHeightProperty().bind(beamShapeAnchorPane.heightProperty()); + peakShapeOverlayPlotWallPane.setToolBarCount(2); + peakShapeOverlayPlotWallPane.setToolBarHeight(35.0); beamShapeAnchorPane.getChildren().add(peakShapeOverlayPlotWallPane); } else { peakShapeOverlayPlotWallPane = (PlotWallPane) beamShapeAnchorPane.getChildren().get(0); @@ -483,7 +469,6 @@ private synchronized void plotBlockEngine(Task plotBuildersTaska) { peakShapeOverlayPlotWallPane.tilePlots(); } - public void plotEnsemblesEngine(PlotBuilder[][] plotBuilders) { PlotBuilder[] ratiosHistogramBuilder = plotBuilders[PLOT_INDEX_RATIOS]; PlotBuilder[] baselineHistogramBuilder = plotBuilders[PLOT_INDEX_BASELINES]; @@ -496,6 +481,8 @@ public void plotEnsemblesEngine(PlotBuilder[][] plotBuilders) { ensemblePlotsWallPane.setBackground(new Background(new BackgroundFill(Paint.valueOf("LINEN"), null, null))); ensemblePlotsWallPane.prefWidthProperty().bind(ensemblePlotsAnchorPane.widthProperty()); ensemblePlotsWallPane.prefHeightProperty().bind(ensemblePlotsAnchorPane.heightProperty()); + ensemblePlotsWallPane.setToolBarCount(2); + ensemblePlotsWallPane.setToolBarHeight(35.0); ensemblePlotsAnchorPane.getChildren().add(ensemblePlotsWallPane); } else { ensemblePlotsWallPane = (PlotWallPane) ensemblePlotsAnchorPane.getChildren().get(0); @@ -518,14 +505,13 @@ private synchronized void showLogsEngine(int blockNumber) { logAnchorPane.getChildren().add(logTextArea); } - private void produceTripoliRatioHistogramPlots(PlotBuilder[] plotBuilder, PlotWallPane plotWallPane) { for (int i = 0; i < plotBuilder.length; i++) { if (plotBuilder[i].isDisplayed()) { HistogramRecord plotRecord = ((RatioHistogramBuilder) plotBuilder[i]).getHistogramRecord(); HistogramRecord invertedPlotRecord = ((RatioHistogramBuilder) plotBuilder[i]).getInvertedRatioHistogramRecord(); HistogramRecord logRatioHistogramRecord = ((RatioHistogramBuilder) plotBuilder[i]).getLogRatioHistogramRecord(); - HistogramRecord logInvertedRatioHistogramRecord = ((RatioHistogramBuilder) plotBuilder[i]).getLogInvertedRatioHistogramRecord(); + HistogramRecord logInvertedRatioHistogramRecord = ((RatioHistogramBuilder) plotBuilder[i]).getInvertedLogRatioHistogramRecord(); TripoliPlotPane tripoliPlotPane = TripoliPlotPane.makePlotPane(plotWallPane); AbstractPlot plot = RatioHistogramPlot.generatePlot( new Rectangle(minPlotWidth, minPlotHeight), @@ -628,8 +614,9 @@ protected void updateItem(String blockIDtext, boolean empty) { if (analysis.getMapBlockIDToEnsembles().isEmpty()) { setText("Block# " + blockID); } else { + Integer burnCount = analysis.getMapOfBlockIdToModelsBurnCount().get(blockID); setText("Block# " + blockID - + " {BurnIn = " + analysis.getMapOfBlockIdToModelsBurnCount().get(blockID) + + " {BurnIn = " + ((burnCount == null) ? 0 : burnCount) + " of " + analysis.getMapBlockIDToEnsembles().get(blockID).size() + " models}"); } } diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotsControllerInterface.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotsControllerInterface.java index be80cc6f..fe20da49 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotsControllerInterface.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/mcmcPlots/MCMCPlotsControllerInterface.java @@ -5,7 +5,7 @@ public interface MCMCPlotsControllerInterface { public void plotEnsemblesEngine(PlotBuilder[][] plotBuilders); - public void plotRatioSessionEngine(); + public void plotAnalysisRatioEngine(); public int getCurrentBlockID(); } \ No newline at end of file diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/OGTripoliPlotsWindow.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/OGTripoliPlotsWindow.java index 0c3d9ba0..a075f4c7 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/OGTripoliPlotsWindow.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/OGTripoliPlotsWindow.java @@ -22,7 +22,7 @@ import javafx.stage.Window; import javafx.stage.WindowEvent; import org.cirdles.tripoli.gui.AnalysisManagerCallbackI; -import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.AllBlockInitForOGTripoli; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.AllBlockInitForOGTripoli; import java.io.IOException; @@ -69,7 +69,7 @@ public void close() { public void loadPlotsWindow() { if (!plottingStage.isShowing()) { - FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/cirdles/tripoli/gui/OGTripoliView.fxml")); + FXMLLoader loader = new FXMLLoader(getClass().getResource("/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/OGTripoliView.fxml")); try { Scene scene = new Scene(loader.load()); plottingStage.setScene(scene); diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/OGTripoliViewController.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/OGTripoliViewController.java index 86b7f625..ce481e6a 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/OGTripoliViewController.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/OGTripoliViewController.java @@ -17,9 +17,9 @@ import org.cirdles.tripoli.plots.compoundPlotBuilders.BlockRatioCyclesRecord; import org.cirdles.tripoli.sessions.analysis.Analysis; import org.cirdles.tripoli.sessions.analysis.AnalysisInterface; -import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.AllBlockInitForOGTripoli; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelRecord; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockRawDataSetRecord; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.AllBlockInitForOGTripoli; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataSourceProcessors.MassSpecOutputSingleBlockRecord; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.detectorSetups.Detector; import org.cirdles.tripoli.species.IsotopicRatio; diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/analysisPlots/BlockRatioCyclesAnalysisPlot.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/analysisPlots/BlockRatioCyclesAnalysisPlot.java index 7b155967..8580b5c6 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/analysisPlots/BlockRatioCyclesAnalysisPlot.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/analysisPlots/BlockRatioCyclesAnalysisPlot.java @@ -22,6 +22,7 @@ import javafx.scene.paint.Paint; import javafx.scene.shape.Rectangle; import javafx.scene.text.Font; +import javafx.scene.text.FontWeight; import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import org.cirdles.tripoli.gui.dataViews.plots.AbstractPlot; import org.cirdles.tripoli.gui.dataViews.plots.PlotWallPane; @@ -53,7 +54,7 @@ private BlockRatioCyclesAnalysisPlot(Rectangle bounds, BlockAnalysisRatioCyclesR super(bounds, 75, 25, new String[]{blockAnalysisRatioCyclesRecord.title()[0] - + " " + "X\u0305" + "=" + String.format("%8.8g", blockAnalysisRatioCyclesRecord.analysisMean()).trim() + + " " + "x\u0304" + "=" + String.format("%8.8g", blockAnalysisRatioCyclesRecord.analysisMean()).trim() , "\u00B1" + String.format("%8.5g", blockAnalysisRatioCyclesRecord.analysisOneSigma()).trim()}, blockAnalysisRatioCyclesRecord.xAxisLabel(), blockAnalysisRatioCyclesRecord.yAxisLabel()); @@ -247,7 +248,7 @@ private void showBlockID(GraphicsContext g2d, int blockID, double xPosition) { g2d.setFill(Paint.valueOf("BLACK")); } - g2d.setFont(Font.font("SansSerif", 10)); + g2d.setFont(Font.font("SansSerif", FontWeight.EXTRA_BOLD, 10)); g2d.fillText("BL#" + Integer.toString(blockID), xPosition, topMargin + plotHeight + 10); g2d.setFill(savedPaint); @@ -300,14 +301,12 @@ public void calcStats() { sessionOneSigmaAbs = descriptiveStatsIncludedCycles.getStandardDeviation(); sessionDalyFaradayGainMean = descriptiveStatsIncludedDFGains.getMean(); - blockAnalysisRatioCyclesRecord.isotopicRatio().setAnalysisDalyFaradayGainMean(sessionDalyFaradayGainMean); sessionDalyFaradayGainOneSigmaAbs = descriptiveStatsIncludedDFGains.getStandardDeviation(); - blockAnalysisRatioCyclesRecord.isotopicRatio().setAnalysisDalyFaradayGainOneSigmaAbs(sessionDalyFaradayGainOneSigmaAbs); plotTitle = new String[]{blockAnalysisRatioCyclesRecord.title()[0] - + " " + "X\u0305" + "=" + String.format("%8.8g", sessionMean).trim() + + " " + "x\u0304" + "=" + String.format("%8.8g", sessionMean).trim() , "\u00B1" + String.format("%8.5g", sessionOneSigmaAbs).trim()}; } diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/analysisPlots/SpeciesIntensityAnalysisPlot.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/analysisPlots/SpeciesIntensityAnalysisPlot.java index 4ff887ed..8bfa504c 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/analysisPlots/SpeciesIntensityAnalysisPlot.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/ogTripoliPlots/analysisPlots/SpeciesIntensityAnalysisPlot.java @@ -421,7 +421,7 @@ public void plotData(GraphicsContext g2d) { private void showBlockID(GraphicsContext g2d, String blockID, double xPosition) { Paint savedPaint = g2d.getFill(); - g2d.setFill(Paint.valueOf("BLACK")); + g2d.setFill(Paint.valueOf("GREEN")); g2d.setFont(Font.font("SansSerif", FontWeight.EXTRA_BOLD, 10)); g2d.fillText("BL#" + blockID, xPosition, 30); g2d.setFill(savedPaint); @@ -708,6 +708,9 @@ public void handle(MouseEvent e) { zoomBoxX = mouseStartX; zoomBoxY = mouseStartY; + } else { + zoomBoxX = mouseStartX; + zoomBoxY = mouseStartY; } repaint(); } diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/HistogramSinglePlot.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/HistogramSinglePlot.java index 0475b416..e6d86015 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/HistogramSinglePlot.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/HistogramSinglePlot.java @@ -38,7 +38,7 @@ protected HistogramSinglePlot(Rectangle bounds, HistogramRecord histogramRecord, super(bounds, 40, 25, new String[]{histogramRecord.title()[0] - + " " + "X\u0305" + "=" + String.format("%8.5g", histogramRecord.mean()).trim() + + " " + "x\u0304" + "=" + String.format("%8.5g", histogramRecord.mean()).trim() , "\u00B1" + String.format("%8.5g", histogramRecord.standardDeviation()).trim()}, histogramRecord.xAxisLabel(), histogramRecord.yAxisLabel()); diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/RatioHistogramPlot.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/RatioHistogramPlot.java index 92ac2baa..71d2dd22 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/RatioHistogramPlot.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/RatioHistogramPlot.java @@ -35,7 +35,7 @@ public class RatioHistogramPlot extends HistogramSinglePlot { private final HistogramRecord invertedRatioHistogramRecord; private HistogramRecord histogramRecordActive; private HistogramRecord logRatioHistogramRecord; - private HistogramRecord logInvertedRatioHistogramRecord; + private HistogramRecord invertedLogRatioHistogramRecord; private AnalysisMethod analysisMethod; private boolean logMode; @@ -44,7 +44,7 @@ private RatioHistogramPlot( HistogramRecord histogramRecord, HistogramRecord invertedRatioHistogramRecord, HistogramRecord logRatioHistogramRecord, - HistogramRecord logInvertedRatioHistogramRecord, + HistogramRecord invertedLogRatioHistogramRecord, AnalysisMethod analysisMethod, PlotWallPane parentWallPane) { super(bounds, histogramRecord, parentWallPane); @@ -53,10 +53,9 @@ private RatioHistogramPlot( // these can be changed by user in plot this.invertedRatioHistogramRecord = invertedRatioHistogramRecord; this.logRatioHistogramRecord = logRatioHistogramRecord; - this.logInvertedRatioHistogramRecord = logInvertedRatioHistogramRecord; + this.invertedLogRatioHistogramRecord = invertedLogRatioHistogramRecord; this.logMode = false; -// this.inverted = false; extendPlotContextMenu(); } @@ -106,7 +105,7 @@ public void preparePanel(boolean reScaleX, boolean reScaleY) { boolean inverted = analysisMethod.getMapOfRatioNamesToInvertedFlag().get(histogramRecord.title()[0]); if (inverted) { if (logMode) { - histogramRecordActive = logInvertedRatioHistogramRecord; + histogramRecordActive = invertedLogRatioHistogramRecord; } else { histogramRecordActive = invertedRatioHistogramRecord; } @@ -119,7 +118,7 @@ public void preparePanel(boolean reScaleX, boolean reScaleY) { } plotTitle = new String[]{histogramRecordActive.title()[0] - + " " + "X\u0305" + "=" + String.format("%8.5g", histogramRecordActive.mean()).trim() + + " " + "x\u0304" + "=" + String.format("%8.5g", histogramRecordActive.mean()).trim() , "\u00B1" + String.format("%8.5g", histogramRecordActive.standardDeviation()).trim()}; plotAxisLabelX = histogramRecordActive.xAxisLabel(); xAxisData = histogramRecordActive.binCenters(); diff --git a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/analysisPlots/HistogramAnalysisPlot.java b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/analysisPlots/AnalysisRatioPlot.java similarity index 54% rename from TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/analysisPlots/HistogramAnalysisPlot.java rename to TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/analysisPlots/AnalysisRatioPlot.java index da508d51..4ce6eb80 100644 --- a/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/analysisPlots/HistogramAnalysisPlot.java +++ b/TripoliApp/src/main/java/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/tripoliPlots/analysisPlots/AnalysisRatioPlot.java @@ -22,45 +22,63 @@ import javafx.scene.shape.Rectangle; import org.cirdles.tripoli.gui.dataViews.plots.AbstractPlot; import org.cirdles.tripoli.gui.dataViews.plots.TicGeneratorForAxes; -import org.cirdles.tripoli.plots.analysisPlotBuilders.HistogramAnalysisRecord; +import org.cirdles.tripoli.plots.analysisPlotBuilders.AnalysisRatioRecord; /** * @author James F. Bowring */ -public class HistogramAnalysisPlot extends AbstractPlot { +public class AnalysisRatioPlot extends AbstractPlot { - private final HistogramAnalysisRecord histogramAnalysisRecord; - private double[] yAxisDataOneSigma; + private final AnalysisRatioRecord analysisRatioRecord; + private double[][] yAxisDataOneSigma; + private boolean logRatioMode; - private HistogramAnalysisPlot(Rectangle bounds, HistogramAnalysisRecord histogramAnalysisRecord) { + private AnalysisRatioPlot(Rectangle bounds, AnalysisRatioRecord analysisRatioRecord) { super(bounds, 75, 25, - new String[]{histogramAnalysisRecord.title()[0] - + " " + "X\u0305" + "=" + String.format("%8.5g", histogramAnalysisRecord.analysisMean()).trim() - , "\u00B1" + String.format("%8.5g", histogramAnalysisRecord.analysisOneSigma()).trim()}, - histogramAnalysisRecord.xAxisLabel(), - histogramAnalysisRecord.yAxisLabel()); - this.histogramAnalysisRecord = histogramAnalysisRecord; + new String[]{analysisRatioRecord.title()[0]}, + analysisRatioRecord.xAxisLabel(), + analysisRatioRecord.yAxisLabel()); + this.analysisRatioRecord = analysisRatioRecord; + this.logRatioMode = false; } - public static AbstractPlot generatePlot(Rectangle bounds, HistogramAnalysisRecord histogramAnalysisRecord) { - return new HistogramAnalysisPlot(bounds, histogramAnalysisRecord); + public static AbstractPlot generatePlot(Rectangle bounds, AnalysisRatioRecord analysisRatioRecord) { + return new AnalysisRatioPlot(bounds, analysisRatioRecord); } @Override public void preparePanel(boolean reScaleX, boolean reScaleY) { - xAxisData = histogramAnalysisRecord.blockIds(); + xAxisData = analysisRatioRecord.blockIds(); minX = 0.0; - maxX = histogramAnalysisRecord.blockCount() + 1; - - yAxisData = histogramAnalysisRecord.blockMeans(); - yAxisDataOneSigma = histogramAnalysisRecord.blockOneSigmas(); + maxX = analysisRatioRecord.blockCount() + 1; + + if (logRatioMode) { + yAxisData = analysisRatioRecord.blockLogRatioMeans(); + yAxisDataOneSigma = new double[2][]; + yAxisDataOneSigma[0] = analysisRatioRecord.blockLogRatioOneSigmas(); + yAxisDataOneSigma[1] = analysisRatioRecord.blockLogRatioOneSigmas(); + plotTitle = new String[]{analysisRatioRecord.title()[0] + + " " + "x\u0304" + "=" + String.format("%8.8g", (analysisRatioRecord.weightedMeanRecord().logRatioWeightedMean())).trim() + , "\u00B1" + String.format("%8.5g", (analysisRatioRecord.weightedMeanRecord().logRatioOneSigmaAbs())).trim() + + (Double.isNaN(analysisRatioRecord.weightedMeanRecord().logRatioReducedChiSquareStatistic()) ? "" + : " \u03C7" + "=" + String.format("%8.5g", (analysisRatioRecord.weightedMeanRecord().logRatioReducedChiSquareStatistic())))}; + plotAxisLabelY = "LogRatio"; + } else { + yAxisData = analysisRatioRecord.blockRatioMeans(); + yAxisDataOneSigma = analysisRatioRecord.blockRatioOneSigmas(); + plotTitle = new String[]{analysisRatioRecord.title()[0].replace("Log", "") + + " " + "x\u0304" + "=" + String.format("%8.8g", (analysisRatioRecord.weightedMeanRecord().ratioWeightedMean())).trim() + , "+" + String.format("%8.5g", (analysisRatioRecord.weightedMeanRecord().ratioHigherOneSigmaAbs())).trim() + + " -" + String.format("%8.5g", (analysisRatioRecord.weightedMeanRecord().ratioLowerOneSigmaAbs())).trim()}; + plotAxisLabelY = "Ratio"; + } minY = Double.MAX_VALUE; maxY = -Double.MAX_VALUE; for (int i = 0; i < yAxisData.length; i++) { - minY = StrictMath.min(minY, yAxisData[i] - yAxisDataOneSigma[i]); - maxY = StrictMath.max(maxY, yAxisData[i] + yAxisDataOneSigma[i]); + maxY = StrictMath.max(maxY, yAxisData[i] + yAxisDataOneSigma[0][i]); + minY = StrictMath.min(minY, yAxisData[i] - yAxisDataOneSigma[1][i]); } displayOffsetX = 0.0; @@ -100,8 +118,8 @@ public void plotData(GraphicsContext g2d) { if (pointInPlot(xAxisData[i], yAxisData[i])) { double dataX = mapX(xAxisData[i]); double dataY = mapY(yAxisData[i]); - double dataYplusSigma = mapY(yAxisData[i] + yAxisDataOneSigma[i]); - double dataYminusSigma = mapY(yAxisData[i] - yAxisDataOneSigma[i]); + double dataYplusSigma = mapY(yAxisData[i] + yAxisDataOneSigma[0][i]); + double dataYminusSigma = mapY(yAxisData[i] - yAxisDataOneSigma[1][i]); g2d.fillOval(dataX - 2.5, dataY - 2.5, 5, 5); g2d.strokeLine(dataX, dataY, dataX, dataYplusSigma); @@ -111,13 +129,20 @@ public void plotData(GraphicsContext g2d) { } public void plotStats(GraphicsContext g2d) { - Paint saveFill = g2d.getFill(); // todo: promote color to constant g2d.setFill(Color.rgb(255, 251, 194)); g2d.setGlobalAlpha(0.6); - double mean = histogramAnalysisRecord.analysisMean(); - double stdDev = histogramAnalysisRecord.analysisOneSigma(); + double mean; + double stdDev; + if (logRatioMode) { + mean = (analysisRatioRecord.weightedMeanRecord().logRatioWeightedMean()); + stdDev = (analysisRatioRecord.weightedMeanRecord().logRatioOneSigmaAbs()); + } else { + mean = (analysisRatioRecord.weightedMeanRecord().ratioWeightedMean()); + // TODO: make this two-sided + stdDev = (analysisRatioRecord.weightedMeanRecord().ratioHigherOneSigmaAbs()); + } double leftX = mapX(minX); if (leftX < leftMargin) leftX = leftMargin; @@ -135,6 +160,10 @@ public void plotStats(GraphicsContext g2d) { g2d.setLineWidth(1.0); g2d.strokeLine(leftX, mapY(mean), rightX, mapY(mean)); } + } + public void toggleRatiosLogRatios() { + logRatioMode = !logRatioMode; + refreshPanel(true, true); } } \ No newline at end of file diff --git a/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/TripoliGUI.fxml b/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/TripoliGUI.fxml index 2b06578e..4a10cdce 100644 --- a/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/TripoliGUI.fxml +++ b/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/TripoliGUI.fxml @@ -48,7 +48,7 @@ - + @@ -63,7 +63,7 @@ - + @@ -72,7 +72,7 @@ - + diff --git a/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/MCMCPlots.fxml b/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/MCMCPlots.fxml index 9a4399b2..6c8af4e3 100644 --- a/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/MCMCPlots.fxml +++ b/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/MCMCPlots.fxml @@ -18,26 +18,24 @@ - - + - + - + - + diff --git a/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/OGTripoliView.fxml b/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/OGTripoliView.fxml similarity index 96% rename from TripoliApp/src/main/resources/org/cirdles/tripoli/gui/OGTripoliView.fxml rename to TripoliApp/src/main/resources/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/OGTripoliView.fxml index 16d97fbb..623bc3b0 100644 --- a/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/OGTripoliView.fxml +++ b/TripoliApp/src/main/resources/org/cirdles/tripoli/gui/dataViews/plots/plotsControllers/OGTripoliView.fxml @@ -5,7 +5,7 @@ - diff --git a/TripoliCore/build.gradle.kts b/TripoliCore/build.gradle.kts index 0383fc0d..62e5f69f 100644 --- a/TripoliCore/build.gradle.kts +++ b/TripoliCore/build.gradle.kts @@ -69,6 +69,10 @@ dependencies { // https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core implementation("org.apache.logging.log4j:log4j-core:2.20.0") + // https://mvnrepository.com/artifact/org.jblas/jblas + implementation("org.jblas:jblas:1.2.5") + + testImplementation("com.github.cirdles:commons:bc38781605") testImplementation("org.junit.jupiter:junit-jupiter-api:5.9.2") @@ -99,6 +103,8 @@ extraJavaModuleInfo { automaticModule("jama-master-SNAPSHOT.jar", "jama") automaticModule("org.ojalgo:ojalgo", "ojalgo") + automaticModule("org.jblas:jblas", "jblas") + //automaticModule("javax.xml.bind:jaxb-api", "jaxb.api")//javax.xml.bind:jaxb-api:2.3.1 } diff --git a/TripoliCore/src/main/java/module-info.java b/TripoliCore/src/main/java/module-info.java index 417aa5d9..481fb178 100644 --- a/TripoliCore/src/main/java/module-info.java +++ b/TripoliCore/src/main/java/module-info.java @@ -25,6 +25,7 @@ requires commons.lang3; requires jakarta.xml.bind; requires java.xml.bind; + requires jblas; exports org.cirdles.tripoli; @@ -57,4 +58,6 @@ exports org.cirdles.tripoli.sessions.analysis.methods.machineMethods.phoenixMassSpec; exports org.cirdles.tripoli.plots.analysisPlotBuilders; exports org.cirdles.tripoli.plots.compoundPlotBuilders; + exports org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers; + exports org.cirdles.tripoli.utilities.mathUtilities.weightedMeans; } \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/AnalysisRatioPlotBuilder.java b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/AnalysisRatioPlotBuilder.java new file mode 100644 index 00000000..08cf171b --- /dev/null +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/AnalysisRatioPlotBuilder.java @@ -0,0 +1,100 @@ +/* + * Copyright 2022 James Bowring, Noah McLean, Scott Burdick, and CIRDLES.org. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cirdles.tripoli.plots.analysisPlotBuilders; + +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; +import org.cirdles.tripoli.plots.PlotBuilder; +import org.cirdles.tripoli.plots.histograms.HistogramRecord; +import org.cirdles.tripoli.species.IsotopicRatio; +import org.cirdles.tripoli.utilities.mathUtilities.weightedMeans.WeighteMeanOfLogRatio; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +/** + * @author James F. Bowring + */ +public class AnalysisRatioPlotBuilder extends PlotBuilder { + private AnalysisRatioRecord analysisRatioRecord; + private int blockCount; + + public AnalysisRatioPlotBuilder() { + } + + private AnalysisRatioPlotBuilder(int blockCount, String[] title, String xAxisLabel, String yAxisLabel) { + super(title, xAxisLabel, yAxisLabel, true); + this.blockCount = blockCount; + } + + public static AnalysisRatioPlotBuilder initializeAnalysisRatioPlotBuilder( + int blockCount, IsotopicRatio ratio, List histogramRecords, String[] title, String xAxisLabel, String yAxisLabel) { + AnalysisRatioPlotBuilder analysisRatioPlotBuilder = new AnalysisRatioPlotBuilder(blockCount, title, xAxisLabel, yAxisLabel); + analysisRatioPlotBuilder.analysisRatioRecord = analysisRatioPlotBuilder.generateAnalysisRatioRecord(ratio, histogramRecords); + return analysisRatioPlotBuilder; + } + + private AnalysisRatioRecord generateAnalysisRatioRecord(IsotopicRatio ratio, List histogramRecords) { + List blockIdList = new ArrayList<>(); + List analysisLogRatioBlockMeans = new ArrayList<>(); + List analysisLogRatioBlockOneSigmas = new ArrayList<>(); + DescriptiveStatistics descriptiveStatisticsAnalysisLogRatio = new DescriptiveStatistics(); + + Map mapBlockIdToHistogramRecord = new TreeMap<>(); + for (HistogramRecord histogramRecord : histogramRecords) { + mapBlockIdToHistogramRecord.put(histogramRecord.blockID(), histogramRecord); + blockIdList.add(histogramRecord.blockID()); + + analysisLogRatioBlockMeans.add(histogramRecord.mean()); + descriptiveStatisticsAnalysisLogRatio.addValue(histogramRecord.mean()); + analysisLogRatioBlockOneSigmas.add(histogramRecord.standardDeviation()); + } + double[] blockIds = blockIdList.stream().mapToDouble(d -> d).toArray(); + double[] blockLogRatioMeans = analysisLogRatioBlockMeans.stream().mapToDouble(d -> d).toArray(); + double[] blockLogRatioOneSigmas = analysisLogRatioBlockOneSigmas.stream().mapToDouble(d -> d).toArray(); + + double analysisLogRatiosMean = (descriptiveStatisticsAnalysisLogRatio.getMean()); + double analysisLogRatiosOneSigma = descriptiveStatisticsAnalysisLogRatio.getStandardDeviation(); + + int countOfActiveBlocks = blockLogRatioMeans.length; + double[][] logRatioCoVariances = new double[countOfActiveBlocks][countOfActiveBlocks]; + for (int i = 0; i < countOfActiveBlocks; i++) { + logRatioCoVariances[i][i] = blockLogRatioOneSigmas[i] * blockLogRatioOneSigmas[i]; + } + + return new AnalysisRatioRecord( + ratio, + blockCount, + mapBlockIdToHistogramRecord, + blockIds, + blockLogRatioMeans, + blockLogRatioOneSigmas, + analysisLogRatiosMean, + analysisLogRatiosOneSigma, + WeighteMeanOfLogRatio.calculateWeightedMean(blockLogRatioMeans, logRatioCoVariances), + title, + "Block Number", + "LogRatio" + ); + + } + + public AnalysisRatioRecord getAnalysisRatioRecord() { + return analysisRatioRecord; + } +} \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/AnalysisRatioRecord.java b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/AnalysisRatioRecord.java new file mode 100644 index 00000000..528fe123 --- /dev/null +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/AnalysisRatioRecord.java @@ -0,0 +1,47 @@ +package org.cirdles.tripoli.plots.analysisPlotBuilders; + +import org.cirdles.tripoli.plots.histograms.HistogramRecord; +import org.cirdles.tripoli.utilities.mathUtilities.weightedMeans.WeighteMeanOfLogRatio; + +import java.io.Serializable; +import java.util.Map; + +import static java.lang.StrictMath.exp; + +public record AnalysisRatioRecord( + org.cirdles.tripoli.species.IsotopicRatio ratio, int blockCount, + Map mapBlockIdToHistogramRecord, + double[] blockIds, + double[] blockLogRatioMeans, + double[] blockLogRatioOneSigmas, + double analysisLogRatioMean, + double analysisLogRatioOneSigma, + WeighteMeanOfLogRatio.WeightedMeanRecord weightedMeanRecord, + String[] title, + String xAxisLabel, + String yAxisLabel +) implements Serializable { + + public double[] blockRatioMeans() { + double[] blockRatioMeans = new double[blockLogRatioMeans.length]; + for (int i = 0; i < blockLogRatioMeans.length; i++) { + blockRatioMeans[i] = exp(blockLogRatioMeans[i]); + } + + return blockRatioMeans; + } + + public double[][] blockRatioOneSigmas() { + double[][] blockRatioOneSigmas = new double[2][blockLogRatioMeans.length]; + for (int i = 0; i < blockLogRatioOneSigmas.length; i++) { + double ratioMean = exp(blockLogRatioMeans[i]); + double ratioHigherOneSigmaAbs = exp(blockLogRatioMeans[i] + blockLogRatioOneSigmas[i]) - ratioMean; + double ratioLowerOneSigmaAbs = ratioMean - exp(blockLogRatioMeans[i] - blockLogRatioOneSigmas[i]); + //TODO: make this two-sided valueModel + blockRatioOneSigmas[0][i] = ratioHigherOneSigmaAbs; + blockRatioOneSigmas[1][i] = ratioLowerOneSigmaAbs; + } + + return blockRatioOneSigmas; + } +} \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/BlockAnalysisRatioCyclesBuilder.java b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/BlockAnalysisRatioCyclesBuilder.java index 2cc45df3..b8da4499 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/BlockAnalysisRatioCyclesBuilder.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/BlockAnalysisRatioCyclesBuilder.java @@ -28,8 +28,6 @@ * @author James F. Bowring */ public class BlockAnalysisRatioCyclesBuilder extends PlotBuilder { - // @Serial -// private static final long serialVersionUID = 9180059676626735662L; private BlockAnalysisRatioCyclesRecord blockAnalysisRatioCyclesRecord; @@ -67,8 +65,8 @@ private BlockAnalysisRatioCyclesRecord generateBlockAnalysisRatioCycles(Isotopic blockIndex++; } // double[] blockIds = blockIdList.stream().mapToDouble(d -> d).toArray(); -// double[] blockMeans = histogramMeans.stream().mapToDouble(d -> d).toArray(); -// double[] blockOneSigmas = histogramOneSigma.stream().mapToDouble(d -> d).toArray(); +// double[] blockLogRatioMeans = histogramMeans.stream().mapToDouble(d -> d).toArray(); +// double[] blockLogRatioOneSigmas = histogramOneSigma.stream().mapToDouble(d -> d).toArray(); return new BlockAnalysisRatioCyclesRecord( isotopicRatio, diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/HistogramAnalysisBuilder.java b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/HistogramAnalysisBuilder.java deleted file mode 100644 index 83dc50d8..00000000 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/HistogramAnalysisBuilder.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright 2022 James Bowring, Noah McLean, Scott Burdick, and CIRDLES.org. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.cirdles.tripoli.plots.analysisPlotBuilders; - -import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; -import org.cirdles.tripoli.plots.PlotBuilder; -import org.cirdles.tripoli.plots.histograms.HistogramRecord; -import org.cirdles.tripoli.species.IsotopicRatio; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -/** - * @author James F. Bowring - */ -public class HistogramAnalysisBuilder extends PlotBuilder { - // @Serial -// private static final long serialVersionUID = 9180059676626735662L; - private HistogramAnalysisRecord histogramAnalysisRecord; - private int blockCount; - - public HistogramAnalysisBuilder() { - } - - private HistogramAnalysisBuilder(int blockCount, String[] title, String xAxisLabel, String yAxisLabel) { - super(title, xAxisLabel, yAxisLabel, true); - this.blockCount = blockCount; - } - - public static HistogramAnalysisBuilder initializeHistogramAnalysis( - int blockCount, IsotopicRatio ratio, List histogramRecords, String[] title, String xAxisLabel, String yAxisLabel) { - HistogramAnalysisBuilder histogramAnalysisBuilder = new HistogramAnalysisBuilder(blockCount, title, xAxisLabel, yAxisLabel); - histogramAnalysisBuilder.histogramAnalysisRecord = histogramAnalysisBuilder.generateHistogramAnalysis(ratio, histogramRecords); - return histogramAnalysisBuilder; - } - - private HistogramAnalysisRecord generateHistogramAnalysis(IsotopicRatio ratio, List histogramRecords) { - List blockIdList = new ArrayList<>(); - List histogramMeans = new ArrayList<>(); - List histogramOneSigma = new ArrayList<>(); - DescriptiveStatistics descriptiveStatisticsAnalysisRatios = new DescriptiveStatistics(); - - Map mapBlockIdToHistogramRecord = new TreeMap<>(); - for (HistogramRecord histogramRecord : histogramRecords) { - mapBlockIdToHistogramRecord.put(histogramRecord.blockID(), histogramRecord); - blockIdList.add((double) histogramRecord.blockID()); - histogramMeans.add(histogramRecord.mean()); - descriptiveStatisticsAnalysisRatios.addValue(histogramRecord.mean()); - histogramOneSigma.add(histogramRecord.standardDeviation()); - } - double[] blockIds = blockIdList.stream().mapToDouble(d -> d).toArray(); - double[] blockMeans = histogramMeans.stream().mapToDouble(d -> d).toArray(); - double[] blockOneSigmas = histogramOneSigma.stream().mapToDouble(d -> d).toArray(); - - double analysisRatiosMean = descriptiveStatisticsAnalysisRatios.getMean(); - double analysisRatiosOneSigma = descriptiveStatisticsAnalysisRatios.getStandardDeviation(); - - ratio.setAnalysisMean(analysisRatiosMean); - ratio.setAnalysisOneSigmaAbs(analysisRatiosOneSigma); - - return new HistogramAnalysisRecord( - ratio, - blockCount, - mapBlockIdToHistogramRecord, - blockIds, - blockMeans, - blockOneSigmas, - analysisRatiosMean, - analysisRatiosOneSigma, - title, - "Block Number", - "Ratio" - ); - } - - public HistogramAnalysisRecord getHistogramAnalysisRecord() { - return histogramAnalysisRecord; - } -} \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/HistogramAnalysisRecord.java b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/HistogramAnalysisRecord.java deleted file mode 100644 index 02c627d2..00000000 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/analysisPlotBuilders/HistogramAnalysisRecord.java +++ /dev/null @@ -1,20 +0,0 @@ -package org.cirdles.tripoli.plots.analysisPlotBuilders; - -import org.cirdles.tripoli.plots.histograms.HistogramRecord; - -import java.io.Serializable; -import java.util.Map; - -public record HistogramAnalysisRecord( - org.cirdles.tripoli.species.IsotopicRatio ratio, int blockCount, - Map mapBlockIdToHistogramRecord, - double[] blockIds, - double[] blockMeans, - double[] blockOneSigmas, - double analysisMean, - double analysisOneSigma, - String[] title, - String xAxisLabel, - String yAxisLabel -) implements Serializable { -} \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/histograms/HistogramBuilder.java b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/histograms/HistogramBuilder.java index f045012a..f63238ef 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/histograms/HistogramBuilder.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/histograms/HistogramBuilder.java @@ -43,12 +43,12 @@ public static HistogramBuilder initializeHistogram(int blockID, double[] data, i } protected HistogramRecord generateHistogram(int blockID, double[] data, int binCount, String[] title, String xAxisLabel) { - DescriptiveStatistics descriptiveStatisticsRatios = new DescriptiveStatistics(); + DescriptiveStatistics descriptiveStatisticsData = new DescriptiveStatistics(); for (int index = 0; index < data.length; index++) { - descriptiveStatisticsRatios.addValue(data[index]); + descriptiveStatisticsData.addValue(data[index]); } - double dataMax = descriptiveStatisticsRatios.getMax(); - double dataMin = descriptiveStatisticsRatios.getMin(); + double dataMax = descriptiveStatisticsData.getMax(); + double dataMin = descriptiveStatisticsData.getMin(); double[] binCounts = new double[binCount]; double binWidth = (dataMax - dataMin) / binCount; @@ -73,8 +73,8 @@ protected HistogramRecord generateHistogram(int blockID, double[] data, int binC return new HistogramRecord( blockID, data, - descriptiveStatisticsRatios.getMean(), - descriptiveStatisticsRatios.getStandardDeviation(), + descriptiveStatisticsData.getMean(), + descriptiveStatisticsData.getStandardDeviation(), binCount, binCounts, binWidth, diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/histograms/RatioHistogramBuilder.java b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/histograms/RatioHistogramBuilder.java index 05fd091d..aa4194ad 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/plots/histograms/RatioHistogramBuilder.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/plots/histograms/RatioHistogramBuilder.java @@ -27,7 +27,7 @@ public class RatioHistogramBuilder extends HistogramBuilder { private IsotopicRatio ratio; private HistogramRecord invertedRatioHistogramRecord; private HistogramRecord logRatioHistogramRecord; - private HistogramRecord logInvertedRatioHistogramRecord; + private HistogramRecord invertedLogRatioHistogramRecord; private RatioHistogramBuilder(int blockID, String[] title, String xAxisLabel, String yAxisLabel, boolean displayed) { @@ -36,7 +36,7 @@ private RatioHistogramBuilder(int blockID, String[] title, String xAxisLabel, St histogramRecord = null; invertedRatioHistogramRecord = null; logRatioHistogramRecord = null; - logInvertedRatioHistogramRecord = null; + invertedLogRatioHistogramRecord = null; this.displayed = displayed; } @@ -46,7 +46,7 @@ public static RatioHistogramBuilder initializeRatioHistogram(int blockID, Isotop ratioHistogramBuilder.histogramRecord = ratioHistogramBuilder.generateHistogram(blockID, ratio.getRatioValuesForBlockEnsembles(), binCount, new String[]{ratio.prettyPrint()}, "Ratio"); ratioHistogramBuilder.invertedRatioHistogramRecord = ratioHistogramBuilder.generateHistogram(blockID, invertedRatio.getRatioValuesForBlockEnsembles(), binCount, new String[]{invertedRatio.prettyPrint()}, "Ratio"); ratioHistogramBuilder.logRatioHistogramRecord = ratioHistogramBuilder.generateHistogram(blockID, ratio.getLogRatioValuesForBlockEnsembles(), binCount, new String[]{"Log " + ratio.prettyPrint()}, "LogRatio"); - ratioHistogramBuilder.logInvertedRatioHistogramRecord = ratioHistogramBuilder.generateHistogram(blockID, invertedRatio.getLogRatioValuesForBlockEnsembles(), binCount, new String[]{"Log " + invertedRatio.prettyPrint()}, "LogRatio"); + ratioHistogramBuilder.invertedLogRatioHistogramRecord = ratioHistogramBuilder.generateHistogram(blockID, invertedRatio.getLogRatioValuesForBlockEnsembles(), binCount, new String[]{"Log " + invertedRatio.prettyPrint()}, "LogRatio"); return ratioHistogramBuilder; } @@ -58,8 +58,8 @@ public HistogramRecord getLogRatioHistogramRecord() { return logRatioHistogramRecord; } - public HistogramRecord getLogInvertedRatioHistogramRecord() { - return logInvertedRatioHistogramRecord; + public HistogramRecord getInvertedLogRatioHistogramRecord() { + return invertedLogRatioHistogramRecord; } public IsotopicRatio getRatio() { diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/Analysis.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/Analysis.java index a52f53c6..35078415 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/Analysis.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/Analysis.java @@ -23,8 +23,16 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import org.cirdles.tripoli.constants.MassSpectrometerContextEnum; import org.cirdles.tripoli.plots.PlotBuilder; +import org.cirdles.tripoli.plots.analysisPlotBuilders.AnalysisRatioPlotBuilder; +import org.cirdles.tripoli.plots.analysisPlotBuilders.AnalysisRatioRecord; import org.cirdles.tripoli.plots.analysisPlotBuilders.SpeciesIntensityAnalysisBuilder; -import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.*; +import org.cirdles.tripoli.plots.histograms.HistogramRecord; +import org.cirdles.tripoli.plots.histograms.RatioHistogramBuilder; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.EnsemblesStore; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelDriver; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelRecord; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockRawDataSetRecord; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.AllBlockInitForOGTripoli; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.peakShapes.SingleBlockPeakDriver; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataSourceProcessors.MassSpecExtractedData; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.detectorSetups.DetectorSetupBuiltinModelFactory; @@ -52,6 +60,7 @@ import static org.cirdles.tripoli.constants.MassSpectrometerContextEnum.PHOENIX_SYNTHETIC; import static org.cirdles.tripoli.constants.MassSpectrometerContextEnum.UNKNOWN; import static org.cirdles.tripoli.constants.TripoliConstants.*; +import static org.cirdles.tripoli.plots.analysisPlotBuilders.AnalysisRatioPlotBuilder.initializeAnalysisRatioPlotBuilder; import static org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethodBuiltinFactory.BURDICK_BL_SYNTHETIC_DATA; import static org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethodBuiltinFactory.KU_204_5_6_7_8_DALY_ALL_FARADAY_PB; @@ -65,7 +74,6 @@ public class Analysis implements Serializable, AnalysisInterface { @Serial private static final long serialVersionUID = 5737165372498262402L; - private final Map mapOfBlockIdToPlots = Collections.synchronizedSortedMap(new TreeMap<>()); private final Map mapOfBlockIdToPeakPlots = Collections.synchronizedSortedMap(new TreeMap<>()); private final Map mapOfBlockToLogs = Collections.synchronizedSortedMap(new TreeMap<>()); @@ -76,6 +84,7 @@ public class Analysis implements Serializable, AnalysisInterface { private final Map mapOfBlockIdToRawData = Collections.synchronizedSortedMap(new TreeMap<>()); private final Map mapOfBlockIdToFinalModel = Collections.synchronizedSortedMap(new TreeMap<>()); private final Map mapOfBlockIdToIncludedPeakData = Collections.synchronizedSortedMap(new TreeMap<>()); + private final Map mapOfRatioToAnalysisRatioRecord = Collections.synchronizedSortedMap(new TreeMap<>()); private String analysisName; private String analystName; private String labName; @@ -87,7 +96,9 @@ public class Analysis implements Serializable, AnalysisInterface { private MassSpecExtractedData massSpecExtractedData; private boolean mutable; private SpeciesIntensityAnalysisBuilder.PlotSpecsSpeciesIntensityAnalysis plotSpecsSpeciesIntensityAnalysis; - private DescriptiveStatistics[] analysisSpeciesStats = new DescriptiveStatistics[1]; + private DescriptiveStatistics[] analysisSpeciesStats = new DescriptiveStatistics[0]; + private double analysisDalyFaradayGainMean; + private double analysisDalyFaradayGainMeanOneSigmaAbs; private Analysis() { } @@ -102,33 +113,31 @@ protected Analysis(String analysisName, AnalysisMethod analysisMethod, String an dataFilePathString = MISSING_STRING_FIELD; massSpecExtractedData = new MassSpecExtractedData(); mutable = true; - if (analysisMethod != null) { + if (null != analysisMethod) { plotSpecsSpeciesIntensityAnalysis = new SpeciesIntensityAnalysisBuilder.PlotSpecsSpeciesIntensityAnalysis( new boolean[analysisMethod.getSpeciesList().size()], true, true, true, true, true, false); } } - - public SpeciesIntensityAnalysisBuilder.PlotSpecsSpeciesIntensityAnalysis getPlotSpecsSpeciesIntensityAnalysis() { - return plotSpecsSpeciesIntensityAnalysis; - } - - public void setPlotSpecsSpeciesIntensityAnalysis(SpeciesIntensityAnalysisBuilder.PlotSpecsSpeciesIntensityAnalysis plotSpecsSpeciesIntensityAnalysis) { - this.plotSpecsSpeciesIntensityAnalysis = plotSpecsSpeciesIntensityAnalysis; - } +// +// public SpeciesIntensityAnalysisBuilder.PlotSpecsSpeciesIntensityAnalysis getPlotSpecsSpeciesIntensityAnalysis() { +// return plotSpecsSpeciesIntensityAnalysis; +// } +// +// public void setPlotSpecsSpeciesIntensityAnalysis(SpeciesIntensityAnalysisBuilder.PlotSpecsSpeciesIntensityAnalysis plotSpecsSpeciesIntensityAnalysis) { +// this.plotSpecsSpeciesIntensityAnalysis = plotSpecsSpeciesIntensityAnalysis; +// } public void setAnalysisSpeciesStats(DescriptiveStatistics[] analysisSpeciesStats) { this.analysisSpeciesStats = analysisSpeciesStats; } - public boolean[] calcDataIncluded() { - int baseLineCount = mapOfBlockIdToRawData.get(1).baselineDataSetMCMC().intensityAccumulatorList().size(); - int faradayCount = mapOfBlockIdToRawData.get(1).onPeakFaradayDataSetMCMC().intensityAccumulatorList().size(); - int photoMultiplierCount = mapOfBlockIdToRawData.get(1).onPeakPhotoMultiplierDataSetMCMC().intensityAccumulatorList().size(); - boolean[] dataIncluded = new boolean[baseLineCount + faradayCount + photoMultiplierCount]; - - - return dataIncluded; - } +// public boolean[] calcDataIncluded() { +// int baseLineCount = mapOfBlockIdToRawData.get(1).baselineDataSetMCMC().intensityAccumulatorList().size(); +// int faradayCount = mapOfBlockIdToRawData.get(1).onPeakFaradayDataSetMCMC().intensityAccumulatorList().size(); +// int photoMultiplierCount = mapOfBlockIdToRawData.get(1).onPeakPhotoMultiplierDataSetMCMC().intensityAccumulatorList().size(); +// boolean[] dataIncluded = new boolean[baseLineCount + faradayCount + photoMultiplierCount]; +// return dataIncluded; +// } public Map> getMapBlockIDToEnsembles() { return mapBlockIDToEnsembles; @@ -256,7 +265,7 @@ public void initializeBlockProcessing() { mapOfBlockIdToRawData.put(blockID, null); mapOfBlockIdToFinalModel.put(blockID, null); - if (analysisMethod != null) { + if (null != analysisMethod) { boolean[][] blockIncludedOnPeak = new boolean[analysisMethod.getSpeciesListSortedByMass().size()][]; for (int index = 0; index < blockIncludedOnPeak.length; index++) { boolean[] row = new boolean[massSpecExtractedData.getBlocksData().get(blockID).onPeakIntensities().length]; @@ -304,7 +313,7 @@ public void updateShadeWidthsForConvergenceLinePlots(int blockID, double shadeWi // TODO: make these indices into constants // PlotBuilder indices for convergence MultiLinePlotBuilders = 10 PlotBuilder[][] plotBuilders = mapOfBlockIdToPlots.get(blockID); - if (plotBuilders != null) { + if (null != plotBuilders) { updatePlotBuildersWithShades(plotBuilders[5], shadeWidth); updatePlotBuildersWithShades(plotBuilders[6], shadeWidth); updatePlotBuildersWithShades(plotBuilders[8], shadeWidth); @@ -376,7 +385,7 @@ public AllBlockInitForOGTripoli.PlottingData assemblePostProcessPlottingData() { for (SingleBlockModelRecord singleBlockModelRecord : singleBlockModelRecordMap.values()) { singleBlockModelRecords[index] = singleBlockModelRecord; index++; - if ((singleBlockModelRecord != null) && (cycleCount == 0)) { + if ((null != singleBlockModelRecord) && (0 == cycleCount)) { cycleCount = singleBlockModelRecord.cycleCount(); } } @@ -439,25 +448,57 @@ public final String prettyPrintAnalysisDataSummary() { } private int[][] calculateSpeciesIncludedCounts() { - int speciesCount = analysisMethod.getSpeciesList().size(); - int blockCount = massSpecExtractedData.getBlocksData().size(); - // 2 rows per species: 0 = total; 1 = included; column 0 is for totals - int[][] speciesIncludedCounts = new int[2 * speciesCount][blockCount + 1]; - for (int blockID = 1; blockID <= blockCount; blockID++) { - for (int speciesIndex = 0; speciesIndex < speciesCount; speciesIndex++) { - speciesIncludedCounts[speciesIndex * 2][blockID] = getMapOfBlockIdToIncludedPeakData().get(blockID)[speciesIndex].length; - speciesIncludedCounts[speciesIndex * 2][0] += speciesIncludedCounts[speciesIndex * 2][blockID]; - - speciesIncludedCounts[speciesIndex * 2 + 1][blockID] = Booleans.countTrue(getMapOfBlockIdToIncludedPeakData().get(blockID)[speciesIndex]); - speciesIncludedCounts[speciesIndex * 2 + 1][0] += speciesIncludedCounts[speciesIndex * 2 + 1][blockID]; + int[][] speciesIncludedCounts = new int[0][0]; + if (analysisMethod != null) { + int speciesCount = analysisMethod.getSpeciesList().size(); + int blockCount = massSpecExtractedData.getBlocksData().size(); + // 2 rows per species: 0 = total; 1 = included; column 0 is for totals + speciesIncludedCounts = new int[2 * speciesCount][blockCount + 1]; + for (int blockID = 1; blockID <= blockCount; blockID++) { + for (int speciesIndex = 0; speciesIndex < speciesCount; speciesIndex++) { + speciesIncludedCounts[speciesIndex * 2][blockID] = mapOfBlockIdToIncludedPeakData.get(blockID)[speciesIndex].length; + speciesIncludedCounts[speciesIndex * 2][0] += speciesIncludedCounts[speciesIndex * 2][blockID]; + + speciesIncludedCounts[speciesIndex * 2 + 1][blockID] = Booleans.countTrue(mapOfBlockIdToIncludedPeakData.get(blockID)[speciesIndex]); + speciesIncludedCounts[speciesIndex * 2 + 1][0] += speciesIncludedCounts[speciesIndex * 2 + 1][blockID]; + } } } return speciesIncludedCounts; } + public void analysisRatioEngine() { + Map> mapRatioToAnalysisLogRatioRecords = new TreeMap<>(); + Iterator> iterator = mapOfBlockIdToPlots.entrySet().iterator(); + while (iterator.hasNext()) { + Map.Entry entry = iterator.next(); + if (SHOW == mapOfBlockIdToProcessStatus.get(entry.getKey())) { + PlotBuilder[] ratiosPlotBuilder = entry.getValue()[PLOT_INDEX_RATIOS]; + for (PlotBuilder ratioPlotBuilder : ratiosPlotBuilder) { + IsotopicRatio ratio = ((RatioHistogramBuilder) ratioPlotBuilder).getRatio(); + if (ratioPlotBuilder.isDisplayed()) { + String ratioName = ratioPlotBuilder.getTitle()[0]; + mapRatioToAnalysisLogRatioRecords.computeIfAbsent(ratio, k -> new ArrayList<>()); + boolean useInvertedRatio = analysisMethod.getMapOfRatioNamesToInvertedFlag().get(ratioName); + mapRatioToAnalysisLogRatioRecords.get(ratio).add( + useInvertedRatio ? + ((RatioHistogramBuilder) ratioPlotBuilder).getInvertedLogRatioHistogramRecord() + : ((RatioHistogramBuilder) ratioPlotBuilder).getLogRatioHistogramRecord()); + + AnalysisRatioPlotBuilder analysisRatioPlotBuilder = initializeAnalysisRatioPlotBuilder( + mapOfBlockIdToProcessStatus.size(), ratio, mapRatioToAnalysisLogRatioRecords.get(ratio), mapRatioToAnalysisLogRatioRecords.get(ratio).get(0).title(), "Block ID", "Ratio"); + AnalysisRatioRecord analysisRatioRecord = analysisRatioPlotBuilder.getAnalysisRatioRecord(); + mapOfRatioToAnalysisRatioRecord.put(ratio, analysisRatioRecord); + } + } + } + } + } + public final String produceReportTemplateOne() { + StringBuilder sb = new StringBuilder(); sb.append(massSpecExtractedData.printHeader()); @@ -467,23 +508,39 @@ public final String produceReportTemplateOne() { int speciesIndex = 0; int[][] calculatedSpeciesIncludedCounts = calculateSpeciesIncludedCounts(); for (SpeciesRecordInterface species : analysisMethod.getSpeciesList()) { - sb.append("intensity " + species.prettyPrintShortForm() + " (cps)" + "," - + analysisSpeciesStats[speciesIndex].getMean() + "," - + analysisSpeciesStats[speciesIndex].getStandardDeviation() + "," - + calculatedSpeciesIncludedCounts[speciesIndex * 2 + 1][0] + "," - + calculatedSpeciesIncludedCounts[speciesIndex * 2 + 0][0] + "\n"); - + if ((analysisSpeciesStats.length > speciesIndex) && (analysisSpeciesStats[speciesIndex] != null)) { + sb.append("intensity " + species.prettyPrintShortForm() + " (cps)" + "," + + analysisSpeciesStats[speciesIndex].getMean() + "," + + analysisSpeciesStats[speciesIndex].getStandardDeviation() + "," + + calculatedSpeciesIncludedCounts[speciesIndex * 2 + 1][0] + "," + + calculatedSpeciesIncludedCounts[speciesIndex * 2][0] + "\n"); + } speciesIndex++; } + for (IsotopicRatio ratio : analysisMethod.getIsotopicRatiosList()) { - sb.append(ratio.prettyPrint() + "," - + ratio.getAnalysisMean() + "," - + ratio.getAnalysisOneSigmaAbs() + ", , \n"); + AnalysisRatioRecord analysisRatioRecord = mapOfRatioToAnalysisRatioRecord.get(ratio); + if (null != analysisRatioRecord) { + sb.append(ratio.prettyPrint() + "," + + analysisRatioRecord.weightedMeanRecord().ratioWeightedMean() + "," + + analysisRatioRecord.weightedMeanRecord().ratioHigherOneSigmaAbs() + + ", , \n"); + } + } + for (IsotopicRatio ratio : analysisMethod.getDerivedIsotopicRatiosList()) { + AnalysisRatioRecord analysisRatioRecord = mapOfRatioToAnalysisRatioRecord.get(ratio); + if (null != analysisRatioRecord) { + sb.append(ratio.prettyPrint() + "," + + analysisRatioRecord.weightedMeanRecord().ratioWeightedMean() + "," + + analysisRatioRecord.weightedMeanRecord().ratioHigherOneSigmaAbs() + + ", , \n"); + } } sb.append("D/F Gain" + "," - + analysisMethod.getIsotopicRatiosList().get(0).getAnalysisDalyFaradayGainMean() + "," - + analysisMethod.getIsotopicRatiosList().get(0).getAnalysisDalyFaradayGainOneSigmaAbs() + ", , \n"); + + analysisDalyFaradayGainMean + "," + + analysisDalyFaradayGainMeanOneSigmaAbs + + ", , \n"); return sb.toString(); } @@ -596,4 +653,16 @@ public Map getMapOfBlockIdToFinalModel() { public Map getMapOfBlockIdToIncludedPeakData() { return mapOfBlockIdToIncludedPeakData; } + + public Map getMapOfRatioToAnalysisRatioRecord() { + return mapOfRatioToAnalysisRatioRecord; + } + + public void setAnalysisDalyFaradayGainMean(double analysisDalyFaradayGainMean) { + this.analysisDalyFaradayGainMean = analysisDalyFaradayGainMean; + } + + public void setAnalysisDalyFaradayGainMeanOneSigmaAbs(double analysisDalyFaradayGainMeanOneSigmaAbs) { + this.analysisDalyFaradayGainMeanOneSigmaAbs = analysisDalyFaradayGainMeanOneSigmaAbs; + } } \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/AnalysisInterface.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/AnalysisInterface.java index 7b8fd249..26daf469 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/AnalysisInterface.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/AnalysisInterface.java @@ -3,10 +3,10 @@ import jakarta.xml.bind.JAXBException; import org.cirdles.tripoli.constants.MassSpectrometerContextEnum; import org.cirdles.tripoli.plots.PlotBuilder; -import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.AllBlockInitForOGTripoli; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.EnsemblesStore; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelRecord; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockRawDataSetRecord; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.AllBlockInitForOGTripoli; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataSourceProcessors.MassSpecExtractedData; import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethod; import org.cirdles.tripoli.utilities.callbacks.LoggingCallbackInterface; diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/BlockEnsemblesPlotter.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/BlockEnsemblesPlotter.java index 39ba38e5..acc57695 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/BlockEnsemblesPlotter.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/BlockEnsemblesPlotter.java @@ -48,14 +48,14 @@ public synchronized static void blockEnsemblePlotEngine( AnalysisInterface analysis) { PlotBuilder[][] plotBuilders = analysis.getMapOfBlockIdToPlots().get(blockID); - int initialModelsBurnCount = ((Analysis) analysis).getMapOfBlockIdToModelsBurnCount().get(blockID); + int initialModelsBurnCount = analysis.getMapOfBlockIdToModelsBurnCount().get(blockID).intValue(); - List ensembleRecordsList = ((Analysis) analysis).getMapBlockIDToEnsembles().get(blockID); + List ensembleRecordsList = analysis.getMapBlockIDToEnsembles().get(blockID); int countOfEnsemblesUsed = ensembleRecordsList.size() - initialModelsBurnCount; AnalysisMethod analysisMethod = analysis.getAnalysisMethod(); SingleBlockRawDataSetRecord singleBlockRawDataSetRecord = analysis.getMapOfBlockIdToRawData().get(blockID); - List isotopicRatioList = analysisMethod.getIsotopicRatiosList(); + List blockIsotopicRatioList = analysisMethod.getCloneOfIsotopicRatiosList(); /* %% Analysis and Plotting @@ -79,29 +79,22 @@ public synchronized static void blockEnsemblePlotEngine( */ // log ratios - double[][] ensembleSetOfLogRatios = new double[isotopicRatioList.size()][countOfEnsemblesUsed]; - double[][] ensembleRatios = new double[isotopicRatioList.size()][countOfEnsemblesUsed]; - double[] logRatioMean = new double[isotopicRatioList.size()]; - double[] logRatioStdDev = new double[isotopicRatioList.size()]; - DescriptiveStatistics descriptiveStatisticsLogRatios = new DescriptiveStatistics(); - for (int ratioIndex = 0; ratioIndex < isotopicRatioList.size(); ratioIndex++) { + double[][] ensembleSetOfLogRatios = new double[blockIsotopicRatioList.size()][countOfEnsemblesUsed]; + double[][] ensembleSetOfRatios = new double[blockIsotopicRatioList.size()][countOfEnsemblesUsed]; + for (int ratioIndex = 0; ratioIndex < blockIsotopicRatioList.size(); ratioIndex++) { for (int index = initialModelsBurnCount; index < countOfEnsemblesUsed + initialModelsBurnCount; index++) { ensembleSetOfLogRatios[ratioIndex][index - initialModelsBurnCount] = ensembleRecordsList.get(index).logRatios()[ratioIndex]; - descriptiveStatisticsLogRatios.addValue(ensembleSetOfLogRatios[ratioIndex][index - initialModelsBurnCount]); - ensembleRatios[ratioIndex][index - initialModelsBurnCount] = exp(ensembleSetOfLogRatios[ratioIndex][index - initialModelsBurnCount]); + ensembleSetOfRatios[ratioIndex][index - initialModelsBurnCount] = exp(ensembleSetOfLogRatios[ratioIndex][index - initialModelsBurnCount]); } - logRatioMean[ratioIndex] = descriptiveStatisticsLogRatios.getMean(); - logRatioStdDev[ratioIndex] = descriptiveStatisticsLogRatios.getStandardDeviation(); - - isotopicRatioList.get(ratioIndex).setRatioValuesForBlockEnsembles(ensembleRatios[ratioIndex]); - isotopicRatioList.get(ratioIndex).setLogRatioValuesForBlockEnsembles(ensembleSetOfLogRatios[ratioIndex]); + blockIsotopicRatioList.get(ratioIndex).setRatioValuesForBlockEnsembles(ensembleSetOfRatios[ratioIndex]); + blockIsotopicRatioList.get(ratioIndex).setLogRatioValuesForBlockEnsembles(ensembleSetOfLogRatios[ratioIndex]); } // derived ratios - List derivedIsotopicRatiosList = analysisMethod.getDerivedIsotopicRatiosList(); + List derivedIsotopicRatiosList = analysisMethod.getCloneOfDerivedIsotopicRatiosList(); int countOfDerivedRatios = derivedIsotopicRatiosList.size(); - double[][] derivedEnsembleRatios = new double[countOfDerivedRatios][countOfEnsemblesUsed]; - double[][] derivedEnsembleLogRatios = new double[countOfDerivedRatios][countOfEnsemblesUsed]; + double[][] derivedEnsembleSetOfRatios = new double[countOfDerivedRatios][countOfEnsemblesUsed]; + double[][] derivedEnsembleSetOfLogRatios = new double[countOfDerivedRatios][countOfEnsemblesUsed]; int derivedRatioIndex = 0; // derive the ratios for (IsotopicRatio isotopicRatio : derivedIsotopicRatiosList) { @@ -110,32 +103,32 @@ public synchronized static void blockEnsemblePlotEngine( SpeciesRecordInterface highestAbundanceSpecies = analysisMethod.retrieveHighestAbundanceSpecies(); if (numerator != highestAbundanceSpecies) { IsotopicRatio numeratorRatio = new IsotopicRatio(numerator, highestAbundanceSpecies, false); - int indexNumeratorRatio = isotopicRatioList.indexOf(numeratorRatio); + int indexNumeratorRatio = blockIsotopicRatioList.indexOf(numeratorRatio); IsotopicRatio denominatorRatio = new IsotopicRatio(denominator, highestAbundanceSpecies, false); - int indexDenominatorRatio = isotopicRatioList.indexOf(denominatorRatio); - for (int ensembleIndex = 0; ensembleIndex < countOfEnsemblesUsed; ensembleIndex++) { - derivedEnsembleRatios[derivedRatioIndex][ensembleIndex] = - ensembleRatios[indexNumeratorRatio][ensembleIndex] / ensembleRatios[indexDenominatorRatio][ensembleIndex]; - derivedEnsembleLogRatios[derivedRatioIndex][ensembleIndex] = - StrictMath.log(derivedEnsembleRatios[derivedRatioIndex][ensembleIndex]); + int indexDenominatorRatio = blockIsotopicRatioList.indexOf(denominatorRatio); + for (int ensembleIndex = initialModelsBurnCount; ensembleIndex < countOfEnsemblesUsed + initialModelsBurnCount; ensembleIndex++) { + derivedEnsembleSetOfLogRatios[derivedRatioIndex][ensembleIndex - initialModelsBurnCount] = + ensembleSetOfLogRatios[indexNumeratorRatio][ensembleIndex - initialModelsBurnCount] - ensembleSetOfLogRatios[indexDenominatorRatio][ensembleIndex - initialModelsBurnCount]; + derivedEnsembleSetOfRatios[derivedRatioIndex][ensembleIndex - initialModelsBurnCount] = + exp(derivedEnsembleSetOfLogRatios[derivedRatioIndex][ensembleIndex - initialModelsBurnCount]); } } else { // assume we are dealing with the inverses of isotopicRatiosList IsotopicRatio targetRatio = new IsotopicRatio(denominator, highestAbundanceSpecies, false); - int indexOfTargetRatio = isotopicRatioList.indexOf(targetRatio); - for (int ensembleIndex = 0; ensembleIndex < countOfEnsemblesUsed; ensembleIndex++) { - derivedEnsembleRatios[derivedRatioIndex][ensembleIndex] = - 1.0 / ensembleRatios[indexOfTargetRatio][ensembleIndex]; - derivedEnsembleLogRatios[derivedRatioIndex][ensembleIndex] = - StrictMath.log(derivedEnsembleRatios[derivedRatioIndex][ensembleIndex]); + int indexOfTargetRatio = blockIsotopicRatioList.indexOf(targetRatio); + for (int ensembleIndex = initialModelsBurnCount; ensembleIndex < countOfEnsemblesUsed + initialModelsBurnCount; ensembleIndex++) { + derivedEnsembleSetOfLogRatios[derivedRatioIndex][ensembleIndex - initialModelsBurnCount] = + -(ensembleSetOfLogRatios[indexOfTargetRatio][ensembleIndex - initialModelsBurnCount]); + derivedEnsembleSetOfRatios[derivedRatioIndex][ensembleIndex - initialModelsBurnCount] = + exp(derivedEnsembleSetOfLogRatios[derivedRatioIndex][ensembleIndex - initialModelsBurnCount]); } } - derivedIsotopicRatiosList.get(derivedRatioIndex).setRatioValuesForBlockEnsembles(derivedEnsembleRatios[derivedRatioIndex]); - derivedIsotopicRatiosList.get(derivedRatioIndex).setLogRatioValuesForBlockEnsembles(derivedEnsembleLogRatios[derivedRatioIndex]); + derivedIsotopicRatiosList.get(derivedRatioIndex).setRatioValuesForBlockEnsembles(derivedEnsembleSetOfRatios[derivedRatioIndex]); + derivedIsotopicRatiosList.get(derivedRatioIndex).setLogRatioValuesForBlockEnsembles(derivedEnsembleSetOfLogRatios[derivedRatioIndex]); + derivedRatioIndex++; } - // baseLines int baselineSize = analysisMethod.getSequenceTable().findFaradayDetectorsUsed().size(); double[][] ensembleBaselines = new double[baselineSize][countOfEnsemblesUsed]; @@ -157,6 +150,8 @@ public synchronized static void blockEnsemblePlotEngine( descriptiveStatisticsDalyFaradayGain.addValue(ensembleDalyFaradayGain[index - initialModelsBurnCount]); } double dalyFaradayGainMean = descriptiveStatisticsDalyFaradayGain.getMean(); + ((Analysis) analysis).setAnalysisDalyFaradayGainMean(dalyFaradayGainMean); + ((Analysis) analysis).setAnalysisDalyFaradayGainMeanOneSigmaAbs(descriptiveStatisticsDalyFaradayGain.getStandardDeviation()); /* for m=1:d0.Nblock @@ -212,18 +207,18 @@ public synchronized static void blockEnsemblePlotEngine( // visualization - Ensembles tab BiMap biMapOfRatiosAndInverses = analysisMethod.getBiMapOfRatiosAndInverses(); - plotBuilders[PLOT_INDEX_RATIOS] = new PlotBuilder[ensembleRatios.length + derivedEnsembleRatios.length]; - for (int i = 0; i < ensembleRatios.length; i++) { + plotBuilders[PLOT_INDEX_RATIOS] = new PlotBuilder[ensembleSetOfRatios.length + derivedEnsembleSetOfRatios.length]; + for (int i = 0; i < ensembleSetOfRatios.length; i++) { plotBuilders[PLOT_INDEX_RATIOS][i] = RatioHistogramBuilder.initializeRatioHistogram( blockID, - isotopicRatioList.get(i), - biMapOfRatiosAndInverses.get(isotopicRatioList.get(i)), + blockIsotopicRatioList.get(i), + biMapOfRatiosAndInverses.get(blockIsotopicRatioList.get(i)), 25); - analysisMethod.getMapOfRatioNamesToInvertedFlag().put(isotopicRatioList.get(i).prettyPrint(), false); + analysisMethod.getMapOfRatioNamesToInvertedFlag().put(blockIsotopicRatioList.get(i).prettyPrint(), false); } - for (int i = 0; i < derivedEnsembleRatios.length; i++) { - plotBuilders[PLOT_INDEX_RATIOS][i + ensembleRatios.length] = + for (int i = 0; i < derivedEnsembleSetOfRatios.length; i++) { + plotBuilders[PLOT_INDEX_RATIOS][i + ensembleSetOfRatios.length] = RatioHistogramBuilder.initializeRatioHistogram( blockID, derivedIsotopicRatiosList.get(i), diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/EnsemblesStore.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/EnsemblesStore.java index 91eb88eb..b404ea38 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/EnsemblesStore.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/EnsemblesStore.java @@ -20,13 +20,14 @@ import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import org.cirdles.tripoli.sessions.analysis.Analysis; import org.cirdles.tripoli.sessions.analysis.AnalysisInterface; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.SingleBlockModelInitForMCMC; import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethod; import org.cirdles.tripoli.species.IsotopicRatio; import java.io.Serializable; import java.util.*; -import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelInitForMCMC.modelInitData; +import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.SingleBlockModelInitForMCMC.modelInitData; /** * @author James F. Bowring diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/MCMCProcess.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/MCMCProcess.java index 5d8c3947..0fa04746 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/MCMCProcess.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/MCMCProcess.java @@ -22,6 +22,7 @@ import org.apache.commons.math3.random.RandomDataGenerator; import org.cirdles.tripoli.plots.PlotBuilder; import org.cirdles.tripoli.sessions.analysis.AnalysisInterface; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.SingleBlockModelInitForMCMC; import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethod; import org.cirdles.tripoli.utilities.callbacks.LoggingCallbackInterface; import org.cirdles.tripoli.utilities.mathUtilities.MatLabCholesky; @@ -36,7 +37,7 @@ import static java.lang.Math.pow; import static java.lang.StrictMath.exp; import static org.apache.commons.math3.special.Gamma.gamma; -import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelInitForMCMC.modelInitData; +import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.SingleBlockModelInitForMCMC.modelInitData; /** * @author James F. Bowring diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/ProposedModelParameters.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/ProposedModelParameters.java index c6ed2081..0c5e4ee2 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/ProposedModelParameters.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/ProposedModelParameters.java @@ -69,7 +69,7 @@ public static ProposalRangesRecord buildProposalRangesRecord(double[] blockInten ); } - record ProposalRangesRecord( + public record ProposalRangesRecord( double[][] priorBaselineFaraday, double[][] priorBaselineDaly, double[][] priorLogRatio, diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/SingleBlockModelDriver.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/SingleBlockModelDriver.java index c77355ff..66d11b9f 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/SingleBlockModelDriver.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/SingleBlockModelDriver.java @@ -19,6 +19,7 @@ import com.google.common.primitives.Doubles; import org.cirdles.tripoli.plots.PlotBuilder; import org.cirdles.tripoli.sessions.analysis.AnalysisInterface; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.SingleBlockModelInitForMCMC; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataSourceProcessors.MassSpecExtractedData; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataSourceProcessors.MassSpecOutputSingleBlockRecord; import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethod; @@ -33,7 +34,7 @@ import java.io.IOException; import java.util.*; -import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelInitForMCMC.initializeModelForSingleBlockMCMC; +import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.SingleBlockModelInitForMCMC.initializeModelForSingleBlockMCMC; /** * @author James F. Bowring @@ -63,7 +64,7 @@ public static PlotBuilder[][] buildAndRunModelForSingleBlock(int blockID, Analys return plotBuilder; } - static SingleBlockRawDataSetRecord prepareSingleBlockDataForMCMC(int blockNumber, MassSpecExtractedData massSpecExtractedData, AnalysisMethod analysisMethod) { + public static SingleBlockRawDataSetRecord prepareSingleBlockDataForMCMC(int blockNumber, MassSpecExtractedData massSpecExtractedData, AnalysisMethod analysisMethod) { SingleBlockRawDataSetRecord singleBlockRawDataSetRecord = null; MassSpecOutputSingleBlockRecord massSpecOutputSingleBlockRecord = massSpecExtractedData.getBlocksData().get(blockNumber); if (massSpecOutputSingleBlockRecord != null) { diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/AllBlockInitForOGTripoli.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/initializers/AllBlockInitForOGTripoli.java similarity index 89% rename from TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/AllBlockInitForOGTripoli.java rename to TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/initializers/AllBlockInitForOGTripoli.java index 371c6537..05b9dd12 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/AllBlockInitForOGTripoli.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/initializers/AllBlockInitForOGTripoli.java @@ -14,16 +14,18 @@ * limitations under the License. */ -package org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc; +package org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers; import org.cirdles.tripoli.sessions.analysis.AnalysisInterface; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelRecord; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockRawDataSetRecord; import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataSourceProcessors.MassSpecExtractedData; import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethod; import org.cirdles.tripoli.utilities.exceptions.TripoliException; import org.ojalgo.RecoverableCondition; import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelDriver.prepareSingleBlockDataForMCMC; -import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelInitForMCMC.initializeModelForSingleBlockMCMC; +import static org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers.SingleBlockModelInitForMCMC.initializeModelForSingleBlockMCMC; /** * @author James F. Bowring diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/SingleBlockModelInitForMCMC.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/initializers/SingleBlockModelInitForMCMC.java similarity index 98% rename from TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/SingleBlockModelInitForMCMC.java rename to TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/initializers/SingleBlockModelInitForMCMC.java index 6a53f1e7..f3ea2d1d 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/SingleBlockModelInitForMCMC.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/massSpectrometerModels/dataModels/mcmc/initializers/SingleBlockModelInitForMCMC.java @@ -14,13 +14,16 @@ * limitations under the License. */ -package org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc; +package org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.initializers; import jama.Matrix; import org.apache.commons.math3.linear.*; import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import org.cirdles.tripoli.sessions.analysis.Analysis; import org.cirdles.tripoli.sessions.analysis.AnalysisInterface; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.ProposedModelParameters; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockModelRecord; +import org.cirdles.tripoli.sessions.analysis.massSpectrometerModels.dataModels.mcmc.SingleBlockRawDataSetRecord; import org.cirdles.tripoli.sessions.analysis.methods.AnalysisMethod; import org.cirdles.tripoli.species.IsotopicRatio; import org.cirdles.tripoli.utilities.mathUtilities.MatLab; @@ -35,10 +38,10 @@ /** * @author James F. Bowring */ -enum SingleBlockModelInitForMCMC { +public enum SingleBlockModelInitForMCMC { ; - static SingleBlockModelRecordWithCov initializeModelForSingleBlockMCMC( + public static SingleBlockModelRecordWithCov initializeModelForSingleBlockMCMC( AnalysisInterface analysis, AnalysisMethod analysisMethod, SingleBlockRawDataSetRecord singleBlockRawDataSetRecord, boolean provideCovariance) throws RecoverableCondition { int baselineCount = singleBlockRawDataSetRecord.baselineDataSetMCMC().intensityAccumulatorList().size(); @@ -47,6 +50,12 @@ static SingleBlockModelRecordWithCov initializeModelForSingleBlockMCMC( int totalIntensityCount = baselineCount + onPeakFaradayCount + onPeakPhotoMultCount; int countOfIsotopes = analysisMethod.getSpeciesList().size(); + // TODO:Fix this per Noah + // NOTE: the speciesList has been sorted by increasing abundances in the original analysisMethod setup + // the ratios are between each species and the most abundant species, with one less ratio than species count + int indexOfMostAbundantIsotope = countOfIsotopes - 1; + int iden = indexOfMostAbundantIsotope + 1; // ordinal + // Baseline statistics ***************************************************************************************** /* for m=1:d0.Nfar%+1 @@ -83,15 +92,9 @@ static SingleBlockModelRecordWithCov initializeModelForSingleBlockMCMC( double meanOfBaseLineMeansStdDev = meanOfBaseLineMeansStdDevDescriptiveStatistics.getMean(); - // TODO:Fix this per Noah - // NOTE: the speciesList has been sorted by increasing abundances in the original analysisMethod setup - // the ratios are between each species and the most abundant species, with one less ratio than species count - int indexOfMostAbundantIsotope = countOfIsotopes - 1; // june 2023 new init line 14 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ // june 2023 new init - will need to be user input - int iden = indexOfMostAbundantIsotope + 1; // ordinal - //TODO: Fix this when using bbase //TODO: handle case of only 2 cycles, which blows up calculateDFGain since it thrwos out first and last double detectorFaradayGain = 0.9; diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/methods/AnalysisMethod.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/methods/AnalysisMethod.java index ae01efd1..76001118 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/methods/AnalysisMethod.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/methods/AnalysisMethod.java @@ -314,10 +314,26 @@ public List getIsotopicRatiosList() { return isotopicRatiosList; } + public List getCloneOfIsotopicRatiosList() { + List cloneOfIsotopicRatios = new ArrayList<>(); + for (IsotopicRatio ir : isotopicRatiosList) { + cloneOfIsotopicRatios.add(new IsotopicRatio(ir.getNumerator(), ir.getDenominator(), ir.isDisplayed())); + } + return cloneOfIsotopicRatios; + } + public List getDerivedIsotopicRatiosList() { return derivedIsotopicRatiosList; } + public List getCloneOfDerivedIsotopicRatiosList() { + List cloneOfDerivedIsotopicRatios = new ArrayList<>(); + for (IsotopicRatio ir : derivedIsotopicRatiosList) { + cloneOfDerivedIsotopicRatios.add(new IsotopicRatio(ir.getNumerator(), ir.getDenominator(), ir.isDisplayed())); + } + return cloneOfDerivedIsotopicRatios; + } + public BiMap getBiMapOfRatiosAndInverses() { return biMapOfRatiosAndInverses; } diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/package-info.java b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/package-info.java new file mode 100644 index 00000000..a3c9b67a --- /dev/null +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/sessions/analysis/package-info.java @@ -0,0 +1 @@ +package org.cirdles.tripoli.sessions.analysis; \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/species/IsotopicRatio.java b/TripoliCore/src/main/java/org/cirdles/tripoli/species/IsotopicRatio.java index 133b00f1..bf8d7d3e 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/species/IsotopicRatio.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/species/IsotopicRatio.java @@ -30,10 +30,6 @@ public class IsotopicRatio implements Serializable, Comparable { private static final long serialVersionUID = 676151940943728743L; private final SpeciesRecordInterface numerator; private final SpeciesRecordInterface denominator; - private double analysisMean = 0.0; - private double analysisOneSigmaAbs = 0.0; - private double analysisDalyFaradayGainMean = 0.0; - private double analysisDalyFaradayGainOneSigmaAbs = 0.0; private double[] ratioValuesForBlockEnsembles; private double[] logRatioValuesForBlockEnsembles; private boolean displayed; @@ -112,38 +108,6 @@ public void setLogRatioValuesForBlockEnsembles(double[] logRatioValuesForBlockEn this.logRatioValuesForBlockEnsembles = logRatioValuesForBlockEnsembles; } - public double getAnalysisMean() { - return analysisMean; - } - - public void setAnalysisMean(double analysisMean) { - this.analysisMean = analysisMean; - } - - public double getAnalysisOneSigmaAbs() { - return analysisOneSigmaAbs; - } - - public void setAnalysisOneSigmaAbs(double analysisOneSigmaAbs) { - this.analysisOneSigmaAbs = analysisOneSigmaAbs; - } - - public double getAnalysisDalyFaradayGainMean() { - return analysisDalyFaradayGainMean; - } - - public void setAnalysisDalyFaradayGainMean(double analysisDalyFaradayGainMean) { - this.analysisDalyFaradayGainMean = analysisDalyFaradayGainMean; - } - - public double getAnalysisDalyFaradayGainOneSigmaAbs() { - return analysisDalyFaradayGainOneSigmaAbs; - } - - public void setAnalysisDalyFaradayGainOneSigmaAbs(double analysisDalyFaradayGainOneSigmaAbs) { - this.analysisDalyFaradayGainOneSigmaAbs = analysisDalyFaradayGainOneSigmaAbs; - } - // private void readObject(ObjectInputStream stream) throws IOException, // ClassNotFoundException { // stream.defaultReadObject(); diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/species/SpeciesRecordInterface.java b/TripoliCore/src/main/java/org/cirdles/tripoli/species/SpeciesRecordInterface.java index 8d0e96f1..09abf16b 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/species/SpeciesRecordInterface.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/species/SpeciesRecordInterface.java @@ -30,4 +30,6 @@ public interface SpeciesRecordInterface { public int compareTo(@NotNull Object o); String prettyPrintShortForm(); + + } \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/utilities/mathUtilities/weightedMeans/WeighteMeanOfLogRatio.java b/TripoliCore/src/main/java/org/cirdles/tripoli/utilities/mathUtilities/weightedMeans/WeighteMeanOfLogRatio.java new file mode 100644 index 00000000..e0d3c444 --- /dev/null +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/utilities/mathUtilities/weightedMeans/WeighteMeanOfLogRatio.java @@ -0,0 +1,100 @@ +/* + * Copyright 2022 James Bowring, Noah McLean, Scott Burdick, and CIRDLES.org. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.cirdles.tripoli.utilities.mathUtilities.weightedMeans; + + +import jama.Matrix; +import org.apache.commons.math3.linear.BlockRealMatrix; +import org.apache.commons.math3.linear.DecompositionSolver; +import org.apache.commons.math3.linear.QRDecomposition; +import org.apache.commons.math3.linear.RealMatrix; + +import java.io.Serializable; +import java.util.Arrays; + +/** + * @author James F. Bowring + */ +public class WeighteMeanOfLogRatio { + + + /** + * see https://github.com/CIRDLES/Tripoli/issues/185 + * + * @param logRatioMeans + * @param logRatioCoVariances + */ + public static WeightedMeanRecord calculateWeightedMean(double[] logRatioMeans, double[][] logRatioCoVariances) { + + RealMatrix logRatioVariancesRealMatrix = new BlockRealMatrix(logRatioCoVariances); + DecompositionSolver solver = new QRDecomposition(logRatioVariancesRealMatrix).getSolver(); + RealMatrix inverse = solver.getInverse(); + double[][] invertedLogRatioVariances = inverse.getData(); + + int countOfElements = logRatioMeans.length; + Matrix logRatioMeansMatrix = new Matrix(logRatioMeans, countOfElements); + double[] ones = new double[countOfElements]; + Arrays.fill(ones, 1); + Matrix onesMatrix = new Matrix(ones, countOfElements); + Matrix invertedLogRatioVariancesMatrix = new Matrix(invertedLogRatioVariances); + + double logRatioWeightedMean = + onesMatrix.transpose().times(invertedLogRatioVariancesMatrix).times(logRatioMeansMatrix).get(0, 0) + / onesMatrix.transpose().times(invertedLogRatioVariancesMatrix).times(onesMatrix).get(0, 0); + + double logRatioOneSigmaAbs = Math.sqrt(1.0 / onesMatrix.transpose().times(invertedLogRatioVariancesMatrix).times(onesMatrix).get(0, 0)); + + Matrix residualsMatrix = (Matrix) logRatioMeansMatrix.clone(); + for (int i = 0; i < countOfElements; i++) { + residualsMatrix.set(i, 0, residualsMatrix.get(i, 0) - logRatioWeightedMean); + } + + double logRatioReducedChiSquareStatistic = residualsMatrix.transpose().times(invertedLogRatioVariancesMatrix).times(residualsMatrix).get(0, 0) / (countOfElements - 1); + + /* + That means you'll be using a calculated mean and 1-sigma uncertainty of a log-ratio. To calculate the ratio, just exponentiate. + To get the uncertainty, you'll want to calculate the log-mean minus one sigma and the log-mean plus one sigma. + Exponentiate both of those limits, then use them to calculate a -1sigma and +1sigma uncertainty for the ratio mean. + If the -1sigma and +1sigma are within some tolerance (we used two significant figures), then report them together as ± X. + If they're different outside that tolerance, then report them separately as +Y/-Z. + */ + + double ratioWeightedMean = StrictMath.exp(logRatioWeightedMean); + double ratioHigherOneSigmaAbs = StrictMath.exp(logRatioWeightedMean + logRatioOneSigmaAbs) - ratioWeightedMean; + double ratioLowerOneSigmaAbs = ratioWeightedMean - StrictMath.exp(logRatioWeightedMean - logRatioOneSigmaAbs); + + return new WeightedMeanRecord( + logRatioWeightedMean, + logRatioOneSigmaAbs, + logRatioReducedChiSquareStatistic, + ratioWeightedMean, + ratioHigherOneSigmaAbs, + ratioLowerOneSigmaAbs + ); + } + + public record WeightedMeanRecord( + double logRatioWeightedMean, + double logRatioOneSigmaAbs, + double logRatioReducedChiSquareStatistic, + double ratioWeightedMean, + double ratioHigherOneSigmaAbs, + double ratioLowerOneSigmaAbs + ) implements Serializable { + } + +} \ No newline at end of file diff --git a/TripoliCore/src/main/java/org/cirdles/tripoli/utilities/stateUtilities/TripoliSerializer.java b/TripoliCore/src/main/java/org/cirdles/tripoli/utilities/stateUtilities/TripoliSerializer.java index e99ecb6f..6bcd34b5 100644 --- a/TripoliCore/src/main/java/org/cirdles/tripoli/utilities/stateUtilities/TripoliSerializer.java +++ b/TripoliCore/src/main/java/org/cirdles/tripoli/utilities/stateUtilities/TripoliSerializer.java @@ -43,7 +43,7 @@ public static void serializeObjectToFile(Object serializableObject, String fileN objectOutputStream.writeObject(serializableObject); } catch (IOException ex) { throw new TripoliException("Cannot serialize object of " + serializableObject.getClass().getSimpleName() + " to: " + fileName - + "\n\nbecause: " + ex.getMessage()); + + "\n\nbecause: \n" + ex.getMessage()); } finally { if (null != objectOutputStream) { diff --git a/buildSrc/src/main/kotlin/common-build.gradle.kts b/buildSrc/src/main/kotlin/common-build.gradle.kts index d1996ab8..51818629 100644 --- a/buildSrc/src/main/kotlin/common-build.gradle.kts +++ b/buildSrc/src/main/kotlin/common-build.gradle.kts @@ -50,7 +50,7 @@ dependencies { val mavenArtifactId = name val mavenGroupId = "org.cirdles" // preserve double quotes in mavenVersion as Tripoli uses regex based on them to check on latest version -val mavenVersion = "0.3.7"//6 Nov 2023 +val mavenVersion = "0.3.8"//11 Nov 2023 object Versions { const val junitVersion = "5.8.2"