Search in sources :

Example 16 with SourceDataInfo

use of cbit.image.SourceDataInfo in project vcell by virtualcell.

the class ImagePlaneManagerPanel method sourceDataInfo_set.

/**
 * Comment
 */
private void sourceDataInfo_set() {
    SourceDataInfo sdi = getSourceDataInfo();
    getdisplayAdapterService1().setValueDomain(sdi != null ? sdi.getMinMax() : null);
    getImagePlaneManager().setSourceDataInfo(sdi);
    if (sdi == null || sdi.getZSize() <= 1) {
        getImagePlanePanel1().setVisible(false);
    } else {
        getImagePlanePanel1().setVisible(true);
    }
}
Also used : SourceDataInfo(cbit.image.SourceDataInfo)

Example 17 with SourceDataInfo

use of cbit.image.SourceDataInfo 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)

Example 18 with SourceDataInfo

use of cbit.image.SourceDataInfo in project vcell by virtualcell.

the class ImportRawTimeSeriesFromHdf5FluorOp method importTimeSeriesFromHDF5Data.

public ImageTimeSeries<UShortImage> importTimeSeriesFromHDF5Data(File inputHDF5File, String fluorDataName, Double maxIntensity, boolean bNoise, int zSliceIndex) throws Exception {
    // if(progressListener != null){
    // progressListener.setMessage("Loading HDF5 file " + inputHDF5File.getAbsolutePath() + "...");
    // }
    DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(null, /*no vcDataIdentifier OK*/
    false, null), inputHDF5File);
    DataOperationResults.DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataOperationResults.DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(new DataOperation.DataProcessingOutputDataValuesOP(null, /*no vcDataIdentifier OK*/
    SimulationContext.FLUOR_DATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null), inputHDF5File);
    ArrayList<SourceDataInfo> sdiArr = dataProcessingOutputDataValues.createSourceDataInfos(dataProcessingOutputInfo.getVariableISize(SimulationContext.FLUOR_DATA_NAME), dataProcessingOutputInfo.getVariableOrigin(SimulationContext.FLUOR_DATA_NAME), dataProcessingOutputInfo.getVariableExtent(SimulationContext.FLUOR_DATA_NAME));
    double[] times = dataProcessingOutputInfo.getVariableTimePoints();
    if (sdiArr.size() != times.length) {
        throw new ImageException("Error FRAPData.createFrapData: times array length must equal SourceDataInfo vector size");
    }
    // construct
    int XY_SIZE = sdiArr.get(0).getXSize() * sdiArr.get(0).getYSize();
    int SLICE_OFFSET = 0 * XY_SIZE;
    // slice always 2D data
    int Z_SIZE = 1;
    // find scale factor to scale up the data to avoid losing precision when casting double to short
    double linearScaleFactor = 1;
    if (maxIntensity != null) {
        double maxDataValue = 0;
        for (int i = 0; i < times.length; i++) {
            if (sdiArr.get(i).getMinMax() != null) {
                maxDataValue = Math.max(maxDataValue, sdiArr.get(i).getMinMax().getMax());
            } else {
                double[] doubleData = (double[]) sdiArr.get(i).getData();
                for (int j = 0; j < doubleData.length; j++) {
                    maxDataValue = Math.max(maxDataValue, doubleData[j]);
                }
            }
        }
        linearScaleFactor = maxIntensity.doubleValue() / maxDataValue;
    }
    // saving each time step 2D double array to a UShortImage
    UShortImage[] dataImages1 = new UShortImage[times.length];
    for (int i = 0; i < times.length; i++) {
        double[] doubleData = (double[]) sdiArr.get(i).getData();
        short[] shortData = new short[XY_SIZE];
        for (int j = 0; j < shortData.length; j++) {
            shortData[j] = (short) (doubleData[j + (SLICE_OFFSET)] * linearScaleFactor);
        }
        dataImages1[i] = new UShortImage(shortData, sdiArr.get(i).getOrigin(), sdiArr.get(i).getExtent(), sdiArr.get(i).getXSize(), sdiArr.get(i).getYSize(), Z_SIZE);
    // if(progressListener != null){
    // int progress = (int)(((i+1)*1.0/times.length)*100);
    // progressListener.setProgress(progress);
    // }
    }
    ImageDataset imageDataSet = new ImageDataset(dataImages1, times, Z_SIZE);
    UShortImage[] dataImages = imageDataSet.getAllImages();
    double[] timeStamps = imageDataSet.getImageTimeStamps();
    ImageTimeSeries<UShortImage> rawImageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, dataImages, timeStamps, 1);
    return rawImageTimeSeries;
}
Also used : ImageException(cbit.image.ImageException) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) SourceDataInfo(cbit.image.SourceDataInfo) DataOperationResults(cbit.vcell.simdata.DataOperationResults) ImageTimeSeries(org.vcell.vmicro.workflow.data.ImageTimeSeries)

Aggregations

SourceDataInfo (cbit.image.SourceDataInfo)18 Range (org.vcell.util.Range)5 DisplayAdapterService (cbit.image.DisplayAdapterService)3 ImageException (cbit.image.ImageException)3 VCImage (cbit.image.VCImage)3 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)2 VariableType (cbit.vcell.math.VariableType)2 DataOperationResults (cbit.vcell.simdata.DataOperationResults)2 CartesianMesh (cbit.vcell.solvers.CartesianMesh)2 ArrayList (java.util.ArrayList)2 ImageTimeSeries (org.vcell.vmicro.workflow.data.ImageTimeSeries)2 ImagePaneModel (cbit.image.ImagePaneModel)1 ImagePlaneManager (cbit.image.ImagePlaneManager)1 VCImageUncompressed (cbit.image.VCImageUncompressed)1 ImagePlaneManagerPanel (cbit.image.gui.ImagePlaneManagerPanel)1 Plot2D (cbit.plot.Plot2D)1 PlotData (cbit.plot.PlotData)1 PlotPane (cbit.plot.gui.PlotPane)1 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)1 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)1