Search in sources :

Example 11 with Plot2D

use of cbit.plot.Plot2D in project vcell by virtualcell.

the class TimeFunctionPanel method refreshPlot.

private void refreshPlot() throws Exception {
    // try {
    Expression exp = new Expression(funcTextField.getText());
    exp.flatten();
    SimpleSymbolTable symbolTable = new SimpleSymbolTable(new String[] { "t", "pi" /*, "x", "y", "z"*/
    });
    exp.bindExpression(symbolTable);
    double[] valueArray = new double[2];
    valueArray[1] = Math.PI;
    // valueArray[ReservedVariable.Z.getIndex()] = 0 ;
    // valueArray[ReservedVariable.Y.getIndex()] = 0 ;
    // valueArray[ReservedVariable.X.getIndex()] = 0 ;
    int totalTimePoints = 0;
    double beginTime = 0;
    double timeStep = 0;
    double parseEndTime = 0;
    try {
        beginTime = Double.parseDouble(timeBegTextField.getText());
    } catch (Exception e) {
        throw new Exception("Couldn't evaluate 'Time Begin' as number\n" + e.getMessage());
    }
    try {
        timeStep = Double.parseDouble(timeStepTextField.getText());
        if (timeStep <= 0) {
            throw new Exception("timestep value = " + timeStep);
        }
    } catch (Exception e) {
        throw new Exception("'Time Step' must be > 0\n" + e.getMessage());
    }
    try {
        parseEndTime = Double.parseDouble(endTimeTextField.getText());
    } catch (Exception e) {
        throw new Exception("Couldn't evaluate 'Time End' as number\n" + e.getMessage());
    }
    try {
        if (beginTime > parseEndTime || beginTime == parseEndTime) {
            throw new Exception("endTime must be greater than beginTime");
        }
        totalTimePoints = (int) Math.ceil((parseEndTime - beginTime) / timeStep);
    // if(totalTimePoints <= 0){
    // throw new Exception("calculated number of time points ="+totalTimePoints);
    // }
    } catch (Exception e) {
        throw new Exception("check beginTime, endTime and timeStep: ((endTime-beginTime)/timeStep) must be greater than 0" + "\n" + e.getMessage());
    }
    double[] timePoints = new double[totalTimePoints];
    double[] funcVals = new double[totalTimePoints];
    for (int i = 0; i < totalTimePoints; i++) {
        valueArray[ReservedVariable.TIME.getIndex()] = beginTime + i * timeStep;
        timePoints[i] = valueArray[ReservedVariable.TIME.getIndex()];
        funcVals[i] = exp.evaluateVector(valueArray);
    }
    PlotData plotData = new PlotData(timePoints, funcVals);
    Plot2D plot2D = new Plot2D(null, null, new String[] { "Time Function" }, new PlotData[] { plotData }, new String[] { "Time Function Value", "Time", "[" + "Time Function" + "]" });
    plotPane.setPlot2D(plot2D);
// } catch (Exception e) {
// e.printStackTrace();
// DialogUtils.showErrorDialog(this, "Error refreshing Plot:\n"+e.getMessage(), e);
// plotPane.setPlot2D(	null);
// }
}
Also used : PlotData(cbit.plot.PlotData) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) Expression(cbit.vcell.parser.Expression) Plot2D(cbit.plot.Plot2D)

Example 12 with Plot2D

use of cbit.plot.Plot2D in project vcell by virtualcell.

the class FRAPDataPanel method showCurve.

private void showCurve(String[] varNames, double[] independent, double[][] dependents) {
    PlotPane plotter = new PlotPane();
    PlotData[] plotDatas = new PlotData[dependents.length];
    for (int i = 0; i < plotDatas.length; i++) {
        plotDatas[i] = new PlotData(independent, dependents[i]);
    }
    Plot2D plot2D = new Plot2D(null, null, varNames, plotDatas);
    plotter.setPlot2D(plot2D);
    ChildWindow plotChildWindow = ChildWindowManager.findChildWindowManager(this).addChildWindow(plotter, plotter, "ROI time course", true);
    plotChildWindow.setTitle("ROI time course");
    plotChildWindow.setIsCenteredOnParent();
    plotChildWindow.setSize(new Dimension(400, 400));
    plotChildWindow.showModal();
}
Also used : PlotData(cbit.plot.PlotData) PlotPane(cbit.plot.gui.PlotPane) Plot2D(cbit.plot.Plot2D) Dimension(java.awt.Dimension) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow)

Example 13 with Plot2D

use of cbit.plot.Plot2D 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 14 with Plot2D

