use of cbit.rmi.event.DataJobEvent 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.rmi.event.DataJobEvent in project vcell by virtualcell.
the class DataSetControllerImpl method fireDataJobEventIfNecessary.
private void fireDataJobEventIfNecessary(VCDataJobID vcDataJobID, int argEventType, VCDataIdentifier argVCDataID, Double argProgress, TimeSeriesJobResults argTSJR, Exception argFailedJobExc) {
if (vcDataJobID == null || !vcDataJobID.isBackgroundTask()) {
return;
}
DataJobEvent dataJobEvent = new DataJobEvent(vcDataJobID, argEventType, argVCDataID.getDataKey(), argVCDataID.getID(), argProgress);
fireDataJobMessage_private(dataJobEvent);
}
use of cbit.rmi.event.DataJobEvent in project vcell by virtualcell.
the class DisplayTimeSeriesOp method getDataSetControllerProvider.
private DataSetControllerProvider getDataSetControllerProvider(final ImageTimeSeries<? extends Image> imageTimeSeries, final PDEDataViewer pdeDataViewer) throws ImageException, IOException {
ISize size = imageTimeSeries.getISize();
int dimension = (size.getZ() > 0) ? (3) : (2);
Extent extent = imageTimeSeries.getExtent();
Origin origin = imageTimeSeries.getAllImages()[0].getOrigin();
// don't care ... no surfaces
double filterCutoffFrequency = 0.5;
VCImage vcImage = new VCImageUncompressed(null, new byte[size.getXYZ()], extent, size.getX(), size.getY(), size.getZ());
RegionImage regionImage = new RegionImage(vcImage, dimension, extent, origin, filterCutoffFrequency);
final CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, size, regionImage);
final DataIdentifier dataIdentifier = new DataIdentifier("var", VariableType.VOLUME, new Domain("domain"), false, "var");
final DataSetController dataSetController = new DataSetController() {
@Override
public ExportEvent makeRemoteFile(OutputContext outputContext, ExportSpecs exportSpecs) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public TimeSeriesJobResults getTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdataID, TimeSeriesJobSpec timeSeriesJobSpec) throws RemoteProxyException, DataAccessException {
pdeDataViewer.dataJobMessage(new DataJobEvent(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_START, vcdataID.getDataKey(), vcdataID.getID(), new Double(0)));
if (!timeSeriesJobSpec.isCalcSpaceStats() && !timeSeriesJobSpec.isCalcTimeStats()) {
int[][] indices = timeSeriesJobSpec.getIndices();
double[] timeStamps = imageTimeSeries.getImageTimeStamps();
// [var][dataindex+1][timeindex]
double[][][] dataValues = new double[1][indices[0].length + 1][timeStamps.length];
for (int timeIndex = 0; timeIndex < timeStamps.length; timeIndex++) {
// index 0 is time
dataValues[0][0][timeIndex] = timeStamps[timeIndex];
}
for (int timeIndex = 0; timeIndex < timeStamps.length; timeIndex++) {
float[] pixelValues = imageTimeSeries.getAllImages()[timeIndex].getFloatPixels();
for (int samplePointIndex = 0; samplePointIndex < indices[0].length; samplePointIndex++) {
int pixelIndex = indices[0][samplePointIndex];
dataValues[0][samplePointIndex + 1][timeIndex] = pixelValues[pixelIndex];
}
}
TSJobResultsNoStats timeSeriesJobResults = new TSJobResultsNoStats(new String[] { "var" }, indices, timeStamps, dataValues);
pdeDataViewer.dataJobMessage(new DataJobEvent(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_COMPLETE, vcdataID.getDataKey(), vcdataID.getID(), new Double(0)));
return timeSeriesJobResults;
}
return null;
}
@Override
public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdataID, String varName, double time) throws RemoteProxyException, DataAccessException {
double timePoint = time;
double[] timePoints = getDataSetTimes(vcdataID);
int index = -1;
for (int i = 0; i < timePoints.length; i++) {
if (timePoint == timePoints[i]) {
index = i;
break;
}
}
double[] data = imageTimeSeries.getAllImages()[index].getDoublePixels();
PDEDataInfo pdeDataInfo = new PDEDataInfo(null, null, varName, time, 0);
VariableType varType = VariableType.VOLUME;
return new SimDataBlock(pdeDataInfo, data, varType);
}
@Override
public boolean getParticleDataExists(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return false;
}
@Override
public ParticleDataBlock getParticleDataBlock(VCDataIdentifier vcdataID, double time) throws DataAccessException, RemoteProxyException {
return null;
}
@Override
public ODESimData getODEData(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return null;
}
@Override
public CartesianMesh getMesh(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return mesh;
}
@Override
public PlotData getLineScan(OutputContext outputContext, VCDataIdentifier vcdataID, String variable, double time, SpatialSelection spatialSelection) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public AnnotatedFunction[] getFunctions(OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
return new AnnotatedFunction[0];
}
@Override
public double[] getDataSetTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return imageTimeSeries.getImageTimeStamps();
}
@Override
public DataSetTimeSeries getDataSetTimeSeries(VCDataIdentifier vcdataID, String[] variableNames) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataSetMetadata getDataSetMetadata(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataIdentifier[] getDataIdentifiers(OutputContext outputContext, VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
return new DataIdentifier[] { dataIdentifier };
}
@Override
public FieldDataFileOperationResults fieldDataFileOperation(FieldDataFileOperationSpec fieldDataFileOperationSpec) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public DataOperationResults doDataOperation(DataOperation dataOperation) throws DataAccessException, RemoteProxyException {
throw new RuntimeException("not yet implemented");
}
@Override
public VtuFileContainer getEmptyVtuMeshFiles(VCDataIdentifier vcdataID, int timeIndex) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public double[] getVtuTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
throw new RuntimeException("not yet implemented");
}
@Override
public double[] getVtuMeshData(OutputContext outputContext, VCDataIdentifier vcdataID, VtuVarInfo var, double time) throws RemoteProxyException, DataAccessException {
// TODO Auto-generated method stub
return null;
}
@Override
public VtuVarInfo[] getVtuVarInfos(OutputContext outputContext, VCDataIdentifier vcDataIdentifier) throws DataAccessException, RemoteProxyException {
// TODO Auto-generated method stub
return null;
}
@Override
public NFSimMolecularConfigurations getNFSimMolecularConfigurations(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
// TODO Auto-generated method stub
return null;
}
};
DataSetControllerProvider dataSetControllerProvider = new DataSetControllerProvider() {
@Override
public DataSetController getDataSetController() throws DataAccessException {
return dataSetController;
}
};
return dataSetControllerProvider;
}
use of cbit.rmi.event.DataJobEvent in project vcell by virtualcell.
the class DisplayTimeSeriesOp method displayImageTimeSeries.
public void displayImageTimeSeries(final ImageTimeSeries<? extends Image> imageTimeSeries, final String title, final WindowListener windowListener) throws ImageException, IOException {
try {
System.out.println("starting to prepare data for time series viewing");
final PDEDataViewer pdeDataViewer = new PDEDataViewer();
DataSetControllerProvider dataSetControllerProvider;
try {
dataSetControllerProvider = getDataSetControllerProvider(imageTimeSeries, pdeDataViewer);
} catch (ImageException | IOException e1) {
e1.printStackTrace();
throw new RuntimeException(e1.getMessage(), e1);
}
VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
final VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {
public User getOwner() {
return new User("nouser", null);
}
public KeyValue getDataKey() {
return null;
}
public String getID() {
return "mydata";
}
};
PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
final ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
final RequestManager requestManager = new RequestManagerAdapter() {
};
final DataViewerManager dataViewerManager = new DataViewerManager() {
public void dataJobMessage(DataJobEvent event) {
}
public void exportMessage(ExportEvent event) {
}
public void addDataListener(DataListener newListener) {
}
public UserPreferences getUserPreferences() {
// getRequestManager().getUserPreferences();
return null;
}
public void removeDataListener(DataListener newListener) {
}
public void startExport(Component requester, OutputContext outputContext, ExportSpecs exportSpecs) {
// getLocalRequestManager().startExport(outputContext, FieldDataWindowManager.this, exportSpecs);
}
public void simStatusChanged(SimStatusEvent simStatusEvent) {
}
public User getUser() {
return new User("dummy", new KeyValue("123"));
// return getRequestManager().getDocumentManager().getUser();
}
public RequestManager getRequestManager() {
return requestManager;
}
};
System.out.println("ready to display time series");
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
JFrame jframe = new TopLevelFrame();
jframe.setTitle(title);
jframe.getContentPane().add(pdeDataViewer);
jframe.setSize(1000, 600);
jframe.setVisible(true);
if (windowListener != null) {
jframe.addWindowListener(windowListener);
}
try {
pdeDataViewer.setDataViewerManager(dataViewerManager);
} catch (PropertyVetoException e) {
e.printStackTrace();
}
pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
});
} catch (InvocationTargetException | InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
use of cbit.rmi.event.DataJobEvent in project vcell by virtualcell.
the class RestEventService method newEventMessage.
private void newEventMessage(MessageEvent event) {
System.out.println(getClass().getName() + ".newEventMessage(" + event.getClass().getSimpleName() + ": " + event);
if (event instanceof ExportEvent) {
ExportEvent exportEvent = (ExportEvent) event;
try {
ExportEventRepresentation exportEventRep = exportEvent.toJsonRep();
ExportEvent event2 = ExportEvent.fromJsonRep(this, exportEventRep);
if (!Compare.isEqual(event2.getFormat(), exportEvent.getFormat())) {
throw new RuntimeException("Export event round-trip failed");
}
if (!Compare.isEqual(event2.getJobID(), exportEvent.getJobID())) {
throw new RuntimeException("Export event round-trip failed");
}
Gson gson = new Gson();
String eventJSON = gson.toJson(exportEventRep);
insert(exportEventRep.username, EventType.ExportEvent, eventJSON);
} catch (Exception e) {
e.printStackTrace();
}
} else if (event instanceof SimulationJobStatusEvent) {
SimulationJobStatusEvent simJobEvent = (SimulationJobStatusEvent) event;
try {
SimulationJobStatusEventRepresentation simJobEventRep = simJobEvent.toJsonRep();
SimulationJobStatusEvent event2 = SimulationJobStatusEvent.fromJsonRep(this, simJobEventRep);
if (!Compare.isEqual(event2.getJobStatus(), simJobEvent.getJobStatus())) {
throw new RuntimeException("SimulationJobStatus event round-trip failed");
}
if (!Compare.isEqual(event2.getProgress(), simJobEvent.getProgress())) {
throw new RuntimeException("SimulationJobStatus <PROGRESS> event round-trip failed");
}
Gson gson = new Gson();
String eventJSON = gson.toJson(simJobEventRep);
insert(simJobEventRep.username, EventType.SimJob, eventJSON);
} catch (Exception e) {
e.printStackTrace();
}
} else if (event instanceof VCellMessageEvent) {
VCellMessageEvent vcellMessageEvent = (VCellMessageEvent) event;
lg.error("event of type VCellMessageEvent not supported");
} else if (event instanceof WorkerEvent) {
lg.error("event of type WorkerEvent not supported");
WorkerEvent workerEvent = (WorkerEvent) event;
} else if (event instanceof PerformanceMonitorEvent) {
lg.error("event of type PerformanceMonitorEvent not supported");
PerformanceMonitorEvent performanceMonitorEvent = (PerformanceMonitorEvent) event;
} else if (event instanceof DataJobEvent) {
lg.error("event of type DataJobEvent not supported");
DataJobEvent dataJobEvent = (DataJobEvent) event;
try {
DataJobEventRepresentation dataJobEventRep = dataJobEvent.toJsonRep();
DataJobEvent event2 = DataJobEvent.fromJsonRep(this, dataJobEventRep);
if (!Compare.isEqual(event2.getDataIdString(), dataJobEvent.getDataIdString())) {
throw new RuntimeException("DataJob event round-trip failed");
}
if (!Compare.isEqual(event2.getProgress(), dataJobEvent.getProgress())) {
throw new RuntimeException("DataJob <PROGRESS> event round-trip failed");
}
Gson gson = new Gson();
String eventJSON = gson.toJson(dataJobEventRep);
insert(dataJobEventRep.username, EventType.DataJob, eventJSON);
} catch (Exception e) {
e.printStackTrace();
}
}
}
Aggregations