Search in sources :

Example 6 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class NonGUIFRAPTest method dumpSpatialResults.

public static void dumpSpatialResults(SpatialAnalysisResults spatialAnalysisResults, double[] frapDataTimeStamps, File outputFile) throws Exception {
    FileWriter fw = new FileWriter(outputFile);
    // FileOutputStream fos = new FileOutputStream(outputFile);
    // BufferedOutputStream bos = new BufferedOutputStream(fos);
    ReferenceData[] referenceDataArr = spatialAnalysisResults.createReferenceDataForAllDiffusionRates(frapDataTimeStamps);
    ODESolverResultSet[] odeSolverResultSetArr = spatialAnalysisResults.createODESolverResultSetForAllDiffusionRates();
    for (int i = 0; i < spatialAnalysisResults.analysisParameters.length; i++) {
        DataSource expDataSource = new DataSource.DataSourceReferenceData("experiment", referenceDataArr[i]);
        DataSource fitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", odeSolverResultSetArr[i]);
    // MultisourcePlotListModel multisourcePlotListModel =
    // new MultisourcePlotListModel();
    // multisourcePlotListModel.setDataSources(new DataSource[] {expDataSource,fitDataSource});
    // System.out.println("AnalysisParameters = "+spatialAnalysisResults.analysisParameters[i]);
    // for (int j = 0; j < multisourcePlotListModel.getSize(); j++) {
    // DataReference dataReference = (DataReference)multisourcePlotListModel.getElementAt(j);
    // DataSource dataSource = dataReference.getDataSource();
    // for (int k = 0; k < dataSource.getNumRows(); k++) {
    // for (int k2 = 0; k2 < dataSource.getNumColumns(); k2++) {
    // System.out.print(dataSource.getRowData(k)[k2]+" ");
    // fw.write(dataSource.getRowData(k)[k2]+" ");
    // }
    // System.out.println();
    // fw.write("\n");
    // }
    // if(dataReference.getDataSource().getSource() instanceof ReferenceData){
    // ReferenceData refData = (ReferenceData)dataReference.getDataSource().getSource();
    // for (int k = 0; k < refData.getNumRows(); k++) {
    // for (int k2 = 0; k2 < refData.getNumColumns(); k2++) {
    // System.out.print(refData.getRowData(k)[k2]+" ");
    // fw.write(refData.getRowData(k)[k2]+" ");
    // }
    // System.out.println();
    // fw.write("\n");
    // }
    // }else{
    // ODESolverResultSet odeRS = (ODESolverResultSet)dataReference.getDataSource().getSource();
    // for (int k = 0; k < odeRS.getRowCount(); k++) {
    // for (int k2 = 0; k2 < odeRS.getDataColumnCount(); k2++) {
    // System.out.print(odeRS.getRow(k)[k2]+" ");
    // fw.write(odeRS.getRow(k)[k2]+" ");
    // }
    // System.out.println();
    // fw.write("\n");
    // }
    // }
    // }
    }
    fw.close();
}
Also used : ReferenceData(cbit.vcell.opt.ReferenceData) FileWriter(java.io.FileWriter) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) DataSource(cbit.vcell.modelopt.DataSource)

Example 7 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class SpatialAnalysisResults method createODESolverResultSet.

