Search in sources :

Example 11 with DataSource

use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.

the class EstParams_TwoDiffComponentPanel 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 = diffTwoPanel.getCurrentFitData();
        // store results
        setCurrentEstimationResults(currentOptFitData);
        if (allDataHash != null && currentOptFitData != null) {
            // populate optimization data---convert it to odeSoverResultSet and further put into datasource
            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 + /*j*/
                    1, values[k]);
                }
                // }
                columncounter++;
            }
            // 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
                final DataSource expDataSource = /*new DataSource(referenceData,"exp")*/
                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 12 with DataSource

use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.

the class MultisourcePlotPane method selectionModel1_ValueChanged.

/**
 * Comment
 */
private void selectionModel1_ValueChanged(javax.swing.event.ListSelectionEvent listSelectionEvent) throws Exception {
    if (listSelectionEvent.getValueIsAdjusting() == true) {
        return;
    }
    int firstIndex = listSelectionEvent.getFirstIndex();
    int lastIndex = listSelectionEvent.getLastIndex();
    if (firstIndex < 0 || lastIndex < 0) {
        getplotPane().setPlot2D(new Plot2D(null, null, new String[0], new PlotData[0]));
    }
    // 
    // make plotDatas for the reference data
    // 
    Vector<PlotData> plotDataList = new Vector<PlotData>();
    Vector<String> nameList = new Vector<String>();
    Vector<Integer> renderHintList = new Vector<Integer>();
    Vector<Color> colorV = new Vector<Color>();
    int[] selectedIndices = getJList1().getSelectedIndices();
    for (int ii = 0; ii < selectedIndices.length; ii++) {
        int selectedIndex = selectedIndices[ii];
        DataReference dataReference = (DataReference) getmultisourcePlotListModel().getElementAt(selectedIndex);
        DataSource dataSource = dataReference.getDataSource();
        // instanceof DataSource.DataSourceReferenceData ? refDataLabelPrefix : modelDataLabelPrefix;
        String prefix = dataSource.getName() + ": ";
        String[] columnNames = dataSource.getColumnNames();
        int timeIndex = dataSource.getTimeColumnIndex();
        if (timeIndex == -1) {
            throw new RuntimeException("no time variable specified");
        }
        for (int i = 0; i < columnNames.length; i++) {
            if (i == timeIndex) {
                continue;
            }
            if (columnNames[i].equals(dataReference.getIdentifier())) {
                double[] independentValues = dataSource.getColumnData(timeIndex);
                double[] dependentValues = dataSource.getColumnData(i);
                PlotData plotData = new PlotData(independentValues, dependentValues);
                plotDataList.add(plotData);
                int unsortedSelecteIndex = (getmultisourcePlotListModel().getSortedDataReferences() == null ? selectedIndex : getmultisourcePlotListModel().getSortedDataReferences().get(selectedIndex).unsortedIndex);
                colorV.add(autoContrastColors[unsortedSelecteIndex]);
                nameList.add(prefix + columnNames[i]);
                renderHintList.add(dataSource.getRenderHints());
                break;
            }
        }
    }
    String[] labels = { "", "t", "" };
    String[] names = (String[]) BeanUtils.getArray(nameList, String.class);
    PlotData[] plotDatas = (PlotData[]) BeanUtils.getArray(plotDataList, PlotData.class);
    boolean[] visibleFlags = new boolean[plotDatas.length];
    for (int i = 0; i < visibleFlags.length; i++) {
        visibleFlags[i] = true;
    }
    int[] renderHints = new int[plotDatas.length];
    for (int i = 0; i < renderHints.length; i++) {
        renderHints[i] = ((Integer) renderHintList.elementAt(i)).intValue();
    }
    Plot2D plot2D = new Plot2D(null, null, names, plotDatas, labels, visibleFlags, renderHints);
    Color[] colorArr = colorV.toArray(new Color[0]);
    // if(colorV.size() == plot2D.getNumberOfPlots()){
    // colorArr = colorV.toArray(new Color[0]);
    // }
    getplotPane().setPlot2D(plot2D, colorArr);
    return;
}
Also used : PlotData(cbit.plot.PlotData) Color(java.awt.Color) DataSource(cbit.vcell.modelopt.DataSource) Plot2D(cbit.plot.Plot2D) Vector(java.util.Vector) DataReference(cbit.vcell.modelopt.DataReference)

Example 13 with DataSource

use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.

the class SpatialAnalysisResults method createSummaryReportSourceData.

