Search in sources :

Example 11 with SpatialSelection

use of cbit.vcell.simdata.SpatialSelection in project vcell by virtualcell.

the class ASCIIExporter method sofyaFormat.

private ExportOutput sofyaFormat(OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, final VCDataIdentifier orig_vcdID, VariableSpecs variableSpecs, TimeSpecs timeSpecs, GeometrySpecs geometrySpecs, ASCIISpecs asciiSpecs, String contextName, FileDataContainerManager fileDataContainerManager) throws DataAccessException, IOException {
    ExportSpecs.SimNameSimDataID[] simNameSimDataIDs = asciiSpecs.getSimNameSimDataIDs();
    // use mesh to calulate indexes
    CartesianMesh mesh = dataServerImpl.getMesh(user, orig_vcdID);
    final int SIM_COUNT = simNameSimDataIDs.length;
    final int PARAMSCAN_COUNT = (asciiSpecs.getExportMultipleParamScans() != null ? asciiSpecs.getExportMultipleParamScans().length : 1);
    final int TIME_COUNT = timeSpecs.getEndTimeIndex() - timeSpecs.getBeginTimeIndex() + 1;
    if (PARAMSCAN_COUNT > 1 || geometrySpecs.getModeID() != GEOMETRY_SELECTIONS) /* || geometrySpecs.getCurves().length != 0*/
    {
        throw new DataAccessException("Alternate csv format cannot have parameter scans and must be 'point selection' type");
    }
    // millisecodns
    final long MESSAGE_LIMIT = 5000;
    final long MAX_DATA = 10000000;
    long totalPoints = SIM_COUNT * TIME_COUNT * variableSpecs.getVariableNames().length * geometrySpecs.getPointCount();
    if (totalPoints > MAX_DATA) {
        throw new DataAccessException("Too much data, select fewer (sims or times or variables or samplepoints).  Exceeded limit by " + NumberUtils.formatNumber(100 * (((double) totalPoints / (double) MAX_DATA) - 1.0), 6) + "%");
    }
    ExportOutput exportOutput1 = new ExportOutput(true, ".csv", SIM_COUNT + "_multisims_", variableSpecs.getVariableNames().length + "_Vars_" + TIME_COUNT + "_times", fileDataContainerManager);
    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\"Model:'" + contextName + "'\"\n\n");
    int[] sampleIndexes = getallSampleIndexes(geometrySpecs, mesh);
    int[][] indexes = new int[variableSpecs.getVariableNames().length][];
    HashMap<Integer, TSJobResultsNoStats> simData = new HashMap<>();
    long lastTime = 0;
    double progressCounter = 0;
    for (int t = 0; t < TIME_COUNT; t++) {
        fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "Time," + timeSpecs.getAllTimes()[timeSpecs.getBeginTimeIndex() + t] + "\n");
        for (int simIndex = 0; simIndex < SIM_COUNT; simIndex++) {
            progressCounter++;
            if ((System.currentTimeMillis() - lastTime) > MESSAGE_LIMIT) {
                lastTime = System.currentTimeMillis();
                exportServiceImpl.fireExportProgress(jobID, orig_vcdID, "multisim-point", progressCounter / (SIM_COUNT * TIME_COUNT));
            }
            int simJobIndex = simNameSimDataIDs[simIndex].getDefaultJobIndex();
            VCDataIdentifier vcdID = simNameSimDataIDs[simIndex].getVCDataIdentifier(simJobIndex);
            if (SIM_COUNT > 1) {
                // check times are the same
                double[] currentTimes = dataServerImpl.getDataSetTimes(user, vcdID);
                if (currentTimes.length != timeSpecs.getAllTimes().length) {
                    throw new DataAccessException("time sets are different length");
                }
                for (int i = 0; i < currentTimes.length; i++) {
                    if (timeSpecs.getAllTimes()[i] != currentTimes[i]) {
                        throw new DataAccessException("time sets have different values");
                    }
                }
            }
            SpatialSelection[] spatialSelections = geometrySpecs.getSelections();
            mesh = dataServerImpl.getMesh(user, vcdID);
            for (int i = 0; i < spatialSelections.length; i++) {
                if (spatialSelections[i].getMesh() == null) {
                    spatialSelections[i].setMesh(mesh);
                } else if (!spatialSelections[i].getMesh().getISize().compareEqual(mesh.getISize()) || spatialSelections[i].getMesh().getNumMembraneElements() != mesh.getNumMembraneElements()) {
                    // check just sizes not areas,normals,etc...
                    // This will throw fail message
                    spatialSelections[i].setMesh(mesh);
                }
            }
            if (simIndex == 0) {
                fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "Variables-->,");
                for (int v = 0; v < variableSpecs.getVariableNames().length; v++) {
                    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\"" + variableSpecs.getVariableNames()[v] + "\"");
                    for (int p = 0; p < sampleIndexes.length; p++) {
                        fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), ",");
                    }
                }
                fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n\"Simulation Name : (point/line)Index-->\",");
                for (int v = 0; v < variableSpecs.getVariableNames().length; v++) {
                    indexes[v] = sampleIndexes;
                    for (int p = 0; p < sampleIndexes.length; p++) {
                        fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), sampleIndexes[p] + ",");
                    }
                }
                fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
            }
            fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\"" + simNameSimDataIDs[simIndex].getSimulationName() + "\"");
            TSJobResultsNoStats timeSeriesJobResults = simData.get(simIndex);
            if (timeSeriesJobResults == null) {
                TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(variableSpecs.getVariableNames(), indexes, null, timeSpecs.getAllTimes()[timeSpecs.getBeginTimeIndex()], 1, timeSpecs.getAllTimes()[timeSpecs.getEndTimeIndex()], VCDataJobID.createVCDataJobID(user, false));
                timeSeriesJobResults = (TSJobResultsNoStats) dataServerImpl.getTimeSeriesValues(outputContext, user, vcdID, timeSeriesJobSpec);
                simData.put(simIndex, timeSeriesJobResults);
            }
            // the length of variableValues[n] is allTimes.length
            for (int v = 0; v < variableSpecs.getVariableNames().length; v++) {
                final double[][] variableValues = timeSeriesJobResults.getTimesAndValuesForVariable(variableSpecs.getVariableNames()[v]);
                for (int p = 0; p < sampleIndexes.length; p++) {
                    fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "," + variableValues[p + 1][t]);
                }
            }
            fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
        }
        fileDataContainerManager.append(exportOutput1.getFileDataContainerID(), "\n");
    }
    return exportOutput1;
}
Also used : TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) HashMap(java.util.HashMap) SinglePoint(cbit.vcell.geometry.SinglePoint) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SpatialSelection(cbit.vcell.simdata.SpatialSelection) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataAccessException(org.vcell.util.DataAccessException) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 12 with SpatialSelection

