Search in sources :

Example 16 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class SimulationServiceImpl method getData.

public List<Double> getData(SimulationInfo simInfo, VariableInfo varInfo, int timeIndex) throws ThriftDataAccessException, TException {
    SimulationServiceContext simServiceContext = sims.get(simInfo.id);
    if (simServiceContext == null) {
        throw new RuntimeException("simulation results not found");
    }
    DataSetControllerImpl datasetController = getDataSetController(simServiceContext);
    try {
        double[] times = datasetController.getDataSetTimes(simServiceContext.vcDataIdentifier);
        OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
        SimDataBlock simDataBlock = datasetController.getSimDataBlock(outputContext, simServiceContext.vcDataIdentifier, varInfo.getVariableVtuName(), times[timeIndex]);
        double[] dataArray = simDataBlock.getData();
        ArrayList<Double> dataList = new ArrayList<Double>();
        for (double d : dataArray) {
            dataList.add(d);
        }
        return dataList;
    } catch (Exception e) {
        e.printStackTrace();
        throw new ThriftDataAccessException("failed to retrieve data for variable " + varInfo.getVariableVtuName() + ": " + e.getMessage());
    }
}
Also used : SimDataBlock(cbit.vcell.simdata.SimDataBlock) ArrayList(java.util.ArrayList) ThriftDataAccessException(org.vcell.vcellij.api.ThriftDataAccessException) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) OutputContext(cbit.vcell.simdata.OutputContext) XMLStreamException(javax.xml.stream.XMLStreamException) ThriftDataAccessException(org.vcell.vcellij.api.ThriftDataAccessException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) TException(org.apache.thrift.TException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException)

Example 17 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class SimulationServiceImpl method mesh.

private CartesianMesh mesh(SimulationInfo simInfo) {
    SimulationServiceContext simServiceContext = sims.get(simInfo.id);
    try {
        DataSetControllerImpl datasetController = getDataSetController(simServiceContext);
        CartesianMesh mesh = datasetController.getMesh(simServiceContext.vcDataIdentifier);
        return mesh;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
Also used : CartesianMesh(cbit.vcell.solvers.CartesianMesh) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) XMLStreamException(javax.xml.stream.XMLStreamException) ThriftDataAccessException(org.vcell.vcellij.api.ThriftDataAccessException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) TException(org.apache.thrift.TException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException)

Example 18 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class SimulationServiceImpl method getVariableList.

public List<VariableInfo> getVariableList(SimulationInfo simInfo) throws ThriftDataAccessException, TException {
    SimulationServiceContext simServiceContext = sims.get(simInfo.id);
    if (simServiceContext == null) {
        throw new ThriftDataAccessException("simulation results not found");
    }
    try {
        DataSetControllerImpl datasetController = getDataSetController(simServiceContext);
        OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
        final DataIdentifier[] dataIdentifiers;
        try {
            dataIdentifiers = datasetController.getDataIdentifiers(outputContext, simServiceContext.vcDataIdentifier);
        } catch (IOException | DataAccessException e) {
            e.printStackTrace();
            throw new RuntimeException("failed to retrieve variable information: " + e.getMessage(), e);
        }
        ArrayList<VariableInfo> varInfos = new ArrayList<VariableInfo>();
        for (DataIdentifier dataIdentifier : dataIdentifiers) {
            final DomainType domainType;
            if (dataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
                domainType = DomainType.VOLUME;
            } else if (dataIdentifier.getVariableType().equals(VariableType.MEMBRANE)) {
                domainType = DomainType.MEMBRANE;
            } else {
                continue;
            }
            String domainName = "";
            if (dataIdentifier.getDomain() != null) {
                domainName = dataIdentifier.getDomain().getName();
            }
            VariableInfo varInfo = new VariableInfo(dataIdentifier.getName(), dataIdentifier.getDisplayName(), domainName, domainType);
            varInfos.add(varInfo);
        }
        return varInfos;
    } catch (Exception e) {
        e.printStackTrace();
        throw new ThriftDataAccessException("failed to retrieve variable list: " + e.getMessage());
    }
}
Also used : VCSimulationDataIdentifier(cbit.vcell.solver.VCSimulationDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) VariableInfo(org.vcell.vcellij.api.VariableInfo) ArrayList(java.util.ArrayList) IOException(java.io.IOException) OutputContext(cbit.vcell.simdata.OutputContext) XMLStreamException(javax.xml.stream.XMLStreamException) ThriftDataAccessException(org.vcell.vcellij.api.ThriftDataAccessException) SbmlException(org.vcell.sbml.SbmlException) SBMLException(org.sbml.jsbml.SBMLException) XmlParseException(cbit.vcell.xml.XmlParseException) SolverException(cbit.vcell.solver.SolverException) TException(org.apache.thrift.TException) IOException(java.io.IOException) DataAccessException(org.vcell.util.DataAccessException) DomainType(org.vcell.vcellij.api.DomainType) ThriftDataAccessException(org.vcell.vcellij.api.ThriftDataAccessException) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) ThriftDataAccessException(org.vcell.vcellij.api.ThriftDataAccessException) DataAccessException(org.vcell.util.DataAccessException)

Example 19 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class SimulationServiceImpl method getDataSetController.

private static DataSetControllerImpl getDataSetController(SimulationServiceContext simServiceContext) {
    try {
        OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
        Cachetable cacheTable = new Cachetable(10000);
        DataSetControllerImpl datasetController = new DataSetControllerImpl(cacheTable, simServiceContext.localSimDataDir.getParentFile(), null);
        simServiceContext.times = datasetController.getDataSetTimes(simServiceContext.vcDataIdentifier);
        simServiceContext.dataIdentifiers = datasetController.getDataIdentifiers(outputContext, simServiceContext.vcDataIdentifier);
        return datasetController;
    } catch (IOException | DataAccessException e1) {
        e1.printStackTrace();
        throw new RuntimeException("failed to read dataset: " + e1.getMessage());
    }
}
Also used : Cachetable(cbit.vcell.simdata.Cachetable) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) IOException(java.io.IOException) OutputContext(cbit.vcell.simdata.OutputContext) ThriftDataAccessException(org.vcell.vcellij.api.ThriftDataAccessException) DataAccessException(org.vcell.util.DataAccessException)

