use of cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP in project vcell by virtualcell.
the class SimulationData method getSimDataBlock.
/**
* This method was created in VisualAge.
* @return cbit.vcell.simdata.DataBlock
* @param user cbit.vcell.server.User
* @param simID java.lang.String
*/
public synchronized SimDataBlock getSimDataBlock(OutputContext outputContext, String varName, double time) throws DataAccessException, IOException {
refreshLogFile();
try {
getFunctionDataIdentifiers(outputContext);
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
try {
if (isPostProcessing(outputContext, varName)) {
PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(), vcDataId.getID(), varName, time, lastDataProcessingOutputInfoTime);
DataProcessingOutputDataValuesOP dataProcessingOutputDataValuesOP = new DataProcessingOutputDataValuesOP(vcDataId, varName, TimePointHelper.createSingleTimeTimePointHelper(extractClosestPostProcessTime(time)), DataIndexHelper.createAllDataIndexesDataIndexHelper(), outputContext, null);
DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataProcessingOutputDataValuesOP, getDataProcessingOutputSourceFileHDF5());
return new SimDataBlock(pdeDataInfo, dataProcessingOutputDataValues.getDataValues()[0], /*1 time only*/
VariableType.POSTPROCESSING);
}
} catch (Exception e) {
// ignore
e.printStackTrace();
}
File pdeFile = getPDEDataFile(time);
if (pdeFile == null) {
return null;
}
DataSet dataSet = getPDEDataSet(pdeFile, time);
File zipFile = null;
try {
zipFile = getPDEDataZipFile(time);
} catch (DataAccessException ex) {
zipFile = null;
}
long lastModified = getLastModified(pdeFile, zipFile);
DataSetIdentifier dsi = getDataSetIdentifier(varName);
if (dsi == null) {
throw new DataAccessException("data not found for variable " + varName);
}
final String varNameInDataSet = dsi.getQualifiedName();
double[] data = dataSet.getData(varNameInDataSet, zipFile, time, amplistorHelper.solverDataType);
int varTypeInt = dataSet.getVariableTypeInteger(varNameInDataSet);
VariableType variableType = null;
try {
variableType = VariableType.getVariableTypeFromInteger(varTypeInt);
} catch (IllegalArgumentException e) {
e.printStackTrace(System.out);
System.out.println("invalid varTypeInt = " + varTypeInt + " for variable " + varName + " at time " + time);
try {
variableType = SimulationData.getVariableTypeFromLength(getMesh(), data.length);
} catch (MathException ex) {
ex.printStackTrace(System.out);
throw new DataAccessException(ex.getMessage());
}
}
PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(), vcDataId.getID(), varName, time, lastModified);
if (data != null) {
return new SimDataBlock(pdeDataInfo, data, variableType);
} else {
return null;
}
}
use of cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP in project vcell by virtualcell.
the class SimulationData method getSimDataTimeSeries0.
/**
* This method was created in VisualAge.
* @return cbit.vcell.simdata.DataBlock
* @param user cbit.vcell.server.User
* @param simID java.lang.String
*/
synchronized double[][][] getSimDataTimeSeries0(OutputContext outputContext, String[] varNames, int[][] indexes, boolean[] wantsThisTime, DataSetControllerImpl.SpatialStatsInfo spatialStatsInfo, DataSetControllerImpl.ProgressListener progressListener) throws DataAccessException, IOException {
refreshLogFile();
try {
getFunctionDataIdentifiers(outputContext);
} catch (Exception ex) {
ex.printStackTrace(System.out);
}
int resultsCounter = 0;
for (int i = 0; i < wantsThisTime.length; i += 1) {
if (wantsThisTime[i]) {
resultsCounter += 1;
}
}
// min,max,mean,wmean
final int NUM_STATS = 4;
// Create results buffer
// [timePoints][varNames][dataIndexes]
double[][][] results = new double[resultsCounter][][];
for (int i = 0; i < results.length; i += 1) {
results[i] = new double[varNames.length][];
for (int j = 0; j < results[i].length; j += 1) {
if (spatialStatsInfo != null) {
// min,max.mean,wmean
results[i][j] = new double[NUM_STATS];
} else {
results[i][j] = new double[indexes[j].length];
}
}
}
try {
if (varNames.length > 0 && isPostProcessing(outputContext, varNames[0])) {
double[] specificTimePoints = new double[results.length];
int counter = 0;
for (int i = 0; i < dataProcessingOutputInfo.getVariableTimePoints().length; i++) {
if (wantsThisTime[i]) {
specificTimePoints[counter] = dataProcessingOutputInfo.getVariableTimePoints()[i];
counter++;
}
}
// PDEDataInfo pdeDataInfo = new PDEDataInfo(vcDataId.getOwner(),vcDataId.getID(),varName,time,lastDataProcessingOutputInfoTime);
for (int i = 0; i < varNames.length; i++) {
DataProcessingOutputDataValuesOP dataProcessingOutputDataValuesOP = new DataProcessingOutputDataValuesOP(vcDataId, varNames[i], TimePointHelper.createSpecificTimePointHelper(specificTimePoints), DataIndexHelper.createSpecificDataIndexHelper(indexes[i]), outputContext, null);
DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) DataSetControllerImpl.getDataProcessingOutput(dataProcessingOutputDataValuesOP, getDataProcessingOutputSourceFileHDF5());
for (int j = 0; j < specificTimePoints.length; j++) {
results[j][i] = dataProcessingOutputDataValues.getDataValues()[j];
}
}
return results;
}
} catch (Exception e) {
// ignore
e.printStackTrace();
}
String[] varNamesInDataSet = new String[varNames.length];
for (int i = 0; i < varNamesInDataSet.length; i++) {
varNamesInDataSet[i] = getDataSetIdentifier(varNames[i]).getQualifiedName();
}
// Setup parameters for SimDataReader
double[] tempDataTimes = dataTimes.clone();
String[] tempZipFileNames = null;
if (bZipFormat2) {
tempZipFileNames = new String[tempDataTimes.length];
}
String[] tempSimDataFileNames = new String[tempDataTimes.length];
for (int i = 0; i < tempDataTimes.length; i += 1) {
if (bZipFormat2 || bZipFormat1) {
if (bZipFormat2) {
tempZipFileNames[i] = getPDEDataZipFile(tempDataTimes[i]).getAbsolutePath();
}
tempSimDataFileNames[i] = dataFilenames[i];
} else {
// userDirectory.getAbsolutePath()+"\\"+dataFilenames[i];//getPDEDataFile(dataTimes[i]).getAbsolutePath();
tempSimDataFileNames[i] = amplistorHelper.getFile(dataFilenames[i]).getName();
}
}
SimDataReader sdr = null;
double[][] singleTimePointResultsBuffer = new double[varNamesInDataSet.length][];
for (int i = 0; i < singleTimePointResultsBuffer.length; i += 1) {
singleTimePointResultsBuffer[i] = new double[indexes[i].length];
}
// In case sim files have been updated since "wantsThisTime" was calculated
if (wantsThisTime.length < tempDataTimes.length) {
double[] tempTempDataTimes = new double[wantsThisTime.length];
System.arraycopy(tempDataTimes, 0, tempTempDataTimes, 0, wantsThisTime.length);
tempDataTimes = tempTempDataTimes;
String[] tempTempZipFileNames = new String[wantsThisTime.length];
System.arraycopy(tempZipFileNames, 0, tempTempZipFileNames, 0, wantsThisTime.length);
tempZipFileNames = tempTempZipFileNames;
String[] tempTempSimDataFileNames = new String[wantsThisTime.length];
System.arraycopy(tempSimDataFileNames, 0, tempTempSimDataFileNames, 0, wantsThisTime.length);
tempSimDataFileNames = tempTempSimDataFileNames;
}
try {
sdr = new SimDataReader(wantsThisTime, tempDataTimes, tempZipFileNames, tempSimDataFileNames, varNamesInDataSet, indexes, isChombo());
int counter = 0;
int progressCounter = 0;
while (sdr.hasMoreData()) {
sdr.getNextDataAtCurrentTime(singleTimePointResultsBuffer);
// Copy data to timeSeries format
if (wantsThisTime[counter]) {
for (int i = 0; i < varNamesInDataSet.length; i += 1) {
if (spatialStatsInfo != null) {
results[progressCounter][i] = calcSpaceStats(singleTimePointResultsBuffer[i], i, spatialStatsInfo);
} else {
for (int j = 0; j < indexes[i].length; j += 1) {
results[progressCounter][i][j] = singleTimePointResultsBuffer[i][j];
}
}
}
progressCounter += 1;
if (progressListener != null) {
progressListener.updateProgress(100.0 * (double) progressCounter / (double) resultsCounter);
}
}
counter += 1;
}
return results;
} catch (DataAccessException e) {
throw e;
} catch (IOException e) {
throw e;
} catch (Throwable e) {
throw new DataAccessException(e.getMessage(), e);
} finally {
if (sdr != null) {
sdr.close();
}
}
}
use of cbit.vcell.simdata.DataOperation.DataProcessingOutputDataValuesOP in project vcell by virtualcell.
the class RunFakeSimOp method runRefSimulation.
public ImageTimeSeries<UShortImage> runRefSimulation(LocalWorkspace localWorkspace, Simulation simulation, double max_intensity, double bleachBlackoutStartTime, double bleachBlackoutStopTime, boolean hasNoise, ClientTaskStatusSupport progressListener) throws Exception {
User owner = LocalWorkspace.getDefaultOwner();
KeyValue simKey = LocalWorkspace.createNewKeyValue();
runFVSolverStandalone(new File(localWorkspace.getDefaultSimDataDirectory()), simulation, progressListener);
Extent extent = simulation.getMathDescription().getGeometry().getExtent();
Origin origin = simulation.getMathDescription().getGeometry().getOrigin();
VCDataIdentifier vcDataIdentifier = new VCSimulationDataIdentifier(new VCSimulationIdentifier(simulation.getKey(), simulation.getVersion().getOwner()), 0);
CartesianMesh mesh = localWorkspace.getDataSetControllerImpl().getMesh(vcDataIdentifier);
ISize isize = new ISize(mesh.getSizeX(), mesh.getSizeY(), mesh.getSizeZ());
double[] dataTimes = localWorkspace.getDataSetControllerImpl().getDataSetTimes(vcDataIdentifier);
DataProcessingOutputDataValues dataProcessingOutputDataValues = (DataProcessingOutputDataValues) localWorkspace.getDataSetControllerImpl().doDataOperation(new DataProcessingOutputDataValuesOP(vcDataIdentifier, SimulationContext.FLUOR_DATA_NAME, TimePointHelper.createAllTimeTimePointHelper(), DataIndexHelper.createSliceDataIndexHelper(0), null, null));
ArrayList<SourceDataInfo> sourceDataInfoArr = dataProcessingOutputDataValues.createSourceDataInfos(new ISize(mesh.getSizeX(), mesh.getSizeY(), 1), origin, extent);
// find scale factor to scale up the data to avoid losing precision when casting double to short
double maxDataValue = 0;
for (int i = 0; i < dataTimes.length; i++) {
if (sourceDataInfoArr.get(i).getMinMax() != null) {
maxDataValue = Math.max(maxDataValue, sourceDataInfoArr.get(i).getMinMax().getMax());
} else {
double[] doubleData = (double[]) sourceDataInfoArr.get(i).getData();
for (int j = 0; j < doubleData.length; j++) {
maxDataValue = Math.max(maxDataValue, doubleData[j]);
}
}
}
double scale = max_intensity / maxDataValue;
ArrayList<UShortImage> outputImages = new ArrayList<UShortImage>();
ArrayList<Double> outputTimes = new ArrayList<Double>();
for (int i = 0; i < dataTimes.length; i++) {
if (dataTimes[i] < bleachBlackoutStartTime || dataTimes[i] > bleachBlackoutStopTime) {
// saving each time step 2D double array to a UShortImage
double[] doubleData = (double[]) sourceDataInfoArr.get(i).getData();
short[] shortData = new short[isize.getX() * isize.getY()];
for (int j = 0; j < shortData.length; j++) {
double dData = doubleData[j] * scale;
if (dData < 0 || dData > 65535.0) {
throw new RuntimeException("scaled pixel out of range of unsigned 16 bit integer, original simulated value = " + doubleData[j] + ", scale = " + scale + ", scaled value = " + dData);
}
short sData = (short) (0x0000ffff & ((int) dData));
if (hasNoise && dData > 0.0) {
if (dData > 20) {
shortData[j] = (short) (0x0000ffff & (int) RandomVariable.normal(dData, Math.sqrt(dData)));
} else {
shortData[j] = (short) (0x0000ffff & RandomVariable.poisson(dData));
}
} else {
shortData[j] = sData;
}
}
outputTimes.add(dataTimes[i]);
outputImages.add(new UShortImage(shortData, sourceDataInfoArr.get(i).getOrigin(), sourceDataInfoArr.get(i).getExtent(), sourceDataInfoArr.get(i).getXSize(), sourceDataInfoArr.get(i).getYSize(), 1));
if (progressListener != null) {
int progress = (int) (((i + 1) * 1.0 / dataTimes.length) * 100);
progressListener.setProgress(progress);
}
}
}
double[] outputTimesArray = new double[outputTimes.size()];
for (int i = 0; i < outputTimes.size(); i++) {
outputTimesArray[i] = outputTimes.get(i);
}
ImageTimeSeries<UShortImage> fakeFluorTimeSeries = new ImageTimeSeries<UShortImage>(UShortImage.class, outputImages.toArray(new UShortImage[0]), outputTimesArray, 1);
return fakeFluorTimeSeries;
}
Aggregations