Search in sources :

Example 46 with VCDataIdentifier

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

the class DataSetControllerImpl method getDataIdentifiers.

/**
 * This method was created by a SmartGuide.
 * @return java.lang.String[]
 */
public DataIdentifier[] getDataIdentifiers(OutputContext outputContext, VCDataIdentifier vcdID) throws DataAccessException, IOException, FileNotFoundException {
    if (lg.isTraceEnabled())
        lg.trace("DataSetControllerImpl.getDataIdentifiers(" + vcdID.getID() + ")");
    VCData simData = getVCData(vcdID);
    // filter names with _INSIDE and _OUTSIDE
    DataIdentifier[] dataIdentifiersIncludingOutsideAndInside = simData.getVarAndFunctionDataIdentifiers(outputContext);
    Vector<DataIdentifier> v = new Vector<DataIdentifier>();
    for (int i = 0; i < dataIdentifiersIncludingOutsideAndInside.length; i++) {
        DataIdentifier di = dataIdentifiersIncludingOutsideAndInside[i];
        if (!di.getName().endsWith(InsideVariable.INSIDE_VARIABLE_SUFFIX) && !di.getName().endsWith(OutsideVariable.OUTSIDE_VARIABLE_SUFFIX)) {
            if (di.getVariableType() == null || di.getVariableType().equals(VariableType.UNKNOWN)) {
                if (di.isFunction()) {
                    AnnotatedFunction f = getFunction(outputContext, vcdID, di.getName());
                    VariableType varType = getVariableTypeForFieldFunction(outputContext, vcdID, f);
                    di = new DataIdentifier(di.getName(), varType, di.getDomain(), di.isFunction(), f.getDisplayName());
                }
            }
            v.addElement(di);
        }
    }
    DataIdentifier[] ids = new DataIdentifier[v.size()];
    v.copyInto(ids);
    return ids;
}
Also used : VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) VariableType(cbit.vcell.math.VariableType) Vector(java.util.Vector) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction)

Example 47 with VCDataIdentifier

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

