Search in sources :

Example 6 with TSJobResultsNoStats

use of org.vcell.util.document.TSJobResultsNoStats 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 7 with TSJobResultsNoStats

use of org.vcell.util.document.TSJobResultsNoStats 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 8 with TSJobResultsNoStats

use of org.vcell.util.document.TSJobResultsNoStats in project vcell by virtualcell.

the class KymographPanel method initDataManagerVariable.

/**
 * Insert the method's description here.
 * Creation date: (12/14/2004 9:47:38 AM)
 * @param timeSeries double[][]
 * @param distances double[]
 */
private void initDataManagerVariable() /*final DataIdentifier dataIdentifer,*/
/*boolean bFromGUI*/
{
    final DataIdentifier dataIdentifer = (DataIdentifier) getVarNamesJComboBox().getSelectedItem();
    // Thread.dumpStack();
    if ((initVariableTimer = ClientTaskDispatcher.getBlockingTimer(this, multiTimePlotHelper.getPdeDatacontext(), null, initVariableTimer, new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            initDataManagerVariable();
        }
    }, "KymographPanel get '" + dataIdentifer.getName() + "'")) != null) {
        return;
    }
    // Create SymbolTableEntry for Copy/Paste functionality
    currentSymbolTablEntry = (symbolTable != null ? symbolTable.getEntry(dataIdentifer.getName()) : null);
    String taskName = "Retrieving data for variable '" + dataIdentifer.getName() + "'";
    AsynchClientTask task1 = new AsynchClientTask(taskName, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(final Hashtable<String, Object> hashTable) throws Exception {
            double[] timeValues = multiTimePlotHelper.getPdeDatacontext().getTimePoints();
            final TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { dataIdentifer.getName() }, new int[][] { dataManagerIndices }, (crossingMembraneIndices != null ? new int[][] { crossingMembraneIndices } : null), resampleStartTimeOrig, resampleStepOrig, timeValues[timeValues.length - 1], VCDataJobID.createVCDataJobID(multiTimePlotHelper.getUser(), true));
            hashTable.put(PDEDataViewer.StringKey_timeSeriesJobSpec, timeSeriesJobSpec);
        }
    };
    // new TimeSeriesDataRetrievalTask(title, PDEDataViewer.this, PDEDataViewer.this.getPdeDataContext());//timeSeriesDataRetrievalTask;
    AsynchClientTask task2 = new PDEDataViewer.TimeSeriesDataRetrievalTask("Retrieving Data", multiTimePlotHelper, multiTimePlotHelper.getPdeDatacontext());
    AsynchClientTask task3 = new AsynchClientTask("Showing kymograph", AsynchClientTask.TASKTYPE_SWING_BLOCKING, false, false) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            Throwable timeSeriesJobFailed = (Throwable) hashTable.get(PDEDataViewer.StringKey_timeSeriesJobException);
            if (timeSeriesJobFailed == null) {
                timeSeriesJobFailed = (Throwable) hashTable.get(ClientTaskDispatcher.TASK_ABORTED_BY_USER);
            }
            if (failMethod(timeSeriesJobFailed, dataIdentifer)) {
                return;
            }
            TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(PDEDataViewer.StringKey_timeSeriesJobResults);
            currentDataIdentifier = dataIdentifer;
            final double[][] timeSeries = tsJobResultsNoStats.getTimesAndValuesForVariable(currentDataIdentifier.getName());
            try {
                initStandAloneTimeSeries_private(timeSeries, dataManagerAccumDistances);
            } catch (Exception e) {
                failMethod(e, dataIdentifer);
                throw e;
            }
            if (isInit) {
                // set crosshair to init time
                // resampleStartTimeOrig;
                double initTime = initialLineScanTime;
                isInit = false;
                int closestTimeIndex = 0;
                double closestDiff = Double.MAX_VALUE;
                for (int i = 0; i < currentTimes.length; i += 1) {
                    double diff = Math.abs(initTime - currentTimes[i]);
                    if (diff < closestDiff) {
                        closestTimeIndex = i;
                        closestDiff = diff;
                    }
                }
                currentSelectionImg = new Point(0, closestTimeIndex);
                currentSelectionUnit = new Point2D.Double(0, (double) closestTimeIndex / (double) (currentTimes.length - 1));
                configurePlotData((int) currentSelectionImg.getX(), (int) currentSelectionImg.getY());
            // ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(pdeDataViewer);
            // //				final ChildWindow childWindow = childWindowManager.addChildWindow(new javax.swing.JPanel(),this,title);
            // final ChildWindow childWindow = childWindowManager.addChildWindow(KymographPanel.this,KymographPanel.this,title);
            // childWindow.setIsCenteredOnParent();
            // childWindow.pack();
            // childWindow.show();
            // Timer timer = new Timer(1000,new ActionListener() {
            // 
            // @Override
            // public void actionPerformed(ActionEvent e) {
            // childWindow.toFront();
            // }
            // });
            // System.out.println("Kymograph panel ChildWindow requesting focus.  Answer is: "+childWindow.requestFocusInWindow());
            // zoomToFill();
            } else {
                getImagePaneScroller1().zooming(new ZoomEvent(getimagePaneView1(), 0, 0));
            }
        }
    };
    AsynchClientTask[] tasks = (task2 == null ? new AsynchClientTask[] { task1, task3 } : new AsynchClientTask[] { task1, task2, task3 });
    ClientTaskDispatcher.dispatch(KymographPanel.this, new Hashtable<String, Object>(), tasks, false, true, true, null, false);
