use of org.vcell.util.document.TSJobResultsNoStats in project vcell by virtualcell.
the class PDEDataViewer method makeSurfaceMovie.
private void makeSurfaceMovie(final SurfaceCanvas surfaceCanvas, final int varTotalNumIndices, final String movieDataVarName, final DisplayAdapterService movieDAS, final VCDataIdentifier movieVCDataIdentifier) {
final SurfaceMovieSettingsPanel smsp = new SurfaceMovieSettingsPanel();
final double[] timePoints = getPdeDataContext().getTimePoints();
final int surfaceWidth = surfaceCanvas.getWidth();
final int surfaceHeight = surfaceCanvas.getHeight();
smsp.init(surfaceWidth, surfaceHeight, timePoints);
while (true) {
if (PopupGenerator.showComponentOKCancelDialog(this, smsp, "Movie Settings for var " + movieDataVarName) != JOptionPane.OK_OPTION) {
return;
}
long movieSize = (smsp.getTotalFrames() * surfaceWidth * surfaceHeight * 3);
// raw data size;
long rawDataSize = (smsp.getTotalFrames() * varTotalNumIndices * 8);
if (movieSize + rawDataSize > 50000000) {
final String YES_RESULT = "Yes";
String result = PopupGenerator.showWarningDialog(this, "Movie processing will require at least " + (movieSize + rawDataSize) / 1000000 + " mega-bytes of memory.\nMovie size will be " + (movieSize >= 1000000 ? movieSize / 1000000 + " mega-bytes." : movieSize / 1000.0 + " kilo-bytes.") + " Continue?", new String[] { YES_RESULT, "No" }, YES_RESULT);
if (result != null && result.equals(YES_RESULT)) {
break;
}
} else {
break;
}
}
final int beginTimeIndex = smsp.getBeginTimeIndex();
final int endTimeIndex = smsp.getEndTimeIndex();
final int step = smsp.getSkipParameter() + 1;
final String[] varNames = new String[] { movieDataVarName };
int[] allIndices = new int[varTotalNumIndices];
for (int i = 0; i < allIndices.length; i++) {
allIndices[i] = i;
}
final TimeSeriesJobSpec timeSeriesJobSpec = new TimeSeriesJobSpec(varNames, new int[][] { allIndices }, null, timePoints[beginTimeIndex], step, timePoints[endTimeIndex], VCDataJobID.createVCDataJobID(getDataViewerManager().getUser(), true));
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put(StringKey_timeSeriesJobSpec, timeSeriesJobSpec);
AsynchClientTask task1 = new TimeSeriesDataRetrievalTask("Retrieving data for variable '" + movieDataVarName + "'", PDEDataViewer.this, getPdeDataContext());
AsynchClientTask task2 = new AsynchClientTask("select a file", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
VCFileChooser fileChooser = new VCFileChooser();
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser.setMultiSelectionEnabled(false);
fileChooser.addChoosableFileFilter(FileFilters.FILE_FILTER_MOV);
// Set the default file filter...
fileChooser.setFileFilter(FileFilters.FILE_FILTER_MOV);
// remove all selector
fileChooser.removeChoosableFileFilter(fileChooser.getAcceptAllFileFilter());
fileChooser.setDialogTitle("Saving surface movie");
File selectedFile = null;
while (true) {
if (fileChooser.showSaveDialog(PDEDataViewer.this) != JFileChooser.APPROVE_OPTION) {
return;
}
selectedFile = fileChooser.getSelectedFile();
if (!selectedFile.getName().endsWith(".mov")) {
selectedFile = new File(selectedFile.getAbsolutePath() + ".mov");
}
if (selectedFile.exists()) {
final String YES_RESULT = "Yes";
String result = PopupGenerator.showWarningDialog(PDEDataViewer.this, "Overwrite exisitng file:\n" + selectedFile.getAbsolutePath() + "?", new String[] { YES_RESULT, "No" }, YES_RESULT);
if (result != null && result.equals(YES_RESULT)) {
break;
}
} else {
break;
}
}
hashTable.put("selectedFile", selectedFile);
}
};
AsynchClientTask task3 = new AsynchClientTask("create movie", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
File selectedFile = (File) hashTable.get("selectedFile");
if (selectedFile == null) {
return;
}
TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(StringKey_timeSeriesJobResults);
double[][] timeSeries = tsJobResultsNoStats.getTimesAndValuesForVariable(movieDataVarName);
int[] singleFrame = new int[surfaceWidth * surfaceHeight];
BufferedImage bufferedImage = new BufferedImage(surfaceWidth, surfaceHeight, BufferedImage.TYPE_3BYTE_BGR);
Graphics2D g2D = bufferedImage.createGraphics();
VideoMediaChunk[] chunks = new VideoMediaChunk[tsJobResultsNoStats.getTimes().length];
VideoMediaSample sample;
int sampleDuration = 0;
int timeScale = smsp.getFramesPerSecond();
int bitsPerPixel = 32;
DisplayAdapterService das = new DisplayAdapterService(movieDAS);
int[][] origSurfacesColors = surfaceCanvas.getSurfacesColors();
DataInfoProvider dataInfoProvider = getPDEDataContextPanel1().getDataInfoProvider();
FileDataContainerManager fileDataContainerManager = new FileDataContainerManager();
try {
try {
for (int t = 0; t < tsJobResultsNoStats.getTimes().length; t++) {
getClientTaskStatusSupport().setMessage("Creating Movie... Progress " + NumberUtils.formatNumber(100.0 * ((double) t / (double) tsJobResultsNoStats.getTimes().length), 3) + "%");
double min = Double.POSITIVE_INFINITY;
double max = Double.NEGATIVE_INFINITY;
for (int index = 1; index < timeSeries.length; index++) {
double v = timeSeries[index][t];
if ((dataInfoProvider == null || dataInfoProvider.isDefined(index - 1)) && !Double.isNaN(v) && !Double.isInfinite(v)) {
min = Math.min(min, v);
max = Math.max(max, v);
}
}
das.setValueDomain(new Range(min, max));
if (das.getAutoScale()) {
das.setActiveScaleRange(new Range(min, max));
}
int[][] surfacesColors = new int[surfaceCanvas.getSurfaceCollection().getSurfaceCount()][];
for (int i = 0; i < surfaceCanvas.getSurfaceCollection().getSurfaceCount(); i += 1) {
Surface surface = surfaceCanvas.getSurfaceCollection().getSurfaces(i);
surfacesColors[i] = new int[surface.getPolygonCount()];
for (int j = 0; j < surface.getPolygonCount(); j += 1) {
int membIndex = meshRegionSurfaces.getMembraneIndexForPolygon(i, j);
surfacesColors[i][j] = das.getColorFromValue(timeSeries[membIndex + 1][t]);
}
}
surfaceCanvas.setSurfacesColors(surfacesColors);
surfaceCanvas.paintImmediately(0, 0, surfaceWidth, surfaceHeight);
surfaceCanvas.paint(g2D);
bufferedImage.getRGB(0, 0, surfaceWidth, surfaceHeight, singleFrame, 0, surfaceWidth);
sampleDuration = 1;
sample = FormatSpecificSpecs.getVideoMediaSample(surfaceWidth, surfaceHeight * varNames.length, sampleDuration, false, FormatSpecificSpecs.CODEC_JPEG, 1.0f, singleFrame);
chunks[t] = new VideoMediaChunk(sample, fileDataContainerManager);
}
} finally {
surfaceCanvas.setSurfacesColors(origSurfacesColors);
surfaceCanvas.paintImmediately(0, 0, surfaceWidth, surfaceHeight);
}
MediaTrack videoTrack = new MediaTrack(chunks);
MediaMovie newMovie = new MediaMovie(videoTrack, videoTrack.getDuration(), timeScale);
newMovie.addUserDataEntry(new UserDataEntry("cpy", "\u00A9" + (new GregorianCalendar()).get(Calendar.YEAR) + ", UCHC"));
newMovie.addUserDataEntry(new UserDataEntry("des", "Dataset name: " + movieVCDataIdentifier.getID()));
newMovie.addUserDataEntry(new UserDataEntry("cmt", "Time range: " + timePoints[beginTimeIndex] + " - " + timePoints[endTimeIndex]));
for (int k = 0; k < varNames.length; k++) {
// pad with 0 if k < 10
String entryType = "v" + (k < 10 ? "0" : "") + k;
UserDataEntry entry = new UserDataEntry(entryType, "Variable name: " + varNames[k] + " min: " + das.getValueDomain().getMin() + " max: " + das.getValueDomain().getMax());
newMovie.addUserDataEntry(entry);
}
getClientTaskStatusSupport().setMessage("Writing Movie to disk...");
FileOutputStream fos = new FileOutputStream(selectedFile);
DataOutputStream movieOutput = new DataOutputStream(new BufferedOutputStream(fos));
MediaMethods.writeMovie(movieOutput, newMovie);
movieOutput.close();
fos.close();
} finally {
fileDataContainerManager.closeAllAndDelete();
}
}
};
ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1, task2, task3 }, true, true, null);
}
use of org.vcell.util.document.TSJobResultsNoStats in project vcell by virtualcell.
the class PdeTimePlotMultipleVariablesPanel method showTimePlot.
public void showTimePlot() {
if ((plotChangeTimer = ClientTaskDispatcher.getBlockingTimer(this, multiTimePlotHelper.getPdeDatacontext(), null, plotChangeTimer, new ActionListener() {
@Override
public void actionPerformed(ActionEvent e2) {
showTimePlot();
}
}, "PdeTimePlotMultipleVariablesPanel update...")) != null) {
return;
}
VariableType varType = multiTimePlotHelper.getVariableType();
Object[] selectedValues = variableJList.getSelectedValues();
DataIdentifier[] selectedDataIdentifiers = new DataIdentifier[selectedValues.length];
System.arraycopy(selectedValues, 0, selectedDataIdentifiers, 0, selectedValues.length);
if (selectedDataIdentifiers.length > 1) {
for (DataIdentifier selectedDataIdentifier : selectedDataIdentifiers) {
if (!selectedDataIdentifier.getVariableType().getVariableDomain().equals(varType.getVariableDomain())) {
PopupGenerator.showErrorDialog(this, "Please choose VOLUME variables or MEMBRANE variables only");
variableJList.clearSelection();
variableJList.setSelectedValue(multiTimePlotHelper.getPdeDatacontext().getVariableName(), true);
return;
}
}
}
try {
final int numSelectedVariables = selectedDataIdentifiers.length;
final int numSelectedSpatialPoints = pointVector.size();
int[][] indices = new int[numSelectedVariables][numSelectedSpatialPoints];
//
for (int i = 0; i < numSelectedSpatialPoints; i++) {
for (int v = 0; v < numSelectedVariables; v++) {
if (selectedDataIdentifiers[v].getVariableType().equals(varType)) {
if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
SpatialSelectionVolume ssv = (SpatialSelectionVolume) pointVector.get(i);
indices[v][i] = ssv.getIndex(0);
} else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) pointVector.get(i);
indices[v][i] = ssm.getIndex(0);
}
} else {
if (varType.equals(VariableType.VOLUME) || varType.equals(VariableType.VOLUME_REGION) || varType.equals(VariableType.POSTPROCESSING)) {
SpatialSelectionVolume ssv = (SpatialSelectionVolume) pointVector2.get(i);
indices[v][i] = ssv.getIndex(0);
} else if (varType.equals(VariableType.MEMBRANE) || varType.equals(VariableType.MEMBRANE_REGION)) {
SpatialSelectionMembrane ssm = (SpatialSelectionMembrane) pointVector2.get(i);
indices[v][i] = ssm.getIndex(0);
}
}
}
}
final String[] selectedVarNames = new String[numSelectedVariables];
for (int i = 0; i < selectedVarNames.length; i++) {
selectedVarNames[i] = selectedDataIdentifiers[i].getName();
}
final double[] timePoints = multiTimePlotHelper.getPdeDatacontext().getTimePoints();
TimeSeriesJobSpec tsjs = new TimeSeriesJobSpec(selectedVarNames, indices, null, timePoints[0], 1, timePoints[timePoints.length - 1], VCDataJobID.createVCDataJobID(multiTimePlotHelper.getUser(), true));
if (!tsjs.getVcDataJobID().isBackgroundTask()) {
throw new RuntimeException("Use getTimeSeries(...) if not a background job");
}
Hashtable<String, Object> hash = new Hashtable<String, Object>();
hash.put(PDEDataViewer.StringKey_timeSeriesJobSpec, tsjs);
AsynchClientTask task1 = new PDEDataViewer.TimeSeriesDataRetrievalTask("Retrieving Data", multiTimePlotHelper, multiTimePlotHelper.getPdeDatacontext());
AsynchClientTask task2 = new AsynchClientTask("showing time plot", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
@Override
public void run(Hashtable<String, Object> hashTable) throws Exception {
TSJobResultsNoStats tsJobResultsNoStats = (TSJobResultsNoStats) hashTable.get(PDEDataViewer.StringKey_timeSeriesJobResults);
int plotCount = numSelectedVariables * numSelectedSpatialPoints;
SymbolTableEntry[] symbolTableEntries = new SymbolTableEntry[plotCount];
String[] plotNames = new String[plotCount];
double[][] plotDatas = new double[1 + plotCount][];
plotDatas[0] = timePoints;
int plotIndex = 0;
for (int v = 0; v < numSelectedVariables; v++) {
String varName = selectedVarNames[v];
double[][] data = tsJobResultsNoStats.getTimesAndValuesForVariable(varName);
for (int i = 1; i < data.length; i++) {
symbolTableEntries[plotIndex] = multiTimePlotHelper.getsimulation().getMathDescription().getEntry(varName);
plotNames[plotIndex] = varName + " at P[" + (i - 1) + "]";
plotDatas[plotIndex + 1] = data[i];
plotIndex++;
}
}
Plot2D plot2D = new SingleXPlot2D(symbolTableEntries, multiTimePlotHelper.getDataSymbolMetadataResolver(), ReservedVariable.TIME.getName(), plotNames, plotDatas, new String[] { "Time Plot", ReservedVariable.TIME.getName(), "" });
plotPane.setPlot2D(plot2D);
}
};
ClientTaskDispatcher.dispatch(this, hash, new AsynchClientTask[] { task1, task2 }, false, true, true, null, false);
} catch (Exception e) {
e.printStackTrace(System.out);
}
}
use of org.vcell.util.document.TSJobResultsNoStats in project vcell by virtualcell.
the class DataSetControllerImpl method getSpecialTimeSeriesValues.
private TimeSeriesJobResults getSpecialTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdID, TimeSeriesJobSpec timeSeriesJobSpec, TimeInfo timeInfo) throws Exception {
String[] variableNames = timeSeriesJobSpec.getVariableNames();
CartesianMesh mesh = getMesh(vcdID);
// Automatically 'special' (non-optimized timedata retrieval) if isAllowOptimizedTimeDataRetrieval() == false
boolean bIsSpecial = !isAllowOptimizedTimeDataRetrieval();
if (!bIsSpecial) {
VCData simData = getVCData(vcdID);
//
// Gradient and FieldData functions are special.
// They have to be evaluated using the 'full data' method using evaluateFunction(...).
// They cannot be evaluated using the fast findFunctionIndexes(...) method.
// Also if the 'roi' is a significant fraction of the whole dataset then
// the 'full data' method of evaluation is more efficient
// a guess for best efficiency
final double SIGNIFICANT_ROI_FRACTION = .2;
final int ABSOLUTE_SIZE_LIMIT = 10000;
for (int i = 0; i < variableNames.length; i += 1) {
DataSetIdentifier dsi = (DataSetIdentifier) simData.getEntry(variableNames[i]);
if (dsi.getVariableType().equals(VariableType.VOLUME)) {
if (timeSeriesJobSpec.getIndices()[i].length > mesh.getNumVolumeElements() * SIGNIFICANT_ROI_FRACTION) {
bIsSpecial = true;
break;
}
} else if (dsi.getVariableType().equals(VariableType.MEMBRANE)) {
if (timeSeriesJobSpec.getIndices()[i].length > mesh.getNumMembraneElements() * SIGNIFICANT_ROI_FRACTION) {
bIsSpecial = true;
break;
}
}
AnnotatedFunction functionFromVarName = getFunction(outputContext, vcdID, variableNames[i]);
if (functionFromVarName != null) {
FieldFunctionArguments[] fieldFunctionArgumentsArr = FieldUtilities.getFieldFunctionArguments(functionFromVarName.getExpression());
if (hasGradient(functionFromVarName.getExpression()) || (fieldFunctionArgumentsArr != null && fieldFunctionArgumentsArr.length > 0)) {
bIsSpecial = true;
break;
}
// check function absolute size limit
Expression exp = functionFromVarName.getExpression();
String[] funcSymbols = exp.getSymbols();
int varCount = 0;
if (funcSymbols != null) {
for (int j = 0; j < funcSymbols.length; j++) {
SymbolTableEntry ste = exp.getSymbolBinding(funcSymbols[j]);
if (ste instanceof DataSetIdentifier) {
varCount += 1;
}
}
}
varCount = Math.max(varCount, 1);
if (varCount * timeSeriesJobSpec.getIndices()[i].length > ABSOLUTE_SIZE_LIMIT) {
bIsSpecial = true;
break;
}
} else if (timeSeriesJobSpec.getIndices()[i].length > ABSOLUTE_SIZE_LIMIT) {
bIsSpecial = true;
break;
}
}
}
if (!bIsSpecial) {
return null;
}
TimeSeriesJobResults tsjr = null;
if (timeSeriesJobSpec.isCalcTimeStats()) {
throw new RuntimeException("Time Stats Not yet implemented for 'special' data");
} else if (timeSeriesJobSpec.isCalcSpaceStats()) {
// Get spatial statistics at each time point
SpatialStatsInfo ssi = calcSpatialStatsInfo(outputContext, timeSeriesJobSpec, vcdID);
double[][] /*time*/
argMin = new double[variableNames.length][timeInfo.desiredTimeValues.length];
double[][] argMax = new double[variableNames.length][timeInfo.desiredTimeValues.length];
double[][] argUnweightedMean = new double[variableNames.length][timeInfo.desiredTimeValues.length];
double[][] argWeightedMean = new double[variableNames.length][timeInfo.desiredTimeValues.length];
double[][] argUnweightedSum = new double[variableNames.length][timeInfo.desiredTimeValues.length];
double[][] argWeightedSum = new double[variableNames.length][timeInfo.desiredTimeValues.length];
double[] /*varName*/
argTotalSpace = new double[variableNames.length];
double[][][] indicesForVarForOneTimepoint = new double[1][][];
for (int varNameIndex = 0; varNameIndex < variableNames.length; varNameIndex += 1) {
int[] dataIndices = timeSeriesJobSpec.getIndices()[varNameIndex];
indicesForVarForOneTimepoint[0] = new double[dataIndices.length + 1][1];
for (int timeIndex = 0; timeIndex < timeInfo.desiredTimeValues.length; timeIndex += 1) {
indicesForVarForOneTimepoint[0][0] = new double[] { timeInfo.desiredTimeValues[timeIndex] };
int num = varNameIndex * timeInfo.desiredTimeValues.length + timeIndex;
int denom = variableNames.length * timeInfo.desiredTimeValues.length;
double progressTime = 100.0 * (double) num / (double) denom;
fireDataJobEventIfNecessary(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_PROGRESS, vcdID, new Double(progressTime), null, null);
SimDataBlock simDatablock = getSimDataBlock(outputContext, vcdID, variableNames[varNameIndex], timeInfo.desiredTimeValues[timeIndex]);
double[] data = simDatablock.getData();
// Put indices in format expected by calcStats (SHOULD BE CHANGED)
for (int dataIndex = 0; dataIndex < dataIndices.length; dataIndex += 1) {
indicesForVarForOneTimepoint[0][dataIndex + 1][0] = data[dataIndices[dataIndex]];
}
if (timeSeriesJobSpec.getCrossingMembraneIndices() != null && timeSeriesJobSpec.getCrossingMembraneIndices().length > 0) {
adjustMembraneAdjacentVolumeValues(outputContext, indicesForVarForOneTimepoint[0], true, simDatablock, timeSeriesJobSpec.getIndices()[varNameIndex], timeSeriesJobSpec.getCrossingMembraneIndices()[varNameIndex], vcdID, variableNames[varNameIndex], mesh, timeInfo);
}
tsjr = calculateStatisticsFromWhole(timeSeriesJobSpec, indicesForVarForOneTimepoint, indicesForVarForOneTimepoint[0][0], ssi);
argMin[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getMinimums()[0][0];
argMax[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getMaximums()[0][0];
argUnweightedMean[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getUnweightedMean()[0][0];
if (((TSJobResultsSpaceStats) tsjr).getWeightedMean() == null) {
argWeightedMean = null;
} else {
argWeightedMean[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getWeightedMean()[0][0];
}
argUnweightedSum[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getUnweightedSum()[0][0];
if (((TSJobResultsSpaceStats) tsjr).getWeightedSum() == null) {
argWeightedSum = null;
} else {
argWeightedSum[varNameIndex][timeIndex] = ((TSJobResultsSpaceStats) tsjr).getWeightedSum()[0][0];
}
if (((TSJobResultsSpaceStats) tsjr).getTotalSpace() == null) {
argTotalSpace = null;
} else {
argTotalSpace[varNameIndex] = ((TSJobResultsSpaceStats) tsjr).getTotalSpace()[0];
}
}
}
tsjr = new TSJobResultsSpaceStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), timeInfo.desiredTimeValues, argMin, argMax, argUnweightedMean, argWeightedMean, argUnweightedSum, argWeightedSum, argTotalSpace);
} else {
// Get the values for for all the variables and indices
double[][][] varIndicesTimesArr = new double[variableNames.length][][];
for (int varNameIndex = 0; varNameIndex < variableNames.length; varNameIndex += 1) {
int[] dataIndices = timeSeriesJobSpec.getIndices()[varNameIndex];
varIndicesTimesArr[varNameIndex] = new double[dataIndices.length + 1][timeInfo.desiredTimeValues.length];
varIndicesTimesArr[varNameIndex][0] = timeInfo.desiredTimeValues;
for (int timeIndex = 0; timeIndex < timeInfo.desiredTimeValues.length; timeIndex += 1) {
int num = varNameIndex * timeInfo.desiredTimeValues.length + timeIndex;
int denom = variableNames.length * timeInfo.desiredTimeValues.length;
double progressTime = 100.0 * (double) num / (double) denom;
fireDataJobEventIfNecessary(timeSeriesJobSpec.getVcDataJobID(), MessageEvent.DATA_PROGRESS, vcdID, new Double(progressTime), null, null);
SimDataBlock simDatablock = getSimDataBlock(outputContext, vcdID, variableNames[varNameIndex], timeInfo.desiredTimeValues[timeIndex]);
double[] data = simDatablock.getData();
for (int dataIndex = 0; dataIndex < dataIndices.length; dataIndex += 1) {
varIndicesTimesArr[varNameIndex][dataIndex + 1][timeIndex] = data[dataIndices[dataIndex]];
}
if (timeSeriesJobSpec.getCrossingMembraneIndices() != null && timeSeriesJobSpec.getCrossingMembraneIndices().length > 0) {
adjustMembraneAdjacentVolumeValues(outputContext, varIndicesTimesArr[varNameIndex], true, simDatablock, timeSeriesJobSpec.getIndices()[varNameIndex], timeSeriesJobSpec.getCrossingMembraneIndices()[varNameIndex], vcdID, variableNames[varNameIndex], mesh, timeInfo);
}
}
}
tsjr = new TSJobResultsNoStats(timeSeriesJobSpec.getVariableNames(), timeSeriesJobSpec.getIndices(), timeInfo.desiredTimeValues, varIndicesTimesArr);
}
return tsjr;
}
use of org.vcell.util.document.TSJobResultsNoStats in project vcell by virtualcell.
the class DataSetControllerImpl method getDataProcessingOutput.
public static DataOperationResults getDataProcessingOutput(DataOperation dataOperation, File dataProcessingOutputFileHDF5) throws Exception {
DataOperationResults dataProcessingOutputResults = null;
FileFormat hdf5FileFormat = null;
try {
if (dataProcessingOutputFileHDF5.exists()) {
// retrieve an instance of H5File
FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
if (fileFormat == null) {
throw new Exception("Cannot find HDF5 FileFormat.");
}
// open the file with read-only access
hdf5FileFormat = fileFormat.open(dataProcessingOutputFileHDF5.getAbsolutePath(), FileFormat.READ);
hdf5FileFormat.setMaxMembers(Simulation.MAX_LIMIT_SPATIAL_TIMEPOINTS);
// open the file and retrieve the file structure
hdf5FileFormat.open();
Group root = (Group) ((javax.swing.tree.DefaultMutableTreeNode) hdf5FileFormat.getRootNode()).getUserObject();
if (dataOperation instanceof DataProcessingOutputInfoOP) {
DataProcessingHelper dataProcessingHelper = new DataProcessingHelper();
iterateHDF5(root, "", dataProcessingHelper);
dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputInfo(dataOperation.getVCDataIdentifier(), dataProcessingHelper.getVarNames(), dataProcessingHelper.getVarISizes(), dataProcessingHelper.times, dataProcessingHelper.getVarUnits(), dataProcessingHelper.getPostProcessDataTypes(), dataProcessingHelper.getVarOrigins(), dataProcessingHelper.getVarExtents(), dataProcessingHelper.getVarStatValues());
// map function names to PostProcess state variable name
ArrayList<String> postProcessImageVarNames = new ArrayList<String>();
for (int i = 0; i < ((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getVariableNames().length; i++) {
String variableName = ((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getVariableNames()[i];
if (((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults).getPostProcessDataType(variableName).equals(DataOperationResults.DataProcessingOutputInfo.PostProcessDataType.image)) {
postProcessImageVarNames.add(variableName);
}
}
HashMap<String, String> mapFunctionNameToStateVarName = null;
if (((DataProcessingOutputInfoOP) dataOperation).getOutputContext() != null) {
mapFunctionNameToStateVarName = new HashMap<String, String>();
for (int i = 0; i < ((DataProcessingOutputInfoOP) dataOperation).getOutputContext().getOutputFunctions().length; i++) {
AnnotatedFunction annotatedFunction = ((DataProcessingOutputInfoOP) dataOperation).getOutputContext().getOutputFunctions()[i];
if (annotatedFunction.getFunctionType().equals(VariableType.POSTPROCESSING)) {
String[] symbols = annotatedFunction.getExpression().flatten().getSymbols();
// Find any PostProcess state var that matches a symbol in the function
for (int j = 0; j < symbols.length; j++) {
if (postProcessImageVarNames.contains(symbols[j])) {
mapFunctionNameToStateVarName.put(annotatedFunction.getName(), symbols[j]);
break;
}
}
}
}
}
if (mapFunctionNameToStateVarName != null && mapFunctionNameToStateVarName.size() > 0) {
dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputInfo(((DataOperationResults.DataProcessingOutputInfo) dataProcessingOutputResults), mapFunctionNameToStateVarName);
}
} else {
OutputContext outputContext = dataOperation.getOutputContext();
String[] variableNames = null;
DataIndexHelper dataIndexHelper = null;
TimePointHelper timePointHelper = null;
if (dataOperation instanceof DataOperation.DataProcessingOutputDataValuesOP) {
variableNames = new String[] { ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getVariableName() };
dataIndexHelper = ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getDataIndexHelper();
timePointHelper = ((DataOperation.DataProcessingOutputDataValuesOP) dataOperation).getTimePointHelper();
} else if (dataOperation instanceof DataOperation.DataProcessingOutputTimeSeriesOP) {
variableNames = ((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getTimeSeriesJobSpec().getVariableNames();
TimeSeriesJobSpec timeSeriesJobSpec = ((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getTimeSeriesJobSpec();
double[] specificTimepoints = extractTimeRange(((DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation).getAllDatasetTimes(), timeSeriesJobSpec.getStartTime(), timeSeriesJobSpec.getEndTime());
timePointHelper = TimePointHelper.createSpecificTimePointHelper(specificTimepoints);
timeSeriesJobSpec.initIndices();
dataIndexHelper = DataIndexHelper.createSpecificDataIndexHelper(timeSeriesJobSpec.getIndices()[0]);
} else {
throw new Exception("Unknown Dataoperation " + dataOperation.getClass().getName());
}
if (variableNames.length != 1) {
throw new Exception("Only 1 variable request at a time");
}
AnnotatedFunction[] annotatedFunctions = (outputContext == null ? null : outputContext.getOutputFunctions());
AnnotatedFunction foundFunction = null;
if (annotatedFunctions != null) {
for (int i = 0; i < annotatedFunctions.length; i++) {
if (annotatedFunctions[i].getName().equals(variableNames[0])) {
foundFunction = annotatedFunctions[i];
break;
}
}
}
double[] alltimes = null;
if (foundFunction != null) {
DataOperationResults.DataProcessingOutputInfo dataProcessingOutputInfo = (DataOperationResults.DataProcessingOutputInfo) getDataProcessingOutput(new DataOperation.DataProcessingOutputInfoOP(dataOperation.getVCDataIdentifier(), false, dataOperation.getOutputContext()), dataProcessingOutputFileHDF5);
alltimes = dataProcessingOutputInfo.getVariableTimePoints();
FunctionHelper functionHelper = getPostProcessStateVariables(foundFunction, dataProcessingOutputInfo);
DataProcessingHelper dataProcessingHelper = new DataProcessingHelper(functionHelper.postProcessStateVars, timePointHelper, dataIndexHelper);
iterateHDF5(root, "", dataProcessingHelper);
dataProcessingOutputResults = evaluatePostProcessFunction(dataProcessingOutputInfo, functionHelper.postProcessStateVars, dataProcessingHelper.specificDataValues, dataIndexHelper, timePointHelper, functionHelper.flattenedBoundExpression, variableNames[0]);
} else {
DataProcessingHelper dataProcessingHelper = new DataProcessingHelper(new String[] { variableNames[0] }, timePointHelper, dataIndexHelper);
iterateHDF5(root, "", dataProcessingHelper);
alltimes = dataProcessingHelper.times;
if (dataProcessingHelper.specificDataValues == null) {
throw new Exception("Couldn't find postprocess data as specified for var=" + variableNames[0]);
}
dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputDataValues(dataOperation.getVCDataIdentifier(), variableNames[0], timePointHelper, dataIndexHelper, dataProcessingHelper.specificDataValues[0]);
}
if (dataOperation instanceof DataOperation.DataProcessingOutputTimeSeriesOP) {
TimeSeriesJobResults timeSeriesJobResults = null;
DataProcessingOutputTimeSeriesOP dataProcessingOutputTimeSeriesOP = (DataOperation.DataProcessingOutputTimeSeriesOP) dataOperation;
// [time][data]
double[][] dataValues = ((DataOperationResults.DataProcessingOutputDataValues) dataProcessingOutputResults).getDataValues();
double[] desiredTimes = (timePointHelper.isAllTimePoints() ? alltimes : timePointHelper.getTimePoints());
double[][][] timeSeriesFormatedValuesArr = new double[variableNames.length][dataIndexHelper.getDataIndexes().length + 1][desiredTimes.length];
for (int i = 0; i < timeSeriesFormatedValuesArr.length; i++) {
// var
for (int j = 0; j < timeSeriesFormatedValuesArr[i].length; j++) {
// index
if (j == 0) {
timeSeriesFormatedValuesArr[i][j] = desiredTimes;
continue;
}
for (int k = 0; k < timeSeriesFormatedValuesArr[i][j].length; k++) {
// time
// assume 1 variable for now
timeSeriesFormatedValuesArr[i][j][k] = dataValues[k][j - 1];
}
}
}
if (dataProcessingOutputTimeSeriesOP.getTimeSeriesJobSpec().isCalcSpaceStats()) {
SpatialStatsInfo spatialStatsInfo = new SpatialStatsInfo();
spatialStatsInfo.bWeightsValid = false;
timeSeriesJobResults = calculateStatisticsFromWhole(dataProcessingOutputTimeSeriesOP.getTimeSeriesJobSpec(), timeSeriesFormatedValuesArr, timePointHelper.getTimePoints(), spatialStatsInfo);
} else {
timeSeriesJobResults = new TSJobResultsNoStats(variableNames, new int[][] { dataIndexHelper.getDataIndexes() }, timePointHelper.getTimePoints(), timeSeriesFormatedValuesArr);
}
dataProcessingOutputResults = new DataOperationResults.DataProcessingOutputTimeSeriesValues(dataOperation.getVCDataIdentifier(), timeSeriesJobResults);
}
}
} else {
throw new FileNotFoundException("Data Processing Output file '" + dataProcessingOutputFileHDF5.getPath() + "' not found");
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (hdf5FileFormat != null) {
try {
hdf5FileFormat.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
return dataProcessingOutputResults;
}
use of org.vcell.util.document.TSJobResultsNoStats 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;
}
Aggregations