use of cbit.rmi.event.DataJobListener 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.DataJobListener in project vcell by virtualcell.
the class TopLevelWindowManager method fireDataJobMessage.
/**
* Method to support listener events.
*/
protected void fireDataJobMessage(DataJobEvent event) {
if (aDataJobListener == null) {
return;
}
;
int currentSize = aDataJobListener.size();
DataJobListener tempListener = null;
for (int index = 0; index < currentSize; index++) {
tempListener = aDataJobListener.elementAt(index);
if (tempListener != null) {
tempListener.dataJobMessage(event);
}
;
}
;
}
use of cbit.rmi.event.DataJobListener in project vcell by virtualcell.
the class VirtualFrapWindowManager method fireDataJobMessage.
/**
* Method to support listener events.
*/
protected void fireDataJobMessage(DataJobEvent event) {
if (aDataJobListener == null) {
return;
}
;
int currentSize = aDataJobListener.size();
DataJobListener tempListener = null;
for (int index = 0; index < currentSize; index++) {
tempListener = (DataJobListener) aDataJobListener.elementAt(index);
if (tempListener != null) {
tempListener.dataJobMessage(event);
}
;
}
;
}
use of cbit.rmi.event.DataJobListener in project vcell by virtualcell.
the class PDEDataViewer method createMultiTimePlotHelper.
// private static class MultiTimePointPropChangeListener implements PropertyChangeListener {
// @Override
// public void propertyChange(PropertyChangeEvent evt) {
// }
// }
private MultiTimePlotHelper createMultiTimePlotHelper(final ClientPDEDataContext copyThisPDEDatacontext, final User user, DataSymbolMetadataResolver argDataSymbolMetadataResolver) throws Exception {
final ClientPDEDataContext[] copyHolder = new ClientPDEDataContext[1];
if (PDEDataViewer.this.isPostProcess()) {
copyHolder[0] = PDEDataViewerPostProcess.createPostProcessPDEDataContext(copyThisPDEDatacontext);
} else {
copyHolder[0] = (ClientPDEDataContext) ((PDEDataManager) copyThisPDEDatacontext.getDataManager()).createNewPDEDataManager(copyThisPDEDatacontext.getVCDataIdentifier(), null).getPDEDataContext();
}
copyHolder[0].setVariableAndTime(copyThisPDEDatacontext.getDataIdentifier(), copyThisPDEDatacontext.getTimePoint());
return new PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper() {
private DataSymbolMetadataResolver dataSymbolMetadataResolver = argDataSymbolMetadataResolver;
private ArrayList<PropertyChangeListener> myPropertyChangeHolder = new ArrayList<>();
private ClientPDEDataContext myPdeDataContext = copyHolder[0];
private VariableType myVariableType = copyThisPDEDatacontext.getDataIdentifier().getVariableType();
// catch events from 'this' PDEDataViewer and pass with new source
private PropertyChangeListener myPropertyChangeListener;
private User myUser = user;
// List<AnnotatedFunction> myAnnots;
// access to anonymous outer class
private PdeTimePlotMultipleVariablesPanel.MultiTimePlotHelper multiTimePlotHelperThis = this;
private PDEPlotControlPanel.IdentifierListCellRenderer myListCellRenderer;
private AnnotatedFunction[] lastAnnotatedFunctions;
private PDEPlotControlPanel.FunctionListProvider functionListProvider = new PDEPlotControlPanel.FunctionListProvider() {
@Override
public List<AnnotatedFunction> getAnnotatedFunctions() {
if (myPdeDataContext.getDataManager().getOutputContext() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions() != null && myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions().length > 0) {
return new ArrayList<>(Arrays.asList(myPdeDataContext.getDataManager().getOutputContext().getOutputFunctions()));
}
return new ArrayList<>();
}
};
private Comparator<AnnotatedFunction> nameComparator = new Comparator<AnnotatedFunction>() {
@Override
public int compare(AnnotatedFunction o1, AnnotatedFunction o2) {
return o2.getName().compareToIgnoreCase(o1.getName());
}
};
@Override
public void removeDataJobListener(DataJobListener dataJobListener) {
PDEDataViewer.this.removeDataJobListener(dataJobListener);
}
@Override
public void addDataJobListener(DataJobListener dataJobListener) {
PDEDataViewer.this.addDataJobListener(dataJobListener);
}
@Override
public User getUser() {
return myUser;
}
@Override
public PDEDataContext getPdeDatacontext() {
return myPdeDataContext;
}
@Override
public DataIdentifier[] getCopyOfDisplayedDataIdentifiers() {
DataIdentifier[] newData = PDEDataViewer.this.getPDEPlotControlPanel1().getDataIdentifierFilter().accept(DefaultDataIdentifierFilter.ALL, functionListProvider.getAnnotatedFunctions(), myPdeDataContext.getDataIdentifiers()).toArray(new DataIdentifier[0]);
return DataIdentifier.collectSortedSimilarDataTypes(this.getVariableType(), newData);
}
@Override
public PDEPlotControlPanel.IdentifierListCellRenderer getListCellRenderer() {
if (myListCellRenderer == null) {
myListCellRenderer = new PDEPlotControlPanel.IdentifierListCellRenderer(functionListProvider);
}
return myListCellRenderer;
}
@Override
public Simulation getsimulation() {
return PDEDataViewer.this.getSimulation();
}
private List<AnnotatedFunction> efficiencyFilter(List<AnnotatedFunction> funcs) {
ArrayList<AnnotatedFunction> outputfunctions = new ArrayList<>();
Iterator<AnnotatedFunction> iter = funcs.iterator();
while (iter.hasNext()) {
AnnotatedFunction theFunc = iter.next();
if ((isPostProcess() && theFunc.getFunctionType().equals(VariableType.POSTPROCESSING)) || (!isPostProcess() && !theFunc.getFunctionType().equals(VariableType.POSTPROCESSING))) {
outputfunctions.add(theFunc);
}
}
return outputfunctions;
}
@Override
public void addPropertyChangeListener(PropertyChangeListener propertyChangeListener) {
myPropertyChangeHolder.add(propertyChangeListener);
if (myPropertyChangeListener == null) {
myPropertyChangeListener = new PropertyChangeListener() {
@Override
public void propertyChange(PropertyChangeEvent evt) {
if (evt.getSource() == PDEDataViewer.this && evt.getPropertyName().equals(PDEDataContext.PROP_PDE_DATA_CONTEXT)) {
// List<AnnotatedFunction> currentOutputFunctions = functionListProvider.getAnnotatedFunctions();
// currentOutputFunctions = efficiencyFilter(currentOutputFunctions);
// currentOutputFunctions.sort(nameComparator);
List<AnnotatedFunction> newOutputFunctions0 = Arrays.asList(((ClientPDEDataContext) PDEDataViewer.this.getPdeDataContext()).getDataManager().getOutputContext().getOutputFunctions());
List<AnnotatedFunction> newOutputFunctions = efficiencyFilter(newOutputFunctions0);
newOutputFunctions.sort(nameComparator);
if (lastAnnotatedFunctions != null && Compare.isEqualOrNullStrict(lastAnnotatedFunctions, newOutputFunctions.toArray(new AnnotatedFunction[0]))) {
return;
}
lastAnnotatedFunctions = new AnnotatedFunction[newOutputFunctions.size()];
for (int i = 0; i < newOutputFunctions.size(); i++) {
lastAnnotatedFunctions[i] = new AnnotatedFunction(newOutputFunctions.get(i));
}
// lastAnnotatedFunctions = newOutputFunctions0.toArray(new AnnotatedFunction[0]);
myPdeDataContext.getDataManager().setOutputContext(new OutputContext(newOutputFunctions0.toArray(new AnnotatedFunction[0])));
myPdeDataContext.refreshIdentifiers();
for (int i = 0; i < myPropertyChangeHolder.size(); i++) {
myPropertyChangeHolder.get(i).propertyChange(new PropertyChangeEvent(multiTimePlotHelperThis, SimDataConstants.PROPERTY_NAME_DATAIDENTIFIERS, null, null));
}
}
}
};
PDEDataViewer.this.addPropertyChangeListener(myPropertyChangeListener);
}
}
@Override
public void removeallPropertyChangeListeners() {
myPropertyChangeHolder.clear();
if (myPropertyChangeListener != null) {
PDEDataViewer.this.removePropertyChangeListener(myPropertyChangeListener);
}
}
@Override
public VariableType getVariableType() {
return myVariableType;
}
// @Override
// public void addExtraTasks(AsynchClientTask[] moreTasks) {
// PDEDataViewer.this.addExtraTasks(moreTasks);
// }
@Override
public DataSymbolMetadataResolver getDataSymbolMetadataResolver() {
return dataSymbolMetadataResolver;
}
};
}
use of cbit.rmi.event.DataJobListener in project vcell by virtualcell.
the class DataSetControllerImpl method fireDataJobMessage_private.
/**
* Method to support listener events.
*/
private void fireDataJobMessage_private(DataJobEvent event) {
if (aDataJobListener == null) {
return;
}
;
int currentSize = aDataJobListener.size();
DataJobListener tempListener = null;
for (int index = 0; index < currentSize; index++) {
tempListener = (DataJobListener) aDataJobListener.elementAt(index);
if (tempListener != null) {
tempListener.dataJobMessage(event);
}
;
}
;
}
Aggregations