use of cbit.vcell.VirtualMicroscopy.ImageDataset 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);
}
use of cbit.vcell.VirtualMicroscopy.ImageDataset in project vcell by virtualcell.
the class FRAPData method crop.
/**
* Method crop.
* @param rect Rectangle
* @return FRAPData
* @throws ImageException
*/
@Override
public FRAPData crop(Rectangle rect) throws ImageException {
ImageDataset croppedImageDataset = getImageDataset().crop(rect);
ROI[] rois = getRois();
ROI[] croppedROIs = new ROI[rois.length];
ROI currentlyDisplayedROI = getCurrentlyDisplayedROI();
ROI croppedCurrentROI = null;
for (int i = 0; i < croppedROIs.length; i++) {
croppedROIs[i] = rois[i].crop(rect);
if (currentlyDisplayedROI == rois[i]) {
croppedCurrentROI = croppedROIs[i];
}
}
FRAPData croppedFrapData = new FRAPData(croppedImageDataset, croppedROIs);
setCurrentlyDisplayedROI(croppedCurrentROI);
return croppedFrapData;
}
use of cbit.vcell.VirtualMicroscopy.ImageDataset in project vcell by virtualcell.
the class ImportRawTimeSeriesFrom2DVCellConcentrationsOp method importRawTimeSeries.
private static ImageDataset importRawTimeSeries(File vcellSimLogFile, String fluorFunctionName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
VCSimulationIdentifier vcSimulationIdentifier = VCellSimReader.getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
DataSetControllerImpl dataSetControllerImpl = VCellSimReader.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 = VCellSimReader.getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
DataIdentifier variableNameDataIdentifier = null;
for (int i = 0; i < dataIdentifiers.length; i++) {
if (dataIdentifiers[i].getName().equals(fluorFunctionName)) {
variableNameDataIdentifier = dataIdentifiers[i];
break;
}
}
if (variableNameDataIdentifier == null) {
throw new IllegalArgumentException("Variable " + fluorFunctionName + " not found.");
}
if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
throw new IllegalArgumentException("Variable " + fluorFunctionName + " 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[] { fluorFunctionName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(VCellSimReader.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 " + fluorFunctionName + "...");
}
for (int i = 0; i < times.length; i++) {
double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, fluorFunctionName, 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 rawImageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
return rawImageDataSet;
}
use of cbit.vcell.VirtualMicroscopy.ImageDataset in project vcell by virtualcell.
the class ImportRawTimeSeriesFrom2DVCellConcentrationsOp method importRawTimeSeries.
public ImageTimeSeries<UShortImage> importRawTimeSeries(File vcellSimLogFile, String fluorFunctionName, double maxIntensity, boolean bNoise) throws Exception {
ClientTaskStatusSupport clientTaskStatusSupport = null;
ImageDataset timeRawData = importRawTimeSeries(vcellSimLogFile, fluorFunctionName, maxIntensity, bNoise, clientTaskStatusSupport);
ImageTimeSeries<UShortImage> imageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, timeRawData.getAllImages(), timeRawData.getImageTimeStamps(), 1);
return imageTimeSeries;
}
use of cbit.vcell.VirtualMicroscopy.ImageDataset in project vcell by virtualcell.
the class ImportRawTimeSeriesFromExperimentImagesOp method importRawTimeSeries.
public ImageTimeSeries<UShortImage> importRawTimeSeries(File[] expTimeSeriesFiles, double timeInterval) throws Exception {
boolean isTimeSeries = true;
ClientTaskStatusSupport clientTaskStatusSupport = null;
ImageDataset rawTimeData = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDatasetFromMultiFiles(expTimeSeriesFiles, clientTaskStatusSupport, isTimeSeries, timeInterval);
ImageTimeSeries<UShortImage> imageTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, rawTimeData.getAllImages(), rawTimeData.getImageTimeStamps(), 1);
return imageTimeSeries;
}
Aggregations