use of org.vcell.util.document.VCDataIdentifier 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 org.vcell.util.document.VCDataIdentifier in project vcell by virtualcell.
the class RestDatabaseService method getDataSetMetadata.
public DataSetMetadata getDataSetMetadata(SimDataServerResource resource, User vcellUser) throws ObjectNotFoundException, DataAccessException, SQLException {
if (vcellUser == null) {
vcellUser = VCellApiApplication.DUMMY_USER;
}
UserLoginInfo userLoginInfo = new UserLoginInfo(vcellUser.getName(), null);
// resource.getRequestAttributes().get(VCellApiApplication.SIMDATAID);
String simId = resource.getAttribute(VCellApiApplication.SIMDATAID);
KeyValue simKey = new KeyValue(simId);
SimulationRep simRep = getSimulationRep(simKey);
if (simRep == null) {
throw new ObjectNotFoundException("Simulation with key " + simKey + " not found");
}
User owner = simRep.getOwner();
int jobIndex = 0;
VCMessageSession rpcSession = vcMessagingService.createProducerSession();
try {
RpcDataServerProxy rpcDataServerProxy = new RpcDataServerProxy(userLoginInfo, rpcSession);
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simKey, owner);
VCDataIdentifier vcdID = new VCSimulationDataIdentifier(vcSimID, jobIndex);
DataSetMetadata dataSetMetadata = rpcDataServerProxy.getDataSetMetadata(vcdID);
return dataSetMetadata;
} finally {
rpcSession.close();
}
}
use of org.vcell.util.document.VCDataIdentifier in project vcell by virtualcell.
the class DataProcessingResultsPanel method onVariablesChange.
private void onVariablesChange() {
try {
// keep old indices
lastSelectedIdxArray = varJList.getSelectedIndices();
Object[] selectedObjects = varJList.getSelectedValues();
int numSelectedVars = selectedObjects.length;
int totalColumns = 1;
for (int v = 0; v < numSelectedVars; v++) {
totalColumns++;
// String varName = (String)selectedObjects[v];
// ucar.nc2.Variable volVar = ncfile.findVariable(varName);
// int[] shape = volVar.getShape();
// int numColumns = shape[1];
//
// totalColumns += numColumns;
}
if (dataProcessingOutputInfo == null) {
throw new RuntimeException("dataProcessingOutInfo null, thread = " + Thread.currentThread().getName());
}
final double[] vtp = dataProcessingOutputInfo.getVariableTimePoints();
if (vtp == null) {
throw new RuntimeException("getVariableTimePoints( ) null, thread = " + Thread.currentThread().getName());
}
final int numTimes = vtp.length;
double[][] plotDatas = new double[totalColumns][numTimes];
// assumes all times same
plotDatas[0] = dataProcessingOutputInfo.getVariableTimePoints();
String[] plotNames = new String[totalColumns - 1];
int columnCount = 0;
for (int v = 0; v < numSelectedVars; v++) {
String varName = ((String) selectedObjects[v]);
// remove the unit from name if exist
if (// "_(" doesn't suppose to be the first char
varName.indexOf("_(") > 0) {
varName = varName.substring(0, varName.indexOf("_("));
}
// }
for (int i = 0; i < /*numColumns*/
1; i++) {
String plotName = varName;
if (i > 0) {
plotName += ": region " + (i - 1);
}
plotNames[columnCount] = plotName;
if (columnCount >= plotDatas.length) {
throw new RuntimeException("invalid columnCount " + columnCount + " >= " + plotDatas.length);
}
for (int j = 0; j < numTimes; j++) {
// data.get(j, i);
double[] vars = dataProcessingOutputInfo.getVariableStatValues().get(varName);
if (j >= vars.length) {
throw new RuntimeException("invalid index " + j + " on " + varName + ", greater than " + vars.length);
}
plotDatas[columnCount + 1][j] = vars[j];
}
columnCount++;
}
}
Plot2D plot2D = new SingleXPlot2D(null, null, ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
plotPane.setPlot2D(plot2D);
} catch (Exception e1) {
VCDataIdentifier id = dataProcessingOutputInfo.getVCDataIdentifier();
DialogUtils.ErrorContext ec = new DialogUtils.ErrorContext(VerboseDataIdentifier.parse(id));
DialogUtils.showErrorDialog(this, e1.getMessage(), e1, ec);
e1.printStackTrace();
}
}
use of org.vcell.util.document.VCDataIdentifier in project vcell by virtualcell.
the class VFrapXmlHelper method LoadVFrapSpecialImages.
// // load and compute prebleach average and first postbleach images
// public void LoadVFrapSpecialImages(AnnotatedImageDataset annotatedImages, int startingIndexRecovery)
// {
// // unnormalized prebleach average
// prebleachAvg = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// for(int j = 0; j < prebleachAvg.length; j++)
// {
// double pixelTotal = 0;
// for(int i = 0 ; i < startingIndexRecovery; i++)
// {
// pixelTotal = pixelTotal + (annotatedImages.getImageDataset().getImage(0, 0, i).getPixels()[j] & 0x0000FFFF);
// }
// prebleachAvg[j] = pixelTotal/startingIndexRecovery;
// }
//
// // unnormalized first post bleach
// firstPostBleach = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// short[] pixels = annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getPixels();
// for(int i = 0; i< pixels.length; i++)
// {
// firstPostBleach[i] = pixels[i] & 0x0000FFFF;
// }
// }
//
// Locate the special images within the vFrap files and load them in memory
//
public static boolean LoadVFrapSpecialImages(Hashtable<String, Object> hashTable, Element vFrapRoot) throws IOException, DataAccessException, MathException, ImageException {
// ------ parse the vfrap file and the log/zip files referred within -----
// many channels of 1 timepoint each
int NumTimePoints = 1;
// the channels: prebleach, postbleach, roi1, roi2 ... roiN
int NumChannels = tokenNames.length;
String[] channelNames = new String[NumChannels];
VariableType[] channelTypes = new VariableType[NumChannels];
DataSymbolType[] channelVFrapImageType = new DataSymbolType[NumChannels];
double[][][] pixData = new double[NumTimePoints][NumChannels][];
// get the path of the file tagged with "ROIExternalDataInfoTag" and open it
Element roiExternalDataInfoElement = vFrapRoot.getChild(MicroscopyXMLTags.ROIExternalDataInfoTag);
if (roiExternalDataInfoElement == null) {
// can't load FieldData for some reason, fall back to importing the biomodel only
return false;
}
// <ROIExternalDataInfo Filename="c:\vFrap\VirtualMicroscopy\SimulationData\SimID_1282941232246_0_.log">
// <ExternalDataIdentifier Name="timeData" KeyValue="1282941232246" OwnerName="SimulationData" OwnerKey="0" />
// </ImageDatasetExternalDataInfo>
// c:\VirtualMicroscopy\SimulationData\SimID_1284149203811_0_.log
String filename = (roiExternalDataInfoElement).getAttributeValue("Filename");
Element childElement = (roiExternalDataInfoElement).getChild("ExternalDataIdentifier");
if (childElement == null) {
// can't load FieldData for some reason, fall back to importing the biomodel only
return false;
}
StringTokenizer tokens = new StringTokenizer(filename, "/\\.");
final ArrayList<String> tokenArray = new ArrayList<String>();
while (tokens.hasMoreElements()) {
tokenArray.add(tokens.nextToken());
}
final String dataID = tokenArray.get(tokenArray.size() - 2);
final String userName = tokenArray.get(tokenArray.size() - 3);
VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {
public String getID() {
return dataID;
}
public KeyValue getDataKey() {
return null;
}
public User getOwner() {
return new User(userName, new KeyValue("123345432334"));
}
};
// ------- recover simulation data for this user name, load the images in memory ------------
// ex c:\\VirtualMicroscopy\\SimulationData
String userDirName = filename.substring(0, filename.indexOf(dataID) - 1);
File userDir = new File(userDirName);
SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
SimulationData simData = new SimulationData(vcDataIdentifier, userDir, null, simDataAmplistorInfo);
// build a valid mesh in 2 steps, what we have in simData is incomplete
CartesianMesh incompleteMesh = simData.getMesh();
Extent extent = incompleteMesh.getExtent();
ISize isize = new ISize(incompleteMesh.getSizeX(), incompleteMesh.getSizeY(), incompleteMesh.getSizeZ());
Origin origin = new Origin(0, 0, 0);
CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
double[] times = simData.getDataTimes();
for (int i = 0; i < dataIdentifiers.length; i++) {
// ex: prebleach_avg, postbleach_first, postbleach_last, bleached_mask, cell_mask, ring1_mask,... ring8_mask
System.out.println(dataIdentifiers[i].getName());
for (double time : times) {
// this loops only once, we have just 1 timepoint for each "special" image
SimDataBlock simDataBlock = simData.getSimDataBlock(null, dataIdentifiers[i].getName(), time);
channelNames[i] = dataIdentifiers[i].getName();
channelTypes[i] = VariableType.VOLUME;
channelVFrapImageType[i] = SymbolEquivalence.typeFromToken(dataIdentifiers[i].getName());
pixData[0][i] = simDataBlock.getData();
// var = prebleach_avg, time = 0.0, data = { 1.0832530361887216 1.0832530361887216 1.0832530361887216 1.0 .... }
System.out.print("var = " + dataIdentifiers[i].getName() + ", time = " + time + ", data = { ");
// show a few
for (int j = 0; j < 5; j++) {
System.out.print(pixData[0][i][j] + " ");
}
// show a few
;
// show a few
System.out.println(" ... ");
}
}
hashTable.put("mesh", mesh);
hashTable.put("pixData", pixData);
hashTable.put("channelNames", channelNames);
hashTable.put("channelTypes", channelTypes);
hashTable.put("channelVFrapImageType", channelVFrapImageType);
return true;
}
use of org.vcell.util.document.VCDataIdentifier in project vcell by virtualcell.
the class SimResultsViewer method initialize.
/**
* Insert the method's description here.
* Creation date: (10/17/2005 11:37:52 PM)
* @exception org.vcell.util.DataAccessException The exception description.
*/
private void initialize() throws DataAccessException {
// create main viewer for jobIndex 0 and wire it up
if (isODEData) {
setMainViewer(createODEDataViewer());
} else {
setMainViewer(createPDEDataViewer());
}
java.beans.PropertyChangeListener pcl = new java.beans.PropertyChangeListener() {
public void propertyChange(java.beans.PropertyChangeEvent evt) {
if (evt.getSource() == SimResultsViewer.this && (evt.getPropertyName().equals("dataViewerManager"))) {
try {
getMainViewer().setDataViewerManager(getDataViewerManager());
} catch (java.beans.PropertyVetoException exc) {
exc.printStackTrace();
}
}
if (evt.getSource() == SimResultsViewer.this && (evt.getPropertyName().equals("simulationModelInfo"))) {
getMainViewer().setSimulationModelInfo(getSimulationModelInfo());
}
}
};
addPropertyChangeListener(pcl);
// if necessarry, create parameter choices panel and wire it up
if (getSimulation().getScanCount() > 1) {
JPanel panel = new JPanel();
panel.setLayout(new BorderLayout(5, 0));
panel.setBorder(BorderFactory.createEtchedBorder());
JLabel label = new JLabel("<html><b>Choose Parameter Values</b></html>");
label.setHorizontalAlignment(SwingConstants.CENTER);
label.setBorder(BorderFactory.createEmptyBorder(2, 2, 0, 2));
panel.add(label, BorderLayout.NORTH);
String[] scanParams = getSimulation().getMathOverrides().getScannedConstantNames();
Arrays.sort(scanParams);
JPanel tablePanel = new JPanel();
tablePanel.setLayout(new BoxLayout(tablePanel, BoxLayout.X_AXIS));
for (int i = 0; i < scanParams.length; i++) {
Constant[] scanConstants = getSimulation().getMathOverrides().getConstantArraySpec(scanParams[i]).getConstants();
String[][] values = new String[scanConstants.length][1];
for (int j = 0; j < scanConstants.length; j++) {
values[j][0] = scanConstants[j].getExpression().infix();
}
class ScanChoicesTableModel extends javax.swing.table.AbstractTableModel {
String[] columnNames;
Object[][] rowData;
ScanChoicesTableModel(Object[][] argData, String[] argNames) {
columnNames = argNames;
rowData = argData;
}
public String getColumnName(int column) {
return columnNames[column].toString();
}
public int getRowCount() {
return rowData.length;
}
public int getColumnCount() {
return columnNames.length;
}
public Object getValueAt(int row, int col) {
return rowData[row][col];
}
public boolean isCellEditable(int row, int column) {
return false;
}
public void setValueAt(Object value, int row, int col) {
rowData[row][col] = value;
fireTableCellUpdated(row, col);
}
}
;
ScanChoicesTableModel tm = new ScanChoicesTableModel(values, new String[] { scanParams[i] });
final JTable table = new JTable(tm);
choicesHash.put(scanParams[i], table);
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().setSelectionInterval(0, 0);
final ListSelectionListener[] nextListSelectionListener = new ListSelectionListener[1];
nextListSelectionListener[0] = new javax.swing.event.ListSelectionListener() {
public void valueChanged(javax.swing.event.ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
DefaultListSelectionModel list = (DefaultListSelectionModel) e.getSource();
int selected = list.getAnchorSelectionIndex();
final int previous = (selected == e.getFirstIndex() ? e.getLastIndex() : e.getFirstIndex());
ListReset listReset = new ListReset() {
@Override
public void reset(VCDataIdentifier myVcDataIdentifier) {
if (myVcDataIdentifier instanceof VCSimulationDataIdentifier) {
int paramScanIndex = ((VCSimulationDataIdentifier) myVcDataIdentifier).getJobIndex();
table.getSelectionModel().removeListSelectionListener(nextListSelectionListener[0]);
try {
table.setRowSelectionInterval(paramScanIndex, paramScanIndex);
} finally {
table.getSelectionModel().addListSelectionListener(nextListSelectionListener[0]);
}
} else {
table.setRowSelectionInterval(previous, previous);
}
}
};
updateScanParamChoices("SimResultsViewer set paramScan index=" + getSelectedParamScanJobIndex(), listReset);
}
}
};
table.getSelectionModel().addListSelectionListener(nextListSelectionListener[0]);
JScrollPane scr = new JScrollPane(table);
JPanel p = new JPanel();
scr.setPreferredSize(new java.awt.Dimension(100, Math.min(150, table.getPreferredSize().height + table.getTableHeader().getPreferredSize().height + 5)));
p.setLayout(new java.awt.BorderLayout());
p.add(scr, java.awt.BorderLayout.CENTER);
p.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
tablePanel.add(p);
}
panel.add(tablePanel, BorderLayout.CENTER);
if (isODEData) {
JPanel buttonPanel = new JPanel(new FlowLayout());
JButton button = new JButton("Time Plot with Multiple Parameter Value Sets");
buttonPanel.add(button);
panel.add(buttonPanel, BorderLayout.SOUTH);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
mainViewer.showTimePlotMultipleScans(dataManager);
}
});
} else {
pdeDataViewer.setSimNameSimDataID(new ExportSpecs.SimNameSimDataID(getSimulation().getName(), getSimulation().getSimulationInfo().getAuthoritativeVCSimulationIdentifier(), SimResultsViewer.getParamScanInfo(getSimulation(), getSelectedParamScanJobIndex())));
}
setParamChoicesPanel(panel);
}
// put things together
setLayout(new java.awt.BorderLayout());
add(getMainViewer(), java.awt.BorderLayout.CENTER);
if (getSimulation().getScanCount() > 1) {
add(getParamChoicesPanel(), java.awt.BorderLayout.SOUTH);
}
}
Aggregations