use of cbit.vcell.simdata.SpatialSelection in project vcell by virtualcell.

the class GeometrySpecs method toString.

/**
 * Insert the method's description here.
 * Creation date: (4/2/2001 4:23:04 PM)
 * @return java.lang.String
 */
public String toString() {
    StringBuffer buf = new StringBuffer();
    buf.append("GeometrySpecs [");
    buf.append("axis: " + axis + ", ");
    buf.append("sliceNumber: " + sliceNumber + ", ");
    buf.append("spatialSelections: ");
    if (serializedSelections != null) {
        buf.append("{");
        SpatialSelection[] selections = getSelections();
        for (int i = 0; i < selections.length; i++) {
            buf.append(selections);
            if (i < selections.length - 1)
                buf.append(",");
        }
        buf.append("}");
    } else {
        buf.append("null");
    }
    buf.append(", modeID: " + modeID + "]");
    return buf.toString();
}
Also used : SpatialSelection(cbit.vcell.simdata.SpatialSelection) SinglePoint(cbit.vcell.geometry.SinglePoint)

Example 13 with SpatialSelection

use of cbit.vcell.simdata.SpatialSelection in project vcell by virtualcell.

the class PDEDataViewer method showTimePlot.

// private static final String PROPERTY_PDEDC = "pdedc";
/**
 * Comment
 */