public ODESolverResultSet createODESolverResultSet(AnalysisParameters argAnalysisParameters, String argROIName, String description) {
    if (argROIName != null) {
        if (!isROITypeOK(argROIName)) {
            throw new IllegalArgumentException("couldn't find ROIType " + argROIName);
        }
    }
    int analysisParametersIndex = -1;
    for (int i = 0; i < analysisParameters.length; i++) {
        if (analysisParameters[i].equals(argAnalysisParameters)) {
            analysisParametersIndex = i;
            break;
        }
    }
    if (analysisParametersIndex == -1) {
        throw new IllegalArgumentException("couldn't find AnalysisParameteers " + analysisParametersIndex);
    }
    int numROITypes = (argROIName == null ? SpatialAnalysisResults.ORDERED_ROINAMES.length : 1);
    ODESolverResultSet fitOdeSolverResultSet = new ODESolverResultSet();
    fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
    for (int j = 0; j < numROITypes; j++) {
        String currentROIName = (argROIName == null ? SpatialAnalysisResults.ORDERED_ROINAMES[j] : argROIName);
        String name = (description == null ? /*"sim D="+diffusionRates[diffusionRateIndex]+"::"*/
        "" : description) + currentROIName;
        fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
    }
    // 
    for (int j = 0; j < shiftedSimTimes.length; j++) {
        double[] row = new double[numROITypes + 1];
        row[0] = shiftedSimTimes[j];
        fitOdeSolverResultSet.addRow(row);
    }
    // 
    for (int j = 0; j < numROITypes; j++) {
        String currentROIName = (argROIName == null ? SpatialAnalysisResults.ORDERED_ROINAMES[j] : argROIName);
        // get simulated data for this ROI
        double[] values = curveHash.get(new CurveInfo(analysisParameters[analysisParametersIndex], currentROIName));
        for (int k = 0; k < values.length; k++) {
            fitOdeSolverResultSet.setValue(k, j + 1, values[k]);
        }
    }
    return fitOdeSolverResultSet;
}
Also used : ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription)

Example 8 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class EstParams_CompareResultsDescriptor method aboutToDisplayPanel.

