Search in sources :

Example 26 with FieldDataFileOperationSpec

use of cbit.vcell.field.io.FieldDataFileOperationSpec in project vcell by virtualcell.

the class FrapDataUtils method saveImageDatasetAsExternalData.

public static void saveImageDatasetAsExternalData(FRAPData frapData, LocalWorkspace localWorkspace, ExternalDataIdentifier newImageExtDataID, int startingIndexForRecovery, CartesianMesh cartesianMesh) throws ObjectNotFoundException, FileNotFoundException {
    ImageDataset imageDataset = frapData.getImageDataset();
    if (imageDataset.getSizeC() > 1) {
        throw new RuntimeException("FRAPData.saveImageDatasetAsExternalData(): multiple channels not yet supported");
    }
    Extent extent = imageDataset.getExtent();
    ISize isize = imageDataset.getISize();
    // not include the prebleach
    int numImageToStore = imageDataset.getSizeT() - startingIndexForRecovery;
    // original fluor data and back ground average
    double[][][] pixData = new double[numImageToStore][2][];
    double[] timesArray = new double[numImageToStore];
    double[] bgAvg = frapData.getAvgBackGroundIntensity();
    for (int tIndex = startingIndexForRecovery; tIndex < imageDataset.getSizeT(); tIndex++) {
        // images according to zIndex at specific time points(tIndex)
        short[] originalData = imageDataset.getPixelsZ(0, tIndex);
        double[] doubleData = new double[originalData.length];
        double[] expandBgAvg = new double[originalData.length];
        for (int i = 0; i < originalData.length; i++) {
            doubleData[i] = 0x0000ffff & originalData[i];
            expandBgAvg[i] = bgAvg[tIndex];
        }
        pixData[tIndex - startingIndexForRecovery][0] = doubleData;
        pixData[tIndex - startingIndexForRecovery][1] = expandBgAvg;
        timesArray[tIndex - startingIndexForRecovery] = imageDataset.getImageTimeStamps()[tIndex] - imageDataset.getImageTimeStamps()[startingIndexForRecovery];
    }
    // changed in March 2008. Though biomodel is not created, we still let user save to xml file.
    Origin origin = new Origin(0, 0, 0);
    FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
    fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
    fdos.cartesianMesh = cartesianMesh;
    fdos.doubleSpecData = pixData;
    fdos.specEDI = newImageExtDataID;
    fdos.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME, "bg_average" };
    fdos.owner = LocalWorkspace.getDefaultOwner();
    fdos.times = timesArray;
    fdos.variableTypes = new VariableType[] { VariableType.VOLUME, VariableType.VOLUME };
    fdos.origin = origin;
    fdos.extent = extent;
    fdos.isize = isize;
    localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
Also used : Origin(org.vcell.util.Origin) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec)

Example 27 with FieldDataFileOperationSpec

use of cbit.vcell.field.io.FieldDataFileOperationSpec in project vcell by virtualcell.

the class FrapDataUtils method saveROIsAsExternalData.

public static void saveROIsAsExternalData(FRAPData frapData, LocalWorkspace localWorkspace, ExternalDataIdentifier newROIExtDataID, int startingIndexForRecovery, CartesianMesh cartesianMesh) throws ObjectNotFoundException, FileNotFoundException {
    ImageDataset imageDataset = frapData.getImageDataset();
    Extent extent = imageDataset.getExtent();
    ISize isize = imageDataset.getISize();
    int NumTimePoints = 1;
    // actually it is total number of ROIs(cell,bleached + 8 rings)+prebleach+firstPostBleach+lastPostBleach
    int NumChannels = 13;
    // dimensions: time points, channels, whole image ordered by z slices.
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    double[] temp_background = frapData.getAvgBackGroundIntensity();
    double[] avgPrebleachDouble = calculatePreBleachAverageXYZ(frapData, startingIndexForRecovery);
    // average of prebleach with background subtracted
    pixData[0][0] = avgPrebleachDouble;
    // first post-bleach with background subtracted
    pixData[0][1] = createDoubleArray(imageDataset.getPixelsZ(0, startingIndexForRecovery), temp_background[startingIndexForRecovery], true);
    // adjustPrebleachAndPostbleachData(avgPrebleachDouble, pixData[0][1]);
    // last post-bleach image (at last time point) with background subtracted
    pixData[0][2] = createDoubleArray(imageDataset.getPixelsZ(0, imageDataset.getSizeT() - 1), temp_background[imageDataset.getSizeT() - 1], true);
    // below are ROIs, we don't need to subtract background for them.
    pixData[0][3] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).getBinaryPixelsXYZ(1), 0, false);
    pixData[0][4] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).getBinaryPixelsXYZ(1), 0, false);
    if (frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name()) == null) {
        // throw new RuntimeException("must first generate \"derived masks\"");
        pixData[0][5] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][6] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][7] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][8] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][9] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][10] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][11] = new double[imageDataset.getISize().getXYZ()];
        pixData[0][12] = new double[imageDataset.getISize().getXYZ()];
    } else {
        pixData[0][5] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][6] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING2.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][7] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING3.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][8] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING4.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][9] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING5.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][10] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING6.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][11] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING7.name()).getBinaryPixelsXYZ(1), 0, false);
        pixData[0][12] = createDoubleArray(frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING8.name()).getBinaryPixelsXYZ(1), 0, false);
    }
    Origin origin = new Origin(0, 0, 0);
    FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
    fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
    fdos.cartesianMesh = cartesianMesh;
    fdos.doubleSpecData = pixData;
    fdos.specEDI = newROIExtDataID;
    fdos.varNames = new String[] { "prebleach_avg", "postbleach_first", "postbleach_last", "bleached_mask", "cell_mask", "ring1_mask", "ring2_mask", "ring3_mask", "ring4_mask", "ring5_mask", "ring6_mask", "ring7_mask", "ring8_mask" };
    fdos.owner = LocalWorkspace.getDefaultOwner();
    fdos.times = new double[] { 0.0 };
    fdos.variableTypes = new VariableType[] { VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME, VariableType.VOLUME };
    fdos.origin = origin;
    fdos.extent = extent;
    fdos.isize = isize;
    localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
