use of cbit.vcell.export.server.JobRequest in project vcell by virtualcell.
the class CLIUtils method exportPDE2HDF5.
public static void exportPDE2HDF5(cbit.vcell.solver.Simulation sim, File userDir, File hdf5OutputFile) throws DataAccessException, IOException {
SimulationContext sc = (SimulationContext) sim.getSimulationOwner();
BioModel bm = sc.getBioModel();
// VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(sim.getKey(), sim.getSimulationInfo().getVersion().getOwner());
User user = new User(userDir.getName(), null);
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(sim.getKey(), user);
if (sim.getScanCount() > 1) {
throw new IllegalArgumentException("Parameter scans to be implemented");
}
VCSimulationDataIdentifier vcId = new VCSimulationDataIdentifier(vcSimID, 0);
Species[] species = bm.getModel().getSpecies();
String[] variableNames = new String[species.length];
for (int i = 0; i < species.length; i++) {
variableNames[i] = species[i].getCommonName();
}
VariableSpecs variableSpecs = new VariableSpecs(variableNames, ExportConstants.VARIABLE_MULTI);
DataSetControllerImpl dsControllerImpl = new DataSetControllerImpl(null, userDir.getParentFile(), null);
double[] dataSetTimes = dsControllerImpl.getDataSetTimes(vcId);
TimeSpecs timeSpecs = new TimeSpecs(0, dataSetTimes.length - 1, dataSetTimes, ExportConstants.TIME_RANGE);
timeSpecs = new TimeSpecs(0, 0, dataSetTimes, ExportConstants.TIME_RANGE);
int geoMode = ExportConstants.GEOMETRY_FULL;
SpatialSelection[] selections = new SpatialSelection[0];
selections = null;
int axis = 2;
int sliceNumber = 0;
GeometrySpecs geometrySpecs = new GeometrySpecs(selections, axis, sliceNumber, geoMode);
ExportConstants.DataType dataType = ExportConstants.DataType.PDE_VARIABLE_DATA;
boolean switchRowsColumns = false;
// String simulationName,VCSimulationIdentifier vcSimulationIdentifier,ExportParamScanInfo exportParamScanInfo
ExportSpecs.SimNameSimDataID snsdi = new ExportSpecs.SimNameSimDataID(sim.getName(), vcSimID, null);
ExportSpecs.SimNameSimDataID[] simNameSimDataIDs = { snsdi };
int[] exportMultipleParamScans = null;
boolean isHDF5 = true;
FormatSpecificSpecs formatSpecificSpecs = new ASCIISpecs(ExportFormat.CSV, dataType, switchRowsColumns, simNameSimDataIDs, exportMultipleParamScans, csvRoiLayout.var_time_val, isHDF5);
OutputFunctionContext ofc = sc.getOutputFunctionContext();
ArrayList<AnnotatedFunction> outputFunctionsList = ofc.getOutputFunctionsList();
AnnotatedFunction[] af = outputFunctionsList.toArray(new AnnotatedFunction[0]);
OutputContext outputContext = new OutputContext(af);
ExportServiceImpl exportServiceImpl = new ExportServiceImpl();
ASCIIExporter ae = new ASCIIExporter(exportServiceImpl);
String contextName = bm.getName() + ":" + sc.getName();
ExportSpecs exportSpecs = new ExportSpecs(vcId, ExportFormat.HDF5, variableSpecs, timeSpecs, geometrySpecs, formatSpecificSpecs, sim.getName(), contextName);
DataServerImpl dataServerImpl = new DataServerImpl(dsControllerImpl, exportServiceImpl);
FileDataContainerManager fileDataContainerManager = new FileDataContainerManager();
JobRequest jobRequest = JobRequest.createExportJobRequest(vcId.getOwner());
Collection<ExportOutput> eo = ae.makeASCIIData(outputContext, jobRequest, vcId.getOwner(), dataServerImpl, exportSpecs, fileDataContainerManager);
Iterator<ExportOutput> iterator = eo.iterator();
ExportOutput aaa = iterator.next();
if (((ASCIISpecs) exportSpecs.getFormatSpecificSpecs()).isHDF5()) {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
// Get location of temp HDF5 file
aaa.writeDataToOutputStream(baos, fileDataContainerManager);
File tempHDF5File = new File(baos.toString());
Files.copy(tempHDF5File, hdf5OutputFile);
tempHDF5File.delete();
}
}
Aggregations