Search in sources :

Example 16 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class ROIAssistPanel method resolveCurrentROI.

private void resolveCurrentROI() {
    final String CELL_ROI = "CELL_ROI";
    AsynchClientTask keepRegionsTask = new AsynchClientTask("Pick Region", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // TODO Auto-generated method stub
            RegionInfo[] keepRegionInfos = pickKeepRegionInfoFromCurrentROI();
            if (keepRegionInfos == null) {
                throw UserCancelException.CANCEL_GENERIC;
            }
            // dataToThreshold.getCurrentlyDisplayedROI().getPixelsXYZ();
            short[] keepPixels = new short[dataToThreshold.getCurrentlyDisplayedROI().getISize().getXYZ()];
            for (int i = 0; i < keepPixels.length; i++) {
                for (int j = 0; j < keepRegionInfos.length; j++) {
                    if (keepRegionInfos[j].isIndexInRegion(i)) {
                        keepPixels[i] = 1;
                    }
                }
            }
            UShortImage ushortImage = new UShortImage(keepPixels, originalROI.getRoiImages()[0].getOrigin(), originalROI.getRoiImages()[0].getExtent(), originalROI.getISize().getX(), originalROI.getISize().getY(), originalROI.getISize().getZ());
            ROI newCellROI = new ROI(ushortImage, originalROI.getROIName());
            hashTable.put(CELL_ROI, newCellROI);
        }
    };
    AsynchClientTask updateDisplayTask = new AsynchClientTask("Updating display", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        @Override
        public void run(Hashtable<String, Object> hashTable) throws Exception {
            dataToThreshold.addReplaceRoi((ROI) hashTable.get(CELL_ROI));
        }
    };
    ClientTaskDispatcher.dispatch(this, new Hashtable<String, Object>(), new AsynchClientTask[] { keepRegionsTask, updateDisplayTask }, false, false, null, true);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) RegionInfo(cbit.vcell.geometry.RegionImage.RegionInfo) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ROI(cbit.vcell.VirtualMicroscopy.ROI)

Example 17 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class RunRefSimulationFastOp method runRefSimulation.