use of cbit.plot.Plot2D in project vcell by virtualcell.

the class KymographPanel method configurePlotData.

/**
 * Insert the method's description here.
 * Creation date: (12/16/2004 10:46:05 AM)
 * @param imgX int
 * @param imgY int
 */
private void configurePlotData(int imgX, int imgY) {
    // 
    // TimeScan Data
    // 
    double[][] timeData = new double[2][currentTimes.length];
    timeData[0] = currentTimes;
    timeData[1] = new double[currentTimes.length];
    for (int i = 0; i < currentTimes.length; i += 1) {
        // timeData[1][i] = timeSeriesDataOrig[1+imgX][i];
        timeData[1][i] = rawValues[imgX + (i * RESAMP_SIZE)];
    }
    ;
    localTimeDataMMMH = calcMMM(timeData[1]);
    final int MAX_TITLE_VAL_LENGTH = 9;
    DecimalFormat nf = new DecimalFormat();
    String valS = null;
    valS = currentDistances[imgX] + "";
    if (valS.length() > MAX_TITLE_VAL_LENGTH) {
        nf.applyPattern("#.###E0");
        valS = nf.format(currentDistances[imgX]);
    }
    currentTimeSeriesPlot2D = new SingleXPlot2D(new SymbolTableEntry[] { currentSymbolTablEntry }, multiTimePlotHelper.getDataSymbolMetadataResolver(), "Time", new String[] { currentDataIdentifier.getName() }, timeData, new String[] { "Time Series (d=" + valS + ") Vert", "Time", /*"Time (s)"*/
    "Value" });
    getPlotPaneTimeSeries().setPlot2D(currentTimeSeriesPlot2D);
    // 
    // LineScan Data
    // 
    double[] lineData = new double[timeSeriesDataOrig.length - 1];
    for (int i = 1; i < timeSeriesDataOrig.length; i += 1) {
        lineData[i - 1] = timeSeriesDataOrig[i][imgY];
    }
    double[] lineScanDistances = accumDistancesDataOrig;
    localDistDataMMMH = calcMMM(lineData);
    PlotData plotData = new PlotData(lineScanDistances, lineData);
    valS = currentTimes[imgY] + "";
    if (valS.length() > MAX_TITLE_VAL_LENGTH) {
        valS = nf.format(currentTimes[imgY]);
    }
    currentLineScanPlot2D = new Plot2D(new SymbolTableEntry[] { currentSymbolTablEntry }, multiTimePlotHelper.getDataSymbolMetadataResolver(), new String[] { currentDataIdentifier.getName() }, new PlotData[] { plotData }, new String[] { "Line Scan (t=" + valS + ") Horz", "Distance", /*"Distance (\u00b5m)"*/
    "Value" });
    getPlotPaneLineScan().setPlot2D(currentLineScanPlot2D);
    Range xRangeTime = new Range(currentTimes[0], currentTimes[currentTimes.length - 1]);
    Range xRangeDist = new Range(lineScanDistances[0], lineScanDistances[lineScanDistances.length - 1]);
    Range yRangeTime = (allDataMMMH != null ? allDataMMMH.getRange() : null);
    Range yRangeDist = yRangeTime;
    if (bLocalScaling) {
        yRangeTime = (localTimeDataMMMH != null ? localTimeDataMMMH.getRange() : null);
        yRangeDist = (localDistDataMMMH != null ? localDistDataMMMH.getRange() : null);
    }
    getPlotPaneTimeSeries().forceXYRange(xRangeTime, yRangeTime);
    getPlotPaneLineScan().forceXYRange(xRangeDist, yRangeDist);
    configureMinMax();
    getimagePaneView1().repaint();
}
Also used : PlotData(cbit.plot.PlotData) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) DecimalFormat(java.text.DecimalFormat) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D) Range(org.vcell.util.Range) Point(java.awt.Point) SingleXPlot2D(cbit.plot.SingleXPlot2D)

Example 15 with Plot2D

use of cbit.plot.Plot2D in project vcell by virtualcell.

the class PDEDataViewer method showSpatialPlot.

/**
 * Comment
 */