public void aboutToDisplayPanel() {
    FRAPStudy fStudy = frapWorkspace.getWorkingFrapStudy();
    // create Mean square error for different models under different ROIs
    // if(fStudy.getAnalysisMSESummaryData() == null)
    // {
    fStudy.createAnalysisMSESummaryData();
    // }
    // auto find best model for user if best model is not selected.
    double[][] mseSummaryData = fStudy.getAnalysisMSESummaryData();
    // for(int i =0; i<10; i++)
    // System.out.print(mseSummaryData[0][i]+"  ");
    // find best model with significance and has least error
    int bestModel = FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT;
    if (// best model is saved and there is no model selection change
    fStudy.getBestModelIndex() != null) {
        bestModel = fStudy.getBestModelIndex().intValue();
    } else // need to find the best model
    {
        // check model significance if more than one model
        if (fStudy.getSelectedModels().size() > 1) {
            if (getFrapWorkspace().getWorkingFrapStudy().getFrapOptData() != null || getFrapWorkspace().getWorkingFrapStudy().getFrapOptFunc() != null) {
                ProfileSummaryData[][] allProfileSumData = FRAPOptimizationUtils.getAllProfileSummaryData(fStudy);
                FRAPModel[] frapModels = frapWorkspace.getWorkingFrapStudy().getModels();
                int confidenceIdx = ((EstParams_CompareResultsPanel) this.getPanelComponent()).getSelectedConfidenceIndex();
                boolean[] modelSignificance = new boolean[FRAPModel.NUM_MODEL_TYPES];
                Arrays.fill(modelSignificance, true);
                if (frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null && frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF; i++) {
                        ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT][i].getConfidenceIntervals();
                        if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters()[i].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters()[i].getLowerBound()) {
                            modelSignificance[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] = false;
                            break;
                        }
                    }
                }
                if (frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] != null && frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF; i++) {
                        ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS][i].getConfidenceIntervals();
                        if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters()[i].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters()[i].getLowerBound()) {
                            modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] = false;
                            break;
                        }
                    }
                }
                if (frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] != null && frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() != null && allProfileSumData != null && allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] != null) {
                    for (int i = 0; i < FRAPModel.NUM_MODEL_PARAMETERS_REACTION_OFF_RATE; i++) {
                        if (i == FRAPModel.INDEX_BLEACH_MONITOR_RATE) {
                            ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE][FRAPModel.INDEX_BLEACH_MONITOR_RATE].getConfidenceIntervals();
                            if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getLowerBound()) {
                                modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] = false;
                                break;
                            }
                        } else if (i == FRAPModel.INDEX_OFF_RATE) {
                            ConfidenceInterval[] intervals = allProfileSumData[FRAPModel.IDX_MODEL_REACTION_OFF_RATE][FRAPModel.INDEX_OFF_RATE].getConfidenceIntervals();
                            if (intervals[confidenceIdx].getUpperBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_OFF_RATE].getUpperBound() && intervals[confidenceIdx].getLowerBound() == frapModels[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters()[FRAPModel.INDEX_OFF_RATE].getLowerBound()) {
                                modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] = false;
                                break;
                            }
                        }
                    }
                }
                // check least error model with significance
                double minError = 1E8;
                if (mseSummaryData != null) {
                    // exclude cell and bkground ROIs, include sum of error
                    int secDimLen = FRAPData.VFRAP_ROI_ENUM.values().length - 2 + 1;
                    if (modelSignificance[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] == modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] && modelSignificance[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] == modelSignificance[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS]) {
                        // if all models' significance are the same, find the least error
                        for (int i = 0; i < FRAPModel.NUM_MODEL_TYPES; i++) {
                            if ((minError > mseSummaryData[i][secDimLen - 1])) {
                                minError = mseSummaryData[i][secDimLen - 1];
                                bestModel = i;
                            }
                        }
                    } else {
                        // if models' significance are different, find the least error with significance
                        for (int i = 0; i < FRAPModel.NUM_MODEL_TYPES; i++) {
                            if (modelSignificance[i] && (minError > mseSummaryData[i][secDimLen - 1])) {
                                minError = mseSummaryData[i][secDimLen - 1];
                                bestModel = i;
                            }
                        }
                    }
                }
            }
        } else // only one model is selected and the selected model should be the best model
        {
            for (int i = 0; i < fStudy.getModels().length; i++) {
                if (fStudy.getModels()[i] != null) {
                    bestModel = i;
                    break;
                }
            }
        }
    }
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).setBestModelRadioButton(bestModel);
    // set data source to multiSourcePlotPane
    // length should be fStudy.getSelectedModels().size()+1, however, reaction binding may not have data
    ArrayList<DataSource> comparableDataSource = new ArrayList<DataSource>();
    // add exp data
    ReferenceData expReferenceData = FRAPOptimizationUtils.doubleArrayToSimpleRefData(fStudy.getDimensionReducedExpData(), fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
    final DataSource expDataSource = new DataSource.DataSourceReferenceData("exp", expReferenceData);
    comparableDataSource.add(expDataSource);
    // add opt/sim data
    // using the same loop, disable the radio button if the model is not included
    // adjust radio buttons
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).disableAllRadioButtons();
    ArrayList<Integer> selectedModelIndexes = fStudy.getSelectedModels();
    for (int i = 0; i < selectedModelIndexes.size(); i++) {
        DataSource newDataSource = null;
        double[] timePoints = fStudy.getFrapData().getImageDataset().getImageTimeStamps();
        int startingIndex = fStudy.getStartingIndexForRecovery();
        double[] truncatedTimes = new double[timePoints.length - startingIndex];
        System.arraycopy(timePoints, startingIndex, truncatedTimes, 0, truncatedTimes.length);
        if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT);
            ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, fStudy.getSelectedROIsForErrorCalculation());
            newDataSource = new DataSource.DataSourceRowColumnResultSet("opt_DF1", temSolverResultSet);
        } else if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS);
            ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, fStudy.getSelectedROIsForErrorCalculation());
            newDataSource = new DataSource.DataSourceRowColumnResultSet("opt_DF2", temSolverResultSet);
        } else if (selectedModelIndexes.get(i).equals(FRAPModel.IDX_MODEL_REACTION_OFF_RATE)) {
            // adjust radio button
            ((EstParams_CompareResultsPanel) this.getPanelComponent()).enableRadioButton(FRAPModel.IDX_MODEL_REACTION_OFF_RATE);
            FRAPModel temModel = fStudy.getFrapModel(FRAPModel.IDX_MODEL_REACTION_OFF_RATE);
            if (temModel.getData() != null) {
                ODESolverResultSet temSolverResultSet = FRAPOptimizationUtils.doubleArrayToSolverResultSet(temModel.getData(), truncatedTimes, 0, // for reaction off model, display curve under bleached region only
                FRAPStudy.createSelectedROIsForReactionOffRateModel());
                newDataSource = new DataSource.DataSourceRowColumnResultSet("sim_Koff", temSolverResultSet);
            }
        }
        if (newDataSource != null) {
            comparableDataSource.add(newDataSource);
        }
    }
    // set data to multiSourcePlotPane
    ((EstParams_CompareResultsPanel) this.getPanelComponent()).setPlotData(comparableDataSource.toArray(new DataSource[comparableDataSource.size()]));
}
Also used : ArrayList(java.util.ArrayList) FRAPModel(cbit.vcell.microscopy.FRAPModel) DataSource(cbit.vcell.modelopt.DataSource) ReferenceData(cbit.vcell.opt.ReferenceData) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ConfidenceInterval(org.vcell.optimization.ConfidenceInterval)