Example 20 with DataSetControllerImpl

use of cbit.vcell.simdata.DataSetControllerImpl in project vcell by virtualcell.

the class ROIDataGenerator method getROIDataGeneratorDescription.

public String getROIDataGeneratorDescription(File userDirectory, SimulationJob simulationJob) throws Exception {
    // DataAccessException, FileNotFoundException, MathException, IOException, DivideByZeroException, ExpressionException
    Simulation simulation = simulationJob.getSimulation();
    StringBuffer sb = new StringBuffer();
    sb.append(ROI_GENERATOR_BEGIN + " " + name + "\n");
    sb.append("VolumePoints " + volumePoints.length + "\n");
    for (int i = 0; i < volumePoints.length; i++) {
        sb.append(volumePoints[i] + " ");
        if ((i + 1) % 20 == 0) {
            sb.append("\n");
        }
    }
    sb.append("\n");
    if (membranePoints != null && membranePoints.length > 0) {
        sb.append("MembranePoints " + membranePoints.length + "\n");
        for (int i = 0; i < membranePoints.length; i++) {
            sb.append(membranePoints[i] + " ");
            if ((i + 1) % 20 == 0) {
                sb.append("\n");
            }
        }
        sb.append("\n");
    }
    sb.append("SampleImage " + numImgRegions + " " + zSlice + " " + fieldDataKey + " " + fieldFuncArguments.infix() + "\n");
    sb.append("StoreEnabled " + bStoreEnabled + "\n");
    // sample image field data file
    FieldDataIdentifierSpec fdis = getSampleImageFieldData(simulation.getVersion().getOwner());
    if (fdis == null) {
        throw new DataAccessException("Can't find sample image in ROI data generator.");
    }
    String secondarySimDataDir = PropertyLoader.getProperty(PropertyLoader.secondarySimDataDirInternalProperty, null);
    DataSetControllerImpl dsci = new DataSetControllerImpl(null, userDirectory.getParentFile(), secondarySimDataDir == null ? null : new File(secondarySimDataDir));
    CartesianMesh origMesh = dsci.getMesh(fdis.getExternalDataIdentifier());
    SimDataBlock simDataBlock = dsci.getSimDataBlock(null, fdis.getExternalDataIdentifier(), fdis.getFieldFuncArgs().getVariableName(), fdis.getFieldFuncArgs().getTime().evaluateConstant());
    VariableType varType = fdis.getFieldFuncArgs().getVariableType();
    VariableType dataVarType = simDataBlock.getVariableType();
    if (!varType.equals(VariableType.UNKNOWN) && !varType.equals(dataVarType)) {
        throw new IllegalArgumentException("field function variable type (" + varType.getTypeName() + ") doesn't match real variable type (" + dataVarType.getTypeName() + ")");
    }
    double[] origData = simDataBlock.getData();
    String filename = SimulationJob.createSimulationJobID(Simulation.createSimulationID(simulation.getKey()), simulationJob.getJobIndex()) + SimulationData.getDefaultFieldDataFileNameForSimulation(fdis.getFieldFuncArgs());
    File fdatFile = new File(userDirectory, filename);
    DataSet.writeNew(fdatFile, new String[] { fdis.getFieldFuncArgs().getVariableName() }, new VariableType[] { simDataBlock.getVariableType() }, new ISize(origMesh.getSizeX(), origMesh.getSizeY(), origMesh.getSizeZ()), new double[][] { origData });
    sb.append("SampleImageFile " + fdis.getFieldFuncArgs().getVariableName() + " " + fdis.getFieldFuncArgs().getTime().infix() + " " + fdatFile + "\n");
    sb.append(ROI_GENERATOR_END);
    return sb.toString();
}
Also used : VariableType(cbit.vcell.math.VariableType) ISize(org.vcell.util.ISize) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Simulation(cbit.vcell.solver.Simulation) SimDataBlock(cbit.vcell.simdata.SimDataBlock) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) DataSetControllerImpl(cbit.vcell.simdata.DataSetControllerImpl) File(java.io.File) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

DataSetControllerImpl (cbit.vcell.simdata.DataSetControllerImpl)23 File (java.io.File)15 DataAccessException (org.vcell.util.DataAccessException)10 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)9 CartesianMesh (cbit.vcell.solvers.CartesianMesh)8 IOException (java.io.IOException)8 ExportServiceImpl (cbit.vcell.export.server.ExportServiceImpl)7 Cachetable (cbit.vcell.simdata.Cachetable)7 FieldDataIdentifierSpec (cbit.vcell.field.FieldDataIdentifierSpec)6 SolverException (cbit.vcell.solver.SolverException)6 VCSimulationIdentifier (cbit.vcell.solver.VCSimulationIdentifier)6 User (org.vcell.util.document.User)6 SimDataBlock (cbit.vcell.simdata.SimDataBlock)5 VariableType (cbit.vcell.math.VariableType)4 DataServerImpl (cbit.vcell.simdata.DataServerImpl)4 OutputContext (cbit.vcell.simdata.OutputContext)4 Simulation (cbit.vcell.solver.Simulation)4 ArrayList (java.util.ArrayList)4 ThriftDataAccessException (org.vcell.vcellij.api.ThriftDataAccessException)4 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)3