use of org.vcell.util.ISize in project vcell by virtualcell.
the class FRAPStudy method getCartesianMesh.
public CartesianMesh getCartesianMesh() throws Exception {
CartesianMesh cartesianMesh = null;
ImageDataset imgDataSet = getFrapData().getImageDataset();
Extent extent = imgDataSet.getExtent();
ISize isize = imgDataSet.getISize();
Origin origin = new Origin(0, 0, 0);
if (getBioModel() == null) {
cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
} else {
RegionImage regionImage = getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().getRegionImage();
if (regionImage == null) {
getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().updateAll();
regionImage = getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().getRegionImage();
}
cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
}
return cartesianMesh;
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class FRAPStudy method getPSFFieldData.
public static FieldDataIdentifierSpec getPSFFieldData(LocalWorkspace localWorkspace) {
// create ROI image
short[] psfFieldData = null;
psfFieldData = new short[9];
psfFieldData[4] = (short) 1;
// create field data
int NumTimePoints = 1;
// 8 rois integrated into 1 image
int NumChannels = 1;
short[][][] pixData = new short[NumTimePoints][NumChannels][1];
pixData[0][0] = psfFieldData;
// get extental data id
ExternalDataIdentifier newPsfExtDataID = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.PSF_DATA_NAME).getExternalDataIdentifier();
CartesianMesh cartesianMesh;
try {
Origin origin = new Origin(0, 0, 0);
Extent ext = new Extent(1, 1, 1);
ISize isize = new ISize(3, 3, 1);
cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, ext, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], ext, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = cartesianMesh;
fdos.shortSpecData = pixData;
fdos.specEDI = newPsfExtDataID;
fdos.varNames = new String[] { "psfVar" };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = new double[] { 0.0 };
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = ext;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
FieldFunctionArguments psfFieldFunc = new FieldFunctionArguments(PSF_DATA_NAME, "psfVar", new Expression(0.0), VariableType.VOLUME);
FieldDataIdentifierSpec fdis = new FieldDataIdentifierSpec(psfFieldFunc, newPsfExtDataID);
return fdis;
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class SimulationTask method getEstimatedMemorySizeMB.
public double getEstimatedMemorySizeMB() {
//
// calculate number of PDE variables and total number of spatial variables
//
SimulationSymbolTable simSymbolTable = getSimulationJob().getSimulationSymbolTable();
Simulation simulation = simSymbolTable.getSimulation();
MathDescription mathDescription = simulation.getMathDescription();
int pdeVarCount = 0;
int odeVarCount = 0;
Variable[] variables = simSymbolTable.getVariables();
for (int i = 0; i < variables.length; i++) {
if (variables[i] instanceof VolVariable) {
if (mathDescription.isPDE((VolVariable) variables[i])) {
pdeVarCount++;
} else {
odeVarCount++;
}
} else if (variables[i] instanceof MemVariable) {
if (mathDescription.isPDE((MemVariable) variables[i])) {
pdeVarCount++;
} else {
odeVarCount++;
}
}
}
long numMeshPoints = 1;
if (simulation.isSpatial()) {
ISize samplingSize = simulation.getMeshSpecification().getSamplingSize();
numMeshPoints = samplingSize.getX() * samplingSize.getY() * samplingSize.getZ();
}
// 180 bytes per pde variable plus ode per mesh point + 15M overhead
// there is 70M PBS overhead which will be added when submitted to pbs
double est = ((180 * pdeVarCount + 16 * odeVarCount) * numMeshPoints / 1e6 + 15);
if (simulation.getSolverTaskDescription().getSolverDescription().equals(SolverDescription.SundialsPDE)) {
est *= 2;
}
return est;
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class DataSetControllerImpl method iterateHDF5.
private static void iterateHDF5(HObject hObject, String indent, DataProcessingHelper dataProcessingHelper) throws Exception {
if (hObject instanceof Group) {
Group group = ((Group) hObject);
printInfo(group, indent);
if (group.getName().equals("/") || group.getName().equals(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_POSTPROCESSING)) {
List<HObject> postProcessMembers = ((Group) hObject).getMemberList();
for (HObject nextHObject : postProcessMembers) {
iterateHDF5(nextHObject, indent + " ", dataProcessingHelper);
}
} else if (group.getName().equals(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_VARIABLESTATISTICS) && dataProcessingHelper.isInfoOnly()) {
populateStatNamesAndUnits(hObject, dataProcessingHelper);
List<HObject> statDataAtEachTime = group.getMemberList();
dataProcessingHelper.statValues = new double[dataProcessingHelper.statVarNames.length][statDataAtEachTime.size()];
for (HObject nextStatData : statDataAtEachTime) {
printInfo(nextStatData, indent + " ");
// always get stats data when ask for info
processDims(nextStatData, dataProcessingHelper, false);
double[] stats = (double[]) dataProcessingHelper.tempData;
int timeIndex = Integer.parseInt(nextStatData.getName().substring("time".length()));
for (int j = 0; j < stats.length; j++) {
dataProcessingHelper.statValues[j][timeIndex] = stats[j];
}
}
} else {
// must be image data
if (dataProcessingHelper.isInfoOnly()) {
dataProcessingHelper.imageNames = new ArrayList<String>();
dataProcessingHelper.imageISize = new ArrayList<ISize>();
dataProcessingHelper.imageOrigin = new ArrayList<Origin>();
dataProcessingHelper.imageExtent = new ArrayList<Extent>();
Origin imgDataOrigin;
Extent imgDataExtent;
HashMap<String, String> attrHashMap = getHDF5Attributes(group);
if (attrHashMap.size() == 2) {
imgDataOrigin = new Origin(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINX)), 0, 0);
// this is 1D, however the extentY, Z cannot take 0
imgDataExtent = new Extent(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTX)), 1, 1);
} else if (attrHashMap.size() == 4) {
imgDataOrigin = new Origin(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINX)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINY)), 0);
// this is 2D, however the extentZ cannot take 0
imgDataExtent = new Extent(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTX)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTY)), 1);
} else if (attrHashMap.size() == 6) {
imgDataOrigin = new Origin(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINX)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINY)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_ORIGINZ)));
imgDataExtent = new Extent(Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTX)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTY)), Double.valueOf(attrHashMap.get(DATA_PROCESSING_OUTPUT_EXTENTZ)));
} else {
throw new Exception("Unexpected number of origin/extent values");
}
dataProcessingHelper.imageNames.add(hObject.getName());
dataProcessingHelper.imageOrigin.add(imgDataOrigin);
dataProcessingHelper.imageExtent.add(imgDataExtent);
// get ISize
processDims((H5ScalarDS) (((Group) hObject).getMemberList()).get(0), dataProcessingHelper, true);
long[] dims = dataProcessingHelper.tempDims;
ISize isize = new ISize((int) dims[0], (int) (dims.length > 1 ? dims[1] : 1), (int) (dims.length > 2 ? dims[2] : 1));
dataProcessingHelper.imageISize.add(isize);
} else {
int currentVarNameIndex = -1;
for (int i = 0; i < dataProcessingHelper.specificVarNames.length; i++) {
if (group.getName().equals(dataProcessingHelper.specificVarNames[i])) {
currentVarNameIndex = i;
break;
}
}
if (currentVarNameIndex == -1) {
// skip this group
return;
}
dataProcessingHelper.specificDataValues[currentVarNameIndex] = new double[(dataProcessingHelper.specificTimePointHelper.isAllTimePoints() ? dataProcessingHelper.times.length : dataProcessingHelper.specificTimePointHelper.getTimePoints().length)][];
List<HObject> imageDataAtEachTime = ((Group) hObject).getMemberList();
int foundTimePointIndex = 0;
for (HObject nextImageData : imageDataAtEachTime) {
// if(dataProcessingHelper.isInfoOnly()){
// printInfo(nextImageData,indent+" ");
// processDims(nextImageData, dataProcessingHelper,true);
// long[] dims = dataProcessingHelper.tempDims;
// ISize isize = new ISize((int)dims[0], (int)(dims.length>1?dims[1]:1), (int)(dims.length>2?dims[2]:1));
// dataProcessingHelper.imageISize.add(isize);
// break;//only need 1st one for info
// }else{
int hdf5GroupTimeIndex = Integer.parseInt(nextImageData.getName().substring(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_TIMEPREFIX.length()));
if (dataProcessingHelper.specificTimePointHelper.isAllTimePoints() || dataProcessingHelper.specificTimePointHelper.getTimePoints()[foundTimePointIndex] == dataProcessingHelper.times[hdf5GroupTimeIndex]) {
int timeIndex = (dataProcessingHelper.specificTimePointHelper.isAllTimePoints() ? hdf5GroupTimeIndex : foundTimePointIndex);
processDims(nextImageData, dataProcessingHelper, false);
long[] dims = dataProcessingHelper.tempDims;
ISize isize = new ISize((int) dims[0], (int) (dims.length > 1 ? dims[1] : 1), (int) (dims.length > 2 ? dims[2] : 1));
if (dataProcessingHelper.specificDataIndexHelper.isAllDataIndexes()) {
dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex] = (double[]) dataProcessingHelper.tempData;
} else if (dataProcessingHelper.specificDataIndexHelper.isSingleSlice()) {
dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex] = new double[isize.getX() * isize.getY()];
System.arraycopy((double[]) dataProcessingHelper.tempData, dataProcessingHelper.specificDataIndexHelper.getSliceIndex() * (isize.getX() * isize.getY()), dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex], 0, isize.getX() * isize.getY());
} else {
dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex] = new double[dataProcessingHelper.specificDataIndexHelper.getDataIndexes().length];
for (int i = 0; i < dataProcessingHelper.specificDataIndexHelper.getDataIndexes().length; i++) {
dataProcessingHelper.specificDataValues[currentVarNameIndex][timeIndex][i] = ((double[]) dataProcessingHelper.tempData)[dataProcessingHelper.specificDataIndexHelper.getDataIndexes()[i]];
}
}
foundTimePointIndex++;
if (!dataProcessingHelper.specificTimePointHelper.isAllTimePoints() && foundTimePointIndex == dataProcessingHelper.specificTimePointHelper.getTimePoints().length) {
// break out after we get our data
break;
}
}
// }
}
}
}
} else if (hObject instanceof Dataset) {
Dataset dataset = (Dataset) hObject;
printInfo(dataset, indent);
if (dataset.getName().equals(SimDataConstants.DATA_PROCESSING_OUTPUT_EXTENSION_TIMES)) {
processDims(hObject, dataProcessingHelper, false);
dataProcessingHelper.times = (double[]) dataProcessingHelper.tempData;
}
} else if (hObject instanceof Datatype) {
printInfo(hObject, indent);
} else {
printInfo(hObject, indent);
}
}
use of org.vcell.util.ISize in project vcell by virtualcell.
the class DataSetControllerImpl method writeFieldFunctionData.
/**
* Insert the method's description here.
* Creation date: (9/21/2006 1:28:12 PM)
* @throws FileNotFoundException
* @throws DataAccessException
*/
public void writeFieldFunctionData(OutputContext outputContext, FieldDataIdentifierSpec[] argFieldDataIDSpecs, boolean[] bResampleFlags, CartesianMesh newMesh, SimResampleInfoProvider simResampleInfoProvider, int simResampleMembraneDataLength, int handleExistingResampleMode) throws FileNotFoundException, DataAccessException, IOException {
if (handleExistingResampleMode != FVSolverStandalone.HESM_KEEP_AND_CONTINUE && handleExistingResampleMode != FVSolverStandalone.HESM_OVERWRITE_AND_CONTINUE && handleExistingResampleMode != FVSolverStandalone.HESM_THROW_EXCEPTION) {
throw new IllegalArgumentException("Unknown mode " + handleExistingResampleMode);
}
if (argFieldDataIDSpecs == null || argFieldDataIDSpecs.length == 0) {
return;
}
HashMap<FieldDataIdentifierSpec, File> uniqueFieldDataIDSpecAndFileH = new HashMap<FieldDataIdentifierSpec, File>();
HashMap<FieldDataIdentifierSpec, Boolean> bFieldDataResample = new HashMap<FieldDataIdentifierSpec, Boolean>();
for (int i = 0; i < argFieldDataIDSpecs.length; i++) {
if (!uniqueFieldDataIDSpecAndFileH.containsKey(argFieldDataIDSpecs[i])) {
File newResampledFieldDataFile = null;
try {
newResampledFieldDataFile = ((SimulationData) getVCData(simResampleInfoProvider)).getFieldDataFile(simResampleInfoProvider, argFieldDataIDSpecs[i].getFieldFuncArgs());
} catch (FileNotFoundException e) {
e.printStackTrace();
// use the original way
newResampledFieldDataFile = new File(getPrimaryUserDir(simResampleInfoProvider.getOwner(), true), SimulationData.createCanonicalResampleFileName(simResampleInfoProvider, argFieldDataIDSpecs[i].getFieldFuncArgs()));
}
if (handleExistingResampleMode == FVSolverStandalone.HESM_THROW_EXCEPTION && newResampledFieldDataFile.exists()) {
throw new RuntimeException("Resample Error: mode not allow overwrite or ignore of " + "existing file\n" + newResampledFieldDataFile.getAbsolutePath());
}
uniqueFieldDataIDSpecAndFileH.put(argFieldDataIDSpecs[i], newResampledFieldDataFile);
bFieldDataResample.put(argFieldDataIDSpecs[i], bResampleFlags[i]);
}
}
try {
Set<Entry<FieldDataIdentifierSpec, File>> resampleSet = uniqueFieldDataIDSpecAndFileH.entrySet();
Iterator<Entry<FieldDataIdentifierSpec, File>> resampleSetIter = resampleSet.iterator();
while (resampleSetIter.hasNext()) {
Entry<FieldDataIdentifierSpec, File> resampleEntry = resampleSetIter.next();
if (handleExistingResampleMode == FVSolverStandalone.HESM_KEEP_AND_CONTINUE && resampleEntry.getValue().exists()) {
continue;
}
FieldDataIdentifierSpec fieldDataIdSpec = resampleEntry.getKey();
boolean bResample = bFieldDataResample.get(fieldDataIdSpec);
CartesianMesh origMesh = getMesh(fieldDataIdSpec.getExternalDataIdentifier());
SimDataBlock simDataBlock = getSimDataBlock(outputContext, fieldDataIdSpec.getExternalDataIdentifier(), fieldDataIdSpec.getFieldFuncArgs().getVariableName(), fieldDataIdSpec.getFieldFuncArgs().getTime().evaluateConstant());
VariableType varType = fieldDataIdSpec.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();
double[] newData = null;
CartesianMesh resampleMesh = newMesh;
if (!bResample) {
if (resampleMesh.getGeometryDimension() != origMesh.getGeometryDimension()) {
throw new DataAccessException("Field data " + fieldDataIdSpec.getFieldFuncArgs().getFieldName() + " (" + origMesh.getGeometryDimension() + "D) should have same dimension as simulation mesh (" + resampleMesh.getGeometryDimension() + "D) because it is not resampled to simulation mesh (e.g. Point Spread Function)");
}
newData = origData;
resampleMesh = origMesh;
} else {
if (CartesianMesh.isSpatialDomainSame(origMesh, resampleMesh)) {
newData = origData;
if (simDataBlock.getVariableType().equals(VariableType.MEMBRANE)) {
if (origData.length != simResampleMembraneDataLength) {
throw new Exception("FieldData variable \"" + fieldDataIdSpec.getFieldFuncArgs().getVariableName() + "\" (" + simDataBlock.getVariableType().getTypeName() + ") " + "resampling failed: Membrane Data lengths must be equal");
}
} else if (!simDataBlock.getVariableType().equals(VariableType.VOLUME)) {
throw new Exception("FieldData variable \"" + fieldDataIdSpec.getFieldFuncArgs().getVariableName() + "\" (" + simDataBlock.getVariableType().getTypeName() + ") " + "resampling failed: Only Volume and Membrane variable types are supported");
}
} else {
if (!simDataBlock.getVariableType().compareEqual(VariableType.VOLUME)) {
throw new Exception("FieldData variable \"" + fieldDataIdSpec.getFieldFuncArgs().getVariableName() + "\" (" + simDataBlock.getVariableType().getTypeName() + ") " + "resampling failed: Only VOLUME FieldData variable type allowed when\n" + "FieldData spatial domain does not match Simulation spatial domain.\n" + "Check dimension, xsize, ysize, zsize, origin and extent are equal.");
}
if (origMesh.getSizeY() == 1 && origMesh.getSizeZ() == 1) {
newData = MathTestingUtilities.resample1DSpatialSimple(origData, origMesh, resampleMesh);
} else if (origMesh.getSizeZ() == 1) {
newData = MathTestingUtilities.resample2DSpatialSimple(origData, origMesh, resampleMesh);
} else {
newData = MathTestingUtilities.resample3DSpatialSimple(origData, origMesh, resampleMesh);
}
}
}
DataSet.writeNew(resampleEntry.getValue(), new String[] { fieldDataIdSpec.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(resampleMesh.getSizeX(), resampleMesh.getSizeY(), resampleMesh.getSizeZ()), new double[][] { newData });
}
} catch (Exception ex) {
ex.printStackTrace(System.out);
throw new DataAccessException(ex.getMessage());
}
}
Aggregations