use of cbit.vcell.simdata.DataSetControllerImpl 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.DataSetControllerImpl in project vcell by virtualcell.
the class SimulationServiceImpl method mesh.
private CartesianMesh mesh(SimulationInfo simInfo) {
SimulationServiceContext simServiceContext = sims.get(simInfo.id);
try {
DataSetControllerImpl datasetController = getDataSetController(simServiceContext);
CartesianMesh mesh = datasetController.getMesh(simServiceContext.vcDataIdentifier);
return mesh;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.
the class SimulationServiceImpl method getVariableList.
public List<VariableInfo> getVariableList(SimulationInfo simInfo) throws ThriftDataAccessException, TException {
SimulationServiceContext simServiceContext = sims.get(simInfo.id);
if (simServiceContext == null) {
throw new ThriftDataAccessException("simulation results not found");
}
try {
DataSetControllerImpl datasetController = getDataSetController(simServiceContext);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
final DataIdentifier[] dataIdentifiers;
try {
dataIdentifiers = datasetController.getDataIdentifiers(outputContext, simServiceContext.vcDataIdentifier);
} catch (IOException | DataAccessException e) {
e.printStackTrace();
throw new RuntimeException("failed to retrieve variable information: " + e.getMessage(), e);
}
ArrayList<VariableInfo> varInfos = new ArrayList<VariableInfo>();
for (DataIdentifier dataIdentifier : dataIdentifiers) {
final DomainType domainType;
if (dataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
domainType = DomainType.VOLUME;
} else if (dataIdentifier.getVariableType().equals(VariableType.MEMBRANE)) {
domainType = DomainType.MEMBRANE;
} else {
continue;
}
String domainName = "";
if (dataIdentifier.getDomain() != null) {
domainName = dataIdentifier.getDomain().getName();
}
VariableInfo varInfo = new VariableInfo(dataIdentifier.getName(), dataIdentifier.getDisplayName(), domainName, domainType);
varInfos.add(varInfo);
}
return varInfos;
} catch (Exception e) {
e.printStackTrace();
throw new ThriftDataAccessException("failed to retrieve variable list: " + e.getMessage());
}
}
use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.
the class SimulationServiceImpl method getDataSetController.
private static DataSetControllerImpl getDataSetController(SimulationServiceContext simServiceContext) {
try {
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
Cachetable cacheTable = new Cachetable(10000);
DataSetControllerImpl datasetController = new DataSetControllerImpl(cacheTable, simServiceContext.localSimDataDir.getParentFile(), null);
simServiceContext.times = datasetController.getDataSetTimes(simServiceContext.vcDataIdentifier);
simServiceContext.dataIdentifiers = datasetController.getDataIdentifiers(outputContext, simServiceContext.vcDataIdentifier);
return datasetController;
} catch (IOException | DataAccessException e1) {
e1.printStackTrace();
throw new RuntimeException("failed to read dataset: " + e1.getMessage());
}
}
use of cbit.vcell.simdata.DataSetControllerImpl 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