Search in sources :

Example 1 with FRAPData

use of cbit.vcell.microscopy.FRAPData in project vcell by virtualcell.

the class FrapDataUtils method importFRAPDataFromVCellSimulationData.

public static FRAPData importFRAPDataFromVCellSimulationData(File vcellSimLogFile, String variableName, String bleachedMaskVarName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
    // bleachedMaskVarName = "laserMask_cell";
    VCSimulationIdentifier vcSimulationIdentifier = getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
    VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
    DataSetControllerImpl dataSetControllerImpl = getDataSetControllerImplFromVCellSimulationData(vcellSimLogFile);
    final DataJobEvent[] bStatus = new DataJobEvent[] { null };
    DataJobListener dataJobListener = new DataJobListener() {

        public void dataJobMessage(DataJobEvent event) {
            bStatus[0] = event;
            if (progressListener != null) {
                progressListener.setProgress((int) (event.getProgress() / 100.0 * .75));
            }
        }
    };
    dataSetControllerImpl.addDataJobListener(dataJobListener);
    DataIdentifier[] dataIdentifiers = getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
    DataIdentifier variableNameDataIdentifier = null;
    for (int i = 0; i < dataIdentifiers.length; i++) {
        if (dataIdentifiers[i].getName().equals(variableName)) {
            variableNameDataIdentifier = dataIdentifiers[i];
            break;
        }
    }
    if (variableNameDataIdentifier == null) {
        throw new IllegalArgumentException("Variable " + variableName + " not found.");
    }
    if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
        throw new IllegalArgumentException("Variable " + variableName + " is not VOLUME type.");
    }
    double[] times = dataSetControllerImpl.getDataSetTimes(vcSimulationDataIdentifier);
    CartesianMesh cartesianMesh = dataSetControllerImpl.getMesh(vcSimulationDataIdentifier);
    BitSet allBitset = new BitSet(cartesianMesh.getNumVolumeElements());
    allBitset.set(0, cartesianMesh.getNumVolumeElements() - 1);
    TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { variableName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(getDotUser(), true));
    TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) dataSetControllerImpl.getTimeSeriesValues(null, vcSimulationDataIdentifier, timeSeriesJobSpec);
    // wait for job to finish
    while (bStatus[0] == null || bStatus[0].getEventTypeID() != DataJobEvent.DATA_COMPLETE) {
        Thread.sleep(100);
    }
    double allTimesMin = tsJobResultsSpaceStats.getMinimums()[0][0];
    double allTimesMax = allTimesMin;
    for (int i = 0; i < times.length; i++) {
        allTimesMin = Math.min(allTimesMin, tsJobResultsSpaceStats.getMinimums()[0][i]);
        allTimesMax = Math.max(allTimesMax, tsJobResultsSpaceStats.getMaximums()[0][i]);
    }
    // double SCALE_MAX = maxIntensity.doubleValue();/*Math.pow(2,16)-1;*///Scale to 16 bits
    double linearScaleFactor = 1;
    if (maxIntensity != null) {
        linearScaleFactor = maxIntensity.doubleValue() / allTimesMax;
    }
    System.out.println("alltimesMin=" + allTimesMin + " allTimesMax=" + allTimesMax + " linearScaleFactor=" + linearScaleFactor);
    UShortImage[] scaledDataImages = new UShortImage[times.length];
    Random rnd = new Random();
    int shortMax = 65535;
    // set messge to load variable
    if (progressListener != null) {
        progressListener.setMessage("Loading variable " + variableName + "...");
    }
    for (int i = 0; i < times.length; i++) {
        double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, variableName, times[i]).getData();
        short[] scaledDataShort = new short[rawData.length];
        for (int j = 0; j < scaledDataShort.length; j++) {
            double scaledRawDataJ = rawData[j] * linearScaleFactor;
            if (bNoise) {
                double ran = rnd.nextGaussian();
                double scaledRawDataJ_withNoise = Math.max(0, (scaledRawDataJ + ran * Math.sqrt(scaledRawDataJ)));
                scaledRawDataJ_withNoise = Math.min(shortMax, scaledRawDataJ_withNoise);
                int scaledValue = (int) (scaledRawDataJ_withNoise);
                scaledDataShort[j] &= 0x0000;
                scaledDataShort[j] |= 0x0000FFFF & scaledValue;
            } else {
                int scaledValue = (int) (scaledRawDataJ);
                scaledDataShort[j] &= 0x0000;
                scaledDataShort[j] |= 0x0000FFFF & scaledValue;
            }
        }
        scaledDataImages[i] = new UShortImage(scaledDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        if (progressListener != null) {
            int progress = (int) (((i + 1) * 1.0 / times.length) * 100);
            progressListener.setProgress(progress);
        }
    }
    ImageDataset imageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
    FRAPData frapData = new FRAPData(imageDataSet, new String[] { FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name(), FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name(), FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name() });
    // get rois from log file
    if (bleachedMaskVarName != null) {
        // set message to load cell ROI variable
        if (progressListener != null) {
            progressListener.setMessage("Loading ROIs...");
        }
        double[] rawROIBleached = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, bleachedMaskVarName, 0).getData();
        short[] scaledCellDataShort = new short[rawROIBleached.length];
        short[] scaledBleachedDataShort = new short[rawROIBleached.length];
        short[] scaledBackgoundDataShort = new short[rawROIBleached.length];
        for (int j = 0; j < scaledCellDataShort.length; j++) {
            boolean isCell = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals("subVolume1");
            boolean isBackground = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals("subVolume0");
            if (isCell) {
                scaledCellDataShort[j] = 1;
            }
            if (isBackground) {
                scaledBackgoundDataShort[j] = 1;
            }
            if (rawROIBleached[j] > 0.2) {
                scaledBleachedDataShort[j] = 1;
            }
        }
        UShortImage cellImage = new UShortImage(scaledCellDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        UShortImage bleachedImage = new UShortImage(scaledBleachedDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
        if (progressListener != null) {
            progressListener.setProgress(100);
        }
        frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).setROIImages(new UShortImage[] { cellImage });
        frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).setROIImages(new UShortImage[] { bleachedImage });
        frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()).setROIImages(new UShortImage[] { backgroundImage });
    }
    return frapData;
}
Also used : VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) FRAPData(cbit.vcell.microscopy.FRAPData) BitSet(java.util.BitSet) TSJobResultsSpaceStats(org.vcell.util.document.TSJobResultsSpaceStats) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataJobEvent(cbit.rmi.event.DataJobEvent) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Random(java.util.Random) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) DataJobListener(cbit.rmi.event.DataJobListener)

