Search in sources :

Example 1 with DataProcessingOutputInfoOP

use of cbit.vcell.simdata.DataOperation.DataProcessingOutputInfoOP in project vcell by virtualcell.

the class PDEDataViewerPostProcess method dispatchPostProcessUpdate.

private void dispatchPostProcessUpdate(ClientPDEDataContext newClientPDEDataContext) {
    ArrayList<AsynchClientTask> allTasks = new ArrayList<>();
    final String SPATIAL_ERROR_KEY = "SPATIAL_ERROR_KEY";
    AsynchClientTask postProcessInfoTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (postProcessPDEDataViewer != null) {
                // already initialized
                return;
            }
            if (getClientTaskStatusSupport() != null) {
                getClientTaskStatusSupport().setMessage("Getting Simulation status...");
            }
            SimulationStatus simStatus = PDEDataViewerPostProcess.this.getDataViewerManager().getRequestManager().getServerSimulationStatus(PDEDataViewerPostProcess.this.getSimulation().getSimulationInfo());
            if (simStatus == null) {
                hashTable.put(SPATIAL_ERROR_KEY, "PostProcessing Image, no simulation status");
                return;
            } else if (!simStatus.isCompleted()) {
                // sim still busy, no postprocessing data
                hashTable.put(SPATIAL_ERROR_KEY, "PostProcessing Image, waiting for completed simulation: " + simStatus.toString());
                return;
            }
            if (getClientTaskStatusSupport() != null) {
                getClientTaskStatusSupport().setMessage("Getting Post Process Info...");
            }
            // Get PostProcess Image state variables info
            DataProcessingOutputInfoOP dataProcessingOutputInfoOP = new DataProcessingOutputInfoOP(PDEDataViewerPostProcess.this.getParentPdeDataContext().getVCDataIdentifier(), false, null);
            DataProcessingOutputInfo dataProcessingOutputInfo = (DataProcessingOutputInfo) PDEDataViewerPostProcess.this.getParentPdeDataContext().doDataOperation(dataProcessingOutputInfoOP);
            boolean bFoundImageStateVariables = false;
            if (dataProcessingOutputInfo != null && dataProcessingOutputInfo.getVariableNames() != null) {
                for (int i = 0; i < dataProcessingOutputInfo.getVariableNames().length; i++) {
                    if (dataProcessingOutputInfo.getPostProcessDataType(dataProcessingOutputInfo.getVariableNames()[i]).equals(DataProcessingOutputInfo.PostProcessDataType.image)) {
                        bFoundImageStateVariables = true;
                        break;
                    }
                }
            }
            if (!bFoundImageStateVariables) {
                hashTable.put(SPATIAL_ERROR_KEY, "No spatial PostProcessing variables found. (see Application->Protocols->Microscope Measurement)");
            }
        }
    };
    AsynchClientTask addPanelTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (postProcessPDEDataViewer != null) {
                return;
            }
            if (hashTable.get(SPATIAL_ERROR_KEY) != null) {
                if (PDEDataViewerPostProcess.this.getComponentCount() == 0) {
                    PDEDataViewerPostProcess.this.add(new JLabel((String) hashTable.get(SPATIAL_ERROR_KEY)), BorderLayout.CENTER);
                } else {
                    ((JLabel) PDEDataViewerPostProcess.this.getComponent(0)).setText((String) hashTable.get(SPATIAL_ERROR_KEY));
                }
                throw UserCancelException.CANCEL_GENERIC;
            }
            postProcessPDEDataViewer = new PDEDataViewer();
            parentDataJobListenerHolder.addDataJobListener(postProcessPDEDataViewer);
            PDEDataViewerPostProcess.this.postProcessPDEDataViewer.setPostProcessingPanelVisible(false);
            PDEDataViewerPostProcess.this.add(PDEDataViewerPostProcess.this.postProcessPDEDataViewer, BorderLayout.CENTER);
            postProcessPDEDataViewer.setDataViewerManager(getDataViewerManager());
            postProcessPDEDataViewer.setSimulationModelInfo(getSimulationModelInfo());
            postProcessPDEDataViewer.setSimulation(getSimulation());
        }
    };
    allTasks.addAll(Arrays.asList(PDEDataViewerPostProcess.this.getUpdateTasks()));
    // AsynchClientTask refreshTask = new AsynchClientTask("refreshPostProcess",AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
    // @Override
    // public void run(Hashtable<String, Object> hashTable) throws Exception {
    // ((ArrayList<AsynchClientTask>)hashTable.get(ClientTaskDispatcher.INTERMEDIATE_TASKS)).addAll(Arrays.asList(PDEDataViewerPostProcess.this.postProcessPDEDataViewer.getRefreshTasks()));
    // }
    // };
    // allTasks.add(refreshTask);
    allTasks.add(0, addPanelTask);
    allTasks.add(0, postProcessInfoTask);
    ClientTaskDispatcher.dispatch(this, new Hashtable<>(), allTasks.toArray(new AsynchClientTask[0]), false, false, false, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) JLabel(javax.swing.JLabel) DataProcessingOutputInfoOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputInfoOP) SimulationStatus(cbit.vcell.server.SimulationStatus) DataProcessingOutputInfo(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputInfo)