the class MergedData 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 SimDataBlock getSimDataBlock(OutputContext outputContext, String varName, double time) throws DataAccessException, IOException {
    VCDataIdentifier vcDataID = getVCDataIdentifierFromDataId(varName);
    if (vcDataID == null) {
        return null;
    }
    DataSetIdentifier varDatasetID = getDataSetIdentifier(varName);
    int actualVarNameIndx = varName.indexOf(".");
    String actualVarName = varName.substring(actualVarNameIndx + 1);
    SimDataBlock simDataBlk = null;
    // 
    if (vcDataID.getID().equals(datasetsIDList[0].getID())) {
        simDataBlk = getDatasetControllerImpl().getSimDataBlock(outputContext, vcDataID, actualVarName, time);
        return simDataBlk;
    } else {
        // TIME INTERPOLATION of datablock
        double[] timeArray = getDatasetControllerImpl().getDataSetTimes(vcDataID);
        boolean bTimesEqual = checkTimeArrays(timeArray);
        double[] timeResampledData = null;
        int timeArrayCounter = 0;
        long lastModified = Long.MIN_VALUE;
        if (bTimesEqual) {
            // If time arrays for both datasets are equal, no need to resample/interpolate in time, just obtain the datablock
            simDataBlk = getDatasetControllerImpl().getSimDataBlock(outputContext, vcDataID, actualVarName, time);
            timeResampledData = simDataBlk.getData();
        } else {
            while ((timeArrayCounter < timeArray.length - 2) && (time > timeArray[timeArrayCounter + 1])) {
                timeArrayCounter++;
            }
            SimDataBlock simDataBlock_1 = getDatasetControllerImpl().getSimDataBlock(outputContext, vcDataID, actualVarName, timeArray[timeArrayCounter]);
            double[] data_1 = simDataBlock_1.getData();
            if ((timeArrayCounter + 1) < (timeArray.length - 1)) {
                SimDataBlock simDataBlock_2 = getDatasetControllerImpl().getSimDataBlock(outputContext, vcDataID, actualVarName, timeArray[timeArrayCounter + 1]);
                lastModified = simDataBlock_2.getPDEDataInfo().getTimeStamp();
                double[] data_2 = simDataBlock_2.getData();
                timeResampledData = new double[data_1.length];
                // 
                for (int m = 0; m < data_1.length; m++) {
                    timeResampledData[m] = data_1[m] + (data_2[m] - data_1[m]) * (time - timeArray[timeArrayCounter]) / (timeArray[timeArrayCounter + 1] - timeArray[timeArrayCounter]);
                }
            } else {
                // past end of array, zero order interpolation
                lastModified = simDataBlock_1.getPDEDataInfo().getTimeStamp();
                timeResampledData = data_1;
            }
        }
        // SPATIAL INTERPOLATION
        CartesianMesh refMesh = null;
        CartesianMesh mesh = null;
        try {
            refMesh = getDatasetControllerImpl().getMesh(datasetsIDList[0]);
            mesh = getDatasetControllerImpl().getMesh(vcDataID);
        } catch (MathException e) {
            e.printStackTrace(System.out);
            throw new RuntimeException("Could not get Mesh for reference or given dataID");
        }
        double[] spaceResampledData = null;
        // Check origin and extent of reference and given dataset. If they don't match, cannot resample spatially
        if (!mesh.getExtent().compareEqual(refMesh.getExtent()) || !mesh.getOrigin().compareEqual(refMesh.getOrigin())) {
            throw new RuntimeException("Different origins and/or extents for the 2 geometries. Cannot compare the 2 simulations");
        }
        // Get dimension of geometry for reference and given datasets (using mesh variables!) to use appropriate
        // resampling algorithm. Check if mesh sizes for the 2 datasets are equal, then there is no need to
        // spatially resample the second dataset.
        int dimension = mesh.getGeometryDimension();
        int refDimension = refMesh.getGeometryDimension();
        if (mesh.getSizeX() != refMesh.getSizeX() || mesh.getSizeY() != refMesh.getSizeY() || mesh.getSizeZ() != refMesh.getSizeZ()) {
            if (varDatasetID.getVariableType().equals(VariableType.VOLUME)) {
                if (dimension == 1 && refDimension == 1) {
                    spaceResampledData = MathTestingUtilities.resample1DSpatial(timeResampledData, mesh, refMesh);
                } else if (dimension == 2 && refDimension == 2) {
                    spaceResampledData = MathTestingUtilities.resample2DSpatial(timeResampledData, mesh, refMesh);
                } else if (dimension == 3 && refDimension == 3) {
                    spaceResampledData = MathTestingUtilities.resample3DSpatial(timeResampledData, mesh, refMesh);
                } else {
                    throw new RuntimeException("Comparison of 2 simulations with different geometry dimensions are not handled at this time!");
                }
            } else {
                throw new RuntimeException("spatial resampling for variable type: " + varDatasetID.getVariableType().getTypeName() + " not supported");
            }
        } else {
            // 
            if (varDatasetID.getVariableType().equals(VariableType.MEMBRANE)) {
                // 
                if (membraneIndexMapping == null) {
                    membraneIndexMapping = mesh.getMembraneIndexMapping(refMesh);
                }
                spaceResampledData = new double[timeResampledData.length];
                for (int i = 0; i < timeResampledData.length; i++) {
                    spaceResampledData[i] = timeResampledData[membraneIndexMapping[i]];
                }
            } else {
                // 
                // no reordering needed for other variable types.
                // 
                spaceResampledData = timeResampledData;
            }
        }
        if (simDataBlk != null) {
            lastModified = simDataBlk.getPDEDataInfo().getTimeStamp();
        }
        PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataID.getOwner(), vcDataID.getID(), varName, time, lastModified);
        if (spaceResampledData != null) {
            return new SimDataBlock(pdeDataInfo, spaceResampledData, varDatasetID.getVariableType());
        } else {
            return null;
        }
    }
}
Also used : CartesianMesh(cbit.vcell.solvers.CartesianMesh) MathException(cbit.vcell.math.MathException) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier)

Example 48 with VCDataIdentifier

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

the class DisplayTimeSeries method displayImageTimeSeries.

