Search in sources :

Example 1 with DataProcessingOutputDataValues

use of cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues in project vcell by virtualcell.

the class DataSetControllerImpl method evaluatePostProcessFunction.

private static DataProcessingOutputDataValues evaluatePostProcessFunction(DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo, String[] postProcessSymbols, double[][][] postProcessData, DataIndexHelper dataIndexHelper, TimePointHelper timePointHelper, Expression flattenedBoundExpression, String varName) throws Exception {
    ISize iSize = dataProcessingOutputInfo.getVariableISize(postProcessSymbols[0]);
    VCImageUncompressed vcImage = new VCImageUncompressed(null, new byte[iSize.getXYZ()], new Extent(1, 1, 1), iSize.getX(), iSize.getY(), iSize.getZ());
    int dimension = 1 + (iSize.getY() > 1 ? 1 : 0) + (iSize.getZ() > 1 ? 1 : 0);
    RegionImage regionImage = new RegionImage(vcImage, dimension, dataProcessingOutputInfo.getVariableExtent(postProcessSymbols[0]), dataProcessingOutputInfo.getVariableOrigin(postProcessSymbols[0]), RegionImage.NO_SMOOTHING);
    CartesianMesh cartesianMesh = CartesianMesh.createSimpleCartesianMesh(dataProcessingOutputInfo.getVariableOrigin(postProcessSymbols[0]), dataProcessingOutputInfo.getVariableExtent(postProcessSymbols[0]), dataProcessingOutputInfo.getVariableISize(postProcessSymbols[0]), regionImage);
    double[] timePoints = null;
    if (timePointHelper.isAllTimePoints()) {
        timePoints = dataProcessingOutputInfo.getVariableTimePoints();
    } else {
        timePoints = timePointHelper.getTimePoints();
    }
    double[][] evaluatedValues = new double[timePoints.length][];
    int dataIndexCount = 0;
    ISize DATA_SIZE = dataProcessingOutputInfo.getVariableISize(postProcessSymbols[0]);
    int DATA_SIZE_XY = DATA_SIZE.getX() * DATA_SIZE.getY();
    if (dataIndexHelper.isAllDataIndexes()) {
        dataIndexCount = DATA_SIZE.getXYZ();
    } else if (dataIndexHelper.isSingleSlice()) {
        dataIndexCount = DATA_SIZE_XY;
    } else {
        dataIndexCount = dataIndexHelper.getDataIndexes().length;
    }
    double[] args = new double[TXYZ_OFFSET + postProcessSymbols.length];
    for (int t = 0; t < timePoints.length; t++) {
        evaluatedValues[t] = new double[dataIndexCount];
        args[0] = timePoints[t];
        for (int i = 0; i < dataIndexCount; i++) {
            Coordinate coord;
            if (dataIndexHelper.isAllDataIndexes()) {
                coord = cartesianMesh.getCoordinateFromVolumeIndex(i);
            } else if (dataIndexHelper.isSingleSlice()) {
                coord = cartesianMesh.getCoordinateFromVolumeIndex(dataIndexHelper.getSliceIndex() * DATA_SIZE_XY + i);
            } else {
                coord = cartesianMesh.getCoordinateFromVolumeIndex(dataIndexHelper.getDataIndexes()[i]);
            }
            args[1] = coord.getX();
            args[2] = coord.getY();
            args[3] = coord.getZ();
            for (int j = 0; j < postProcessSymbols.length; j++) {
                args[TXYZ_OFFSET + j] = postProcessData[j][t][i];
            }
            evaluatedValues[t][i] = flattenedBoundExpression.evaluateVector(args);
        // System.out.println("in="+args[4]+" out="+evaluatedValues[t][i]+" sin(in)="+Math.sin(args[4]));
        }
    }
    return new DataOperationResults.DataProcessingOutputDataValues(dataProcessingOutputInfo.getVCDataIdentifier(), varName, timePointHelper, dataIndexHelper, evaluatedValues);
}
Also used : CartesianMesh(cbit.vcell.solvers.CartesianMesh) Extent(org.vcell.util.Extent) Coordinate(org.vcell.util.Coordinate) ISize(org.vcell.util.ISize) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) RegionImage(cbit.vcell.geometry.RegionImage) VCImageUncompressed(cbit.image.VCImageUncompressed)