// This function put exp data and sim data in a hashtable, the key is analysisParameters(right now only 1)
public Hashtable<AnalysisParameters, DataSource[]> createSummaryReportSourceData(final double[] frapDataTimeStamps, int startIndexForRecovery, boolean[] selecredROIs, boolean isSimData) throws Exception {
    Hashtable<AnalysisParameters, DataSource[]> allDataHash = new Hashtable<AnalysisParameters, DataSource[]>();
    Hashtable<CurveInfo, double[]> ROIInfoHash = curveHash;
    Set<CurveInfo> roiInfoSet = ROIInfoHash.keySet();
    Iterator<CurveInfo> roiInfoIter = roiInfoSet.iterator();
    // exp data are stored by ROI type.
    Hashtable<String, double[]> expROIData = new Hashtable<String, double[]>();
    // sim data are stored by AnalysisParameters and then by ROI type.
    Hashtable<AnalysisParameters, Hashtable<String, double[]>> simROIData = new Hashtable<AnalysisParameters, Hashtable<String, double[]>>();
    int roiCount = 0;
    // how many set of parameters are used for sim. 1 for now.
    int analysisParametersCount = 0;
    while (roiInfoIter.hasNext()) {
        CurveInfo roiCurveInfo = roiInfoIter.next();
        if (roiCurveInfo.isExperimentInfo()) {
            expROIData.put(roiCurveInfo.getROIName(), ROIInfoHash.get(roiCurveInfo));
            roiCount++;
        } else {
            Hashtable<String, double[]> simROIDataHash = simROIData.get(roiCurveInfo.getAnalysisParameters());
            if (simROIDataHash == null) {
                simROIDataHash = new Hashtable<String, double[]>();
                simROIData.put(roiCurveInfo.getAnalysisParameters(), simROIDataHash);
                analysisParametersCount++;
            }
            simROIDataHash.put(roiCurveInfo.getROIName(), ROIInfoHash.get(roiCurveInfo));
        }
    }
    // this is for exp data. each row of reference data contains time + intensities under 9 ROIs(bleached + ring1..8). totally 10 cols for each row.
    ReferenceData referenceData = createReferenceData(frapDataTimeStamps, startIndexForRecovery, "", selecredROIs);
    // loop only 1 time, right now the analysisParameters[]'s length is 1.
    for (int analysisParametersRow = 0; analysisParametersRow < analysisParametersCount; analysisParametersRow++) {
        AnalysisParameters currentAnalysisParameters = analysisParameters[analysisParametersRow];
        DataSource[] newDataSourceArr = new DataSource[2];
        // rows for time points and cols for t + roibleached + ring1--8 (10 cols)
        final DataSource expDataSource = new DataSource.DataSourceReferenceData("exp", referenceData);
        newDataSourceArr[ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
        DataSource simDataSource = null;
        if (isSimData) {
            ODESolverResultSet odeSolverResultSet = createODESolverResultSet(currentAnalysisParameters, null, "");
            // rows for time points and cols for t + roibleached + ring1--8 (10 cols)
            simDataSource = new DataSource.DataSourceRowColumnResultSet("sim", odeSolverResultSet);
        }
        newDataSourceArr[ARRAY_INDEX_SIMDATASOURCE] = simDataSource;
        allDataHash.put(currentAnalysisParameters, newDataSourceArr);
    }
    return allDataHash;
}
Also used : Hashtable(java.util.Hashtable) DataSource(cbit.vcell.modelopt.DataSource) SimpleReferenceData(cbit.vcell.opt.SimpleReferenceData) ReferenceData(cbit.vcell.opt.ReferenceData) ODESolverResultSet(cbit.vcell.solver.ode.ODESolverResultSet)

Aggregations

DataSource (cbit.vcell.modelopt.DataSource)13 ODESolverResultSet (cbit.vcell.solver.ode.ODESolverResultSet)9 ReferenceData (cbit.vcell.opt.ReferenceData)6 ODESolverResultSetColumnDescription (cbit.vcell.math.ODESolverResultSetColumnDescription)5 Color (java.awt.Color)5 DataReference (cbit.vcell.modelopt.DataReference)3 SimpleReferenceData (cbit.vcell.opt.SimpleReferenceData)3 ExpressionException (cbit.vcell.parser.ExpressionException)3 FunctionColumnDescription (cbit.vcell.math.FunctionColumnDescription)2 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)2 SortDataReferenceHelper (cbit.vcell.modelopt.gui.MultisourcePlotListModel.SortDataReferenceHelper)2 Plot2D (cbit.plot.Plot2D)1 PlotData (cbit.plot.PlotData)1 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)1 Variable (cbit.vcell.math.Variable)1 FRAPModel (cbit.vcell.microscopy.FRAPModel)1 ReservedSymbol (cbit.vcell.model.Model.ReservedSymbol)1 ModelOptimizationSpec (cbit.vcell.modelopt.ModelOptimizationSpec)1 ReferenceDataMappingSpec (cbit.vcell.modelopt.ReferenceDataMappingSpec)1 MultisourcePlotPane (cbit.vcell.modelopt.gui.MultisourcePlotPane)1