private void showSpatialPlot() {
    // check selections
    final SpatialSelection[] sl = getPDEDataContextPanel1().fetchSpatialSelections(false, true);
    if (sl == null) {
        PopupGenerator.showErrorDialog(this, "Nothing selected!");
        return;
    }
    for (int i = 0; i < sl.length; i++) {
        if (sl[i].isPoint()) {
            PopupGenerator.showErrorDialog(this, "One or more selections are single points - no spatial plot will be produced for those selections");
            break;
        }
    }
    final String varName = getPdeDataContext().getVariableName();
    final double timePoint = getPdeDataContext().getTimePoint();
    final SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[1];
    if (getSimulation() != null && getSimulation().getMathDescription() != null) {
        symbolTableEntries[0] = getSimulation().getMathDescription().getEntry(varName);
    }
    if (symbolTableEntries[0] == null) {
        // TODO domain
        Domain domain = null;
        symbolTableEntries[0] = new VolVariable(varName, domain);
    }
    AsynchClientTask task1 = new AsynchClientTask("Retrieving spatial series for variable '" + varName, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // get plots, ignoring points
            PlotData[] plotDatas = new PlotData[sl.length];
            for (int i = 0; i < sl.length; i++) {
                PlotData plotData = null;
                if (getPdeDataContext() instanceof PDEDataViewerPostProcess.PostProcessDataPDEDataContext) {
                    SpatialSelectionVolume ssVolume = (SpatialSelectionVolume) sl[i];
                    SpatialSelection.SSHelper ssvHelper = ssVolume.getIndexSamples(0.0, 1.0);
                    ssvHelper.initializeValues_VOLUME(getPdeDataContext().getDataValues());
                    double[] values = ssvHelper.getSampledValues();
                    plotData = new PlotData(ssvHelper.getWorldCoordinateLengths(), values);
                } else {
                    plotData = getPdeDataContext().getLineScan(varName, timePoint, sl[i]);
                }
                plotDatas[i] = plotData;
            }
            hashTable.put("plotDatas", plotDatas);
        }
    };
    AsynchClientTask task2 = new AsynchClientTask("Showing spatial plot for variable" + varName, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            PlotData[] plotDatas = (PlotData[]) hashTable.get("plotDatas");
            for (PlotData plotData : plotDatas) {
                if (plotData != null) {
                    PlotPane plotPane = new PlotPane();
                    Plot2D plot2D = new Plot2D(symbolTableEntries, getSimulationModelInfo().getDataSymbolMetadataResolver(), new String[] { varName }, new PlotData[] { plotData }, new String[] { "Values along curve", "Distance (\u00b5m)", "[" + varName + "]" });
                    plotPane.setPlot2D(plot2D);
                    String title = createContextTitle(PDEDataViewer.this.isPostProcess(), "Spatial Plot:'" + varName + "' ", getPdeDataContext(), getSimulationModelInfo(), getSimulation());
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
                    ChildWindow childWindow = childWindowManager.addChildWindow(plotPane, plotPane, title);
                    childWindow.setIsCenteredOnParent();
                    childWindow.pack();
                    childWindow.show();
                // System.out.println("Spatial plot requesting focus.  Result is: "+childWindow.requestFocusInWindow());
                }
            }
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { task1, task2 }, false);
}
Also used : PlotData(cbit.plot.PlotData) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) VolVariable(cbit.vcell.math.VolVariable) Hashtable(java.util.Hashtable) PostProcessDataPDEDataContext(cbit.vcell.client.data.PDEDataViewerPostProcess.PostProcessDataPDEDataContext) ChildWindowManager(cbit.vcell.client.ChildWindowManager) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) SymbolTableEntry(cbit.vcell.parser.SymbolTableEntry) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) PlotPane(cbit.plot.gui.PlotPane) SingleXPlot2D(cbit.plot.SingleXPlot2D) Plot2D(cbit.plot.Plot2D) VariableDomain(cbit.vcell.math.VariableType.VariableDomain) Domain(cbit.vcell.math.Variable.Domain)

Aggregations

Plot2D (cbit.plot.Plot2D)24 PlotData (cbit.plot.PlotData)12 SingleXPlot2D (cbit.plot.SingleXPlot2D)12 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)7 PlotPane (cbit.plot.gui.PlotPane)5 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)4 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)3 VariableType (cbit.vcell.math.VariableType)3 Point (java.awt.Point)3 Hashtable (java.util.Hashtable)3 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)2 VolVariable (cbit.vcell.math.VolVariable)2 Parameter (cbit.vcell.opt.Parameter)2 SimpleSymbolTable (cbit.vcell.parser.SimpleSymbolTable)2 DataIdentifier (cbit.vcell.simdata.DataIdentifier)2 SpatialSelectionMembrane (cbit.vcell.simdata.SpatialSelectionMembrane)2 DataSymbolMetadataResolver (cbit.vcell.solver.SimulationModelInfo.DataSymbolMetadataResolver)2 GridBagConstraints (java.awt.GridBagConstraints)2 GridBagLayout (java.awt.GridBagLayout)2 Paint (java.awt.Paint)2