private RowColumnResultSet runRefSimulation(ROI cellROI, ROI[] imageDataROIs, UShortImage psf, FloatImage initRefConc, double experimentalRecoveryTime, LocalWorkspace localWorkspace, ClientTaskStatusSupport progressListener) throws Exception {
    User owner = LocalWorkspace.getDefaultOwner();
    KeyValue simKey = LocalWorkspace.createNewKeyValue();
    // 
    // save first image from normalized time series as the initial concentration field data
    // 
    ExternalDataInfo initialConcentrationExtData = createNewExternalDataInfo(localWorkspace, INITCONC_EXTDATA_NAME);
    Extent extent = initRefConc.getExtent();
    Origin origin = initRefConc.getOrigin();
    ISize isize = new ISize(initRefConc.getNumX(), initRefConc.getNumY(), initRefConc.getNumZ());
    saveExternalData(initRefConc, INITCONC_EXTDATA_VARNAME, initialConcentrationExtData.getExternalDataIdentifier(), localWorkspace);
    FieldFunctionArguments initConditionFFA = new FieldFunctionArguments(INITCONC_EXTDATA_NAME, INITCONC_EXTDATA_VARNAME, new Expression(0.0), VariableType.VOLUME);
    // 
    // save ROIs as a multivariate field data
    // 
    ExternalDataInfo roiExtData = createNewExternalDataInfo(localWorkspace, ROI_EXTDATA_NAME);
    saveROIsAsExternalData(imageDataROIs, localWorkspace, roiExtData.getExternalDataIdentifier());
    ArrayList<FieldFunctionArguments> roiFFAs = new ArrayList<FieldFunctionArguments>();
    for (ROI roi : imageDataROIs) {
        roiFFAs.add(new FieldFunctionArguments(ROI_EXTDATA_NAME, ROI_MASK_NAME_PREFIX + roi.getROIName(), new Expression(0.0), VariableType.VOLUME));
    }
    // 
    // save PSF as a field data
    // 
    ExternalDataInfo psfExtData = createNewExternalDataInfo(localWorkspace, PSF_EXTDATA_NAME);
    savePsfAsExternalData(psf, PSF_EXTDATA_VARNAME, psfExtData.getExternalDataIdentifier(), localWorkspace);
    FieldFunctionArguments psfFFA = new FieldFunctionArguments(PSF_EXTDATA_NAME, PSF_EXTDATA_VARNAME, new Expression(0.0), VariableType.VOLUME);
    TimeBounds timeBounds = getEstimatedRefTimeBound(experimentalRecoveryTime);
    double timeStepVal = REFERENCE_DIFF_DELTAT;
    Expression chirpedDiffusionRate = new Expression(REFERENCE_DIFF_RATE_COEFFICIENT + "*(t+" + REFERENCE_DIFF_DELTAT + ")");
    BioModel bioModel = createRefSimBioModel(simKey, owner, origin, extent, cellROI, timeStepVal, timeBounds, VAR_NAME, new Expression(initConditionFFA.infix()), psfFFA, chirpedDiffusionRate);
    if (progressListener != null) {
        progressListener.setMessage("Running Reference Simulation...");
    }
    // run simulation
    Simulation simulation = bioModel.getSimulation(0);
    ROIDataGenerator roiDataGenerator = getROIDataGenerator(localWorkspace, imageDataROIs);
    simulation.getMathDescription().getPostProcessingBlock().addDataGenerator(roiDataGenerator);
    runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), simulation, initialConcentrationExtData.getExternalDataIdentifier(), roiExtData.getExternalDataIdentifier(), psfExtData.getExternalDataIdentifier(), progressListener, true);
    KeyValue referenceSimKeyValue = simulation.getVersion().getVersionKey();
    VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(referenceSimKeyValue, LocalWorkspace.getDefaultOwner());
    VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, 0);
    File hdf5File = new File(localWorkspace.getDefaultSimDataDirectory(), vcSimDataID.getID() + SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_HDF5);
    // get post processing info (time points, variable sizes)
    DataOperation.DataProcessingOutputInfoOP dataOperationInfo = new DataOperation.DataProcessingOutputInfoOP(null, /*no vcDataIdentifier OK*/
    false, null);
    DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) DataSetControllerImpl.getDataProcessingOutput(dataOperationInfo, hdf5File);
    // get post processing data
    DataOperation.DataProcessingOutputDataValuesOP dataOperationDataValues = new DataOperation.DataProcessingOutputDataValuesOP(null, /*no vcDataIdentifier OK*/
    ROI_EXTDATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null);
    DataOperationResults.DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataOperationResults.DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataOperationDataValues, hdf5File);
    // 
    // delete the simulation files
    // 
    // 
    // remove reference simulation files and field data files
    // 
    File userDir = new File(localWorkspace.getDefaultSimDataDirectory());
    File[] oldSimFilesToDelete = getSimulationFileNames(userDir, referenceSimKeyValue);
    for (int i = 0; oldSimFilesToDelete != null && i < oldSimFilesToDelete.length; i++) {
        oldSimFilesToDelete[i].delete();
    }
    deleteCanonicalExternalData(localWorkspace, initialConcentrationExtData.getExternalDataIdentifier());
    deleteCanonicalExternalData(localWorkspace, roiExtData.getExternalDataIdentifier());
    deleteCanonicalExternalData(localWorkspace, roiExtData.getExternalDataIdentifier());
    // get ref sim time points (distorted by time dilation acceleration)
    double[] rawRefDataTimePoints = dataProcessingOutputInfo.getVariableTimePoints();
    // get shifted time points
    double[] correctedRefDataTimePoints = shiftTimeForBaseDiffRate(rawRefDataTimePoints);
    double[][] refData = dataProcessingOutputDataValues.getDataValues();
    // 
    // for rowColumnResultSet with { "t", "roi1", .... , "roiN" } for reference data
    // 
    int numROIs = imageDataROIs.length;
    String[] columnNames = new String[numROIs + 1];
    columnNames[0] = "t";
    for (int i = 0; i < numROIs; i++) {
        columnNames[i + 1] = imageDataROIs[i].getROIName();
    }
    RowColumnResultSet reducedData = new RowColumnResultSet(columnNames);
    for (int i = 0; i < correctedRefDataTimePoints.length; i++) {
        double[] row = new double[numROIs + 1];
        row[0] = correctedRefDataTimePoints[i];
        double[] roiData = refData[i];
        for (int j = 0; j < numROIs; j++) {
            // roiData[0] is the average over the cell .. postbleach this shouldn't change for pure diffusion
            row[j + 1] = roiData[j + 1];
        }
        reducedData.addRow(row);
    }
    return reducedData;
}
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) TimeBounds(cbit.vcell.solver.TimeBounds) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) DataOperation(cbit.vcell.simdata.DataOperation) ExternalDataInfo(org.vcell.vmicro.workflow.data.ExternalDataInfo) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ROI(cbit.vcell.VirtualMicroscopy.ROI) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) ROIDataGenerator(org.vcell.vmicro.workflow.data.ROIDataGenerator) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) DataOperationResults(cbit.vcell.simdata.DataOperationResults) File(java.io.File)