Example 2 with DataProcessingOutputDataValues

use of cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues in project vcell by virtualcell.

the class SimulationData method getSimDataBlock.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.simdata.DataBlock
 * @param user cbit.vcell.server.User
 * @param simID java.lang.String
 */
public synchronized SimDataBlock getSimDataBlock(OutputContext outputContext, String varName, double time) throws DataAccessException, IOException {
    refreshLogFile();
    try {
        getFunctionDataIdentifiers(outputContext);
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    }
    try {
        if (isPostProcessing(outputContext, varName)) {
            PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(), vcDataId.getID(), varName, time, lastDataProcessingOutputInfoTime);
            DataProcessingOutputDataValuesOP dataProcessingOutputDataValuesOP = new DataProcessingOutputDataValuesOP(vcDataId, varName, TimePointHelper.createSingleTimeTimePointHelper(extractClosestPostProcessTime(time)), DataIndexHelper.createAllDataIndexesDataIndexHelper(), outputContext, null);
            DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataProcessingOutputDataValuesOP, getDataProcessingOutputSourceFileHDF5());
            return new SimDataBlock(pdeDataInfo, dataProcessingOutputDataValues.getDataValues()[0], /*1 time only*/
            VariableType.POSTPROCESSING);
        }
    } catch (Exception e) {
        // ignore
        e.printStackTrace();
    }
    File pdeFile = getPDEDataFile(time);
    if (pdeFile == null) {
        return null;
    }
    DataSet dataSet = getPDEDataSet(pdeFile, time);
    File zipFile = null;
    try {
        zipFile = getPDEDataZipFile(time);
    } catch (DataAccessException ex) {
        zipFile = null;
    }
    long lastModified = getLastModified(pdeFile, zipFile);
    DataSetIdentifier dsi = getDataSetIdentifier(varName);
    if (dsi == null) {
        throw new DataAccessException("data not found for variable " + varName);
    }
    final String varNameInDataSet = dsi.getQualifiedName();
    double[] data = dataSet.getData(varNameInDataSet, zipFile, time, amplistorHelper.solverDataType);
    int varTypeInt = dataSet.getVariableTypeInteger(varNameInDataSet);
    VariableType variableType = null;
    try {
        variableType = VariableType.getVariableTypeFromInteger(varTypeInt);
    } catch (IllegalArgumentException e) {
        e.printStackTrace(System.out);
        System.out.println("invalid varTypeInt = " + varTypeInt + " for variable " + varName + " at time " + time);
        try {
            variableType = SimulationData.getVariableTypeFromLength(getMesh(), data.length);
        } catch (MathException ex) {
            ex.printStackTrace(System.out);
            throw new DataAccessException(ex.getMessage());
        }
    }
    PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(), vcDataId.getID(), varName, time, lastModified);
    if (data != null) {
        return new SimDataBlock(pdeDataInfo, data, variableType);
    } else {
        return null;
    }
}
Also used : VariableType(cbit.vcell.math.VariableType) 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) DataProcessingOutputDataValuesOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP) MathException(cbit.vcell.math.MathException) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException)

Example 3 with DataProcessingOutputDataValues

use of cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues in project vcell by virtualcell.

the class SimulationData method getSimDataTimeSeries0.

/**
 * This method was created in VisualAge.
 * @return cbit.vcell.simdata.DataBlock
 * @param user cbit.vcell.server.User
 * @param simID java.lang.String
 */