Example 9 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class EstParams_OneDiffComponentPanel method plotDerivedSimulationResults.

private void plotDerivedSimulationResults(AnalysisParameters[] anaParams) {
    try {
        String description = null;
        int totalROIlen = FRAPData.VFRAP_ROI_ENUM.values().length;
        boolean[] wantsROITypes = new boolean[totalROIlen];
        System.arraycopy(frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation(), 0, wantsROITypes, 0, totalROIlen);
        ODESolverResultSet fitOdeSolverResultSet = new ODESolverResultSet();
        fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        for (int j = 0; j < totalROIlen; j++) {
            if (!wantsROITypes[j]) {
                continue;
            }
            String currentROIName = FRAPData.VFRAP_ROI_ENUM.values()[j].name();
            String name = (description == null ? /*"sim D="+diffusionRates[diffusionRateIndex]+"::"*/
            "" : description) + currentROIName;
            fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
        }
        int totalWantedROIlen = 0;
        for (int i = 0; i < wantsROITypes.length; i++) {
            if (wantsROITypes[i]) {
                totalWantedROIlen++;
            }
        }
        // 
        // populate time
        // 
        double[] shiftedSimTimes = frapOptData.getReducedExpTimePoints();
        int startIndexRecovery = frapOptData.getExpFrapStudy().getStartingIndexForRecovery();
        for (int j = 0; j < shiftedSimTimes.length; j++) {
            double[] row = new double[totalWantedROIlen + 1];
            row[0] = shiftedSimTimes[j] + frapOptData.getExpFrapStudy().getFrapData().getImageDataset().getImageTimeStamps()[startIndexRecovery];
            fitOdeSolverResultSet.addRow(row);
        }
        // populate values
        double[][] currentOptFitData = getPureDiffusionPanel().getCurrentFitData();
        // store results
        setCurrentEstimationResults(currentOptFitData);
        if (allDataHash != null && currentOptFitData != null) {
            // populate optimization data
            int columncounter = 0;
            for (int j = 0; j < totalROIlen; j++) {
                if (!wantsROITypes[j]) {
                    continue;
                }
                // if(!isSimData) //opt data
                // {
                double[] values = currentOptFitData[j];
                for (int k = 0; k < values.length; k++) {
                    fitOdeSolverResultSet.setValue(k, columncounter + 1, values[k]);
                }
                // }
                columncounter++;
            }
            // boolean hasSimData = false;
            // anaParams[0] is the key in allDataHash to get the dataSource[]:exp & sim
            DataSource[] selectedRowDataSourceArr = allDataHash.get(anaParams[0]);
            if (selectedRowDataSourceArr != null) {
                // referenceData is the exp data
                // ReferenceData referenceData = (ReferenceData)selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
                // new DataSource.DataSourceReferenceData("exp", referenceData);
                final DataSource expDataSource = selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
                DataSource optDataSource = new DataSource.DataSourceRowColumnResultSet("opt", fitOdeSolverResultSet);
                DataSource[] newDataSourceArr = new DataSource[2];
                newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
                newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_SIMDATASOURCE] = optDataSource;
                if (currentOptFitData == null) {
                    multisourcePlotPane.setDataSources(null);
                } else {
                    // the following paragraph of code is just to get selected color for selected ROIs
                    // and make them the same as we show on ChooseModel_RoiForErrorPanel/RoiForErrorPanel
                    // double valid ROI colors (not include cell and background)
                    int validROISize = FRAPData.VFRAP_ROI_ENUM.values().length - 2;
                    Color[] fullColors = ColorUtil.generateAutoColor(validROISize * 2, getBackground(), new Integer(0));
                    boolean[] selectedROIs = frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation();
                    int selectedROICounter = 0;
                    for (int i = 0; i < selectedROIs.length; i++) {
                        if (selectedROIs[i]) {
                            selectedROICounter++;
                        }
                    }
                    // double the size, each ROI is a comparison of exp and sim
                    Color[] selectedColors = new Color[selectedROICounter * 2];
                    int selectedColorIdx = 0;
                    for (int i = 0; i < selectedROIs.length; i++) {
                        if (selectedROIs[i] && i == 0) {
                            selectedColors[selectedColorIdx] = fullColors[i];
                            selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i + validROISize];
                            selectedColorIdx++;
                        }
                        if (// skip cell and background ROIs
                        selectedROIs[i] && i > 2) {
                            selectedColors[selectedColorIdx] = fullColors[i - 2];
                            selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i - 2 + validROISize];
                            selectedColorIdx++;
                        }
                    }
                    int[] selectedIndices = multisourcePlotPane.getUnsortedSelectedIndices();
                    multisourcePlotPane.setDataSources(newDataSourceArr, selectedColors);
                    if (selectedIndices.length == 0) {
                        multisourcePlotPane.selectAll();
                    } else {
                        multisourcePlotPane.setUnsortedSelectedIndices(selectedIndices);
                    }
                }
            }
        }
    } catch (Exception e2) {
        e2.printStackTrace();
        DialogUtils.showErrorDialog(this, "Error graphing Optimizer data " + e2.getMessage());
    }
}
Also used : Color(java.awt.Color) DataSource(cbit.vcell.modelopt.DataSource) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription)