Example 18 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class RunRefSimulationFastOp method saveROIsAsExternalData.

private void saveROIsAsExternalData(ROI[] rois, LocalWorkspace localWorkspace, ExternalDataIdentifier newROIExtDataID) throws ObjectNotFoundException, ImageException, IOException {
    ISize isize = rois[0].getISize();
    Origin origin = rois[0].getRoiImages()[0].getOrigin();
    Extent extent = rois[0].getRoiImages()[0].getExtent();
    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 cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
    int NumTimePoints = 1;
    int NumChannels = rois.length;
    // dimensions: time points, channels, whole image ordered by z slices.
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    int index = 0;
    for (ROI roi : rois) {
        pixData[0][index++] = createDoubleArray(roi.getBinaryPixelsXYZ(1));
    }
    // 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;
    ArrayList<String> varNames = new ArrayList<String>();
    ArrayList<VariableType> varTypes = new ArrayList<VariableType>();
    for (ROI roi : rois) {
        varNames.add(ROI_MASK_NAME_PREFIX + roi.getROIName());
        varTypes.add(VariableType.VOLUME);
    }
    fdos.varNames = varNames.toArray(new String[0]);
    fdos.owner = LocalWorkspace.getDefaultOwner();
    fdos.times = new double[] { 0.0 };
    fdos.variableTypes = varTypes.toArray(new VariableType[0]);
    fdos.origin = origin;
    fdos.extent = extent;
    fdos.isize = isize;
    localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
}
Also used : Origin(org.vcell.util.Origin) VariableType(cbit.vcell.math.VariableType) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) ArrayList(java.util.ArrayList) VCImage(cbit.image.VCImage) VCImageUncompressed(cbit.image.VCImageUncompressed) ROI(cbit.vcell.VirtualMicroscopy.ROI) CartesianMesh(cbit.vcell.solvers.CartesianMesh) RegionImage(cbit.vcell.geometry.RegionImage)

Example 19 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class VFrapProcess method compute.