synchronized double[][][] getSimDataTimeSeries0(OutputContext outputContext, String[] varNames, int[][] indexes, boolean[] wantsThisTime, DataSetControllerImpl.SpatialStatsInfo spatialStatsInfo, DataSetControllerImpl.ProgressListener progressListener) throws DataAccessException, IOException {
    refreshLogFile();
    try {
        getFunctionDataIdentifiers(outputContext);
    } catch (Exception ex) {
        ex.printStackTrace(System.out);
    }
    int resultsCounter = 0;
    for (int i = 0; i < wantsThisTime.length; i += 1) {
        if (wantsThisTime[i]) {
            resultsCounter += 1;
        }
    }
    // min,max,mean,wmean
    final int NUM_STATS = 4;
    // Create results buffer
    // [timePoints][varNames][dataIndexes]
    double[][][] results = new double[resultsCounter][][];
    for (int i = 0; i < results.length; i += 1) {
        results[i] = new double[varNames.length][];
        for (int j = 0; j < results[i].length; j += 1) {
            if (spatialStatsInfo != null) {
                // min,max.mean,wmean
                results[i][j] = new double[NUM_STATS];
            } else {
                results[i][j] = new double[indexes[j].length];
            }
        }
    }
    try {
        if (varNames.length > 0 && isPostProcessing(outputContext, varNames[0])) {
            double[] specificTimePoints = new double[results.length];
            int counter = 0;
            for (int i = 0; i < dataProcessingOutputInfo.getVariableTimePoints().length; i++) {
                if (wantsThisTime[i]) {
                    specificTimePoints[counter] = dataProcessingOutputInfo.getVariableTimePoints()[i];
                    counter++;
                }
            }
            // PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(),vcDataId.getID(),varName,time,lastDataProcessingOutputInfoTime);
            for (int i = 0; i < varNames.length; i++) {
                DataProcessingOutputDataValuesOP dataProcessingOutputDataValuesOP = new DataProcessingOutputDataValuesOP(vcDataId, varNames[i], TimePointHelper.createSpecificTimePointHelper(specificTimePoints), DataIndexHelper.createSpecificDataIndexHelper(indexes[i]), outputContext, null);
                DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataProcessingOutputDataValuesOP, getDataProcessingOutputSourceFileHDF5());
                for (int j = 0; j < specificTimePoints.length; j++) {
                    results[j][i] = dataProcessingOutputDataValues.getDataValues()[j];
                }
            }
            return results;
        }
    } catch (Exception e) {
        // ignore
        e.printStackTrace();
    }
    String[] varNamesInDataSet = new String[varNames.length];
    for (int i = 0; i < varNamesInDataSet.length; i++) {
        varNamesInDataSet[i] = getDataSetIdentifier(varNames[i]).getQualifiedName();
    }
    // Setup parameters for SimDataReader
    double[] tempDataTimes = dataTimes.clone();
    String[] tempZipFileNames = null;
    if (bZipFormat2) {
        tempZipFileNames = new String[tempDataTimes.length];
    }
    String[] tempSimDataFileNames = new String[tempDataTimes.length];
    for (int i = 0; i < tempDataTimes.length; i += 1) {
        if (bZipFormat2 || bZipFormat1) {
            if (bZipFormat2) {
                tempZipFileNames[i] = getPDEDataZipFile(tempDataTimes[i]).getAbsolutePath();
            }
            tempSimDataFileNames[i] = dataFilenames[i];
        } else {
            // userDirectory.getAbsolutePath()+"\\"+dataFilenames[i];//getPDEDataFile(dataTimes[i]).getAbsolutePath();
            tempSimDataFileNames[i] = amplistorHelper.getFile(dataFilenames[i]).getName();
        }
    }
    SimDataReader sdr = null;
    double[][] singleTimePointResultsBuffer = new double[varNamesInDataSet.length][];
    for (int i = 0; i < singleTimePointResultsBuffer.length; i += 1) {
        singleTimePointResultsBuffer[i] = new double[indexes[i].length];
    }
    // In case sim files have been updated since "wantsThisTime" was calculated
    if (wantsThisTime.length < tempDataTimes.length) {
        double[] tempTempDataTimes = new double[wantsThisTime.length];
        System.arraycopy(tempDataTimes, 0, tempTempDataTimes, 0, wantsThisTime.length);
        tempDataTimes = tempTempDataTimes;
        String[] tempTempZipFileNames = new String[wantsThisTime.length];
        System.arraycopy(tempZipFileNames, 0, tempTempZipFileNames, 0, wantsThisTime.length);
        tempZipFileNames = tempTempZipFileNames;
        String[] tempTempSimDataFileNames = new String[wantsThisTime.length];
        System.arraycopy(tempSimDataFileNames, 0, tempTempSimDataFileNames, 0, wantsThisTime.length);
        tempSimDataFileNames = tempTempSimDataFileNames;
    }
    try {
        sdr = new SimDataReader(wantsThisTime, tempDataTimes, tempZipFileNames, tempSimDataFileNames, varNamesInDataSet, indexes, isChombo());
        int counter = 0;
        int progressCounter = 0;
        while (sdr.hasMoreData()) {
            sdr.getNextDataAtCurrentTime(singleTimePointResultsBuffer);
            // Copy data to timeSeries format
            if (wantsThisTime[counter]) {
                for (int i = 0; i < varNamesInDataSet.length; i += 1) {
                    if (spatialStatsInfo != null) {
                        results[progressCounter][i] = calcSpaceStats(singleTimePointResultsBuffer[i], i, spatialStatsInfo);
                    } else {
                        for (int j = 0; j < indexes[i].length; j += 1) {
                            results[progressCounter][i][j] = singleTimePointResultsBuffer[i][j];
                        }
                    }
                }
                progressCounter += 1;
                if (progressListener != null) {
                    progressListener.updateProgress(100.0 * (double) progressCounter / (double) resultsCounter);
                }
            }
            counter += 1;
        }
        return results;
    } catch (DataAccessException e) {
        throw e;
    } catch (IOException e) {
        throw e;
    } catch (Throwable e) {
        throw new DataAccessException(e.getMessage(), e);
    } finally {
        if (sdr != null) {
            sdr.close();
        }
    }
}
Also used : IOException(java.io.IOException) 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) DataProcessingOutputDataValuesOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) DataAccessException(org.vcell.util.DataAccessException)

