use of cbit.vcell.simdata.SimDataBlock in project vcell by virtualcell.
the class FRAPStudy method spatialAnalysis.
public static SpatialAnalysisResults spatialAnalysis(PDEDataManager simulationDataManager, int startingIndexForRecovery, double startingForRecoveryExperimentalTime, Parameter[] modelParameters, FRAPData frapData, double[] preBleachAverageXYZ) throws Exception {
String[] varNames = new String[] { SPECIES_NAME_PREFIX_COMBINED };
AnalysisParameters analysisParameters = new AnalysisParameters(modelParameters);
//
// for each simulation time step, get the data under each ROI <indexed by ROI, then diffusion
//
// preallocate arrays for all data first
Hashtable<CurveInfo, double[]> curveHash = new Hashtable<CurveInfo, double[]>();
ArrayList<int[]> nonZeroIndicesForROI = new ArrayList<int[]>();
for (int i = 0; i < SpatialAnalysisResults.ORDERED_ROINAMES.length; i++) {
// for (int j = 0; j < diffusionRates.length; j++) {
curveHash.put(new CurveInfo(analysisParameters, SpatialAnalysisResults.ORDERED_ROINAMES[i]), new double[frapData.getImageDataset().getImageTimeStamps().length - startingIndexForRecovery]);
// }
ROI roi_2D = frapData.getRoi(SpatialAnalysisResults.ORDERED_ROINAMES[i]);
nonZeroIndicesForROI.add(roi_2D.getRoiImages()[0].getNonzeroIndices());
}
//
// collect data for experiment (over all ROIs), normalized with pre-bleach average
//
double[] avgBkIntensity = frapData.getAvgBackGroundIntensity();
for (int i = 0; i < SpatialAnalysisResults.ORDERED_ROINAMES.length; i++) {
double[] normalizedAverageFluorAtEachTimeUnderROI = new double[frapData.getImageDataset().getImageTimeStamps().length];
for (int j = 0; j < normalizedAverageFluorAtEachTimeUnderROI.length; j++) {
normalizedAverageFluorAtEachTimeUnderROI[j] = frapData.getAverageUnderROI(j, frapData.getRoi(SpatialAnalysisResults.ORDERED_ROINAMES[i]), preBleachAverageXYZ, avgBkIntensity[j]);
}
curveHash.put(new CurveInfo(null, SpatialAnalysisResults.ORDERED_ROINAMES[i]), normalizedAverageFluorAtEachTimeUnderROI);
}
//
// get times to compare experimental data with simulated results.
//
double[] shiftedSimTimes = null;
if (simulationDataManager != null) {
double[] simTimes = simulationDataManager.getDataSetTimes();
shiftedSimTimes = simTimes.clone();
for (int j = 0; j < simTimes.length; j++) {
// timeStamps[startingIndexOfRecovery];
shiftedSimTimes[j] = simTimes[j] + startingForRecoveryExperimentalTime;
}
// curveHash was intialized with exp time data length. so, we have to replace it with the real sim data length.
if (simTimes.length != (frapData.getImageDataset().getImageTimeStamps().length - startingIndexForRecovery)) {
for (int k = 0; k < SpatialAnalysisResults.ORDERED_ROINAMES.length; k++) {
CurveInfo ci = new CurveInfo(analysisParameters, SpatialAnalysisResults.ORDERED_ROINAMES[k]);
curveHash.remove(ci);
curveHash.put(ci, new double[simTimes.length]);
}
}
for (int i = 0; i < simTimes.length; i++) {
for (int j = 0; j < varNames.length; j++) {
SimDataBlock simDataBlock = simulationDataManager.getSimDataBlock(varNames[j], simTimes[i]);
double[] data = simDataBlock.getData();
for (int k = 0; k < SpatialAnalysisResults.ORDERED_ROINAMES.length; k++) {
CurveInfo ci = new CurveInfo(analysisParameters, SpatialAnalysisResults.ORDERED_ROINAMES[k]);
int[] roiIndices = nonZeroIndicesForROI.get(k);
if (roiIndices != null && roiIndices.length > 0) {
double accum = 0.0;
for (int index = 0; index < roiIndices.length; index++) {
accum += data[roiIndices[index]];
}
double[] values = curveHash.get(ci);
values[i] = accum / roiIndices.length;
}
}
}
}
}
SpatialAnalysisResults spatialAnalysisResults = new SpatialAnalysisResults(new AnalysisParameters[] { analysisParameters }, shiftedSimTimes, curveHash);
return spatialAnalysisResults;
}
use of cbit.vcell.simdata.SimDataBlock in project vcell by virtualcell.
the class ROIDataGenerator method getROIDataGeneratorDescription.
public String getROIDataGeneratorDescription(File userDirectory, SimulationJob simulationJob) throws Exception {
// DataAccessException, FileNotFoundException, MathException, IOException, DivideByZeroException, ExpressionException
Simulation simulation = simulationJob.getSimulation();
StringBuffer sb = new StringBuffer();
sb.append(ROI_GENERATOR_BEGIN + " " + name + "\n");
sb.append("VolumePoints " + volumePoints.length + "\n");
for (int i = 0; i < volumePoints.length; i++) {
sb.append(volumePoints[i] + " ");
if ((i + 1) % 20 == 0) {
sb.append("\n");
}
}
sb.append("\n");
if (membranePoints != null && membranePoints.length > 0) {
sb.append("MembranePoints " + membranePoints.length + "\n");
for (int i = 0; i < membranePoints.length; i++) {
sb.append(membranePoints[i] + " ");
if ((i + 1) % 20 == 0) {
sb.append("\n");
}
}
sb.append("\n");
}
sb.append("SampleImage " + numImgRegions + " " + zSlice + " " + fieldDataKey + " " + fieldFuncArguments.infix() + "\n");
sb.append("StoreEnabled " + bStoreEnabled + "\n");
// sample image field data file
FieldDataIdentifierSpec fdis = getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in ROI data generator.");
}
String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
DataSetControllerImpl dsci = new DataSetControllerImpl(null, userDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fdis.getFieldFuncArgs().getVariableType();
VariableType dataVarType = simDataBlock.getVariableType();
if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
}
double[] origData = simDataBlock.getData();
String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simulationJob.getJobIndex()) + SimulationData.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
File fdatFile = new File(userDirectory, filename);
DataSet.writeNew(fdatFile, new String[] { fdis.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(origMesh.getSizeX(), origMesh.getSizeY(), origMesh.getSizeZ()), new double[][] { origData });
sb.append("SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile + "\n");
sb.append(ROI_GENERATOR_END);
return sb.toString();
}
use of cbit.vcell.simdata.SimDataBlock in project vcell by virtualcell.
the class SimulationServiceImpl method getData.
public List<Double> getData(SimulationInfo simInfo, VariableInfo varInfo, int timeIndex) throws ThriftDataAccessException, TException {
SimulationServiceContext simServiceContext = sims.get(simInfo.id);
if (simServiceContext == null) {
throw new RuntimeException("simulation results not found");
}
DataSetControllerImpl datasetController = getDataSetController(simServiceContext);
try {
double[] times = datasetController.getDataSetTimes(simServiceContext.vcDataIdentifier);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
SimDataBlock simDataBlock = datasetController.getSimDataBlock(outputContext, simServiceContext.vcDataIdentifier, varInfo.getVariableVtuName(), times[timeIndex]);
double[] dataArray = simDataBlock.getData();
ArrayList<Double> dataList = new ArrayList<Double>();
for (double d : dataArray) {
dataList.add(d);
}
return dataList;
} catch (Exception e) {
e.printStackTrace();
throw new ThriftDataAccessException("failed to retrieve data for variable " + varInfo.getVariableVtuName() + ": " + e.getMessage());
}
}
use of cbit.vcell.simdata.SimDataBlock in project vcell by virtualcell.
the class ROIDataGenerator method getROIDataGeneratorDescription.
public String getROIDataGeneratorDescription(File userDirectory, SimulationJob simulationJob) throws Exception {
// DataAccessException, FileNotFoundException, MathException, IOException, DivideByZeroException, ExpressionException
Simulation simulation = simulationJob.getSimulation();
StringBuffer sb = new StringBuffer();
sb.append(ROI_GENERATOR_BEGIN + " " + name + "\n");
sb.append("VolumePoints " + volumePoints.length + "\n");
for (int i = 0; i < volumePoints.length; i++) {
sb.append(volumePoints[i] + " ");
if ((i + 1) % 20 == 0) {
sb.append("\n");
}
}
sb.append("\n");
if (membranePoints != null && membranePoints.length > 0) {
sb.append("MembranePoints " + membranePoints.length + "\n");
for (int i = 0; i < membranePoints.length; i++) {
sb.append(membranePoints[i] + " ");
if ((i + 1) % 20 == 0) {
sb.append("\n");
}
}
sb.append("\n");
}
sb.append("SampleImage " + numImgRegions + " " + zSlice + " " + fieldDataKey + " " + fieldFuncArguments.infix() + "\n");
sb.append("StoreEnabled " + bStoreEnabled + "\n");
// sample image field data file
FieldDataIdentifierSpec fdis = getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in ROI data generator.");
}
String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
DataSetControllerImpl dsci = new DataSetControllerImpl(null, userDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fdis.getFieldFuncArgs().getVariableType();
VariableType dataVarType = simDataBlock.getVariableType();
if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
}
double[] origData = simDataBlock.getData();
String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simulationJob.getJobIndex()) + SimulationData.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
File fdatFile = new File(userDirectory, filename);
DataSet.writeNew(fdatFile, new String[] { fdis.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(origMesh.getSizeX(), origMesh.getSizeY(), origMesh.getSizeZ()), new double[][] { origData });
sb.append("SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile + "\n");
sb.append(ROI_GENERATOR_END);
return sb.toString();
}
use of cbit.vcell.simdata.SimDataBlock in project vcell by virtualcell.
the class DisplayTimeSeries method displayImageTimeSeries.
public static void displayImageTimeSeries(final ImageTimeSeries<Image> imageTimeSeries, String title, WindowListener windowListener) 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 {
throw new RuntimeException("not yet implemented");
}
@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;
}
};
VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {
public User getOwner() {
return new User("nouser", null);
}
public KeyValue getDataKey() {
return null;
}
public String getID() {
return "mydata";
}
};
PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
PDEDataViewer pdeDataViewer = new PDEDataViewer();
JFrame jframe = new JFrame();
jframe.setTitle(title);
jframe.getContentPane().add(pdeDataViewer);
jframe.setSize(1000, 600);
jframe.setVisible(true);
if (windowListener != null) {
jframe.addWindowListener(windowListener);
}
pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
Aggregations