// if(bFromGUI){
// ClientTaskDispatcher.dispatch(KymographPanel.this,  new Hashtable<String, Object>(), tasks, false, true, true, null, false);
// System.out.println("Waiting here");
// }else{
// multiTimePlotHelper.addExtraTasks(tasks);
// }
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) DataIdentifier(cbit.vcell.simdata.DataIdentifier) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ActionEvent(java.awt.event.ActionEvent) Hashtable(java.util.Hashtable) Point(java.awt.Point) DataAccessException(org.vcell.util.DataAccessException) Point(java.awt.Point) ZoomEvent(cbit.image.ZoomEvent) ActionListener(java.awt.event.ActionListener) Point2D(java.awt.geom.Point2D) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 9 with TSJobResultsNoStats

use of org.vcell.util.document.TSJobResultsNoStats in project vcell by virtualcell.

the class DataSetControllerImpl method getTimeSeriesValues_private.

private TimeSeriesJobResults getTimeSeriesValues_private(OutputContext outputContext, final VCDataIdentifier vcdID, final TimeSeriesJobSpec timeSeriesJobSpec) throws DataAccessException {
    double[] dataTimes = null;
    boolean isPostProcessing = false;
    try {
        if (getVCData(vcdID) instanceof SimulationData && ((SimulationData) getVCData(vcdID)).isPostProcessing(outputContext, timeSeriesJobSpec.getVariableNames()[0])) {
            isPostProcessing = true;
            dataTimes = ((SimulationData) getVCData(vcdID)).getDataTimesPostProcess(outputContext);
        }
    } catch (Exception e) {
        // ignore
        e.printStackTrace();
    }
    if (dataTimes == null) {
        dataTimes = getDataSetTimes(vcdID);
    }
    TimeInfo timeInfo = new TimeInfo(vcdID, timeSeriesJobSpec.getStartTime(), timeSeriesJobSpec.getStep(), timeSeriesJobSpec.getEndTime(), dataTimes);
    if (dataTimes.length <= 0) {
        return null;
    }
    boolean[] wantsTheseTimes = new boolean[dataTimes.length];
    double[] desiredTimeValues = null;
    int desiredNumTimes = 0;
    Arrays.fill(wantsTheseTimes, false);
    double[] tempTimes = new double[dataTimes.length];
    int stepCounter = 0;
    for (int i = 0; i < dataTimes.length; i += 1) {
        if (dataTimes[i] > timeSeriesJobSpec.getEndTime()) {
            break;
        }
        if (dataTimes[i] == timeSeriesJobSpec.getStartTime()) {
            tempTimes[desiredNumTimes] = dataTimes[i];
            desiredNumTimes += 1;
            stepCounter = 0;
            wantsTheseTimes[i] = true;
            if (timeSeriesJobSpec.getStep() == 0) {
                break;
            }
        } else if (desiredNumTimes > 0 && stepCounter % timeSeriesJobSpec.getStep() == 0) {
            tempTimes[desiredNumTimes] = dataTimes[i];
            desiredNumTimes += 1;
            wantsTheseTimes[i] = true;
        }
        stepCounter += 1;
    }
    if (desiredNumTimes == 0) {
        throw new IllegalArgumentException("Couldn't find startTime " + timeSeriesJobSpec.getStartTime());
    }
    desiredTimeValues = new double[desiredNumTimes];
    System.arraycopy(tempTimes, 0, desiredTimeValues, 0, desiredNumTimes);
    // Check timeInfo
    if (desiredTimeValues.length != timeInfo.getDesiredTimeValues().length) {
        throw new DataAccessException("timeInfo check failed");
    }
    for (int i = 0; i < desiredTimeValues.length; i++) {
        if (desiredTimeValues[i] != timeInfo.getDesiredTimeValues()[i]) {
            throw new DataAccessException("timeInfo check failed");
        }
    }
    for (int i = 0; i < wantsTheseTimes.length; i++) {
        if (wantsTheseTimes[i] != timeInfo.getWantsTheseTimes()[i]) {
            throw new DataAccessException("timeInfo check failed");
        }
    }
    try {
        timeSeriesJobSpec.initIndices();
        // See if we need special processing
        TimeSeriesJobResults specialTSJR = getSpecialTimeSeriesValues(outputContext, vcdID, timeSeriesJobSpec, timeInfo);
        if (specialTSJR != null) {
            return specialTSJR;
        }
        // 
        VCData vcData = getVCData(vcdID);
        // 
        // Determine Memory Usage for this job to protect server
        // 
        // No TimeSeries jobs larger than this
        final long MAX_MEM_USAGE = 20000000;
        long memUsage = 0;
        // efficient function stats are not yet implemented so check to adjust calculation
        boolean bHasFunctionVars = false;
        for (int i = 0; i < timeSeriesJobSpec.getVariableNames().length; i += 1) {
            bHasFunctionVars = bHasFunctionVars || (getFunction(outputContext, vcdID, timeSeriesJobSpec.getVariableNames()[i]) != null);
        }
        for (int i = 0; i < timeSeriesJobSpec.getIndices().length; i += 1) {
            memUsage += (timeSeriesJobSpec.isCalcSpaceStats() && !bHasFunctionVars ? NUM_STATS : timeSeriesJobSpec.getIndices()[i].length);
        }
        memUsage *= desiredNumTimes * 8 * 2;
        System.out.println("DataSetControllerImpl.getTimeSeriesValues: job memory=" + memUsage);
        if (memUsage > MAX_MEM_USAGE) {
            throw new DataAccessException("DataSetControllerImpl.getTimeSeriesValues: Job too large" + (bHasFunctionVars ? "(has function vars)" : "") + ", requires approx. " + memUsage + " bytes of memory (only " + MAX_MEM_USAGE + " bytes allowed).  Choose fewer datapoints or times.");
        }
        // 
        Vector<double[][]> valuesV = new Vector<double[][]>();
        SpatialStatsInfo spatialStatsInfo = null;
        if (timeSeriesJobSpec.isCalcSpaceStats()) {
            spatialStatsInfo = calcSpatialStatsInfo(outputContext, timeSeriesJobSpec, vcdID);
        }
        final EventRateLimiter eventRateLimiter = new EventRateLimiter();
        for (int k = 0; k < timeSeriesJobSpec.getVariableNames().length; k += 1) {
            double[][] timeSeries = null;
            String varName = timeSeriesJobSpec.getVariableNames()[k];
            int[] indices = timeSeriesJobSpec.getIndices()[k];
            if (timeSeriesJobSpec.isCalcSpaceStats() && !bHasFunctionVars) {
                timeSeries = new double[NUM_STATS + 1][desiredNumTimes];
            } else {
                timeSeries = new double[indices.length + 1][desiredNumTimes];
            }
            timeSeries[0] = desiredTimeValues;
            ProgressListener progressListener = new ProgressListener() {

                public void updateProgress(double progress) {
                    // System.out.println("Considering firing progress event at "+new Date());
                    if (eventRateLimiter.isOkayToFireEventNow()) {
                        // System.out.println("ACTUALLY firing Progress event at "+new Date());
                        fireDataJobEventIfNecessary(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_PROGRESS, vcdID, new Double(progress), null, null);
                    }
                }

                public void updateMessage(String message) {
                // ignore
                }
            };
            AnnotatedFunction function = getFunction(outputContext, vcdID, varName);
            if (function != null) {
                if (vcData instanceof SimulationData) {
                    function = ((SimulationData) vcData).simplifyFunction(function);
                } else {
                    throw new Exception("DataSetControllerImpl::getTimeSeriesValues_private(): has to be SimulationData to get time plot.");
                }
                MultiFunctionIndexes mfi = new MultiFunctionIndexes(vcdID, function, indices, wantsTheseTimes, progressListener, outputContext);
                for (int i = 0; i < desiredTimeValues.length; i++) {
                    fireDataJobEventIfNecessary(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_PROGRESS, vcdID, new Double(NumberUtils.formatNumber(100.0 * (double) (k * desiredTimeValues.length + i) / (double) (timeSeriesJobSpec.getVariableNames().length * desiredTimeValues.length), 3)), null, null);
                    for (int j = 0; j < indices.length; j++) {
                        timeSeries[j + 1][i] = mfi.evaluateTimeFunction(outputContext, i, j);
                    }
                }
            } else {
                double[][][] valuesOverTime = null;
                if (timeSeriesJobSpec.isCalcSpaceStats() && !bHasFunctionVars) {
                    valuesOverTime = vcData.getSimDataTimeSeries(outputContext, new String[] { varName }, new int[][] { indices }, wantsTheseTimes, spatialStatsInfo, progressListener);
                } else {
                    valuesOverTime = vcData.getSimDataTimeSeries(outputContext, new String[] { varName }, new int[][] { indices }, wantsTheseTimes, progressListener);
                }
                for (int i = 0; i < desiredTimeValues.length; i++) {
                    fireDataJobEventIfNecessary(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_PROGRESS, vcdID, new Double(NumberUtils.formatNumber(100.0 * (double) (k * desiredTimeValues.length + i) / (double) (timeSeriesJobSpec.getVariableNames().length * desiredTimeValues.length), 3)), null, null);
                    if (timeSeriesJobSpec.isCalcSpaceStats() && !bHasFunctionVars) {
                        // min
                        timeSeries[MIN_OFFSET + 1][i] = valuesOverTime[i][0][MIN_OFFSET];
                        // max
                        timeSeries[MAX_OFFSET + 1][i] = valuesOverTime[i][0][MAX_OFFSET];
                        // mean
                        timeSeries[MEAN_OFFSET + 1][i] = valuesOverTime[i][0][MEAN_OFFSET];
                        // wmean
                        timeSeries[WMEAN_OFFSET + 1][i] = valuesOverTime[i][0][WMEAN_OFFSET];
                        // sum
                        timeSeries[SUM_OFFSET + 1][i] = valuesOverTime[i][0][SUM_OFFSET];
                        // wsum
                        timeSeries[WSUM_OFFSET + 1][i] = valuesOverTime[i][0][WSUM_OFFSET];
                    } else {
                        for (int j = 0; j < indices.length; j++) {
                            timeSeries[j + 1][i] = valuesOverTime[i][0][j];
                        }
                    }
                }
            }
            valuesV.add(timeSeries);
        }
        if (timeSeriesJobSpec.isCalcSpaceStats() && !bHasFunctionVars) {
            double[][] min = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
            double[][] max = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
            double[][] mean = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
            double[][] wmean = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
            double[][] sum = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
            double[][] wsum = new double[timeSeriesJobSpec.getVariableNames().length][desiredTimeValues.length];
            for (int i = 0; i < valuesV.size(); i += 1) {
                double[][] timeStat = (double[][]) valuesV.elementAt(i);
                for (int j = 0; j < desiredTimeValues.length; j += 1) {
                    min[i][j] = timeStat[MIN_OFFSET + 1][j];
                    max[i][j] = timeStat[MAX_OFFSET + 1][j];
                    mean[i][j] = timeStat[MEAN_OFFSET + 1][j];
                    wmean[i][j] = timeStat[WMEAN_OFFSET + 1][j];
                    sum[i][j] = timeStat[SUM_OFFSET + 1][j];
                    wsum[i][j] = timeStat[WSUM_OFFSET + 1][j];
                }
            }
            return new TSJobResultsSpaceStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), desiredTimeValues, min, max, mean, (spatialStatsInfo.bWeightsValid ? wmean : null), sum, (spatialStatsInfo.bWeightsValid ? wsum : null), (spatialStatsInfo.bWeightsValid ? spatialStatsInfo.totalSpace : null));
        } else if (timeSeriesJobSpec.isCalcSpaceStats() && bHasFunctionVars) {
            double[][][] timeSeriesFormatedValuesArr = new double[valuesV.size()][][];
            valuesV.copyInto(timeSeriesFormatedValuesArr);
            return calculateStatisticsFromWhole(timeSeriesJobSpec, timeSeriesFormatedValuesArr, desiredTimeValues, spatialStatsInfo);
        } else {
            double[][][] timeSeriesFormatedValuesArr = new double[valuesV.size()][][];
            valuesV.copyInto(timeSeriesFormatedValuesArr);
            TSJobResultsNoStats tsJobResultsNoStats = new TSJobResultsNoStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), desiredTimeValues, timeSeriesFormatedValuesArr);
            if (!isPostProcessing && timeSeriesJobSpec.getCrossingMembraneIndices() != null && timeSeriesJobSpec.getCrossingMembraneIndices().length > 0) {
                adjustMembraneAdjacentVolumeValues(outputContext, tsJobResultsNoStats.getTimesAndValuesForVariable(timeSeriesJobSpec.getVariableNames()[0]), true, null, timeSeriesJobSpec.getIndices()[0], timeSeriesJobSpec.getCrossingMembraneIndices()[0], vcdID, timeSeriesJobSpec.getVariableNames()[0], getMesh(vcdID), timeInfo);
            }
            return tsJobResultsNoStats;
        }
    } catch (DataAccessException e) {
        lg.error(e.getMessage(), e);
        throw e;
    } catch (Throwable e) {
        lg.error(e.getMessage(), e);
        throw new DataAccessException("DataSetControllerImpl.getTimeSeriesValues: " + (e.getMessage() == null ? e.getClass().getName() : e.getMessage()));
    }
}
Also used : TimeSeriesJobResults(org.vcell.util.document.TimeSeriesJobResults) Vector(java.util.Vector) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) EventRateLimiter(cbit.vcell.util.EventRateLimiter) TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DivideByZeroException(cbit.vcell.parser.DivideByZeroException) CacheException(org.vcell.util.CacheException) ExpressionBindingException(cbit.vcell.parser.ExpressionBindingException) FileNotFoundException(java.io.FileNotFoundException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Aggregations

TSJobResultsNoStats (org.vcell.util.document.TSJobResultsNoStats)9 TimeSeriesJobSpec (org.vcell.util.document.TimeSeriesJobSpec)7 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)4 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)4 Hashtable (java.util.Hashtable)4 DataAccessException (org.vcell.util.DataAccessException)4 SinglePoint (cbit.vcell.geometry.SinglePoint)3 VariableType (cbit.vcell.math.VariableType)3 DataIdentifier (cbit.vcell.simdata.DataIdentifier)3 CartesianMesh (cbit.vcell.solvers.CartesianMesh)3 MathException (cbit.vcell.math.MathException)2 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)2 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 SymbolTableEntry (cbit.vcell.parser.SymbolTableEntry)2 SpatialSelection (cbit.vcell.simdata.SpatialSelection)2 Point (java.awt.Point)2 Vector (java.util.Vector)2 TimeSeriesJobResults (org.vcell.util.document.TimeSeriesJobResults)2 DisplayAdapterService (cbit.image.DisplayAdapterService)1