Also used : Origin(org.vcell.util.Origin) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec)

Example 28 with FieldDataFileOperationSpec

use of cbit.vcell.field.io.FieldDataFileOperationSpec 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 29 with FieldDataFileOperationSpec

use of cbit.vcell.field.io.FieldDataFileOperationSpec in project vcell by virtualcell.

the class RunRefSimulationFastOp method getROIDataGenerator.

private ROIDataGenerator getROIDataGenerator(LocalContext localWorkspace, ROI[] rois) throws ImageException, IOException {
    // create ROI image
    short[] roiFieldData = null;
    if (rois.length > 0) {
        Origin origin = new Origin(0, 0, 0);
        Extent extent = rois[0].getRoiImages()[0].getExtent();
        ISize isize = rois[0].getISize();
        int numROIX = rois[0].getISize().getX();
        int numROIY = rois[0].getISize().getY();
        roiFieldData = new short[numROIX * numROIY];
        short regionCounter = 1;
        for (int roiIdx = 0; roiIdx < rois.length; roiIdx++) {
            short[] roiImg = rois[roiIdx].getPixelsXYZ();
            for (int pixelIdx = 0; pixelIdx < (numROIX * numROIY); pixelIdx++) {
                if (roiImg[pixelIdx] > 0) {
                    roiFieldData[pixelIdx] = regionCounter;
                }
            }
            regionCounter++;
        }
        // create field data
        int NumTimePoints = 1;
        // 8 rois integrated into 1 image
        int NumChannels = 1;
        short[][][] pixData = new short[NumTimePoints][NumChannels][];
        pixData[0][0] = roiFieldData;
        // get extental data id
        VCImage vcImage = new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ());
        RegionImage regionImage = new RegionImage(vcImage, 0, null, null, RegionImage.NO_SMOOTHING);
        CartesianMesh simpleCartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
        ExternalDataIdentifier newROIExtDataID = createNewExternalDataInfo(localWorkspace, ROI_SUMDATA_NAME).getExternalDataIdentifier();
        try {
            FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
            fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
            fdos.cartesianMesh = simpleCartesianMesh;
            fdos.shortSpecData = pixData;
            fdos.specEDI = newROIExtDataID;
            fdos.varNames = new String[] { "roiSumDataVar" };
            fdos.owner = LocalWorkspace.getDefaultOwner();
            fdos.times = new double[] { 0.0 };
            fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
            fdos.origin = origin;
            fdos.extent = extent;
            fdos.isize = isize;
            localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return new ROIDataGenerator(ROI_EXTDATA_NAME, /*name*/
        new int[] { 0 }, /* volumePoints*/
        new int[0], /* membranePoints*/
        regionCounter, /*numRegions*/
        0, /*zSlice*/
        newROIExtDataID.getKey(), /* fieldDataKey, sample image*/
        new FieldFunctionArguments(ROI_SUMDATA_NAME, ROI_SUMDATA_VARNAME, new Expression(0), VariableType.VOLUME), /*FieldFunctionArguments, sample image*/
        false);
    }
    return null;
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed) ImageException(cbit.image.ImageException) ObjectNotFoundException(org.vcell.util.ObjectNotFoundException) IOException(java.io.IOException) UserCancelException(org.vcell.util.UserCancelException) ROIDataGenerator(org.vcell.vmicro.workflow.data.ROIDataGenerator) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Expression(cbit.vcell.parser.Expression) RegionImage(cbit.vcell.geometry.RegionImage) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier)

Aggregations

FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)29 ISize (org.vcell.util.ISize)19 Origin (org.vcell.util.Origin)18 CartesianMesh (cbit.vcell.solvers.CartesianMesh)16 Extent (org.vcell.util.Extent)16 RegionImage (cbit.vcell.geometry.RegionImage)14 UserCancelException (org.vcell.util.UserCancelException)13 VCImageUncompressed (cbit.image.VCImageUncompressed)12 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)10 VCImage (cbit.image.VCImage)9 ImageException (cbit.image.ImageException)8 Hashtable (java.util.Hashtable)8 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)7 VariableType (cbit.vcell.math.VariableType)6 DataFormatException (java.util.zip.DataFormatException)6 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)5 File (java.io.File)5 ClientRequestManager (cbit.vcell.client.ClientRequestManager)4 RequestManager (cbit.vcell.client.RequestManager)4 SimDataBlock (cbit.vcell.simdata.SimDataBlock)4