use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.
the class SimulationServiceImpl method getVariableList.
public List<VariableInfo> getVariableList(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);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
final DataIdentifier[] dataIdentifiers;
try {
dataIdentifiers = datasetController.getDataIdentifiers(outputContext, simServiceContext.vcDataIdentifier);
} catch (IOException | DataAccessException e) {
e.printStackTrace();
throw new RuntimeException("failed to retrieve variable information: " + e.getMessage(), e);
}
ArrayList<VariableInfo> varInfos = new ArrayList<VariableInfo>();
for (DataIdentifier dataIdentifier : dataIdentifiers) {
final DomainType domainType;
if (dataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
domainType = DomainType.VOLUME;
} else if (dataIdentifier.getVariableType().equals(VariableType.MEMBRANE)) {
domainType = DomainType.MEMBRANE;
} else {
continue;
}
String domainName = "";
if (dataIdentifier.getDomain() != null) {
domainName = dataIdentifier.getDomain().getName();
}
VariableInfo varInfo = new VariableInfo(dataIdentifier.getName(), dataIdentifier.getDisplayName(), domainName, domainType);
varInfos.add(varInfo);
}
return varInfos;
} catch (Exception e) {
e.printStackTrace();
throw new ThriftDataAccessException("failed to retrieve variable list: " + e.getMessage());
}
}
use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.
the class ChomboVtkFileWriter method getVtuVarInfos.
public VtuVarInfo[] getVtuVarInfos(ChomboFiles chomboFiles, OutputContext outputContext, VCData vcData) throws DataAccessException, IOException {
//
// read the time=0 chombo dataset into memory to get the var names (probably a more efficient way of doing this).
//
ChomboDataset chomboDataset;
try {
int timeIndex = 0;
chomboDataset = ChomboFileReader.readDataset(chomboFiles, chomboFiles.getTimeIndices().get(timeIndex));
} catch (Exception e) {
throw new DataAccessException("failed to read chombo dataset: " + e.getMessage(), e);
}
DataIdentifier[] dataIdentifiers = vcData.getVarAndFunctionDataIdentifiers(outputContext);
for (DataIdentifier di : dataIdentifiers) {
System.out.println(((di.getDomain() != null) ? di.getDomain().getName() : "none") + "::" + di.getName() + "-" + di.getVariableType());
}
//
// for each ChomboDomain get list of built-in (mesh) variables, component (regular) volume variables, and Membrane Variables (still tied to the volume).
//
ArrayList<VtuVarInfo> varInfos = new ArrayList<VtuVarInfo>();
for (ChomboCombinedVolumeMembraneDomain chomboCombinedVolumeMembraneDomain : chomboDataset.getCombinedVolumeMembraneDomains()) {
ChomboMeshData chomboMeshData = chomboCombinedVolumeMembraneDomain.getChomboMeshData();
//
// process Volume variables for this combined domain (chombo stores membrane data with volume)
//
{
String volumeDomainName = chomboCombinedVolumeMembraneDomain.getVolumeDomainName();
VariableDomain volVariableDomain = VariableDomain.VARIABLEDOMAIN_VOLUME;
for (String builtinVarName : chomboMeshData.getVolumeBuiltinNames()) {
String varName = builtinVarName;
String displayName = "(" + volumeDomainName + ") " + varName;
String expressionString = null;
boolean bMeshVariable = true;
varInfos.add(new VtuVarInfo(varName, displayName, volumeDomainName, volVariableDomain, expressionString, DataType.CellData, bMeshVariable));
}
for (String componentVarName : chomboMeshData.getVisibleVolumeDataNames()) {
String varName = componentVarName;
String displayName = "(" + volumeDomainName + ") " + varName;
String expressionString = null;
boolean bMeshVariable = false;
varInfos.add(new VtuVarInfo(varName, displayName, volumeDomainName, volVariableDomain, expressionString, DataType.CellData, bMeshVariable));
}
for (DataIdentifier dataID : dataIdentifiers) {
if (dataID.isVisible() && dataID.getVariableType().getVariableDomain() == VariableDomain.VARIABLEDOMAIN_VOLUME && (dataID.getDomain() == null || dataID.getDomain().getName().equals(volumeDomainName))) {
String displayName = "(" + volumeDomainName + ") " + dataID.getDisplayName();
String expressionString = null;
AnnotatedFunction f = vcData.getFunction(outputContext, dataID.getName());
if (f != null) {
expressionString = f.getExpression().infix();
}
boolean bMeshVar = false;
varInfos.add(new VtuVarInfo(dataID.getName(), displayName, volumeDomainName, volVariableDomain, expressionString, DataType.CellData, bMeshVar));
}
}
}
//
// process membrane variables for this combined domain (chombo stores membrane data with volume)
//
{
String memDomainName = chomboCombinedVolumeMembraneDomain.getMembraneDomainName();
VariableDomain memVariableDomain = VariableDomain.VARIABLEDOMAIN_MEMBRANE;
for (ChomboMembraneVarData membraneVarData : chomboMeshData.getMembraneVarData()) {
String varName = membraneVarData.getName();
String displayName = "(" + membraneVarData.getDomainName() + ") " + varName;
String expressionString = null;
boolean bMeshVariable = false;
varInfos.add(new VtuVarInfo(varName, displayName, memDomainName, memVariableDomain, expressionString, DataType.CellData, bMeshVariable));
}
for (String builtinVarName : chomboMeshData.getMembraneBuiltinNames()) {
String varName = builtinVarName;
String displayName = "(" + memDomainName + ") " + varName;
String expressionString = null;
boolean bMeshVariable = true;
varInfos.add(new VtuVarInfo(varName, displayName, memDomainName, memVariableDomain, expressionString, DataType.CellData, bMeshVariable));
}
for (DataIdentifier dataID : dataIdentifiers) {
if (dataID.isVisible() && dataID.getVariableType().getVariableDomain() == VariableDomain.VARIABLEDOMAIN_MEMBRANE && (dataID.getDomain() == null || dataID.getDomain().getName().equals(memDomainName))) {
String displayName = "(" + memDomainName + ") " + dataID.getDisplayName();
String expressionString = null;
AnnotatedFunction f = vcData.getFunction(outputContext, dataID.getName());
if (f != null) {
expressionString = f.getExpression().infix();
}
boolean bMeshVar = false;
varInfos.add(new VtuVarInfo(dataID.getName(), displayName, memDomainName, memVariableDomain, expressionString, DataType.CellData, bMeshVar));
}
}
}
}
return varInfos.toArray(new VtuVarInfo[0]);
}
use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.
the class CartesianMeshVtkFileWriter method getVtuVarInfos.
public VtuVarInfo[] getVtuVarInfos(VCellSimFiles vcellFiles, OutputContext outputContext, VCData vcData) throws IOException, DataAccessException, MathException {
CartesianMeshFileReader reader = new CartesianMeshFileReader();
CartesianMesh mesh = reader.readFromFiles(vcellFiles);
List<String> volumeDomainNames = mesh.getVolumeDomainNames();
List<String> membraneDomainNames = mesh.getMembraneDomainNames();
ArrayList<String> allDomains = new ArrayList<String>();
allDomains.addAll(volumeDomainNames);
allDomains.addAll(membraneDomainNames);
DataIdentifier[] dataIdentifiers = vcData.getVarAndFunctionDataIdentifiers(outputContext);
AnnotatedFunction[] annotationFunctions = vcData.getFunctions(outputContext);
ArrayList<VtuVarInfo> varInfos = new ArrayList<VtuVarInfo>();
for (String domainName : allDomains) {
VariableDomain varDomain = VariableDomain.VARIABLEDOMAIN_UNKNOWN;
if (volumeDomainNames.contains(domainName)) {
varDomain = VariableDomain.VARIABLEDOMAIN_VOLUME;
} else if (membraneDomainNames.contains(domainName)) {
varDomain = VariableDomain.VARIABLEDOMAIN_MEMBRANE;
}
for (DataIdentifier dataID : dataIdentifiers) {
if (dataID.getDomain() == null || dataID.getDomain().getName().equals(domainName)) {
boolean bMeshVar = isMeshVar(dataID);
String expressionString = null;
if (dataID.isFunction()) {
for (AnnotatedFunction f : annotationFunctions) {
if (f.getName().equals(dataID.getName())) {
expressionString = f.getExpression().infix();
}
}
}
varInfos.add(new VtuVarInfo(dataID.getName(), "(" + domainName + ") " + dataID.getDisplayName(), domainName, varDomain, expressionString, DataType.CellData, bMeshVar));
}
}
varInfos.add(new VtuVarInfo(GLOBAL_INDEX_VAR, "(" + domainName + ") " + GLOBAL_INDEX_VAR, domainName, varDomain, null, DataType.CellData, true));
varInfos.add(new VtuVarInfo(REGION_ID_VAR, "(" + domainName + ") " + REGION_ID_VAR, domainName, varDomain, null, DataType.CellData, true));
}
return varInfos.toArray(new VtuVarInfo[0]);
}
use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.
the class DisplayTimeSeries method displayImageTimeSeries.
public static void displayImageTimeSeries(final ImageTimeSeries<Image> imageTimeSeries, String title, WindowListener windowListener) 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 {
throw new RuntimeException("not yet implemented");
}
@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;
}
};
VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
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);
ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
PDEDataViewer pdeDataViewer = new PDEDataViewer();
JFrame jframe = new JFrame();
jframe.setTitle(title);
jframe.getContentPane().add(pdeDataViewer);
jframe.setSize(1000, 600);
jframe.setVisible(true);
if (windowListener != null) {
jframe.addWindowListener(windowListener);
}
pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
use of cbit.vcell.simdata.DataIdentifier in project vcell by virtualcell.
the class ImportRawTimeSeriesFrom2DVCellConcentrationsOp method importRawTimeSeries.
private static ImageDataset importRawTimeSeries(File vcellSimLogFile, String fluorFunctionName, Double maxIntensity, boolean bNoise, final ClientTaskStatusSupport progressListener) throws Exception {
VCSimulationIdentifier vcSimulationIdentifier = VCellSimReader.getVCSimulationIdentifierFromVCellSimulationData(vcellSimLogFile);
VCSimulationDataIdentifier vcSimulationDataIdentifier = new VCSimulationDataIdentifier(vcSimulationIdentifier, 0);
DataSetControllerImpl dataSetControllerImpl = VCellSimReader.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 = VCellSimReader.getDataIdentiferListFromVCellSimulationData(vcellSimLogFile, 0);
DataIdentifier variableNameDataIdentifier = null;
for (int i = 0; i < dataIdentifiers.length; i++) {
if (dataIdentifiers[i].getName().equals(fluorFunctionName)) {
variableNameDataIdentifier = dataIdentifiers[i];
break;
}
}
if (variableNameDataIdentifier == null) {
throw new IllegalArgumentException("Variable " + fluorFunctionName + " not found.");
}
if (!variableNameDataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
throw new IllegalArgumentException("Variable " + fluorFunctionName + " 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[] { fluorFunctionName }, new BitSet[] { allBitset }, times[0], 1, times[times.length - 1], true, false, VCDataJobID.createVCDataJobID(VCellSimReader.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 " + fluorFunctionName + "...");
}
for (int i = 0; i < times.length; i++) {
double[] rawData = dataSetControllerImpl.getSimDataBlock(null, vcSimulationDataIdentifier, fluorFunctionName, 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 rawImageDataSet = new ImageDataset(scaledDataImages, times, cartesianMesh.getSizeZ());
return rawImageDataSet;
}
Aggregations