Example 10 with ODESolverResultSet

use of cbit.vcell.solver.ode.ODESolverResultSet in project vcell by virtualcell.

the class EstParams_ReacBindingPanel method plotDerivedSimulationResults.

private void plotDerivedSimulationResults(AnalysisParameters[] anaParams) {
    try {
        if (getCurrentSimResults() == null || getCurrentRawSimTimePoints() == null || allDataHash == null || allDataHash.get(anaParams[0]) == null || (allDataHash.get(anaParams[0])[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE]) == null) {
            multisourcePlotPane.setDataSources(null);
            return;
        }
        String description = null;
        int totalROIlen = FRAPData.VFRAP_ROI_ENUM.values().length;
        boolean[] wantsROITypes = new boolean[totalROIlen];
        System.arraycopy(frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation(), 0, wantsROITypes, 0, totalROIlen);
        ODESolverResultSet simSolverResultSet = new ODESolverResultSet();
        simSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
        for (int j = 0; j < totalROIlen; j++) {
            if (!wantsROITypes[j]) {
                continue;
            }
            String currentROIName = FRAPData.VFRAP_ROI_ENUM.values()[j].name();
            String name = (description == null ? /*"sim D="+diffusionRates[diffusionRateIndex]+"::"*/
            "" : description) + currentROIName;
            simSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
        }
        int totalWantedROIlen = 0;
        for (int i = 0; i < wantsROITypes.length; i++) {
            if (wantsROITypes[i]) {
                totalWantedROIlen++;
            }
        }
        FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
        // 
        // populate time
        // 
        double[] shiftedSimTimes = getCurrentRawSimTimePoints();
        int startIndexRecovery = fStudy.getStartingIndexForRecovery();
        for (int j = 0; j < shiftedSimTimes.length; j++) {
            double[] row = new double[totalWantedROIlen + 1];
            row[0] = shiftedSimTimes[j] + fStudy.getFrapData().getImageDataset().getImageTimeStamps()[startIndexRecovery];
            simSolverResultSet.addRow(row);
        }
        // 
        // populate values
        // 
        double[][] currentSimData = getCurrentSimResults();
        // populate sim data
        int columncounter = 0;
        for (int j = 0; j < totalROIlen; j++) {
            if (!wantsROITypes[j]) {
                continue;
            }
            double[] values = currentSimData[j];
            for (int k = 0; k < values.length; k++) {
                simSolverResultSet.setValue(k, columncounter + 1, values[k]);
            }
            columncounter++;
        }
        // get exp data and generate datasource to display
        // anaParams[0] is the key in allDataHash to get the dataSource[]:exp & sim
        DataSource[] selectedRowDataSourceArr = allDataHash.get(anaParams[0]);
        if (selectedRowDataSourceArr != null) {
            // referenceData is the exp data
            // ReferenceData referenceData = (ReferenceData)selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE].getSource();
            final DataSource expDataSource = /*new DataSource(referenceData,"exp")*/
            selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
            // from simulation
            final DataSource simDataSource = new DataSource.DataSourceRowColumnResultSet("sim", simSolverResultSet);
            DataSource[] newDataSourceArr = new DataSource[2];
            newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
            newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_SIMDATASOURCE] = simDataSource;
            // the following paragraph of code is just to get selected color for selected ROIs
            // and make them the same as we show on ChooseModel_RoiForErrorPanel/RoiForErrorPanel
            // double valid ROI colors (not include cell and background)
            int validROISize = FRAPData.VFRAP_ROI_ENUM.values().length - 2;
            Color[] fullColors = ColorUtil.generateAutoColor(validROISize * 2, getBackground(), new Integer(0));
            boolean[] selectedROIs = frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation();
            int selectedROICounter = 0;
            for (int i = 0; i < selectedROIs.length; i++) {
                if (selectedROIs[i]) {
                    selectedROICounter++;
                }
            }
            // double the size, each ROI is a comparison of exp and sim
            Color[] selectedColors = new Color[selectedROICounter * 2];
            int selectedColorIdx = 0;
            for (int i = 0; i < selectedROIs.length; i++) {
                if (selectedROIs[i] && i == 0) {
                    selectedColors[selectedColorIdx] = fullColors[i];
                    selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i + validROISize];
                    selectedColorIdx++;
                }
                if (// skip cell and background ROIs
                selectedROIs[i] && i > 2) {
                    selectedColors[selectedColorIdx] = fullColors[i - 2];
                    selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i - 2 + validROISize];
                    selectedColorIdx++;
                }
            }
            multisourcePlotPane.setDataSources(newDataSourceArr, selectedColors);
            multisourcePlotPane.selectAll();
        }
    } catch (Exception e2) {
        e2.printStackTrace();
        DialogUtils.showErrorDialog(this, "Error graphing Optimizer data " + e2.getMessage());
    }
}
Also used : Color(java.awt.Color) DataSource(cbit.vcell.modelopt.DataSource) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet) ODESolverResultSetColumnDescription(cbit.vcell.math.ODESolverResultSetColumnDescription)

Aggregations

ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)37 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)18 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)11 Expression (cbit.vcell.parser.Expression)10 DataSource (cbit.vcell.modelopt.DataSource)9 ReferenceData (cbit.vcell.opt.ReferenceData)8 ExpressionException (cbit.vcell.parser.ExpressionException)7 Simulation (cbit.vcell.solver.Simulation)7 SimulationSymbolTable (cbit.vcell.solver.SimulationSymbolTable)6 SolverException (cbit.vcell.solver.SolverException)6 IOException (java.io.IOException)6 Variable (cbit.vcell.math.Variable)4 SimulationTask (cbit.vcell.messaging.server.SimulationTask)4 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)4 SbmlException (org.vcell.sbml.SbmlException)4 SBMLImportException (org.vcell.sbml.vcell.SBMLImportException)4 BioModel (cbit.vcell.biomodel.BioModel)3 Function (cbit.vcell.math.Function)3 MathDescription (cbit.vcell.math.MathDescription)3 MathException (cbit.vcell.math.MathException)3