Example 4 with DataProcessingOutputDataValues

use of cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues in project vcell by virtualcell.

the class RunFakeSimOp method runRefSimulation.

public ImageTimeSeries<UShortImage> runRefSimulation(LocalWorkspace localWorkspace, Simulation simulation, double max_intensity, double bleachBlackoutStartTime, double bleachBlackoutStopTime, boolean hasNoise, ClientTaskStatusSupport progressListener) throws Exception {
    User owner = LocalWorkspace.getDefaultOwner();
    KeyValue simKey = LocalWorkspace.createNewKeyValue();
    runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), simulation, progressListener);
    Extent extent = simulation.getMathDescription().getGeometry().getExtent();
    Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
    VCDataIdentifier vcDataIdentifier = new VCSimulationDataIdentifier(new VCSimulationIdentifier(simulation.getKey(), simulation.getVersion().getOwner()), 0);
    CartesianMesh mesh = localWorkspace.getDataSetControllerImpl().getMesh(vcDataIdentifier);
    ISize isize = new ISize(mesh.getSizeX(), mesh.getSizeY(), mesh.getSizeZ());
    double[] dataTimes = localWorkspace.getDataSetControllerImpl().getDataSetTimes(vcDataIdentifier);
    DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) localWorkspace.getDataSetControllerImpl().doDataOperation(new DataProcessingOutputDataValuesOP(vcDataIdentifier, SimulationContext.FLUOR_DATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null));
    ArrayList<SourceDataInfo> sourceDataInfoArr = dataProcessingOutputDataValues.createSourceDataInfos(new ISize(mesh.getSizeX(), mesh.getSizeY(), 1), origin, extent);
    // find scale factor to scale up the data to avoid losing precision when casting double to short
    double maxDataValue = 0;
    for (int i = 0; i < dataTimes.length; i++) {
        if (sourceDataInfoArr.get(i).getMinMax() != null) {
            maxDataValue = Math.max(maxDataValue, sourceDataInfoArr.get(i).getMinMax().getMax());
        } else {
            double[] doubleData = (double[]) sourceDataInfoArr.get(i).getData();
            for (int j = 0; j < doubleData.length; j++) {
                maxDataValue = Math.max(maxDataValue, doubleData[j]);
            }
        }
    }
    double scale = max_intensity / maxDataValue;
    ArrayList<UShortImage> outputImages = new ArrayList<UShortImage>();
    ArrayList<Double> outputTimes = new ArrayList<Double>();
    for (int i = 0; i < dataTimes.length; i++) {
        if (dataTimes[i] < bleachBlackoutStartTime || dataTimes[i] > bleachBlackoutStopTime) {
            // saving each time step 2D double array to a UShortImage
            double[] doubleData = (double[]) sourceDataInfoArr.get(i).getData();
            short[] shortData = new short[isize.getX() * isize.getY()];
            for (int j = 0; j < shortData.length; j++) {
                double dData = doubleData[j] * scale;
                if (dData < 0 || dData > 65535.0) {
                    throw new RuntimeException("scaled pixel out of range of unsigned 16 bit integer, original simulated value = " + doubleData[j] + ", scale = " + scale + ", scaled value = " + dData);
                }
                short sData = (short) (0x0000ffff & ((int) dData));
                if (hasNoise && dData > 0.0) {
                    if (dData > 20) {
                        shortData[j] = (short) (0x0000ffff & (int) RandomVariable.normal(dData, Math.sqrt(dData)));
                    } else {
                        shortData[j] = (short) (0x0000ffff & RandomVariable.poisson(dData));
                    }
                } else {
                    shortData[j] = sData;
                }
            }
            outputTimes.add(dataTimes[i]);
            outputImages.add(new UShortImage(shortData, sourceDataInfoArr.get(i).getOrigin(), sourceDataInfoArr.get(i).getExtent(), sourceDataInfoArr.get(i).getXSize(), sourceDataInfoArr.get(i).getYSize(), 1));
            if (progressListener != null) {
                int progress = (int) (((i + 1) * 1.0 / dataTimes.length) * 100);
                progressListener.setProgress(progress);
            }
        }
    }
    double[] outputTimesArray = new double[outputTimes.size()];
    for (int i = 0; i < outputTimes.size(); i++) {
        outputTimesArray[i] = outputTimes.get(i);
    }
    ImageTimeSeries<UShortImage> fakeFluorTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, outputImages.toArray(new UShortImage[0]), outputTimesArray, 1);
    return fakeFluorTimeSeries;
}
Also used : Origin(org.vcell.util.Origin) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ArrayList(java.util.ArrayList) SourceDataInfo(cbit.image.SourceDataInfo) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) CartesianMesh(cbit.vcell.solvers.CartesianMesh) DataProcessingOutputDataValuesOP(cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP) DataProcessingOutputDataValues(cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues) File(java.io.File) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Aggregations

DataProcessingOutputDataValues (cbit.vcell.simdata.DataOperationResults.DataProcessingOutputDataValues)4 DataProcessingOutputDataValuesOP (cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP)3 MathException (cbit.vcell.math.MathException)2 ExpressionException (cbit.vcell.parser.ExpressionException)2 CartesianMesh (cbit.vcell.solvers.CartesianMesh)2 XmlParseException (cbit.vcell.xml.XmlParseException)2 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 DataAccessException (org.vcell.util.DataAccessException)2 Extent (org.vcell.util.Extent)2 ISize (org.vcell.util.ISize)2 SourceDataInfo (cbit.image.SourceDataInfo)1 VCImageUncompressed (cbit.image.VCImageUncompressed)1 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)1 RegionImage (cbit.vcell.geometry.RegionImage)1 VariableType (cbit.vcell.math.VariableType)1 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)1 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)1 ArrayList (java.util.ArrayList)1