Example 2 with FRAPData

use of cbit.vcell.microscopy.FRAPData in project vcell by virtualcell.

the class BackgroundROIDescriptor method preNextProcess.

public ArrayList<AsynchClientTask> preNextProcess() {
    // create AsynchClientTask arraylist
    ArrayList<AsynchClientTask> taskArrayList = new ArrayList<AsynchClientTask>();
    final String nextROIStr = null;
    AsynchClientTask setCurrentROITask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // save current ROI and load ROI in the panel it goes next to
            ((BatchRunROIImgPanel) imgPanel).setCurrentROI(nextROIStr, true);
            FRAPData fData = ((BatchRunROIImgPanel) imgPanel).getBatchRunWorkspace().getWorkingFrapStudy().getFrapData();
            fData.setCurrentlyDisplayedROI(fData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()), true);
        }
    };
    taskArrayList.add(setCurrentROITask);
    return taskArrayList;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) FRAPData(cbit.vcell.microscopy.FRAPData) ArrayList(java.util.ArrayList)

Example 3 with FRAPData

use of cbit.vcell.microscopy.FRAPData in project vcell by virtualcell.

the class BatchRunROIImgPanel method refreshUI.

public void refreshUI() {
    FRAPStudy workingFrapStudy = getBatchRunWorkspace().getWorkingFrapStudy();
    if (workingFrapStudy != null && workingFrapStudy.getFrapData() != null) {
        FRAPData fData = workingFrapStudy.getFrapData();
        // OriginalGlobalScaleInfo originalGlobalScaleInfo = fData.getOriginalGlobalScaleInfo();
        centerPanel.getOverlayEditorPanelJAI().setImages((fData == null ? null : fData.getImageDataset()), true);
        centerPanel.getOverlayEditorPanelJAI().setRoiSouceData(fData);
        centerPanel.getOverlayEditorPanelJAI().setROI(workingFrapStudy.getFrapData().getCurrentlyDisplayedROI());
    }
}
Also used : FRAPData(cbit.vcell.microscopy.FRAPData) FRAPStudy(cbit.vcell.microscopy.FRAPStudy)

