use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class DataSetControllerImpl method getFieldDataIdentifierSpecs_private.
private FieldDataIdentifierSpec[] getFieldDataIdentifierSpecs_private(FieldFunctionArguments[] fieldFuncArgumentsArr, User user, boolean bForceUpdate) throws DataAccessException {
Vector<ExternalDataIdentifier> userExtDataIdentifiersV = userExtDataIDH.get(user);
if (userExtDataIdentifiersV == null || userExtDataIdentifiersV.size() < fieldFuncArgumentsArr.length || bForceUpdate) {
// must refresh
ExternalDataIdentifierService extDataIDService = VCellServiceHelper.getInstance().loadService(ExternalDataIdentifierService.class);
userExtDataIDH = extDataIDService.getAllExternalDataIdentifiers();
userExtDataIdentifiersV = userExtDataIDH.get(user);
}
FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFuncArgumentsArr.length];
Arrays.fill(fieldDataIdentifierSpecs, null);
for (int i = 0; i < fieldFuncArgumentsArr.length; i++) {
for (int j = 0; userExtDataIdentifiersV != null && j < userExtDataIdentifiersV.size(); j++) {
if (fieldFuncArgumentsArr[i].getFieldName().equals(userExtDataIdentifiersV.elementAt(j).getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFuncArgumentsArr[i], userExtDataIdentifiersV.elementAt(j));
break;
}
}
if (fieldDataIdentifierSpecs[i] == null) {
throw new ObjectNotFoundException("The data locator for FieldData Function '" + fieldFuncArgumentsArr[i].getFieldName() + "' could not be found.");
}
}
return fieldDataIdentifierSpecs;
}
use of cbit.vcell.field.FieldDataIdentifierSpec 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());
}
}
use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class DataProcessingInstructions method getSampleImageFieldData.
public FieldDataIdentifierSpec getSampleImageFieldData(User user) {
if (scriptInput != null) {
int index = scriptInput.indexOf("SampleImage");
StringTokenizer st = new StringTokenizer(scriptInput.substring(index));
// SampleImage
st.nextToken();
// numRegions
st.nextToken();
if (getScriptName().equals(VFRAP)) {
// zSlice
st.nextToken();
}
// key
String key = st.nextToken();
index = scriptInput.indexOf(FieldFunctionDefinition.FUNCTION_name);
if (index >= 0) {
st = new StringTokenizer(scriptInput.substring(index), "\n");
if (st.hasMoreTokens()) {
String fieldFunction = st.nextToken();
try {
Expression exp = new Expression(fieldFunction);
FieldFunctionArguments[] ffa = FieldUtilities.getFieldFunctionArguments(exp);
return new FieldDataIdentifierSpec(ffa[0], new ExternalDataIdentifier(KeyValue.fromString(key), user, ffa[0].getFieldName()));
} catch (ExpressionException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed to load data processing script.");
}
}
}
}
return null;
}
use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class ROIDataGenerator method getSampleImageFieldData.
public FieldDataIdentifierSpec getSampleImageFieldData(User user) {
// key
String key = fieldDataKey.toString();
String fieldInput = fieldFuncArguments.infix();
StringTokenizer st = null;
int index = fieldInput.indexOf(FieldFunctionDefinition.FUNCTION_name);
if (index >= 0) {
st = new StringTokenizer(fieldInput.substring(index), "\n");
if (st.hasMoreTokens()) {
String fieldFunction = st.nextToken();
try {
Expression exp = new Expression(fieldFunction);
FieldFunctionArguments[] ffa = FieldUtilities.getFieldFunctionArguments(exp);
return new FieldDataIdentifierSpec(ffa[0], new ExternalDataIdentifier(KeyValue.fromString(key), user, ffa[0].getFieldName()));
} catch (ExpressionException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed to load data processing script.");
}
}
}
return null;
}
use of cbit.vcell.field.FieldDataIdentifierSpec 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();
}
Aggregations