use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.
the class SmoldynFileWriter method writeDataProcessor.
private void writeDataProcessor() throws DataAccessException, IOException, MathException, DivideByZeroException, ExpressionException {
Simulation simulation = simTask.getSimulation();
DataProcessingInstructions dpi = simulation.getDataProcessingInstructions();
if (dpi == null) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " begin " + DataProcessingInstructions.ROI_TIME_SERIES);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " end");
} else {
FieldDataIdentifierSpec fdis = dpi.getSampleImageFieldData(simulation.getVersion().getOwner());
if (fdis == null) {
throw new DataAccessException("Can't find sample image in data processing instructions");
}
File userDirectory = outputFile.getParentFile();
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()), simTask.getSimulationJob().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 });
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " begin " + dpi.getScriptName());
StringTokenizer st = new StringTokenizer(dpi.getScriptInput(), "\n\r");
while (st.hasMoreTokens()) {
String str = st.nextToken();
if (str.trim().length() > 0) {
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " " + str);
}
}
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile);
printWriter.println(SmoldynVCellMapper.SmoldynKeyword.cmd + " " + SmoldynVCellMapper.SmoldynKeyword.B + " " + VCellSmoldynKeyword.vcellDataProcess + " end");
}
}
use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.
the class SimulationServiceImpl method getTimePoints.
public List<Double> getTimePoints(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);
ArrayList<Double> times = new ArrayList<Double>();
double[] timeArray;
timeArray = datasetController.getDataSetTimes(simServiceContext.vcDataIdentifier);
for (double t : timeArray) {
times.add(t);
}
return times;
} catch (Exception e) {
e.printStackTrace();
throw new ThriftDataAccessException("failed to retrieve times for simulation: " + e.getMessage());
}
}
use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.
the class LocalWorkspace method getDataSetControllerImpl.
/**
* Method getDataSetControllerImpl.
* @return DataSetControllerImpl
* @throws FileNotFoundException
*/
public DataSetControllerImpl getDataSetControllerImpl() throws FileNotFoundException {
if (dataSetControllerImpl == null) {
File rootDir = new File(getDefaultWorkspaceDirectory());
dataSetControllerImpl = new DataSetControllerImpl(new Cachetable(10000), rootDir, rootDir);
}
return dataSetControllerImpl;
}
use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.
the class FrapDataUtils method importFRAPDataFromVCellSimulationData.
public static FRAPData importFRAPDataFromVCellSimulationData(File vcellSimLogFile, String variableName, String bleachedMaskVarName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
// bleachedMaskVarName = "laserMask_cell";
VCSimulationIdentifier vcSimulationIdentifier = getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
DataSetControllerImpl dataSetControllerImpl = getDataSetControllerImplFromVCellSimulationData(vcellSimLogFile);
final DataJobEvent[] bStatus = new DataJobEvent[] { null };
DataJobListener dataJobListener = new DataJobListener() {
public void dataJobMessage(DataJobEvent event) {
bStatus[0] = event;
if (progressListener != null) {
progressListener.setProgress((int) (event.getProgress() / 100.0 * .75));
}
}
};
dataSetControllerImpl.addDataJobListener(dataJobListener);
DataIdentifier[] dataIdentifiers = getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
DataIdentifier variableNameDataIdentifier = null;
for (int i = 0; i < dataIdentifiers.length; i++) {
if (dataIdentifiers[i].getName().equals(variableName)) {
variableNameDataIdentifier = dataIdentifiers[i];
break;
}
}
if (variableNameDataIdentifier == null) {
throw new IllegalArgumentException("Variable " + variableName + " not found.");
}
if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
throw new IllegalArgumentException("Variable " + variableName + " is not VOLUME type.");
}
double[] times = dataSetControllerImpl.getDataSetTimes(vcSimulationDataIdentifier);
CartesianMesh cartesianMesh = dataSetControllerImpl.getMesh(vcSimulationDataIdentifier);
BitSet allBitset = new BitSet(cartesianMesh.getNumVolumeElements());
allBitset.set(0, cartesianMesh.getNumVolumeElements() - 1);
TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(new String[] { variableName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(getDotUser(), true));
TSJobResultsSpaceStats tsJobResultsSpaceStats = (TSJobResultsSpaceStats) dataSetControllerImpl.getTimeSeriesValues(null, vcSimulationDataIdentifier, timeSeriesJobSpec);
// wait for job to finish
while (bStatus[0] == null || bStatus[0].getEventTypeID() != DataJobEvent.DATA_COMPLETE) {
Thread.sleep(100);
}
double allTimesMin = tsJobResultsSpaceStats.getMinimums()[0][0];
double allTimesMax = allTimesMin;
for (int i = 0; i < times.length; i++) {
allTimesMin = Math.min(allTimesMin, tsJobResultsSpaceStats.getMinimums()[0][i]);
allTimesMax = Math.max(allTimesMax, tsJobResultsSpaceStats.getMaximums()[0][i]);
}
// double SCALE_MAX = maxIntensity.doubleValue();/*Math.pow(2,16)-1;*///Scale to 16 bits
double linearScaleFactor = 1;
if (maxIntensity != null) {
linearScaleFactor = maxIntensity.doubleValue() / allTimesMax;
}
System.out.println("alltimesMin=" + allTimesMin + " allTimesMax=" + allTimesMax + " linearScaleFactor=" + linearScaleFactor);
UShortImage[] scaledDataImages = new UShortImage[times.length];
Random rnd = new Random();
int shortMax = 65535;
// set messge to load variable
if (progressListener != null) {
progressListener.setMessage("Loading variable " + variableName + "...");
}
for (int i = 0; i < times.length; i++) {
double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, variableName, times[i]).getData();
short[] scaledDataShort = new short[rawData.length];
for (int j = 0; j < scaledDataShort.length; j++) {
double scaledRawDataJ = rawData[j] * linearScaleFactor;
if (bNoise) {
double ran = rnd.nextGaussian();
double scaledRawDataJ_withNoise = Math.max(0, (scaledRawDataJ + ran * Math.sqrt(scaledRawDataJ)));
scaledRawDataJ_withNoise = Math.min(shortMax, scaledRawDataJ_withNoise);
int scaledValue = (int) (scaledRawDataJ_withNoise);
scaledDataShort[j] &= 0x0000;
scaledDataShort[j] |= 0x0000FFFF & scaledValue;
} else {
int scaledValue = (int) (scaledRawDataJ);
scaledDataShort[j] &= 0x0000;
scaledDataShort[j] |= 0x0000FFFF & scaledValue;
}
}
scaledDataImages[i] = new UShortImage(scaledDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
if (progressListener != null) {
int progress = (int) (((i + 1) * 1.0 / times.length) * 100);
progressListener.setProgress(progress);
}
}
ImageDataset imageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
FRAPData frapData = new FRAPData(imageDataSet, new String[] { FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name(), FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name(), FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name() });
// get rois from log file
if (bleachedMaskVarName != null) {
// set message to load cell ROI variable
if (progressListener != null) {
progressListener.setMessage("Loading ROIs...");
}
double[] rawROIBleached = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, bleachedMaskVarName, 0).getData();
short[] scaledCellDataShort = new short[rawROIBleached.length];
short[] scaledBleachedDataShort = new short[rawROIBleached.length];
short[] scaledBackgoundDataShort = new short[rawROIBleached.length];
for (int j = 0; j < scaledCellDataShort.length; j++) {
boolean isCell = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals("subVolume1");
boolean isBackground = cartesianMesh.getCompartmentSubdomainNamefromVolIndex(j).equals("subVolume0");
if (isCell) {
scaledCellDataShort[j] = 1;
}
if (isBackground) {
scaledBackgoundDataShort[j] = 1;
}
if (rawROIBleached[j] > 0.2) {
scaledBleachedDataShort[j] = 1;
}
}
UShortImage cellImage = new UShortImage(scaledCellDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
UShortImage bleachedImage = new UShortImage(scaledBleachedDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
UShortImage backgroundImage = new UShortImage(scaledBackgoundDataShort, cartesianMesh.getOrigin(), cartesianMesh.getExtent(), cartesianMesh.getSizeX(), cartesianMesh.getSizeY(), cartesianMesh.getSizeZ());
if (progressListener != null) {
progressListener.setProgress(100);
}
frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()).setROIImages(new UShortImage[] { cellImage });
frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()).setROIImages(new UShortImage[] { bleachedImage });
frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name()).setROIImages(new UShortImage[] { backgroundImage });
}
return frapData;
}
use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.
the class ClientSimManager method showSimulationResults0.
private AsynchClientTask[] showSimulationResults0(final boolean isLocal, final ViewerType viewerType) {
// Create the AsynchClientTasks
ArrayList<AsynchClientTask> taskList = new ArrayList<AsynchClientTask>();
taskList.add(new AsynchClientTaskFunction(h -> {
h.put(H_LOCAL_SIM, isLocal);
h.put(H_VIEWER_TYPE, viewerType);
}, "setLocal", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING));
final DocumentWindowManager documentWindowManager = getDocumentWindowManager();
AsynchClientTask retrieveResultsTask = new AsynchClientTask("Retrieving results", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
final VCSimulationIdentifier vcSimulationIdentifier = sim.getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
OutputContext outputContext = (OutputContext) hashTable.get("outputContext");
if (simWindow == null && (viewerType == ViewerType.BothNativeAndPython || viewerType == ViewerType.NativeViewer_only)) {
try {
// make the manager and wire it up
DataViewerController dataViewerController = null;
if (!isLocal) {
dataViewerController = documentWindowManager.getRequestManager().getDataViewerController(outputContext, sim, 0);
// For changes in time or variable
documentWindowManager.addDataListener(dataViewerController);
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = sim.getVersion().getOwner();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
LocalVCDataIdentifier vcDataId = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
DataManager dataManager = null;
if (sim.isSpatial()) {
dataManager = new PDEDataManager(outputContext, vcDataManager, vcDataId);
} else {
dataManager = new ODEDataManager(outputContext, vcDataManager, vcDataId);
}
dataViewerController = new SimResultsViewerController(dataManager, sim);
dataSetControllerImpl.addDataJobListener(documentWindowManager);
}
// make the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
if (dataViewerControllers == null) {
dataViewerControllers = new Hashtable<VCSimulationIdentifier, DataViewerController>();
hashTable.put(H_DATA_VIEWER_CONTROLLERS, dataViewerControllers);
}
dataViewerControllers.put(vcSimulationIdentifier, dataViewerController);
} catch (Throwable exc) {
exc.printStackTrace(System.out);
saveFailure(hashTable, sim, exc);
}
}
try {
if (viewerType == ViewerType.PythonViewer_only || viewerType == ViewerType.BothNativeAndPython) {
VtkManager vtkManager = null;
if (!isLocal) {
vtkManager = documentWindowManager.getRequestManager().getVtkManager(outputContext, new VCSimulationDataIdentifier(vcSimulationIdentifier, 0));
} else {
// ---- preliminary : construct the localDatasetControllerProvider
File primaryDir = ResourceUtil.getLocalRootDir();
User usr = sim.getVersion().getOwner();
DataSetControllerImpl dataSetControllerImpl = new DataSetControllerImpl(null, primaryDir, null);
ExportServiceImpl localExportServiceImpl = new ExportServiceImpl();
LocalDataSetControllerProvider localDSCProvider = new LocalDataSetControllerProvider(usr, dataSetControllerImpl, localExportServiceImpl);
VCDataManager vcDataManager = new VCDataManager(localDSCProvider);
File localSimDir = ResourceUtil.getLocalSimDir(User.tempUser.getName());
VCSimulationDataIdentifier simulationDataIdentifier = new LocalVCSimulationDataIdentifier(vcSimulationIdentifier, 0, localSimDir);
vtkManager = new VtkManager(outputContext, vcDataManager, simulationDataIdentifier);
}
//
// test ability to read data
//
VtuVarInfo[] vtuVarInfos = vtkManager.getVtuVarInfos();
double[] times = vtkManager.getDataSetTimes();
//
// create the SimulationDataSetRef
//
VCDocument modelDocument = null;
if (documentWindowManager instanceof BioModelWindowManager) {
modelDocument = ((BioModelWindowManager) documentWindowManager).getBioModel();
} else if (documentWindowManager instanceof MathModelWindowManager) {
modelDocument = ((MathModelWindowManager) documentWindowManager).getMathModel();
}
SimulationDataSetRef simulationDataSetRef = VCellClientDataServiceImpl.createSimulationDataSetRef(sim, modelDocument, 0, isLocal);
// Hashtable<VCSimulationIdentifier, SimulationDataSetRef> simDataSetRefs = (Hashtable<VCSimulationIdentifier, SimulationDataSetRef>)hashTable.get(H_SIM_DATASET_REFS);
// if (simDataSetRefs == null) {
// simDataSetRefs = new Hashtable<VCSimulationIdentifier, SimulationDataSetRef>();
// hashTable.put(H_SIM_DATASET_REFS, simDataSetRefs);
// }
// simDataSetRefs.put(vcSimulationIdentifier, simulationDataSetRef);
File visitExe = VCellConfiguration.getFileProperty(PropertyLoader.visitExe);
if (visitExe != null) {
VisitSupport.launchVisTool(visitExe, simulationDataSetRef);
}
}
} catch (Throwable exc) {
exc.printStackTrace(System.out);
saveFailure(hashTable, sim, exc);
}
}
}
};
taskList.add(retrieveResultsTask);
AsynchClientTask displayResultsTask = new AsynchClientTask("Showing results", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@SuppressWarnings("unchecked")
public void run(Hashtable<String, Object> hashTable) throws Exception {
boolean isLocal = fetch(hashTable, H_LOCAL_SIM, Boolean.class, true);
SimulationWindow.LocalState localState = isLocal ? LocalState.LOCAL : LocalState.SERVER;
Hashtable<Simulation, Throwable> failures = (Hashtable<Simulation, Throwable>) hashTable.get(H_FAILURES);
Simulation[] simsToShow = (Simulation[]) hashTable.get("simsArray");
for (int i = 0; i < simsToShow.length; i++) {
final Simulation sim = simsToShow[i];
if (failures != null && failures.containsKey(sim)) {
continue;
}
final VCSimulationIdentifier vcSimulationIdentifier = simsToShow[i].getSimulationInfo().getAuthoritativeVCSimulationIdentifier();
final SimulationWindow simWindow = documentWindowManager.haveSimulationWindow(vcSimulationIdentifier);
if (simWindow != null) {
ChildWindowManager childWindowManager = ChildWindowManager.findChildWindowManager(documentWindowManager.getComponent());
ChildWindow childWindow = childWindowManager.getChildWindowFromContext(simWindow);
if (childWindow == null) {
childWindow = childWindowManager.addChildWindow(simWindow.getDataViewer(), simWindow);
childWindow.pack();
childWindow.setIsCenteredOnParent();
childWindow.show();
}
setFinalWindow(hashTable, childWindow);
simWindow.setLocalState(localState);
} else {
// wire it up the viewer
Hashtable<VCSimulationIdentifier, DataViewerController> dataViewerControllers = (Hashtable<VCSimulationIdentifier, DataViewerController>) hashTable.get(H_DATA_VIEWER_CONTROLLERS);
DataViewerController viewerController = dataViewerControllers.get(vcSimulationIdentifier);
Throwable ex = (failures == null ? null : failures.get(sim));
if (viewerController != null && ex == null) {
// no failure
DataViewer viewer = viewerController.createViewer();
getSimWorkspace().getSimulationOwner().getOutputFunctionContext().addPropertyChangeListener(viewerController);
documentWindowManager.addExportListener(viewer);
// For data related activities such as calculating statistics
documentWindowManager.addDataJobListener(viewer);
viewer.setSimulationModelInfo(new SimulationWorkspaceModelInfo(getSimWorkspace().getSimulationOwner(), sim.getName()));
viewer.setDataViewerManager(documentWindowManager);
SimulationWindow newWindow = new SimulationWindow(vcSimulationIdentifier, sim, getSimWorkspace().getSimulationOwner(), viewer);
BeanUtils.addCloseWindowKeyboardAction(newWindow.getDataViewer());
documentWindowManager.addResultsFrame(newWindow);
setFinalWindow(hashTable, viewer);
newWindow.setLocalState(localState);
}
}
}
StringBuffer failMessage = new StringBuffer();
if (failures != null) {
if (!failures.isEmpty()) {
failMessage.append("Error, " + failures.size() + " of " + simsToShow.length + " sim results failed to display:\n");
Enumeration<Simulation> en = failures.keys();
while (en.hasMoreElements()) {
Simulation sim = en.nextElement();
Throwable exc = (Throwable) failures.get(sim);
failMessage.append("'" + sim.getName() + "' - " + exc.getMessage());
}
}
}
if (failMessage.length() > 0) {
PopupGenerator.showErrorDialog(ClientSimManager.this.getDocumentWindowManager(), failMessage.toString());
}
}
};
if (viewerType == ViewerType.BothNativeAndPython || viewerType == ViewerType.NativeViewer_only) {
taskList.add(displayResultsTask);
}
// Dispatch the tasks using the ClientTaskDispatcher.
AsynchClientTask[] taskArray = new AsynchClientTask[taskList.size()];
taskList.toArray(taskArray);
return taskArray;
}
Aggregations