private void showTimePlot() {
    VariableType varType = getPdeDataContext().getDataIdentifier().getVariableType();
    // Collect all sample curves created by user
    SpatialSelection[] spatialSelectionArr = getPDEDataContextPanel1().fetchSpatialSelections(true, true);
    SpatialSelection[] spatialSelectionArr2 = null;
    if (varType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_VOLUME) || varType.getVariableDomain().equals(VariableDomain.VARIABLEDOMAIN_POSTPROCESSING)) {
        spatialSelectionArr2 = getPDEDataContextPanel1().fetchSpatialSelections(varType, true, true);
    } else {
        spatialSelectionArr2 = getPDEDataContextPanel1().fetchSpatialSelections(varType.equals(VariableType.MEMBRANE) ? VariableType.MEMBRANE_REGION : VariableType.MEMBRANE, true, true);
    }
    final Vector<SpatialSelection> singlePointSSOnly = new Vector<SpatialSelection>();
    final Vector<SpatialSelection> singlePointSSOnly2 = new Vector<SpatialSelection>();
    if (spatialSelectionArr != null && spatialSelectionArr.length > 0) {
        for (int i = 0; i < spatialSelectionArr.length; i++) {
            if (spatialSelectionArr[i].isPoint() || (spatialSelectionArr[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr[i]).getSelectionSource() instanceof SinglePoint)) {
                singlePointSSOnly.add(spatialSelectionArr[i]);
            }
            if (spatialSelectionArr2[i].isPoint() || (spatialSelectionArr2[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr2[i]).getSelectionSource() instanceof SinglePoint)) {
                singlePointSSOnly2.add(spatialSelectionArr2[i]);
            }
        }
    }
    final String varName = getPdeDataContext().getVariableName();
    if (singlePointSSOnly.size() == 0) {
        PopupGenerator.showErrorDialog(this, "No Time sampling points match DataType=" + varType);
        return;
    }
    try {
        int[] indices = null;
        // 
        indices = new int[singlePointSSOnly.size()];
        for (int i = 0; i < singlePointSSOnly.size(); i++) {
            if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
                SpatialSelectionVolume ssv = (SpatialSelectionVolume) singlePointSSOnly.get(i);
                indices[i] = ssv.getIndex(0);
            } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
                SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) singlePointSSOnly.get(i);
                indices[i] = ssm.getIndex(0);
            }
        }
        double[] timePoints = getPdeDataContext().getTimePoints();
        final TimeSeriesJobSpec tsjs = new TimeSeriesJobSpec(new String[] { varName }, new int[][] { indices }, null, timePoints[0], 1, timePoints[timePoints.length - 1], VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
        if (!tsjs.getVcDataJobID().isBackgroundTask()) {
            throw new RuntimeException("Use getTimeSeries(...) if not a background job");
        }
        Hashtable<String, Object> hash = new Hashtable<String, Object>();
        hash.put(StringKey_timeSeriesJobSpec, tsjs);
        AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieving Data for '" + varName + "'...", PDEDataViewer.this, getPdeDataContext());
        AsynchClientTask multiTimePlotHelperTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelper = createMultiTimePlotHelper((ClientPDEDataContext) PDEDataViewer.this.getPdeDataContext(), PDEDataViewer.this.getDataViewerManager().getUser(), getSimulationModelInfo().getDataSymbolMetadataResolver());
                hashTable.put(MULTITPHELPER_TASK_KEY, multiTimePlotHelper);
            }
        };
        AsynchClientTask task2 = new AsynchClientTask("showing time plot for '" + varName + "'", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            @Override
            public void run(Hashtable<String, Object> hashTable) throws Exception {
                TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(StringKey_timeSeriesJobResults);
                // Make independent Plotviewer that is unaffected by changes (time,var,paramscan) in 'this' PDEDataviewer except to pass-thru OutputContext changes
                PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelper = (PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) hashTable.get(MULTITPHELPER_TASK_KEY);
                try {
                    PdeTimePlotMultipleVariablesPanel pdeTimePlotPanel = new PdeTimePlotMultipleVariablesPanel(multiTimePlotHelper, singlePointSSOnly, singlePointSSOnly2, tsJobResultsNoStats);
                    ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
                    String prefix = "Time Plot (" + getPDEPlotControlPanel1().getPlotVariableJList().getSelectedValue().getVariableType().getTypeName() + ") ";
                    ChildWindow childWindow = childWindowManager.addChildWindow(pdeTimePlotPanel, pdeTimePlotPanel, createContextTitle(PDEDataViewer.this.isPostProcess(), prefix, getPdeDataContext(), getSimulationModelInfo(), getSimulation()));
                    childWindow.getParent().addWindowListener(new WindowAdapter() {

                        @Override
                        public void windowClosing(WindowEvent e) {
                            super.windowClosing(e);
                            multiTimePlotHelper.removeallPropertyChangeListeners();
                        }

                        @Override
                        public void windowClosed(WindowEvent e) {
                            super.windowClosed(e);
                            multiTimePlotHelper.removeallPropertyChangeListeners();
                        }
                    });
                    // childWindow.addChildWindowListener(new ChildWindowListener() {
                    // @Override
                    // public void closing(ChildWindow childWindow) {
                    // multiTimePlotHelper.removeallPropertyChangeListeners();
                    // }
                    // @Override
                    // public void closed(ChildWindow childWindow) {
                    // multiTimePlotHelper.removeallPropertyChangeListeners();
                    // }
                    // });
                    childWindow.setSize(900, 550);
                    childWindow.setIsCenteredOnParent();
                    childWindow.show();
                } catch (Exception e) {
                    e.printStackTrace();
                    multiTimePlotHelper.removeallPropertyChangeListeners();
                }
            }
        };
        // ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1,multiTimePlotHelperTask, task2 }, true, true, null);
        ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1, multiTimePlotHelperTask, task2 }, null, false, false, true, null, false);
    } catch (Exception e) {
        e.printStackTrace(System.out);
    }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) WindowAdapter(java.awt.event.WindowAdapter) SinglePoint(cbit.vcell.geometry.SinglePoint) PdeTimePlotMultipleVariablesPanel(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel) SpatialSelection(cbit.vcell.simdata.SpatialSelection) Vector(java.util.Vector) MultiTimePlotHelper(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) ChildWindowManager(cbit.vcell.client.ChildWindowManager) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume) MultiTimePlotHelper(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) WindowEvent(java.awt.event.WindowEvent) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 14 with SpatialSelection