Example 4 with FRAPData

use of cbit.vcell.microscopy.FRAPData in project vcell by virtualcell.

the class FRAPDataPanel method propertyChange.

// implementation of propertychange as a propertyChangeListener
public void propertyChange(PropertyChangeEvent e) {
    if (e.getSource() instanceof ImageLoadingProgress && e.getPropertyName().equals("ImageLoadingProgress")) {
        int prog = ((Integer) e.getNewValue()).intValue();
        VirtualFrapMainFrame.updateProgress(prog);
    } else if (e.getPropertyName().equals(VFrap_OverlayEditorPanelJAI.FRAP_DATA_CROP_PROPERTY)) {
        try {
            crop((Rectangle) e.getNewValue());
        } catch (Exception ex) {
            PopupGenerator.showErrorDialog(this, "Error Cropping:\n" + ex.getMessage());
        }
    } else if (e.getPropertyName().equals(FRAPSingleWorkspace.PROPERTY_CHANGE_CURRENTLY_DISPLAYED_ROI_WITH_SAVE)) {
        // To save only when the image is editable in this panel
        if (isEditable) {
            getOverlayEditorPanelJAI().saveUserChangesToROI();
        }
        // Set new ROI on viewer
        getOverlayEditorPanelJAI().setROI(getFrapWorkspace().getWorkingFrapStudy().getFrapData().getCurrentlyDisplayedROI());
    } else if (e.getPropertyName().equals(FRAPSingleWorkspace.PROPERTY_CHANGE_CURRENTLY_DISPLAYED_ROI_WITHOUT_SAVE)) {
        // Set new ROI on viewer
        getOverlayEditorPanelJAI().setROI(getFrapWorkspace().getWorkingFrapStudy().getFrapData().getCurrentlyDisplayedROI());
    } else if (e.getPropertyName().equals(FRAPSingleWorkspace.PROPERTY_CHANGE_FRAPSTUDY_NEW) || e.getPropertyName().equals(FRAPSingleWorkspace.PROPERTY_CHANGE_FRAPSTUDY_UPDATE) || e.getPropertyName().equals(FRAPSingleWorkspace.PROPERTY_CHANGE_FRAPSTUDY_BATCHRUN)) {
        if (e.getNewValue() instanceof FRAPStudy) {
            FRAPStudy fStudy = (FRAPStudy) e.getNewValue();
            FRAPStudy oldFrapStudy = (FRAPStudy) e.getOldValue();
            FRAPData fData = ((fStudy != null) ? (fStudy.getFrapData()) : (null));
            FRAPData oldFrapData = (oldFrapStudy != null) ? (oldFrapStudy.getFrapData()) : (null);
            if (oldFrapData != null) {
                oldFrapData.removePropertyChangeListener(this);
            }
            if (fData != null) {
                fData.addPropertyChangeListener(this);
            }
            if (e.getPropertyName().equals(FRAPSingleWorkspace.PROPERTY_CHANGE_FRAPSTUDY_NEW) || e.getPropertyName().equals(FRAPSingleWorkspace.PROPERTY_CHANGE_FRAPSTUDY_BATCHRUN)) {
                overlayEditorPanel.setImages((fData == null ? null : fData.getImageDataset()), true);
            } else {
                overlayEditorPanel.setImages((fData == null ? null : fData.getImageDataset()), false);
            }
            if (fData != null && fData.getROILength() > 0) {
                overlayEditorPanel.setRoiSouceData(fData);
                if (e.getPropertyName().equals(FRAPSingleWorkspace.PROPERTY_CHANGE_FRAPSTUDY_BATCHRUN)) {
                    fData.setCurrentlyDisplayedROIForBatchRun(fData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()));
                } else {
                    fData.setCurrentlyDisplayedROI(fData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()));
                }
            }
        }
    } else if (e.getPropertyName().equals(FRAPSingleWorkspace.FRAPDATA_VERIFY_INFO_PROPERTY)) {
        FRAPData fData = (FRAPData) e.getNewValue();
        overlayEditorPanel.setImages((fData == null ? null : fData.getImageDataset()), true);
        overlayEditorPanel.setRoiSouceData(fData);
        fData.setCurrentlyDisplayedROI(fData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()));
    }
}
Also used : FRAPData(cbit.vcell.microscopy.FRAPData) ImageLoadingProgress(cbit.vcell.VirtualMicroscopy.ImageLoadingProgress) Rectangle(java.awt.Rectangle) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) ImageException(cbit.image.ImageException)

