use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class XmlHelper method simTaskToXML.
public static String simTaskToXML(SimulationTask simTask) throws XmlParseException {
String simTaskString = null;
if (simTask == null) {
throw new XmlParseException("Invalid input for SimulationTask: " + simTask);
}
Xmlproducer xmlProducer = new Xmlproducer(true);
SimulationJob simJob = simTask.getSimulationJob();
Simulation sim = simJob.getSimulation();
Element container = new Element(SimulationTask_tag);
int taskId = simTask.getTaskID();
container.setAttribute(TaskId_attr, "" + taskId);
int jobIndex = simJob.getJobIndex();
container.setAttribute(JobIndex_attr, "" + jobIndex);
String computeResource = simTask.getComputeResource();
if (computeResource != null) {
Element computeResourceElement = new Element(ComputeResource_tag);
Text text = new Text(computeResource);
computeResourceElement.addContent(text);
container.addContent(computeResourceElement);
}
FieldDataIdentifierSpec[] fdisSpecs = simJob.getFieldDataIdentifierSpecs();
if (fdisSpecs != null) {
for (FieldDataIdentifierSpec fdisSpec : fdisSpecs) {
Element fdisElement = new Element(FieldFunctionIdentifierSpec_tag);
fdisElement.setText(fdisSpec.toCSVString());
container.addContent(fdisElement);
}
}
MathDescription md = sim.getMathDescription();
Element mathElement = xmlProducer.getXML(md);
container.addContent(mathElement);
Element simElement = xmlProducer.getXML(sim);
container.addContent(simElement);
Geometry geom = md.getGeometry();
if (geom != null) {
Element geomElement = xmlProducer.getXML(geom);
container.addContent(geomElement);
} else {
System.err.println("No corresponding geometry for the simulation: " + sim.getName());
}
container = XmlUtil.setDefaultNamespace(container, Namespace.getNamespace(XMLTags.VCML_NS));
simTaskString = XmlUtil.xmlToString(container);
return simTaskString;
}
use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class FRAPStudy method runFVSolverStandalone_ref.
public static void runFVSolverStandalone_ref(File simulationDataDir, Simulation sim, ExternalDataIdentifier imageDataExtDataID, ExternalDataIdentifier roiExtDataID, ExternalDataIdentifier psfExtDataID, ClientTaskStatusSupport progressListener, boolean bCheckSteadyState) throws Exception {
FieldFunctionArguments[] fieldFunctionArgs = FieldUtilities.getFieldFunctionArguments(sim.getMathDescription());
FieldDataIdentifierSpec[] fieldDataIdentifierSpecs = new FieldDataIdentifierSpec[fieldFunctionArgs.length];
for (int i = 0; i < fieldDataIdentifierSpecs.length; i++) {
if (fieldFunctionArgs[i].getFieldName().equals(imageDataExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], imageDataExtDataID);
} else if (fieldFunctionArgs[i].getFieldName().equals(roiExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], roiExtDataID);
} else if (fieldFunctionArgs[i].getFieldName().equals(psfExtDataID.getName())) {
fieldDataIdentifierSpecs[i] = new FieldDataIdentifierSpec(fieldFunctionArgs[i], psfExtDataID);
} else {
throw new RuntimeException("failed to resolve field named " + fieldFunctionArgs[i].getFieldName());
}
}
int jobIndex = 0;
SimulationTask simTask = new SimulationTask(new SimulationJob(sim, jobIndex, fieldDataIdentifierSpecs), 0);
SolverUtilities.prepareSolverExecutable(sim.getSolverTaskDescription().getSolverDescription());
// if we need to check steady state, do the following two lines
if (bCheckSteadyState) {
simTask.getSimulation().getSolverTaskDescription().setStopAtSpatiallyUniformErrorTolerance(ErrorTolerance.getDefaultSpatiallyUniformErrorTolerance());
// simJob.getSimulation().getSolverTaskDescription().setErrorTolerance(new ErrorTolerance(1e-6, 1e-2));
}
FVSolverStandalone fvSolver = new FVSolverStandalone(simTask, simulationDataDir, false);
fvSolver.startSolver();
SolverStatus status = fvSolver.getSolverStatus();
while (status.getStatus() != SolverStatus.SOLVER_FINISHED && status.getStatus() != SolverStatus.SOLVER_ABORTED) {
if (progressListener != null) {
progressListener.setProgress((int) (fvSolver.getProgress() * 100));
if (progressListener.isInterrupted()) {
fvSolver.stopSolver();
throw UserCancelException.CANCEL_GENERIC;
}
}
try {
Thread.sleep(1000);
} catch (InterruptedException ex) {
ex.printStackTrace(System.out);
// catch interrupted exception and ignore it, otherwise it will popup a dialog in user interface saying"sleep interrupted"
}
status = fvSolver.getSolverStatus();
}
if (status.getStatus() != SolverStatus.SOLVER_FINISHED) {
throw new Exception("Sover did not finish normally." + status);
}
}
use of cbit.vcell.field.FieldDataIdentifierSpec 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 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();
}
use of cbit.vcell.field.FieldDataIdentifierSpec in project vcell by virtualcell.
the class DataSetControllerImpl method getVariableTypeForFieldFunction.
private VariableType getVariableTypeForFieldFunction(OutputContext outputContext, VCDataIdentifier vcdID, AnnotatedFunction function) throws DataAccessException {
VariableType funcType = function.getFunctionType();
if (funcType == null || funcType.equals(VariableType.UNKNOWN)) {
FieldFunctionArguments[] ffas = FieldUtilities.getFieldFunctionArguments(function.getExpression());
if (ffas == null || ffas.length == 0) {
throw new DataAccessException("Unknown function type for function " + function.getName());
}
// use the type from the first field function
FieldDataIdentifierSpec[] fdiss = getFieldDataIdentifierSpecs(ffas, vcdID.getOwner());
SimDataBlock dataBlock = getSimDataBlock(outputContext, fdiss[0].getExternalDataIdentifier(), ffas[0].getVariableName(), 0.0);
funcType = dataBlock.getVariableType();
}
return funcType;
}
Aggregations