use of cbit.vcell.simdata.SpatialSelection in project vcell by virtualcell.

the class PDEDataViewer method showKymograph.

private void showKymograph() {
    String title = createContextTitle(PDEDataViewer.this.isPostProcess(), "Kymograph: ", getPdeDataContext(), getSimulationModelInfo(), getSimulation());
    final String INDICES_KEY = "INDICES_KEY";
    final String CROSSING_KEY = "CROSSING_KEY";
    final String ACCUM_KEY = "ACCUM_KEY";
    AsynchClientTask multiTimePlotHelperTask = new AsynchClientTask("multiTimePlotHelperTask...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // Collect all sample curves created by user
            SpatialSelection[] spatialSelectionArr = getPDEDataContextPanel1().fetchSpatialSelections(false, true);
            final Vector<SpatialSelection> lineSSOnly = new Vector<SpatialSelection>();
            if (spatialSelectionArr != null && spatialSelectionArr.length > 0) {
                // 
                for (int i = 0; i < spatialSelectionArr.length; i++) {
                    if (spatialSelectionArr[i].isPoint() || (spatialSelectionArr[i] instanceof SpatialSelectionMembrane && ((SpatialSelectionMembrane) spatialSelectionArr[i]).getSelectionSource() instanceof cbit.vcell.geometry.SinglePoint)) {
                    } else {
                        lineSSOnly.add(spatialSelectionArr[i]);
                    }
                }
            }
            // 
            if (lineSSOnly.size() == 0) {
                throw new Exception("No line samples match DataType=" + getPdeDataContext().getDataIdentifier().getVariableType());
            }
            VariableType varType = getPdeDataContext().getDataIdentifier().getVariableType();
            int[] indices = null;
            int[] crossingMembraneIndices = null;
            double[] accumDistances = null;
            for (int i = 0; i < lineSSOnly.size(); i++) {
                if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
                    SpatialSelectionVolume ssv = (SpatialSelectionVolume) lineSSOnly.get(i);
                    SpatialSelection.SSHelper ssh = ssv.getIndexSamples(0.0, 1.0);
                    indices = ssh.getSampledIndexes();
                    crossingMembraneIndices = ssh.getMembraneIndexesInOut();
                    accumDistances = ssh.getWorldCoordinateLengths();
                } else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
                    SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) lineSSOnly.get(i);
                    SpatialSelection.SSHelper ssh = ssm.getIndexSamples();
                    indices = ssh.getSampledIndexes();
                    accumDistances = ssh.getWorldCoordinateLengths();
                }
            }
            if (indices != null) {
                hashTable.put(INDICES_KEY, indices);
            }
            if (crossingMembraneIndices != null) {
                hashTable.put(CROSSING_KEY, crossingMembraneIndices);
            }
            if (accumDistances != null) {
                hashTable.put(ACCUM_KEY, accumDistances);
            }
            MultiTimePlotHelper multiTimePlotHelper = createMultiTimePlotHelper((ClientPDEDataContext) getPdeDataContext(), getDataViewerManager().getUser(), getSimulationModelInfo().getDataSymbolMetadataResolver());
            hashTable.put(MULTITPHELPER_TASK_KEY, multiTimePlotHelper);
        }
    };
    AsynchClientTask kymographTask = new AsynchClientTask("Kymograph showing...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            KymographPanel kymographPanel = new KymographPanel(PDEDataViewer.this, title, (MultiTimePlotHelper) hashTable.get(MULTITPHELPER_TASK_KEY));
            SymbolTable symbolTable;
            if (getSimulation() != null && getSimulation().getMathDescription() != null) {
                symbolTable = getSimulation().getMathDescription();
            } else {
                symbolTable = new SimpleSymbolTable(new String[] { getPdeDataContext().getDataIdentifier().getName() });
            }
            ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(PDEDataViewer.this);
            ChildWindow childWindow = childWindowManager.addChildWindow(kymographPanel, kymographPanel, title);
            childWindow.setSize(new Dimension(700, 500));
            childWindow.show();
            kymographPanel.initDataManager(getPdeDataContext().getDataIdentifier(), getPdeDataContext().getTimePoints()[0], 1, getPdeDataContext().getTimePoints()[getPdeDataContext().getTimePoints().length - 1], (int[]) hashTable.get(INDICES_KEY), (int[]) hashTable.get(CROSSING_KEY), (double[]) hashTable.get(ACCUM_KEY), true, getPdeDataContext().getTimePoint(), symbolTable);
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { multiTimePlotHelperTask, kymographTask }, null, false, false, true, null, false);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) SpatialSelectionMembrane(cbit.vcell.simdata.SpatialSelectionMembrane) SpatialSelection(cbit.vcell.simdata.SpatialSelection) SinglePoint(cbit.vcell.geometry.SinglePoint) Vector(java.util.Vector) MultiTimePlotHelper(cbit.vcell.simdata.gui.PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper) VariableType(cbit.vcell.math.VariableType) Hashtable(java.util.Hashtable) SimulationSymbolTable(cbit.vcell.solver.SimulationSymbolTable) SymbolTable(cbit.vcell.parser.SymbolTable) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) ChildWindowManager(cbit.vcell.client.ChildWindowManager) Dimension(java.awt.Dimension) ChildWindow(cbit.vcell.client.ChildWindowManager.ChildWindow) Point(java.awt.Point) SinglePoint(cbit.vcell.geometry.SinglePoint) DataAccessException(org.vcell.util.DataAccessException) PropertyVetoException(java.beans.PropertyVetoException) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) SimpleSymbolTable(cbit.vcell.parser.SimpleSymbolTable) SSHelper(cbit.vcell.simdata.SpatialSelection.SSHelper) SpatialSelectionVolume(cbit.vcell.simdata.SpatialSelectionVolume)