public static void displayImageTimeSeries(final ImageTimeSeries<Image> imageTimeSeries, String title, WindowListener windowListener) throws ImageException, IOException {
    ISize size = imageTimeSeries.getISize();
    int dimension = (size.getZ() > 0) ? (3) : (2);
    Extent extent = imageTimeSeries.getExtent();
    Origin origin = imageTimeSeries.getAllImages()[0].getOrigin();
    // don't care ... no surfaces
    double filterCutoffFrequency = 0.5;
    VCImage vcImage = new VCImageUncompressed(null, new byte[size.getXYZ()], extent, size.getX(), size.getY(), size.getZ());
    RegionImage regionImage = new RegionImage(vcImage, dimension, extent, origin, filterCutoffFrequency);
    final CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, size, regionImage);
    final DataIdentifier dataIdentifier = new DataIdentifier("var", VariableType.VOLUME, new Domain("domain"), false, "var");
    final DataSetController dataSetController = new DataSetController() {

        @Override
        public ExportEvent makeRemoteFile(OutputContext outputContext, ExportSpecs exportSpecs) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public TimeSeriesJobResults getTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdataID, TimeSeriesJobSpec timeSeriesJobSpec) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdataID, String varName, double time) throws RemoteProxyException, DataAccessException {
            double timePoint = time;
            double[] timePoints = getDataSetTimes(vcdataID);
            int index = -1;
            for (int i = 0; i < timePoints.length; i++) {
                if (timePoint == timePoints[i]) {
                    index = i;
                    break;
                }
            }
            double[] data = imageTimeSeries.getAllImages()[index].getDoublePixels();
            PDEDataInfo pdeDataInfo = new PDEDataInfo(null, null, varName, time, 0);
            VariableType varType = VariableType.VOLUME;
            return new SimDataBlock(pdeDataInfo, data, varType);
        }

        @Override
        public boolean getParticleDataExists(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return false;
        }

        @Override
        public ParticleDataBlock getParticleDataBlock(VCDataIdentifier vcdataID, double time) throws DataAccessException, RemoteProxyException {
            return null;
        }

        @Override
        public ODESimData getODEData(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return null;
        }

        @Override
        public CartesianMesh getMesh(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return mesh;
        }

        @Override
        public PlotData getLineScan(OutputContext outputContext, VCDataIdentifier vcdataID, String variable, double time, SpatialSelection spatialSelection) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public AnnotatedFunction[] getFunctions(OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return new AnnotatedFunction[0];
        }

        @Override
        public double[] getDataSetTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return imageTimeSeries.getImageTimeStamps();
        }

        @Override
        public DataSetTimeSeries getDataSetTimeSeries(VCDataIdentifier vcdataID, String[] variableNames) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataSetMetadata getDataSetMetadata(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataIdentifier[] getDataIdentifiers(OutputContext outputContext, VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return new DataIdentifier[] { dataIdentifier };
        }

        @Override
        public FieldDataFileOperationResults fieldDataFileOperation(FieldDataFileOperationSpec fieldDataFileOperationSpec) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataOperationResults doDataOperation(DataOperation dataOperation) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public VtuFileContainer getEmptyVtuMeshFiles(VCDataIdentifier vcdataID, int timeIndex) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public double[] getVtuTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public double[] getVtuMeshData(OutputContext outputContext, VCDataIdentifier vcdataID, VtuVarInfo var, double time) throws RemoteProxyException, DataAccessException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public VtuVarInfo[] getVtuVarInfos(OutputContext outputContext, VCDataIdentifier vcDataIdentifier) throws DataAccessException, RemoteProxyException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public NFSimMolecularConfigurations getNFSimMolecularConfigurations(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            // TODO Auto-generated method stub
            return null;
        }
    };
    DataSetControllerProvider dataSetControllerProvider = new DataSetControllerProvider() {

        @Override
        public DataSetController getDataSetController() throws DataAccessException {
            return dataSetController;
        }
    };
    VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
    OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
    VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {

        public User getOwner() {
            return new User("nouser", null);
        }

        public KeyValue getDataKey() {
            return null;
        }

        public String getID() {
            return "mydata";
        }
    };
    PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
    ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
    PDEDataViewer pdeDataViewer = new PDEDataViewer();
    JFrame jframe = new JFrame();
    jframe.setTitle(title);
    jframe.getContentPane().add(pdeDataViewer);
    jframe.setSize(1000, 600);
    jframe.setVisible(true);
    if (windowListener != null) {
        jframe.addWindowListener(windowListener);
    }
    pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
Also used : Origin(org.vcell.util.Origin) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) User(org.vcell.util.document.User) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ExportSpecs(cbit.vcell.export.server.ExportSpecs) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) VCImage(cbit.image.VCImage) PDEDataInfo(cbit.vcell.simdata.PDEDataInfo) DataSetControllerProvider(cbit.vcell.server.DataSetControllerProvider) SimDataBlock(cbit.vcell.simdata.SimDataBlock) SpatialSelection(cbit.vcell.simdata.SpatialSelection) JFrame(javax.swing.JFrame) VCDataManager(cbit.vcell.simdata.VCDataManager) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) DataOperation(cbit.vcell.simdata.DataOperation) VariableType(cbit.vcell.math.VariableType) DataSetController(cbit.vcell.server.DataSetController) VCImageUncompressed(cbit.image.VCImageUncompressed) OutputContext(cbit.vcell.simdata.OutputContext) CartesianMesh(cbit.vcell.solvers.CartesianMesh) PDEDataManager(cbit.vcell.simdata.PDEDataManager) RegionImage(cbit.vcell.geometry.RegionImage) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) Domain(cbit.vcell.math.Variable.Domain) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) PDEDataViewer(cbit.vcell.client.data.PDEDataViewer)

Example 49 with VCDataIdentifier

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

VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)49 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)20 CartesianMesh (cbit.vcell.solvers.CartesianMesh)17 DataAccessException (org.vcell.util.DataAccessException)15 Vector (java.util.Vector)12 IOException (java.io.IOException)11 User (org.vcell.util.document.User)11 File (java.io.File)10 ArrayList (java.util.ArrayList)10 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)10 SimDataBlock (cbit.vcell.simdata.SimDataBlock)9 KeyValue (org.vcell.util.document.KeyValue)9 MathException (cbit.vcell.math.MathException)8 DataIdentifier (cbit.vcell.simdata.DataIdentifier)8 PDEDataManager (cbit.vcell.simdata.PDEDataManager)8 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)8 ObjectNotFoundException (org.vcell.util.ObjectNotFoundException)8 ExportSpecs (cbit.vcell.export.server.ExportSpecs)7 VariableType (cbit.vcell.math.VariableType)7 OutputContext (cbit.vcell.simdata.OutputContext)7