use of org.vcell.util.document.ExternalDataIdentifier in project vcell by virtualcell.
the class MicroscopyXmlReader method getExternalDataIdentifier.
/**
* Method getExternalDataIdentifier.
* @param externalDataIDElement Element
* @return ExternalDataIdentifier
*/
private static ExternalDataIdentifier getExternalDataIdentifier(Element externalDataIDElement) {
String name = externalDataIDElement.getAttributeValue(XMLTags.NameAttrTag);
String keyValueStr = externalDataIDElement.getAttributeValue(XMLTags.KeyValueAttrTag);
String ownerName = externalDataIDElement.getAttributeValue(MicroscopyXMLTags.OwnerNameAttrTag);
String ownerKey = externalDataIDElement.getAttributeValue(XMLTags.OwnerKeyAttrTag);
return new ExternalDataIdentifier(new KeyValue(keyValueStr), new User(ownerName, new KeyValue(ownerKey)), name);
}
use of org.vcell.util.document.ExternalDataIdentifier 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.ExternalDataIdentifier in project vcell by virtualcell.
the class VFrapXmlHelper method SaveVFrapSpecialImagesAsFieldData.
//
// save the special images in the database as field data
//
public static ExternalDataIdentifier SaveVFrapSpecialImagesAsFieldData(Hashtable<String, Object> hashTable, DocumentManager documentManager) throws DataAccessException {
CartesianMesh mesh = (CartesianMesh) hashTable.get("mesh");
double[][][] pixData = (double[][][]) hashTable.get("pixData");
String[] channelNames = (String[]) hashTable.get("channelNames");
VariableType[] channelTypes = (VariableType[]) hashTable.get("channelTypes");
// DataSymbolType[] channelVFrapImageType = (DataSymbolType[])hashTable.get("channelVFrapImageType");
String mixedFieldDataName = (String) hashTable.get("mixedFieldDataName");
FieldDataFileOperationSpec vfrapMiscFieldDataOpSpec = new FieldDataFileOperationSpec();
vfrapMiscFieldDataOpSpec.opType = FieldDataFileOperationSpec.FDOS_ADD;
vfrapMiscFieldDataOpSpec.cartesianMesh = mesh;
vfrapMiscFieldDataOpSpec.doubleSpecData = pixData;
vfrapMiscFieldDataOpSpec.specEDI = null;
// item name as it comes from vFrap
vfrapMiscFieldDataOpSpec.varNames = channelNames;
vfrapMiscFieldDataOpSpec.owner = documentManager.getUser();
vfrapMiscFieldDataOpSpec.times = new double[] { 0.0 };
vfrapMiscFieldDataOpSpec.variableTypes = channelTypes;
vfrapMiscFieldDataOpSpec.origin = new Origin(0, 0, 0);
vfrapMiscFieldDataOpSpec.extent = mesh.getExtent();
vfrapMiscFieldDataOpSpec.isize = new ISize(mesh.getSizeX(), mesh.getSizeY(), mesh.getSizeZ());
ExternalDataIdentifier vfrapMisc = documentManager.saveFieldData(vfrapMiscFieldDataOpSpec, mixedFieldDataName);
return vfrapMisc;
}
use of org.vcell.util.document.ExternalDataIdentifier in project vcell by virtualcell.
the class PointSpreadFunctionManagement method importPointSpreadFunction.
public void importPointSpreadFunction() {
AsynchClientTask[] taskArray = new AsynchClientTask[3];
// select the desired PSF file
taskArray[0] = new AsynchClientTask("Select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
ChoosePSFFile(hashTable);
}
};
// create and save the field data object
taskArray[1] = new AsynchClientTask("Import objects", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
Component requesterComponent = parentWindow;
DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(requesterComponent, DocumentWindow.class);
DocumentManager documentManager = documentWindow.getTopLevelWindowManager().getRequestManager().getDocumentManager();
if (documentManager == null) {
throw new RuntimeException("Not connected to server.");
}
// the following line of code may modify initialFieldDataName
// normal file name
checkNameAvailability(hashTable, false, documentManager, requesterComponent);
File filePSF = (File) hashTable.get("filePSF");
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
ImageDataset imageDataset = ImageDatasetReaderService.getInstance().getImageDatasetReader().readImageDataset(filePSF.getAbsolutePath(), null);
Extent extent = imageDataset.getExtent();
ISize isize = imageDataset.getISize();
Origin origin = new Origin(0, 0, 0);
CartesianMesh cartesianMesh = 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));
// save field data
int NumTimePoints = imageDataset.getImageTimeStamps().length;
int NumChannels = 1;
double[][][] pixData = new double[NumTimePoints][NumChannels][];
for (int i = 0; i < NumTimePoints; i++) {
// images according to zIndex at specific time points(tIndex)
short[] originalData = imageDataset.getPixelsZ(0, i);
double[] doubleData = new double[originalData.length];
for (int j = 0; j < originalData.length; j++) {
doubleData[j] = 0x0000ffff & originalData[j];
}
pixData[i][NumChannels - 1] = doubleData;
}
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
// try {
// fdos = ClientRequestManager.createFDOSFromImageFile(filePSF, false, null);
// } catch (DataFormatException ex) {
// throw new Exception("Cannot read image " + filePSF.getAbsolutePath()+"\n"+ex.getMessage());
// }
fdos.owner = documentManager.getUser();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = cartesianMesh;
fdos.doubleSpecData = pixData;
fdos.specEDI = null;
fdos.varNames = new String[] { SimulationContext.FLUOR_DATA_NAME };
fdos.times = imageDataset.getImageTimeStamps();
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
ExternalDataIdentifier pSFImageEDI = documentManager.saveFieldData(fdos, initialFieldDataName);
hashTable.put("pSFImageEDI", pSFImageEDI);
}
};
// create a data symbol for the PSF image saved above as field data
taskArray[2] = new AsynchClientTask("Display Data Symbols", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// --- create the data symbols associated with the time series
String initialFieldDataName = (String) hashTable.get("initialFieldDataName");
ExternalDataIdentifier pSFImageEDI = (ExternalDataIdentifier) hashTable.get("pSFImageEDI");
String fluorName = "psf_" + initialFieldDataName;
DataSymbol fluorDataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.POINT_SPREAD_FUNCTION, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), pSFImageEDI, SimulationContext.FLUOR_DATA_NAME, VariableType.VOLUME.getTypeName(), 0D);
simulationContext.getDataContext().addDataSymbol(fluorDataSymbol);
}
};
Hashtable<String, Object> hash = new Hashtable<String, Object>();
ClientTaskDispatcher.dispatch(parentWindow, hash, taskArray, false, true, null);
}
use of org.vcell.util.document.ExternalDataIdentifier in project vcell by virtualcell.
the class DataSymbolsPanel method addAssociate.
private void addAssociate() {
DocumentWindow documentWindow = (DocumentWindow) BeanUtils.findTypeParentOfComponent(this, DocumentWindow.class);
documentWindow.getTopLevelWindowManager().getRequestManager().showFieldDataWindow(new FieldDataWindowManager.DataSymbolCallBack() {
public void createDataSymbol(ExternalDataIdentifier dataSetID, String fieldDataVarName, VariableType fieldDataVarType, double fieldDataVarTime) {
System.out.println(dataSetID + " " + fieldDataVarName + " " + fieldDataVarType + " " + fieldDataVarTime);
// ex: incomplete 51780592 danv(26766043) fluor Volume_VariableType 23.680419921875
// max time interval we can display is about 11 days
DecimalFormat df = new DecimalFormat("###000.00");
String fluorName = fieldDataVarName + "_" + df.format(fieldDataVarTime).substring(0, df.format(fieldDataVarTime).indexOf(".")) + "s" + df.format(fieldDataVarTime).substring(1 + df.format(fieldDataVarTime).indexOf(".")) + "_" + dataSetID.getName();
// TODO: symbol names may not be unique, must check for unicity and prompt the user
FieldDataSymbol dataSymbol = new FieldDataSymbol(fluorName, DataSymbolType.GENERIC_SYMBOL, simulationContext.getDataContext(), simulationContext.getModel().getUnitSystem().getInstance_TBD(), dataSetID, fieldDataVarName, fieldDataVarType.getTypeName(), fieldDataVarTime);
simulationContext.getDataContext().addDataSymbol(dataSymbol);
}
});
}
Aggregations