Search in sources :

Example 1 with FormatSpecificSpecs

use of cbit.vcell.export.server.FormatSpecificSpecs 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();
    }
}
Also used : DataServerImpl(cbit.vcell.simdata.DataServerImpl) VCSimulationIdentifier(cbit.vcell.solver.VCSimulationIdentifier) ExportConstants(cbit.vcell.export.server.ExportConstants) User(org.vcell.util.document.User) ExportOutput(cbit.vcell.export.server.ExportOutput) ExportSpecs(cbit.vcell.export.server.ExportSpecs) ASCIIExporter(cbit.vcell.export.server.ASCIIExporter) FileDataContainerManager(cbit.vcell.export.server.FileDataContainerManager) GeometrySpecs(cbit.vcell.export.server.GeometrySpecs) FormatSpecificSpecs(cbit.vcell.export.server.FormatSpecificSpecs) JobRequest(cbit.vcell.export.server.JobRequest) SpatialSelection(cbit.vcell.simdata.SpatialSelection) ExportServiceImpl(cbit.vcell.export.server.ExportServiceImpl) Species(cbit.vcell.model.Species) TimeSpecs(cbit.vcell.export.server.TimeSpecs) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) ASCIISpecs(cbit.vcell.export.server.ASCIISpecs) SimulationContext(cbit.vcell.mapping.SimulationContext) VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) OutputContext(cbit.vcell.simdata.OutputContext) VariableSpecs(cbit.vcell.export.server.VariableSpecs) OutputFunctionContext(cbit.vcell.solver.OutputFunctionContext) BioModel(cbit.vcell.biomodel.BioModel) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl)

Aggregations

BioModel (cbit.vcell.biomodel.BioModel)1 ASCIIExporter (cbit.vcell.export.server.ASCIIExporter)1 ASCIISpecs (cbit.vcell.export.server.ASCIISpecs)1 ExportConstants (cbit.vcell.export.server.ExportConstants)1 ExportOutput (cbit.vcell.export.server.ExportOutput)1 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)1 ExportSpecs (cbit.vcell.export.server.ExportSpecs)1 FileDataContainerManager (cbit.vcell.export.server.FileDataContainerManager)1 FormatSpecificSpecs (cbit.vcell.export.server.FormatSpecificSpecs)1 GeometrySpecs (cbit.vcell.export.server.GeometrySpecs)1 JobRequest (cbit.vcell.export.server.JobRequest)1 TimeSpecs (cbit.vcell.export.server.TimeSpecs)1 VariableSpecs (cbit.vcell.export.server.VariableSpecs)1 SimulationContext (cbit.vcell.mapping.SimulationContext)1 Species (cbit.vcell.model.Species)1 DataServerImpl (cbit.vcell.simdata.DataServerImpl)1 DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)1 OutputContext (cbit.vcell.simdata.OutputContext)1 SpatialSelection (cbit.vcell.simdata.SpatialSelection)1 AnnotatedFunction (cbit.vcell.solver.AnnotatedFunction)1