public static VFrapProcessResults compute(ImageTimeSeries rawTimeSeriesImages, double bleachThreshold, double cellThreshold, LocalWorkspace localWorkspace, ClientTaskStatusSupport clientTaskStatusSupport) throws Exception {
    GenerateCellROIsFromRawFrapTimeSeriesOp generateCellROIs = new GenerateCellROIsFromRawFrapTimeSeriesOp();
    GeometryRoisAndBleachTiming geometryAndTiming = generateCellROIs.generate(rawTimeSeriesImages, cellThreshold);
    GenerateNormalizedFrapDataOp generateNormalizedFrapData = new GenerateNormalizedFrapDataOp();
    NormalizedFrapDataResults normalizedFrapResults = generateNormalizedFrapData.generate(rawTimeSeriesImages, geometryAndTiming.backgroundROI_2D, geometryAndTiming.indexOfFirstPostbleach);
    GenerateBleachRoiOp generateROIs = new GenerateBleachRoiOp();
    ROI bleachROI = generateROIs.generateBleachRoi(normalizedFrapResults.normalizedFrapData.getAllImages()[0], geometryAndTiming.cellROI_2D, bleachThreshold);
    GenerateDependentImageROIsOp generateDependentROIs = new GenerateDependentImageROIsOp();
    ROI[] dataROIs = generateDependentROIs.generate(geometryAndTiming.cellROI_2D, bleachROI);
    NormalizedSampleFunction[] roiSampleFunctions = new NormalizedSampleFunction[dataROIs.length];
    for (int i = 0; i < dataROIs.length; i++) {
        roiSampleFunctions[i] = NormalizedSampleFunction.fromROI(dataROIs[i]);
    }
    GenerateReducedDataOp generateReducedNormalizedData = new GenerateReducedDataOp();
    RowColumnResultSet reducedData = generateReducedNormalizedData.generateReducedData(normalizedFrapResults.normalizedFrapData, roiSampleFunctions);
    ComputeMeasurementErrorOp computeMeasurementError = new ComputeMeasurementErrorOp();
    RowColumnResultSet measurementError = computeMeasurementError.computeNormalizedMeasurementError(roiSampleFunctions, geometryAndTiming.indexOfFirstPostbleach, rawTimeSeriesImages, normalizedFrapResults.prebleachAverage, clientTaskStatusSupport);
    GenerateTrivial2DPsfOp psf_2D = new GenerateTrivial2DPsfOp();
    UShortImage psf = psf_2D.generateTrivial2D_Psf();
    // RunRefSimulationOp runRefSimulationFull = new RunRefSimulationOp();
    // GenerateReducedROIDataOp generateReducedRefSimData = new GenerateReducedROIDataOp();
    RunRefSimulationFastOp runRefSimulationFast = new RunRefSimulationFastOp();
    RowColumnResultSet refData = runRefSimulationFast.runRefSimFast(geometryAndTiming.cellROI_2D, normalizedFrapResults.normalizedFrapData, dataROIs, psf, localWorkspace, clientTaskStatusSupport);
    final double refDiffusionRate = 1.0;
    double[] refSimTimePoints = refData.extractColumn(0);
    int numRois = refData.getDataColumnCount() - 1;
    int numRefSimTimes = refData.getRowCount();
    double[][] refSimData = new double[numRois][numRefSimTimes];
    for (int roi = 0; roi < numRois; roi++) {
        double[] roiData = refData.extractColumn(roi + 1);
        for (int t = 0; t < numRefSimTimes; t++) {
            refSimData[roi][t] = roiData[t];
        }
    }
    ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
    OptModelOneDiff optModelOneDiff = new OptModelOneDiff(refSimData, refSimTimePoints, refDiffusionRate);
    Generate2DOptContextOp generate2DOptContextOne = new Generate2DOptContextOp();
    OptContext optContextOneDiff = generate2DOptContextOne.generate2DOptContext(optModelOneDiff, reducedData, measurementError, errorFunction);
    RunProfileLikelihoodGeneralOp runProfileLikelihoodOne = new RunProfileLikelihoodGeneralOp();
    ProfileData[] profileDataOne = runProfileLikelihoodOne.runProfileLikihood(optContextOneDiff, clientTaskStatusSupport);
    // OptModelTwoDiffWithoutPenalty optModelTwoDiffWithoutPenalty = new OptModelTwoDiffWithoutPenalty(refSimData, refSimTimePoints, refDiffusionRate);
    // Generate2DOptContextOp generate2DOptContextTwoWithoutPenalty = new Generate2DOptContextOp();
    // OptContext optContextTwoDiffWithoutPenalty = generate2DOptContextTwoWithoutPenalty.generate2DOptContext(optModelTwoDiffWithoutPenalty, reducedData, measurementError);
    // RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithoutPenalty = new RunProfileLikelihoodGeneralOp();
    // ProfileData[] profileDataTwoWithoutPenalty = runProfileLikelihoodTwoWithoutPenalty.runProfileLikihood(optContextTwoDiffWithoutPenalty, clientTaskStatusSupport);
    OptModelTwoDiffWithPenalty optModelTwoDiffWithPenalty = new OptModelTwoDiffWithPenalty(refSimData, refSimTimePoints, refDiffusionRate);
    Generate2DOptContextOp generate2DOptContextTwoWithPenalty = new Generate2DOptContextOp();
    OptContext optContextTwoDiffWithPenalty = generate2DOptContextTwoWithPenalty.generate2DOptContext(optModelTwoDiffWithPenalty, reducedData, measurementError, errorFunction);
    RunProfileLikelihoodGeneralOp runProfileLikelihoodTwoWithPenalty = new RunProfileLikelihoodGeneralOp();
    ProfileData[] profileDataTwoWithPenalty = runProfileLikelihoodTwoWithPenalty.runProfileLikihood(optContextTwoDiffWithPenalty, clientTaskStatusSupport);
    // 
    // SLOW WAY
    // 
    // runRefSimulationFull.cellROI_2D,generateCellROIs.cellROI_2D);
    // runRefSimulationFull.normalizedTimeSeries,generateNormalizedFrapData.normalizedFrapData);
    // workflow.addTask(runRefSimulationFull);
    // generateReducedRefSimData.imageTimeSeries,runRefSimulationFull.refSimTimeSeries);
    // generateReducedRefSimData.imageDataROIs,generateDependentROIs.imageDataROIs);
    // workflow.addTask(generateReducedRefSimData);
    // DataHolder<RowColumnResultSet> reducedROIData = generateReducedRefSimData.reducedROIData;
    // DataHolder<Double> refSimDiffusionRate = runRefSimulationFull.refSimDiffusionRate;
    VFrapProcessResults results = new VFrapProcessResults(dataROIs, geometryAndTiming.cellROI_2D, bleachROI, normalizedFrapResults.normalizedFrapData, reducedData, profileDataOne, profileDataTwoWithPenalty);
    return results;
}
Also used : OptModelOneDiff(org.vcell.vmicro.workflow.data.OptModelOneDiff) GenerateCellROIsFromRawFrapTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp) GenerateDependentImageROIsOp(org.vcell.vmicro.op.GenerateDependentImageROIsOp) RunProfileLikelihoodGeneralOp(org.vcell.vmicro.op.RunProfileLikelihoodGeneralOp) ErrorFunctionNoiseWeightedL2(org.vcell.vmicro.workflow.data.ErrorFunctionNoiseWeightedL2) OptContext(org.vcell.vmicro.workflow.data.OptContext) NormalizedSampleFunction(org.vcell.vmicro.workflow.data.NormalizedSampleFunction) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) OptModelTwoDiffWithPenalty(org.vcell.vmicro.workflow.data.OptModelTwoDiffWithPenalty) GenerateTrivial2DPsfOp(org.vcell.vmicro.op.GenerateTrivial2DPsfOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ErrorFunction(org.vcell.vmicro.workflow.data.ErrorFunction) GeometryRoisAndBleachTiming(org.vcell.vmicro.op.GenerateCellROIsFromRawFrapTimeSeriesOp.GeometryRoisAndBleachTiming) NormalizedFrapDataResults(org.vcell.vmicro.op.GenerateNormalizedFrapDataOp.NormalizedFrapDataResults) GenerateBleachRoiOp(org.vcell.vmicro.op.GenerateBleachRoiOp) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) ProfileData(org.vcell.optimization.ProfileData) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) RunRefSimulationFastOp(org.vcell.vmicro.op.RunRefSimulationFastOp) GenerateNormalizedFrapDataOp(org.vcell.vmicro.op.GenerateNormalizedFrapDataOp)