Example 2 with DataProcessingOutputInfoOP

use of cbit.vcell.simdata.DataOperation.DataProcessingOutputInfoOP in project vcell by virtualcell.

the class DataSetControllerImpl method getDataProcessingOutput.

public static DataOperationResults getDataProcessingOutput(DataOperation dataOperation, File dataProcessingOutputFileHDF5) throws Exception {
    DataOperationResults dataProcessingOutputResults = null;
    FileFormat hdf5FileFormat = null;
    try {
        if (dataProcessingOutputFileHDF5.exists()) {
            // retrieve an instance of H5File
            FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
            if (fileFormat == null) {
                throw new Exception("Cannot find HDF5 FileFormat.");
            }
            // open the file with read-only access
            hdf5FileFormat = fileFormat.open(dataProcessingOutputFileHDF5.getAbsolutePath(), FileFormat.READ);
            hdf5FileFormat.setMaxMembers(Simulation.MAX_LIMIT_SPATIAL_TIMEPOINTS);
            // open the file and retrieve the file structure
            hdf5FileFormat.open();
            Group root = (Group) ((javax.swing.tree.DefaultMutableTreeNode) hdf5FileFormat.getRootNode()).getUserObject();
            if (dataOperation instanceof DataProcessingOutputInfoOP) {
                DataProcessingHelper dataProcessingHelper = new DataProcessingHelper();
                iterateHDF5(root, "", dataProcessingHelper);
                dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputInfo(dataOperation.getVCDataIdentifier(), dataProcessingHelper.getVarNames(), dataProcessingHelper.getVarISizes(), dataProcessingHelper.times, dataProcessingHelper.getVarUnits(), dataProcessingHelper.getPostProcessDataTypes(), dataProcessingHelper.getVarOrigins(), dataProcessingHelper.getVarExtents(), dataProcessingHelper.getVarStatValues());
                // map function names to PostProcess state variable name
                ArrayList<String> postProcessImageVarNames = new ArrayList<String>();
                for (int i = 0; i < ((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getVariableNames().length; i++) {
                    String variableName = ((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getVariableNames()[i];
                    if (((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getPostProcessDataType(variableName).equals(DataOperationResults.DataProcessingOutputInfo.PostProcessDataType.image)) {
                        postProcessImageVarNames.add(variableName);
                    }
                }
                HashMap<String, String> mapFunctionNameToStateVarName = null;
                if (((DataProcessingOutputInfoOP) dataOperation).getOutputContext() != null) {
                    mapFunctionNameToStateVarName = new HashMap<String, String>();
                    for (int i = 0; i < ((DataProcessingOutputInfoOP) dataOperation).getOutputContext().getOutputFunctions().length; i++) {
                        AnnotatedFunction annotatedFunction = ((DataProcessingOutputInfoOP) dataOperation).getOutputContext().getOutputFunctions()[i];
                        if (annotatedFunction.getFunctionType().equals(VariableType.POSTPROCESSING)) {
                            String[] symbols = annotatedFunction.getExpression().flatten().getSymbols();
                            // Find any PostProcess state var that matches a symbol in the function
                            for (int j = 0; j < symbols.length; j++) {
                                if (postProcessImageVarNames.contains(symbols[j])) {
                                    mapFunctionNameToStateVarName.put(annotatedFunction.getName(), symbols[j]);
                                    break;
                                }
                            }
                        }
                    }
                }
                if (mapFunctionNameToStateVarName != null && mapFunctionNameToStateVarName.size() > 0) {
                    dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputInfo(((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults), mapFunctionNameToStateVarName);
                }
            } else {
                OutputContext outputContext = dataOperation.getOutputContext();
                String[] variableNames = null;
                DataIndexHelper dataIndexHelper = null;
                TimePointHelper timePointHelper = null;
                if (dataOperation instanceof DataOperation.DataProcessingOutputDataValuesOP) {
                    variableNames = new String[] { ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getVariableName() };
                    dataIndexHelper = ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getDataIndexHelper();
                    timePointHelper = ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getTimePointHelper();
                } else if (dataOperation instanceof DataOperation.DataProcessingOutputTimeSeriesOP) {
                    variableNames = ((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getTimeSeriesJobSpec().getVariableNames();
                    TimeSeriesJobSpec timeSeriesJobSpec = ((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getTimeSeriesJobSpec();
                    double[] specificTimepoints = extractTimeRange(((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getAllDatasetTimes(), timeSeriesJobSpec.getStartTime(), timeSeriesJobSpec.getEndTime());
                    timePointHelper = TimePointHelper.createSpecificTimePointHelper(specificTimepoints);
                    timeSeriesJobSpec.initIndices();
                    dataIndexHelper = DataIndexHelper.createSpecificDataIndexHelper(timeSeriesJobSpec.getIndices()[0]);
                } else {
                    throw new Exception("Unknown Dataoperation " + dataOperation.getClass().getName());
                }
                if (variableNames.length != 1) {
                    throw new Exception("Only 1 variable request at a time");
                }
                AnnotatedFunction[] annotatedFunctions = (outputContext == null ? null : outputContext.getOutputFunctions());
                AnnotatedFunction foundFunction = null;
                if (annotatedFunctions != null) {
                    for (int i = 0; i < annotatedFunctions.length; i++) {
                        if (annotatedFunctions[i].getName().equals(variableNames[0])) {
                            foundFunction = annotatedFunctions[i];
                            break;
                        }
                    }
                }
                double[] alltimes = null;
                if (foundFunction != null) {
                    DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(dataOperation.getVCDataIdentifier(), false, dataOperation.getOutputContext()), dataProcessingOutputFileHDF5);
                    alltimes = dataProcessingOutputInfo.getVariableTimePoints();
                    FunctionHelper functionHelper = getPostProcessStateVariables(foundFunction, dataProcessingOutputInfo);
                    DataProcessingHelper dataProcessingHelper = new DataProcessingHelper(functionHelper.postProcessStateVars, timePointHelper, dataIndexHelper);
                    iterateHDF5(root, "", dataProcessingHelper);
                    dataProcessingOutputResults = evaluatePostProcessFunction(dataProcessingOutputInfo, functionHelper.postProcessStateVars, dataProcessingHelper.specificDataValues, dataIndexHelper, timePointHelper, functionHelper.flattenedBoundExpression, variableNames[0]);
                } else {
                    DataProcessingHelper dataProcessingHelper = new DataProcessingHelper(new String[] { variableNames[0] }, timePointHelper, dataIndexHelper);
                    iterateHDF5(root, "", dataProcessingHelper);
                    alltimes = dataProcessingHelper.times;
                    if (dataProcessingHelper.specificDataValues == null) {
                        throw new Exception("Couldn't find postprocess data as specified for var=" + variableNames[0]);
                    }
                    dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputDataValues(dataOperation.getVCDataIdentifier(), variableNames[0], timePointHelper, dataIndexHelper, dataProcessingHelper.specificDataValues[0]);
                }
                if (dataOperation instanceof DataOperation.DataProcessingOutputTimeSeriesOP) {
                    TimeSeriesJobResults timeSeriesJobResults = null;
                    DataProcessingOutputTimeSeriesOP dataProcessingOutputTimeSeriesOP = (DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation;
                    // [time][data]
                    double[][] dataValues = ((DataOperationResults.DataProcessingOutputDataValues) dataProcessingOutputResults).getDataValues();
                    double[] desiredTimes = (timePointHelper.isAllTimePoints() ? alltimes : timePointHelper.getTimePoints());
                    double[][][] timeSeriesFormatedValuesArr = new double[variableNames.length][dataIndexHelper.getDataIndexes().length + 1][desiredTimes.length];
                    for (int i = 0; i < timeSeriesFormatedValuesArr.length; i++) {
                        // var
                        for (int j = 0; j < timeSeriesFormatedValuesArr[i].length; j++) {
                            // index
                            if (j == 0) {
                                timeSeriesFormatedValuesArr[i][j] = desiredTimes;
                                continue;
                            }
                            for (int k = 0; k < timeSeriesFormatedValuesArr[i][j].length; k++) {
                                // time
                                // assume 1 variable for now
                                timeSeriesFormatedValuesArr[i][j][k] = dataValues[k][j - 1];
                            }
                        }
                    }
                    if (dataProcessingOutputTimeSeriesOP.getTimeSeriesJobSpec().isCalcSpaceStats()) {
                        SpatialStatsInfo spatialStatsInfo = new SpatialStatsInfo();
                        spatialStatsInfo.bWeightsValid = false;
                        timeSeriesJobResults = calculateStatisticsFromWhole(dataProcessingOutputTimeSeriesOP.getTimeSeriesJobSpec(), timeSeriesFormatedValuesArr, timePointHelper.getTimePoints(), spatialStatsInfo);
                    } else {
                        timeSeriesJobResults = new TSJobResultsNoStats(variableNames, new int[][] { dataIndexHelper.getDataIndexes() }, timePointHelper.getTimePoints(), timeSeriesFormatedValuesArr);
                    }
                    dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputTimeSeriesValues(dataOperation.getVCDataIdentifier(), timeSeriesJobResults);
                }
            }
        } else {
            throw new FileNotFoundException("Data Processing Output file '" + dataProcessingOutputFileHDF5.getPath() + "' not found");
        }
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        if (hdf5FileFormat != null) {
            try {
                hdf5FileFormat.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    return dataProcessingOutputResults;
}
Also used : Group(ncsa.hdf.object.Group) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ArrayList(java.util.ArrayList) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) FileNotFoundException(java.io.FileNotFoundException) FileFormat(ncsa.hdf.object.FileFormat) DataProcessingOutputInfoOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputInfoOP) DataIndexHelper(cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP.DataIndexHelper) DataProcessingOutputTimeSeriesOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputTimeSeriesOP) TimeSeriesJobResults(org.vcell.util.document.TimeSeriesJobResults) TimePointHelper(cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP.TimePointHelper) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) 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) DataProcessingOutputTimeSeriesOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputTimeSeriesOP) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) TSJobResultsNoStats(org.vcell.util.document.TSJobResultsNoStats)

Example 3 with DataProcessingOutputInfoOP

use of cbit.vcell.simdata.DataOperation.DataProcessingOutputInfoOP in project vcell by virtualcell.

the class SimulationData method refreshDataProcessingOutputInfo.

private void refreshDataProcessingOutputInfo(OutputContext outputContext) throws DataAccessException {
    File dataProcessingOutputFile = getDataProcessingOutputSourceFileHDF5();
    if (dataProcessingOutputInfo == null && !dataProcessingOutputFile.exists()) {
        return;
    }
    AnnotatedFunction[] lastFunctions = (lastOutputContext == null ? null : lastOutputContext.getOutputFunctions());
    AnnotatedFunction[] currentFunctions = (outputContext == null ? null : outputContext.getOutputFunctions());
    boolean bFunctionsEqual = Compare.isEqualOrNull(lastFunctions, currentFunctions);
    if (!bFunctionsEqual || dataProcessingOutputInfo == null || lastDataProcessingOutputInfoTime != dataProcessingOutputFile.lastModified()) {
        lastDataProcessingOutputInfoTime = dataProcessingOutputFile.lastModified();
        lastOutputContext = outputContext;
        DataProcessingOutputInfoOP dataProcessingOutputInfoOP = new DataProcessingOutputInfoOP(vcDataId, false, outputContext);
        try {
            dataProcessingOutputInfo = (DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(dataProcessingOutputInfoOP, dataProcessingOutputFile);
        } catch (Exception e) {
            throw new DataAccessException(e.getMessage(), (e.getCause() == null ? e : e.getCause()));
        }
    }
}
Also used : ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) DataProcessingOutputInfoOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputInfoOP) FileNotFoundException(java.io.FileNotFoundException) XmlParseException(cbit.vcell.xml.XmlParseException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) ExpressionException(cbit.vcell.parser.ExpressionException) MathException(cbit.vcell.math.MathException) DataAccessException(org.vcell.util.DataAccessException) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Aggregations

DataProcessingOutputInfoOP (cbit.vcell.simdata.DataOperation.DataProcessingOutputInfoOP)3 MathException (cbit.vcell.math.MathException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)2 XmlParseException (cbit.vcell.xml.XmlParseException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 DataAccessException (org.vcell.util.DataAccessException)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1 DivideByZeroException (cbit.vcell.parser.DivideByZeroException)1 ExpressionBindingException (cbit.vcell.parser.ExpressionBindingException)1 SimulationStatus (cbit.vcell.server.SimulationStatus)1 DataIndexHelper (cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP.DataIndexHelper)1 TimePointHelper (cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP.TimePointHelper)1 DataProcessingOutputTimeSeriesOP (cbit.vcell.simdata.DataOperation.DataProcessingOutputTimeSeriesOP)1 DataProcessingOutputDataValues (cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues)1 DataProcessingOutputInfo (cbit.vcell.simdata.DataOperationResults.DataProcessingOutputInfo)1 File (java.io.File)1 Hashtable (java.util.Hashtable)1