use of org.vcell.util.ISize in project vcell by virtualcell.
the class RunRefSimulationOp method runRefSimulation.
private static ImageTimeSeries<FloatImage> runRefSimulation(LocalWorkspace localWorkspace, ROI cellROI, double timeStepVal, TimeBounds timeBounds, FloatImage initRefConc, double baseDiffusionRate, ClientTaskStatusSupport progressListener) throws Exception {
String INITCONC_EXTDATA_NAME = "initConc";
String INITCONC_EXTDATA_VARNAME = "conc";
String VAR_NAME = "species";
User owner = LocalWorkspace.getDefaultOwner();
KeyValue simKey = LocalWorkspace.createNewKeyValue();
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);
BioModel bioModel = createRefSimBioModel(simKey, owner, origin, extent, cellROI, timeStepVal, timeBounds, VAR_NAME, new Expression(initConditionFFA.infix()), baseDiffusionRate);
if (progressListener != null) {
progressListener.setMessage("Running Reference Simulation...");
}
// run simulation
runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), bioModel.getSimulation(0), initialConcentrationExtData.getExternalDataIdentifier(), progressListener, true);
VCDataIdentifier vcDataIdentifier = new VCSimulationDataIdentifier(new VCSimulationIdentifier(simKey, owner), 0);
double[] dataTimes = localWorkspace.getDataSetControllerImpl().getDataSetTimes(vcDataIdentifier);
FloatImage[] solutionImages = new FloatImage[dataTimes.length];
for (int i = 0; i < dataTimes.length; i++) {
SimDataBlock simDataBlock = localWorkspace.getDataSetControllerImpl().getSimDataBlock(null, vcDataIdentifier, VAR_NAME, dataTimes[i]);
double[] doubleData = simDataBlock.getData();
float[] floatPixels = new float[doubleData.length];
for (int j = 0; j < doubleData.length; j++) {
floatPixels[j] = (float) doubleData[j];
}
solutionImages[i] = new FloatImage(floatPixels, origin, extent, isize.getX(), isize.getY(), isize.getZ());
}
ImageTimeSeries<FloatImage> solution = new ImageTimeSeries<FloatImage>(FloatImage.class, solutionImages, dataTimes, 1);
return solution;
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class BrownianDynamicsTest method main.
public static void main(String[] args) {
try {
Options commandOptions = new Options();
Option noiseOption = new Option(OPTION_NOISE, false, "sampled images use Poisson statistics for photons, default is to count particles");
commandOptions.addOption(noiseOption);
Option psfOption = new Option(OPTION_PSF, false, "sampled images are convolve with microscope psf, default is to bin");
commandOptions.addOption(psfOption);
Option imageFileOption = new Option(OPTION_IMAGEFILE, true, "file to store image time series");
imageFileOption.setArgName("filename");
imageFileOption.setValueSeparator('=');
commandOptions.addOption(imageFileOption);
Option plotFileOption = new Option(OPTION_PLOTFILE, true, "file to store CSV time series (reduced data for ROIs)");
plotFileOption.setArgName("filename");
plotFileOption.setValueSeparator('=');
commandOptions.addOption(plotFileOption);
Option displayImageOption = new Option(OPTION_DISPLAY_IMAGE, false, "display image time series");
commandOptions.addOption(displayImageOption);
Option displayPlotOption = new Option(OPTION_DISPLAY_PLOT, false, "display plot of bleach roi");
commandOptions.addOption(displayPlotOption);
Option extentOption = new Option(OPTION_EXTENT, true, "extent of entire domain (default " + DEFAULT_EXTENT_SCALE + ")");
extentOption.setArgName("extent");
extentOption.setValueSeparator('=');
commandOptions.addOption(extentOption);
Option imageSizeOption = new Option(OPTION_IMAGE_SIZE, true, "num pixels in x and y (default " + DEFAULT_IMAGE_SIZE + ")");
imageSizeOption.setArgName("numPixels");
imageSizeOption.setValueSeparator('=');
commandOptions.addOption(imageSizeOption);
Option numParticlesOption = new Option(OPTION_NUM_PARTICLES, true, "num particles (default " + DEFAULT_NUM_PARTICLES + ")");
numParticlesOption.setArgName("num");
numParticlesOption.setValueSeparator('=');
commandOptions.addOption(numParticlesOption);
Option diffusionOption = new Option(OPTION_DIFFUSION, true, "diffusion rate (default " + DEFAULT_DIFFUSION + ")");
diffusionOption.setArgName("rate");
diffusionOption.setValueSeparator('=');
commandOptions.addOption(diffusionOption);
Option bleachRadiusOption = new Option(OPTION_BLEACH_RADIUS, true, "bleach radius (default " + DEFAULT_BLEACH_RADIUS + ")");
bleachRadiusOption.setArgName("radius");
bleachRadiusOption.setValueSeparator('=');
commandOptions.addOption(bleachRadiusOption);
Option psfRadiusOption = new Option(OPTION_PSF_RADIUS, true, "psf radius (default " + DEFAULT_PSF_RADIUS + ")");
psfRadiusOption.setArgName("radius");
psfRadiusOption.setValueSeparator('=');
commandOptions.addOption(psfRadiusOption);
Option bleachDurationOption = new Option(OPTION_BLEACH_DURATION, true, "psf radius (default " + DEFAULT_BLEACH_DURATION + ")");
bleachDurationOption.setArgName("duration");
bleachDurationOption.setValueSeparator('=');
commandOptions.addOption(bleachDurationOption);
Option endTimeOption = new Option(OPTION_ENDTIME, true, "end time (default " + DEFAULT_ENDTIME + ")");
endTimeOption.setArgName("time");
endTimeOption.setValueSeparator('=');
commandOptions.addOption(endTimeOption);
CommandLine cmdLine = null;
try {
Parser parser = new BasicParser();
cmdLine = parser.parse(commandOptions, args);
} catch (ParseException e1) {
e1.printStackTrace();
HelpFormatter hf = new HelpFormatter();
hf.printHelp("BrownianDynamicsTest", commandOptions);
System.exit(2);
}
boolean bNoise = cmdLine.hasOption(OPTION_NOISE);
boolean bConvolve = cmdLine.hasOption(OPTION_PSF);
File imageFile = null;
if (cmdLine.hasOption(OPTION_IMAGEFILE)) {
imageFile = new File(cmdLine.getOptionValue(OPTION_IMAGEFILE));
}
File plotFile = null;
if (cmdLine.hasOption(OPTION_PLOTFILE)) {
plotFile = new File(cmdLine.getOptionValue(OPTION_PLOTFILE));
}
boolean bDisplayImage = cmdLine.hasOption(OPTION_DISPLAY_IMAGE);
boolean bDisplayPlot = cmdLine.hasOption(OPTION_DISPLAY_PLOT);
double extentScale = DEFAULT_EXTENT_SCALE;
if (cmdLine.hasOption(OPTION_EXTENT)) {
extentScale = Double.parseDouble(cmdLine.getOptionValue(OPTION_EXTENT));
}
int imageSize = DEFAULT_IMAGE_SIZE;
if (cmdLine.hasOption(OPTION_IMAGE_SIZE)) {
imageSize = Integer.parseInt(cmdLine.getOptionValue(OPTION_IMAGE_SIZE));
}
int numParticles = DEFAULT_NUM_PARTICLES;
if (cmdLine.hasOption(OPTION_NUM_PARTICLES)) {
numParticles = Integer.parseInt(cmdLine.getOptionValue(OPTION_NUM_PARTICLES));
}
double diffusionRate = DEFAULT_DIFFUSION;
if (cmdLine.hasOption(OPTION_DIFFUSION)) {
diffusionRate = Double.parseDouble(cmdLine.getOptionValue(OPTION_DIFFUSION));
}
double bleachRadius = DEFAULT_BLEACH_RADIUS;
if (cmdLine.hasOption(OPTION_BLEACH_RADIUS)) {
bleachRadius = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_RADIUS));
}
double psfRadius = DEFAULT_PSF_RADIUS;
if (cmdLine.hasOption(OPTION_PSF_RADIUS)) {
psfRadius = Double.parseDouble(cmdLine.getOptionValue(OPTION_PSF_RADIUS));
}
double bleachDuration = DEFAULT_BLEACH_DURATION;
if (cmdLine.hasOption(OPTION_BLEACH_DURATION)) {
bleachDuration = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_DURATION));
}
double endTime = DEFAULT_ENDTIME;
if (cmdLine.hasOption(OPTION_ENDTIME)) {
endTime = Double.parseDouble(cmdLine.getOptionValue(OPTION_BLEACH_DURATION));
}
//
// hard coded parameters
//
Origin origin = new Origin(0, 0, 0);
Extent extent = new Extent(extentScale, extentScale, 1);
int numX = imageSize;
int numY = imageSize;
double psfVar = psfRadius * psfRadius;
BrownianDynamicsTest test = new BrownianDynamicsTest();
ImageTimeSeries<UShortImage> rawTimeSeries = test.generateTestData(origin, extent, numX, numY, numParticles, diffusionRate, psfVar, bleachRadius * bleachRadius, bNoise, bConvolve, bleachDuration, endTime);
//
if (imageFile != null) {
new ExportRawTimeSeriesToVFrapOp().exportToVFRAP(imageFile, rawTimeSeries, null);
}
//
if (bDisplayImage) {
new DisplayTimeSeriesOp().displayImageTimeSeries(rawTimeSeries, "time series", null);
}
//
// compute reduced data if needed for plotting or saving.
//
RowColumnResultSet reducedData = null;
if (bDisplayPlot || plotFile != null) {
double muX = origin.getX() + 0.5 * extent.getX();
double muY = origin.getY() + 0.5 * extent.getY();
double sigma = Math.sqrt(psfVar);
NormalizedSampleFunction gaussian = NormalizedSampleFunction.fromGaussian("psf", origin, extent, new ISize(numX, numY, 1), muX, muY, sigma);
reducedData = new GenerateReducedDataOp().generateReducedData(rawTimeSeries, new NormalizedSampleFunction[] { gaussian });
}
//
if (plotFile != null) {
FileOutputStream fos = new FileOutputStream(plotFile);
new CSV().exportTo(fos, reducedData);
}
if (bDisplayPlot) {
new DisplayPlotOp().displayPlot(reducedData, "bleached roi", null);
}
} catch (Exception e) {
e.printStackTrace();
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class DisplayTimeSeriesOp method getDataSetControllerProvider.
private DataSetControllerProvider getDataSetControllerProvider(final ImageTimeSeries<? extends Image> imageTimeSeries, final PDEDataViewer pdeDataViewer) 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 {
pdeDataViewer.dataJobMessage(new DataJobEvent(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_START, vcdataID.getDataKey(), vcdataID.getID(), new Double(0)));
if (!timeSeriesJobSpec.isCalcSpaceStats() && !timeSeriesJobSpec.isCalcTimeStats()) {
int[][] indices = timeSeriesJobSpec.getIndices();
double[] timeStamps = imageTimeSeries.getImageTimeStamps();
// [var][dataindex+1][timeindex]
double[][][] dataValues = new double[1][indices[0].length + 1][timeStamps.length];
for (int timeIndex = 0; timeIndex < timeStamps.length; timeIndex++) {
// index 0 is time
dataValues[0][0][timeIndex] = timeStamps[timeIndex];
}
for (int timeIndex = 0; timeIndex < timeStamps.length; timeIndex++) {
float[] pixelValues = imageTimeSeries.getAllImages()[timeIndex].getFloatPixels();
for (int samplePointIndex = 0; samplePointIndex < indices[0].length; samplePointIndex++) {
int pixelIndex = indices[0][samplePointIndex];
dataValues[0][samplePointIndex + 1][timeIndex] = pixelValues[pixelIndex];
}
}
TSJobResultsNoStats timeSeriesJobResults = new TSJobResultsNoStats(new String[] { "var" }, indices, timeStamps, dataValues);
pdeDataViewer.dataJobMessage(new DataJobEvent(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_COMPLETE, vcdataID.getDataKey(), vcdataID.getID(), new Double(0)));
return timeSeriesJobResults;
}
return null;
}
@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;
}
};
return dataSetControllerProvider;
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class RunSimulation2DOp method runRefSimulation.
public ImageTimeSeries<FloatImage> runRefSimulation(LocalWorkspace localWorkspace, Simulation simulation, String varName, 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(simKey, owner), 0);
CartesianMesh mesh = localWorkspace.getDataSetControllerImpl().getMesh(vcDataIdentifier);
ISize isize = new ISize(mesh.getSizeX(), mesh.getSizeY(), mesh.getSizeZ());
double[] dataTimes = localWorkspace.getDataSetControllerImpl().getDataSetTimes(vcDataIdentifier);
FloatImage[] solutionImages = new FloatImage[dataTimes.length];
for (int i = 0; i < dataTimes.length; i++) {
SimDataBlock simDataBlock = localWorkspace.getDataSetControllerImpl().getSimDataBlock(null, vcDataIdentifier, varName, dataTimes[i]);
double[] doubleData = simDataBlock.getData();
float[] floatPixels = new float[doubleData.length];
for (int j = 0; j < doubleData.length; j++) {
floatPixels[j] = (float) doubleData[j];
}
solutionImages[i] = new FloatImage(floatPixels, origin, extent, isize.getX(), isize.getY(), isize.getZ());
}
ImageTimeSeries<FloatImage> solution = new ImageTimeSeries<FloatImage>(FloatImage.class, solutionImages, dataTimes, 1);
return solution;
}
use of org.vcell.util.ISize 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);
}
Aggregations