Example 20 with ROI

use of cbit.vcell.VirtualMicroscopy.ROI in project vcell by virtualcell.

the class PhotoactivationExperimentTest method analyzePhotoactivation.

/**
 * Fits raw image time series data to uniform disk models (with Guassian or Uniform fluorescence).
 *
 * @param rawTimeSeriesImages
 * @param localWorkspace
 * @throws Exception
 */
private static void analyzePhotoactivation(ImageTimeSeries<UShortImage> rawTimeSeriesImages, LocalWorkspace localWorkspace) throws Exception {
    // 
    // correct the timestamps (1 per second).
    // 
    double[] timeStamps = rawTimeSeriesImages.getImageTimeStamps();
    for (int i = 0; i < timeStamps.length; i++) {
        timeStamps[i] = i;
    }
    new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeriesImages, "raw images", (WindowListener) null);
    ImageTimeSeries<UShortImage> blurredRaw = blurTimeSeries(rawTimeSeriesImages);
    new DisplayTimeSeriesOp().displayImageTimeSeries(blurredRaw, "blurred raw images", (WindowListener) null);
    double cellThreshold = 0.4;
    GeometryRoisAndActivationTiming cellROIresults = new GenerateCellROIsFromRawPhotoactivationTimeSeriesOp().generate(blurredRaw, cellThreshold);
    ROI backgroundROI = cellROIresults.backgroundROI_2D;
    ROI cellROI = cellROIresults.cellROI_2D;
    int indexOfFirstPostactivation = cellROIresults.indexOfFirstPostactivation;
    boolean backgroundSubtract = false;
    boolean normalizeByPreActivation = false;
    NormalizedPhotoactivationDataResults normResults = new GenerateNormalizedPhotoactivationDataOp().generate(rawTimeSeriesImages, backgroundROI, indexOfFirstPostactivation, backgroundSubtract, normalizeByPreActivation);
    ImageTimeSeries<FloatImage> normalizedTimeSeries = normResults.normalizedPhotoactivationData;
    FloatImage preactivationAvg = normResults.preactivationAverageImage;
    FloatImage normalizedPostactivation = normalizedTimeSeries.getAllImages()[0];
    new DisplayTimeSeriesOp().displayImageTimeSeries(normalizedTimeSeries, "normalized images", (WindowListener) null);
    // 
    // create a single bleach ROI by thresholding
    // 
    double activatedThreshold = 1000;
    ROI activatedROI = new GenerateActivationRoiOp().generateActivatedRoi(blurredRaw.getAllImages()[indexOfFirstPostactivation], cellROI, activatedThreshold);
    new DisplayImageOp().displayImage(activatedROI.getRoiImages()[0], "activated roi", null);
    new DisplayImageOp().displayImage(cellROI.getRoiImages()[0], "cell roi", null);
    new DisplayImageOp().displayImage(backgroundROI.getRoiImages()[0], "background roi", null);
    {
        // 
        // only use bleach ROI for fitting etc.
        // 
        NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI) };
        // 
        // get reduced data and errors for each ROI
        // 
        RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
        RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
        DisplayPlotOp displayReducedData = new DisplayPlotOp();
        displayReducedData.displayPlot(reducedData, "reduced data", null);
        DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
        displayMeasurementError.displayPlot(measurementErrors, "measurement error", null);
        // 
        // 2 parameter uniform disk model
        // 
        Parameter tau = new Parameter("tau", 0.001, 200.0, 1.0, 0.1);
        Parameter f_init = new Parameter("f_init", 0.5, 4000, 1.0, 1.0);
        Parameter f_final = new Parameter("f_final", 0.01, 4000, 1.0, 0.5);
        Parameter[] parameters = new Parameter[] { tau, f_init, f_final };
        OptModel optModel = new OptModel("photoactivation (activated roi)", parameters) {

            @Override
            public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
                double tau = newParams[0];
                double max = newParams[1];
                double offset = newParams[2];
                double[][] solution = new double[1][solutionTimePoints.length];
                for (int i = 0; i < solution[0].length; i++) {
                    double t = solutionTimePoints[i];
                    solution[0][i] = offset + (max - offset) * Math.exp(-t / tau);
                }
                return solution;
            }

            @Override
            public double getPenalty(double[] parameters2) {
                return 0;
            }
        };
        ErrorFunction errorFunction = new ErrorFunctionNoiseWeightedL2();
        OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
        new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated ROI only", null);
    }
    {
        // 
        // only activation ROI for chemistry, cellROI for bleaching
        // 
        NormalizedSampleFunction[] dataROIs = new NormalizedSampleFunction[] { NormalizedSampleFunction.fromROI(activatedROI), NormalizedSampleFunction.fromROI(cellROI) };
        // 
        // get reduced data and errors for each ROI
        // 
        RowColumnResultSet reducedData = new GenerateReducedDataOp().generateReducedData(normalizedTimeSeries, dataROIs);
        RowColumnResultSet measurementErrors = new ComputeMeasurementErrorOp().computeNormalizedMeasurementError(dataROIs, indexOfFirstPostactivation, rawTimeSeriesImages, preactivationAvg, null);
        DisplayPlotOp displayReducedData = new DisplayPlotOp();
        displayReducedData.displayPlot(reducedData, "reduced data (2)", null);
        DisplayPlotOp displayMeasurementError = new DisplayPlotOp();
        displayMeasurementError.displayPlot(measurementErrors, "measurement error (2)", null);
        // 
        // 2 parameter uniform disk model
        // 
        Parameter tau_active = new Parameter("tau_active", 0.001, 200.0, 1.0, 0.1);
        Parameter f_active_init = new Parameter("f_active_init", 0.5, 4000, 1.0, 1.0);
        Parameter f_active_amplitude = new Parameter("f_active_amplitude", 0.01, 4000, 1.0, 0.5);
        Parameter f_cell_init = new Parameter("f_cell_init", 0.01, 4000, 1.0, 0.1);
        Parameter f_cell_amplitude = new Parameter("f_cell_amplitude", 0.01, 4000, 1.0, 0.1);
        Parameter tau_cell = new Parameter("tau_cell", 0.00001, 200, 1.0, 1);
        Parameter[] parameters = new Parameter[] { tau_active, f_active_init, f_active_amplitude, tau_cell, f_cell_init, f_cell_amplitude };
        OptModel optModel = new OptModel("photoactivation (activated and cell rois)", parameters) {

            @Override
            public double[][] getSolution0(double[] newParams, double[] solutionTimePoints) {
                double tau_active = newParams[0];
                double max_active = newParams[1];
                double amplitude_active = newParams[2];
                double tau_cell = newParams[3];
                double max_cell = newParams[4];
                double amplitude_cell = newParams[5];
                final int ACTIVE_ROI = 0;
                final int CELL_ROI = 1;
                final int NUM_ROIS = 2;
                double[][] solution = new double[NUM_ROIS][solutionTimePoints.length];
                for (int i = 0; i < solution[0].length; i++) {
                    double t = solutionTimePoints[i];
                    solution[ACTIVE_ROI][i] = (max_active - amplitude_active) + (amplitude_active) * Math.exp(-t / tau_active) * Math.exp(-t / tau_cell);
                    solution[CELL_ROI][i] = (max_cell - amplitude_cell) + (amplitude_cell) * Math.exp(-t / tau_cell);
                }
                return solution;
            }

            @Override
            public double getPenalty(double[] parameters2) {
                return 0;
            }
        };
        ErrorFunctionNoiseWeightedL2 errorFunction = new ErrorFunctionNoiseWeightedL2();
        OptContext uniformDisk2Context = new Generate2DOptContextOp().generate2DOptContext(optModel, reducedData, measurementErrors, errorFunction);
        new DisplayInteractiveModelOp().displayOptModel(uniformDisk2Context, dataROIs, localWorkspace, "nonspatial photoactivation - activated and cell ROIs", null);
    }
}
Also used : FloatImage(cbit.vcell.VirtualMicroscopy.FloatImage) GenerateCellROIsFromRawPhotoactivationTimeSeriesOp(org.vcell.vmicro.op.GenerateCellROIsFromRawPhotoactivationTimeSeriesOp) ErrorFunctionNoiseWeightedL2(org.vcell.vmicro.workflow.data.ErrorFunctionNoiseWeightedL2) OptContext(org.vcell.vmicro.workflow.data.OptContext) OptModel(org.vcell.vmicro.workflow.data.OptModel) DisplayPlotOp(org.vcell.vmicro.op.display.DisplayPlotOp) NormalizedPhotoactivationDataResults(org.vcell.vmicro.op.GenerateNormalizedPhotoactivationDataOp.NormalizedPhotoactivationDataResults) DisplayImageOp(org.vcell.vmicro.op.display.DisplayImageOp) DisplayTimeSeriesOp(org.vcell.vmicro.op.display.DisplayTimeSeriesOp) GeometryRoisAndActivationTiming(org.vcell.vmicro.op.GenerateCellROIsFromRawPhotoactivationTimeSeriesOp.GeometryRoisAndActivationTiming) DisplayInteractiveModelOp(org.vcell.vmicro.op.display.DisplayInteractiveModelOp) GenerateActivationRoiOp(org.vcell.vmicro.op.GenerateActivationRoiOp) GenerateReducedDataOp(org.vcell.vmicro.op.GenerateReducedDataOp) RowColumnResultSet(cbit.vcell.math.RowColumnResultSet) ErrorFunction(org.vcell.vmicro.workflow.data.ErrorFunction) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) Generate2DOptContextOp(org.vcell.vmicro.op.Generate2DOptContextOp) ROI(cbit.vcell.VirtualMicroscopy.ROI) ComputeMeasurementErrorOp(org.vcell.vmicro.op.ComputeMeasurementErrorOp) Parameter(cbit.vcell.opt.Parameter) GenerateNormalizedPhotoactivationDataOp(org.vcell.vmicro.op.GenerateNormalizedPhotoactivationDataOp)

Aggregations

ROI (cbit.vcell.VirtualMicroscopy.ROI)72 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)26 RowColumnResultSet (cbit.vcell.math.RowColumnResultSet)10 ArrayList (java.util.ArrayList)10 UserCancelException (org.vcell.util.UserCancelException)10 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)9 ImageException (cbit.image.ImageException)8 Image (cbit.vcell.VirtualMicroscopy.Image)7 FRAPData (cbit.vcell.microscopy.FRAPData)7 BioModel (cbit.vcell.biomodel.BioModel)6 FloatImage (cbit.vcell.VirtualMicroscopy.FloatImage)5 FieldFunctionArguments (cbit.vcell.field.FieldFunctionArguments)5 RegionInfo (cbit.vcell.geometry.RegionImage.RegionInfo)5 File (java.io.File)5 Hashtable (java.util.Hashtable)5 Element (org.jdom.Element)5 Extent (org.vcell.util.Extent)5 VCImage (cbit.image.VCImage)4 VCImageUncompressed (cbit.image.VCImageUncompressed)4 Expression (cbit.vcell.parser.Expression)4