Example 15 with SpatialSelection

use of cbit.vcell.simdata.SpatialSelection 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

SpatialSelection (cbit.vcell.simdata.SpatialSelection)16 SinglePoint (cbit.vcell.geometry.SinglePoint)11 TimeSeriesJobSpec (org.vcell.util.document.TimeSeriesJobSpec)8 SpatialSelectionVolume (cbit.vcell.simdata.SpatialSelectionVolume)7 SpatialSelectionMembrane (cbit.vcell.simdata.SpatialSelectionMembrane)6 VariableType (cbit.vcell.math.VariableType)5 CartesianMesh (cbit.vcell.solvers.CartesianMesh)5 DataAccessException (org.vcell.util.DataAccessException)5 TSJobResultsNoStats (org.vcell.util.document.TSJobResultsNoStats)5 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)5 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)4 ExportSpecs (cbit.vcell.export.server.ExportSpecs)4 Vector (java.util.Vector)4 ImageException (cbit.image.ImageException)3 ChildWindowManager (cbit.vcell.client.ChildWindowManager)3 ChildWindow (cbit.vcell.client.ChildWindowManager.ChildWindow)3 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)3 DataSetController (cbit.vcell.server.DataSetController)3 DataSetControllerProvider (cbit.vcell.server.DataSetControllerProvider)3 DataIdentifier (cbit.vcell.simdata.DataIdentifier)3