Example 5 with FRAPData

use of cbit.vcell.microscopy.FRAPData in project vcell by virtualcell.

the class FRAPDataPanel method crop.

// There are two FRAPDataPanel instances, one is in MainFrame and antoher is in DefineROIWizard
// The crop function is called in DefineROIWizard, the image change will only be reflected in the
// FRAPDataPanel in DefineROIWizard. The newFrapStudy will only be set to FrapdataPanel in Mainframe
// when FINISH button is pressed.
protected void crop(Rectangle cropRectangle) throws ImageException {
    FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
    if (fStudy == null || fStudy.getFrapData() == null) {
        return;
    }
    getOverlayEditorPanelJAI().saveUserChangesToROI();
    FRAPData frapData = fStudy.getFrapData();
    FRAPData newFrapData = frapData.crop(cropRectangle);
    FRAPStudy newFrapStudy = new FRAPStudy();
    newFrapStudy.setFrapData(newFrapData);
    newFrapStudy.setXmlFilename(fStudy.getXmlFilename());
    newFrapStudy.setFrapDataExternalDataInfo(fStudy.getFrapDataExternalDataInfo());
    newFrapStudy.setRoiExternalDataInfo(fStudy.getRoiExternalDataInfo());
    newFrapStudy.setStoredRefData(fStudy.getStoredRefData());
    newFrapStudy.setModels(fStudy.getModels());
    newFrapStudy.setStartingIndexForRecovery(fStudy.getStartingIndexForRecovery());
    getFrapWorkspace().setFrapStudy(newFrapStudy, false);
}
Also used : FRAPData(cbit.vcell.microscopy.FRAPData) FRAPStudy(cbit.vcell.microscopy.FRAPStudy)

Aggregations

FRAPData (cbit.vcell.microscopy.FRAPData)20 ROI (cbit.vcell.VirtualMicroscopy.ROI)7 ArrayList (java.util.ArrayList)6 FRAPStudy (cbit.vcell.microscopy.FRAPStudy)4 Color (java.awt.Color)4 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)3 ImageException (cbit.image.ImageException)2 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)2 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)2 Hashtable (java.util.Hashtable)2 DataJobEvent (cbit.rmi.event.DataJobEvent)1 DataJobListener (cbit.rmi.event.DataJobListener)1 ImageLoadingProgress (cbit.vcell.VirtualMicroscopy.ImageLoadingProgress)1 DataIdentifier (cbit.vcell.simdata.DataIdentifier)1 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)1 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)1 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)1 CartesianMesh (cbit.vcell.solvers.CartesianMesh)1 Rectangle (java.awt.Rectangle)1 BitSet (java.util.BitSet)1