use of cbit.vcell.export.nrrd.NrrdInfo in project vcell by virtualcell.
the class RasterExporter method exportPDEData.
private NrrdInfo[] exportPDEData(OutputContext outputContext, long jobID, User user, DataServerImpl dataServerImpl, VCDataIdentifier vcdID, VariableSpecs variableSpecs, TimeSpecs timeSpecs2, GeometrySpecs geometrySpecs, RasterSpecs rasterSpecs, FileDataContainerManager fileDataContainerManager) throws RemoteException, DataAccessException, IOException {
CartesianMesh mesh = dataServerImpl.getMesh(user, vcdID);
DataProcessingOutputInfo dataProcessingOutputInfo = null;
// check if any of export variables are PostProcess and if so try to get PostProcessOutputInfo
exportServiceImpl.fireExportProgress(jobID, vcdID, "Check PostProcess", 0.0);
DataIdentifier[] dataIdentifiers = dataServerImpl.getDataIdentifiers(outputContext, user, vcdID);
for (int i = 0; i < dataIdentifiers.length; i++) {
for (int j = 0; j < variableSpecs.getVariableNames().length; j++) {
if (variableSpecs.getVariableNames()[j].equals(dataIdentifiers[i].getName()) && VariableType.POSTPROCESSING.equals(dataIdentifiers[i].getVariableType())) {
try {
// we need PostProcessOutputInfo
exportServiceImpl.fireExportProgress(jobID, vcdID, "Read PostProcess", 0.0);
dataProcessingOutputInfo = (DataProcessingOutputInfo) dataServerImpl.doDataOperation(user, new DataOperation.DataProcessingOutputInfoOP(vcdID, false, outputContext));
break;
} catch (Exception e) {
throw new DataAccessException("Export variable '" + variableSpecs.getVariableNames()[j] + "' is PostProcessing type. Error reading PostProcessing data: " + e.getClass().getName() + " " + e.getMessage());
}
}
}
}
long lastUpdateTime = 0;
switch(rasterSpecs.getFormat()) {
case NRRD_SINGLE:
{
switch(geometrySpecs.getModeID()) {
case GEOMETRY_FULL:
{
NrrdInfo nrrdInfo = NRRDHelper.getSizeCheckedNrrdHelper(variableSpecs, mesh.getISize(), mesh.getExtent(), dataProcessingOutputInfo).createSingleFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs, rasterSpecs, timeSpecs2);
int progressIndex = 1;
int progressEnd = variableSpecs.getVariableNames().length * (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-snglfull", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
NRRDHelper.appendDoubleData(nrrdInfo, fileDataContainerManager, data, variableSpecs.getVariableNames()[i]);
}
}
nrrdInfo = NrrdWriter.writeNRRD(nrrdInfo, fileDataContainerManager);
return new NrrdInfo[] { nrrdInfo };
}
case GEOMETRY_SLICE:
{
NrrdInfo sliceNrrdInfo = createSliceNrrdHelper(mesh, dataProcessingOutputInfo, vcdID, variableSpecs, timeSpecs2, geometrySpecs, rasterSpecs, fileDataContainerManager).createSingleFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs, rasterSpecs, timeSpecs2);
int progressIndex = 1;
int progressEnd = variableSpecs.getVariableNames().length * (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-snglslice", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
appendSlice(variableSpecs.getVariableNames()[i], data, sliceNrrdInfo, mesh, geometrySpecs, fileDataContainerManager);
}
}
sliceNrrdInfo = NrrdWriter.writeNRRD(sliceNrrdInfo, fileDataContainerManager);
return new NrrdInfo[] { sliceNrrdInfo };
}
default:
{
throw new DataAccessException("NRRD export from slice not yet supported");
}
}
}
case NRRD_BY_TIME:
{
switch(geometrySpecs.getModeID()) {
case GEOMETRY_FULL:
{
NRRDHelper nrrdHelper = NRRDHelper.getSizeCheckedNrrdHelper(variableSpecs, mesh.getISize(), mesh.getExtent(), dataProcessingOutputInfo);
Vector<NrrdInfo> nrrdinfoV = new Vector<NrrdInfo>();
int progressIndex = 1;
int progressEnd = (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-timefull", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
NrrdInfo nrrdInfo = nrrdHelper.createTimeFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs, timeSpecs2.getAllTimes()[j], rasterSpecs);
nrrdinfoV.add(nrrdInfo);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
NRRDHelper.appendDoubleData(nrrdInfo, fileDataContainerManager, data, variableSpecs.getVariableNames()[i]);
}
NrrdWriter.writeNRRD(nrrdInfo, fileDataContainerManager);
}
if (nrrdinfoV.size() > 0) {
NrrdInfo[] nrrdinfoArr = new NrrdInfo[nrrdinfoV.size()];
nrrdinfoV.copyInto(nrrdinfoArr);
return nrrdinfoArr;
}
return null;
}
case GEOMETRY_SLICE:
{
Vector<NrrdInfo> nrrdinfoV = new Vector<NrrdInfo>();
int progressIndex = 1;
int progressEnd = (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-timeslice", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
NrrdInfo sliceNrrdInfo = createSliceNrrdHelper(mesh, dataProcessingOutputInfo, vcdID, variableSpecs, timeSpecs2, geometrySpecs, rasterSpecs, fileDataContainerManager).createTimeFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs, timeSpecs2.getAllTimes()[j], rasterSpecs);
nrrdinfoV.add(sliceNrrdInfo);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
appendSlice(variableSpecs.getVariableNames()[i], data, sliceNrrdInfo, mesh, geometrySpecs, fileDataContainerManager);
}
NrrdWriter.writeNRRD(sliceNrrdInfo, fileDataContainerManager);
}
if (nrrdinfoV.size() > 0) {
NrrdInfo[] nrrdinfoArr = new NrrdInfo[nrrdinfoV.size()];
nrrdinfoV.copyInto(nrrdinfoArr);
return nrrdinfoArr;
}
return null;
}
default:
{
throw new DataAccessException("NRRD export from slice not yet supported");
}
}
}
case NRRD_BY_VARIABLE:
{
switch(geometrySpecs.getModeID()) {
case GEOMETRY_FULL:
{
Vector<NrrdInfo> nrrdinfoV = new Vector<NrrdInfo>();
int progressIndex = 1;
int progressEnd = variableSpecs.getVariableNames().length * (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
NRRDHelper nrrdhelHelper = new NRRDHelper(variableSpecs.getVariableNames()[i], mesh.getISize(), mesh.getExtent(), dataProcessingOutputInfo);
NrrdInfo nrrdInfo = nrrdhelHelper.createVariableFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2, rasterSpecs);
nrrdinfoV.add(nrrdInfo);
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-varsfull", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
NRRDHelper.appendDoubleData(nrrdInfo, fileDataContainerManager, data, variableSpecs.getVariableNames()[i]);
}
nrrdInfo = NrrdWriter.writeNRRD(nrrdInfo, fileDataContainerManager);
}
if (nrrdinfoV.size() > 0) {
NrrdInfo[] nrrdinfoArr = new NrrdInfo[nrrdinfoV.size()];
nrrdinfoV.copyInto(nrrdinfoArr);
return nrrdinfoArr;
}
return null;
}
case GEOMETRY_SLICE:
{
Vector<NrrdInfo> nrrdinfoV = new Vector<NrrdInfo>();
int progressIndex = 1;
int progressEnd = variableSpecs.getVariableNames().length * (timeSpecs2.getEndTimeIndex() - timeSpecs2.getBeginTimeIndex() + 1);
for (int i = 0; i < variableSpecs.getVariableNames().length; i++) {
NrrdInfo sliceNrrdInfo = createSliceNrrdHelper(mesh, dataProcessingOutputInfo, vcdID, variableSpecs, timeSpecs2, geometrySpecs, rasterSpecs, fileDataContainerManager).createVariableFullNrrdInfo(fileDataContainerManager, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2, rasterSpecs);
nrrdinfoV.add(sliceNrrdInfo);
for (int j = timeSpecs2.getBeginTimeIndex(); j <= timeSpecs2.getEndTimeIndex(); j++) {
lastUpdateTime = fireThrottledProgress(exportServiceImpl, lastUpdateTime, "NRRD-varsfull", jobID, vcdID, progressIndex, progressEnd);
progressIndex++;
double[] data = dataServerImpl.getSimDataBlock(outputContext, user, vcdID, variableSpecs.getVariableNames()[i], timeSpecs2.getAllTimes()[j]).getData();
appendSlice(variableSpecs.getVariableNames()[i], data, sliceNrrdInfo, mesh, geometrySpecs, fileDataContainerManager);
}
NrrdWriter.writeNRRD(sliceNrrdInfo, fileDataContainerManager);
}
if (nrrdinfoV.size() > 0) {
NrrdInfo[] nrrdinfoArr = new NrrdInfo[nrrdinfoV.size()];
nrrdinfoV.copyInto(nrrdinfoArr);
return nrrdinfoArr;
}
return null;
}
default:
{
throw new DataAccessException("NRRD export from slice not yet supported");
}
}
}
default:
{
throw new DataAccessException("Multiple NRRD file export not yet supported");
}
}
}
use of cbit.vcell.export.nrrd.NrrdInfo in project vcell by virtualcell.
the class ImageJHelper method vcellWantImage0.
private static File vcellWantImage0(ClientTaskStatusSupport clientTaskStatusSupport, String description, ImageJConnection imageJConnection) throws Exception {
if (clientTaskStatusSupport != null) {
clientTaskStatusSupport.setMessage("Waiting for ImageJ to send image...");
}
// Create nrrd file from socket input
// integer (dimensions)
imageJConnection.dis.readInt();
// get size of the standard 5 dimensions in this order (width, height, nChannels, nSlices, nFrames)
int xsize = imageJConnection.dis.readInt();
int ysize = imageJConnection.dis.readInt();
imageJConnection.dis.readInt();
imageJConnection.dis.readInt();
imageJConnection.dis.readInt();
// read data
int slices = imageJConnection.dis.readInt();
byte[] data = new byte[slices * xsize * ysize * Double.BYTES];
ByteBuffer byteBuffer = ByteBuffer.wrap(data);
for (int i = 0; i < slices; i++) {
if (clientTaskStatusSupport != null) {
clientTaskStatusSupport.setMessage("Reading Fiji/ImageJ slice " + (i + 1) + " of " + slices + "...");
if (clientTaskStatusSupport.isInterrupted()) {
throw UserCancelException.CANCEL_GENERIC;
}
}
String arraytype = imageJConnection.dis.readUTF();
int arrLength = imageJConnection.dis.readInt();
if (arraytype.equals(byte[].class.getName())) {
// byte array
byte[] bytes = new byte[arrLength];
int numread = 0;
while (numread != bytes.length) {
numread += imageJConnection.dis.read(bytes, numread, bytes.length - numread);
}
for (int j = 0; j < bytes.length; j++) {
byteBuffer.putDouble((double) Byte.toUnsignedInt(bytes[j]));
}
System.out.println("bytesRead=" + numread);
} else if (arraytype.equals(short[].class.getName())) {
// short array
short[] shorts = new short[arrLength];
for (int j = 0; j < shorts.length; j++) {
shorts[j] = imageJConnection.dis.readShort();
byteBuffer.putDouble((double) Short.toUnsignedInt(shorts[j]));
}
System.out.println("shortsRead=" + shorts.length);
}
}
if (clientTaskStatusSupport != null) {
clientTaskStatusSupport.setMessage("Converting slices to file...");
if (clientTaskStatusSupport.isInterrupted()) {
throw UserCancelException.CANCEL_GENERIC;
}
}
NrrdInfo nrrdInfo = NrrdInfo.createBasicNrrdInfo(5, new int[] { xsize, ysize, slices, 1, 1 }, "double", "raw", NrrdInfo.createXYZTVMap());
FileDataContainerManager fileDataContainerManager = new FileDataContainerManager();
nrrdInfo.setDataFileID(fileDataContainerManager.getNewFileDataContainerID());
fileDataContainerManager.append(nrrdInfo.getDataFileID(), byteBuffer.array());
NrrdWriter.writeNRRD(nrrdInfo, fileDataContainerManager);
File tempFile = File.createTempFile("fijinrrd", ".nrrd");
fileDataContainerManager.writeAndFlush(nrrdInfo.getHeaderFileID(), new FileOutputStream(tempFile));
if (clientTaskStatusSupport != null) {
clientTaskStatusSupport.setMessage("Finished ImageJ data conversion...");
if (clientTaskStatusSupport.isInterrupted()) {
throw UserCancelException.CANCEL_GENERIC;
}
}
return tempFile;
}
use of cbit.vcell.export.nrrd.NrrdInfo in project vcell by virtualcell.
the class ExportServiceImpl method makeRemoteFile.
public ExportEvent makeRemoteFile(OutputContext outputContext, User user, DataServerImpl dataServerImpl, ExportSpecs exportSpecs, boolean bSaveAsZip, ClientTaskStatusSupport clientTaskStatusSupport) throws DataAccessException {
// if export completes successfully, we return the generated event for logging
if (user == null) {
throw new DataAccessException("ERROR: user is null");
}
JobRequest newExportJob = JobRequest.createExportJobRequest(user);
jobRequestIDs.put(new Long(newExportJob.getJobID()), user);
if (lg.isTraceEnabled())
lg.trace("ExportServiceImpl.makeRemoteFile(): " + newExportJob + ", " + exportSpecs);
String fileFormat = null;
switch(exportSpecs.getFormat()) {
case CSV:
fileFormat = "CSV";
break;
case QUICKTIME:
fileFormat = "MOV";
break;
case GIF:
case ANIMATED_GIF:
fileFormat = "GIF";
break;
case FORMAT_JPEG:
fileFormat = "JPEG";
break;
case NRRD:
fileFormat = "NRRD";
break;
case IMAGEJ:
fileFormat = "IMAGEJ";
break;
}
fireExportStarted(newExportJob.getJobID(), exportSpecs.getVCDataIdentifier(), fileFormat);
try {
String exportBaseURL = PropertyLoader.getRequiredProperty(PropertyLoader.exportBaseURLProperty);
String exportBaseDir = PropertyLoader.getRequiredProperty(PropertyLoader.exportBaseDirInternalProperty);
// we need to make new output
if (lg.isTraceEnabled())
lg.trace("ExportServiceImpl.makeRemoteFile(): Starting new export job: " + newExportJob);
FileDataContainerManager fileDataContainerManager = new FileDataContainerManager();
try {
ExportOutput[] exportOutputs = null;
switch(exportSpecs.getFormat()) {
case CSV:
Collection<ExportOutput> asciiOut = asciiExporter.makeASCIIData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
exportOutputs = asciiOut.toArray(new ExportOutput[asciiOut.size()]);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
case QUICKTIME:
case GIF:
case FORMAT_JPEG:
case ANIMATED_GIF:
exportOutputs = imgExporter.makeMediaData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, clientTaskStatusSupport, fileDataContainerManager);
boolean bOverrideZip = exportOutputs.length == 1;
if (bSaveAsZip && !bOverrideZip) {
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
} else {
return makeRemoteFile_Unzipped(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
}
case NRRD:
case IMAGEJ:
NrrdInfo[] nrrdInfos = rrExporter.makeRasterData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, nrrdInfos, exportSpecs, newExportJob, fileDataContainerManager);
case UCD:
exportOutputs = rrExporter.makeUCDData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
case PLY:
exportOutputs = rrExporter.makePLYWithTexData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
case VTK_IMAGE:
exportOutputs = rrExporter.makeVTKImageData(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
case VTK_UNSTRUCT:
exportOutputs = rrExporter.makeVTKUnstructuredData0(outputContext, newExportJob, user, dataServerImpl, exportSpecs, fileDataContainerManager);
return makeRemoteFile(fileFormat, exportBaseDir, exportBaseURL, exportOutputs, exportSpecs, newExportJob, fileDataContainerManager);
default:
throw new DataAccessException("Unknown export format requested");
}
} finally {
fileDataContainerManager.closeAllAndDelete();
}
} catch (UserCancelException ex) {
throw ex;
} catch (Throwable exc) {
lg.error(exc.getMessage(), exc);
fireExportFailed(newExportJob.getJobID(), exportSpecs.getVCDataIdentifier(), fileFormat, exc.getMessage());
throw new DataAccessException(exc.getMessage());
}
}
Aggregations