Search in sources :

Example 51 with VariableType

use of cbit.vcell.math.VariableType in project vcell by virtualcell.

the class SimulationDataSpatialHdf5 method retriveVariableNames.

private void retriveVariableNames() throws Exception {
    // read variables only when I have never read the file since variables don't change
    if (dataSetIdentifierList.size() > 0) {
        return;
    }
    File tempFile = getTempSimHdf5File(0.0);
    FileFormat fileFormat = FileFormat.getFileFormat(FileFormat.FILE_TYPE_HDF5);
    FileFormat meshFile = fileFormat.createInstance(tempFile.getAbsolutePath(), FileFormat.READ);
    meshFile.open();
    DefaultMutableTreeNode rootNode = (DefaultMutableTreeNode) meshFile.getRootNode();
    Group rootGroup = (Group) rootNode.getUserObject();
    Group solGroup = (Group) rootGroup.getMemberList().get(0);
    List<Attribute> solAttrList = solGroup.getMetadata();
    String[] varNames = null;
    int[] varTypes = null;
    for (Attribute attr : solAttrList) {
        String attrName = attr.getName();
        Object value = attr.getValue();
        if (attrName.equals(SOLUTION_ATTR_VARIABLES)) {
            varNames = (String[]) value;
        } else if (attrName.equals(SOLUTION_ATTR_VARIABLE_TYPES)) {
            varTypes = (int[]) value;
        }
    }
    for (int i = 0; i < varNames.length; i++) {
        VariableType varType = VariableType.getVariableTypeFromInteger(varTypes[i]);
        Domain domain = Variable.getDomainFromCombinedIdentifier(varNames[i]);
        String varName = Variable.getNameFromCombinedIdentifier(varNames[i]);
        dataSetIdentifierList.add(new DataSetIdentifier(varName, varType, domain));
    }
}
Also used : Group(ncsa.hdf.object.Group) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) VariableType(cbit.vcell.math.VariableType) Attribute(ncsa.hdf.object.Attribute) FileFormat(ncsa.hdf.object.FileFormat) HObject(ncsa.hdf.object.HObject) Domain(cbit.vcell.math.Variable.Domain) ZipFile(org.apache.commons.compress.archivers.zip.ZipFile) File(java.io.File)

Example 52 with VariableType

use of cbit.vcell.math.VariableType in project vcell by virtualcell.

the class OutputFunctionContext method propertyChange.

public void propertyChange(java.beans.PropertyChangeEvent event) {
    if (event.getSource() == simulationOwner && event.getPropertyName().equals("mathDescription")) {
        rebindAll();
    }
    if (event.getPropertyName().equals("geometry")) {
        Geometry oldGeometry = (Geometry) event.getOldValue();
        Geometry newGeometry = (Geometry) event.getNewValue();
        // changing from ode to pde
        if (oldGeometry != null && oldGeometry.getDimension() == 0 && newGeometry.getDimension() > 0) {
            ArrayList<AnnotatedFunction> newFuncList = new ArrayList<AnnotatedFunction>();
            for (AnnotatedFunction function : outputFunctionsList) {
                try {
                    Expression newexp = new Expression(function.getExpression());
                    // making sure that output function is not direct function of constant.
                    newexp.bindExpression(this);
                    // here use math description as symbol table because we allow
                    // new expression itself to be function of constant.
                    MathDescription mathDescription = getSimulationOwner().getMathDescription();
                    newexp = MathUtilities.substituteFunctions(newexp, mathDescription).flatten();
                    VariableType newFuncType = VariableType.VOLUME;
                    String[] symbols = newexp.getSymbols();
                    if (symbols != null) {
                        // figure out the function type
                        VariableType[] varTypes = new VariableType[symbols.length];
                        for (int i = 0; i < symbols.length; i++) {
                            Variable var = mathDescription.getVariable(symbols[i]);
                            varTypes[i] = VariableType.getVariableType(var);
                        }
                        // check with flattened expression to find out the variable type of the new expression
                        Function flattenedFunction = new Function(function.getName(), newexp, function.getDomain());
                        newFuncType = SimulationSymbolTable.getFunctionVariableType(flattenedFunction, getSimulationOwner().getMathDescription(), symbols, varTypes, true);
                    }
                    AnnotatedFunction newFunc = new AnnotatedFunction(function.getName(), function.getExpression(), function.getDomain(), "", newFuncType, FunctionCategory.OUTPUTFUNCTION);
                    newFuncList.add(newFunc);
                    newFunc.bind(this);
                } catch (ExpressionException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException(ex.getMessage());
                } catch (InconsistentDomainException ex) {
                    ex.printStackTrace();
                    throw new RuntimeException(ex.getMessage());
                }
            }
            try {
                setOutputFunctions0(newFuncList);
            } catch (PropertyVetoException e) {
                e.printStackTrace();
                throw new RuntimeException(e.getMessage());
            }
        }
    }
}
Also used : ReservedVariable(cbit.vcell.math.ReservedVariable) InsideVariable(cbit.vcell.math.InsideVariable) OutsideVariable(cbit.vcell.math.OutsideVariable) Variable(cbit.vcell.math.Variable) VariableType(cbit.vcell.math.VariableType) MathDescription(cbit.vcell.math.MathDescription) ArrayList(java.util.ArrayList) ExpressionException(cbit.vcell.parser.ExpressionException) Geometry(cbit.vcell.geometry.Geometry) PropertyVetoException(java.beans.PropertyVetoException) Function(cbit.vcell.math.Function) Expression(cbit.vcell.parser.Expression) InconsistentDomainException(cbit.vcell.math.InconsistentDomainException)

Example 53 with VariableType

use of cbit.vcell.math.VariableType 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)

Example 54 with VariableType

use of cbit.vcell.math.VariableType in project vcell by virtualcell.

the class DisplayTimeSeries method displayImageTimeSeries.

public static void displayImageTimeSeries(final ImageTimeSeries<Image> imageTimeSeries, String title, WindowListener windowListener) throws ImageException, IOException {
    ISize size = imageTimeSeries.getISize();
    int dimension = (size.getZ() > 0) ? (3) : (2);
    Extent extent = imageTimeSeries.getExtent();
    Origin origin = imageTimeSeries.getAllImages()[0].getOrigin();
    // don't care ... no surfaces
    double filterCutoffFrequency = 0.5;
    VCImage vcImage = new VCImageUncompressed(null, new byte[size.getXYZ()], extent, size.getX(), size.getY(), size.getZ());
    RegionImage regionImage = new RegionImage(vcImage, dimension, extent, origin, filterCutoffFrequency);
    final CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, size, regionImage);
    final DataIdentifier dataIdentifier = new DataIdentifier("var", VariableType.VOLUME, new Domain("domain"), false, "var");
    final DataSetController dataSetController = new DataSetController() {

        @Override
        public ExportEvent makeRemoteFile(OutputContext outputContext, ExportSpecs exportSpecs) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public TimeSeriesJobResults getTimeSeriesValues(OutputContext outputContext, VCDataIdentifier vcdataID, TimeSeriesJobSpec timeSeriesJobSpec) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public SimDataBlock getSimDataBlock(OutputContext outputContext, VCDataIdentifier vcdataID, String varName, double time) throws RemoteProxyException, DataAccessException {
            double timePoint = time;
            double[] timePoints = getDataSetTimes(vcdataID);
            int index = -1;
            for (int i = 0; i < timePoints.length; i++) {
                if (timePoint == timePoints[i]) {
                    index = i;
                    break;
                }
            }
            double[] data = imageTimeSeries.getAllImages()[index].getDoublePixels();
            PDEDataInfo pdeDataInfo = new PDEDataInfo(null, null, varName, time, 0);
            VariableType varType = VariableType.VOLUME;
            return new SimDataBlock(pdeDataInfo, data, varType);
        }

        @Override
        public boolean getParticleDataExists(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return false;
        }

        @Override
        public ParticleDataBlock getParticleDataBlock(VCDataIdentifier vcdataID, double time) throws DataAccessException, RemoteProxyException {
            return null;
        }

        @Override
        public ODESimData getODEData(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return null;
        }

        @Override
        public CartesianMesh getMesh(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return mesh;
        }

        @Override
        public PlotData getLineScan(OutputContext outputContext, VCDataIdentifier vcdataID, String variable, double time, SpatialSelection spatialSelection) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public AnnotatedFunction[] getFunctions(OutputContext outputContext, VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            return new AnnotatedFunction[0];
        }

        @Override
        public double[] getDataSetTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return imageTimeSeries.getImageTimeStamps();
        }

        @Override
        public DataSetTimeSeries getDataSetTimeSeries(VCDataIdentifier vcdataID, String[] variableNames) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataSetMetadata getDataSetMetadata(VCDataIdentifier vcdataID) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataIdentifier[] getDataIdentifiers(OutputContext outputContext, VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            return new DataIdentifier[] { dataIdentifier };
        }

        @Override
        public FieldDataFileOperationResults fieldDataFileOperation(FieldDataFileOperationSpec fieldDataFileOperationSpec) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public DataOperationResults doDataOperation(DataOperation dataOperation) throws DataAccessException, RemoteProxyException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public VtuFileContainer getEmptyVtuMeshFiles(VCDataIdentifier vcdataID, int timeIndex) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public double[] getVtuTimes(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            throw new RuntimeException("not yet implemented");
        }

        @Override
        public double[] getVtuMeshData(OutputContext outputContext, VCDataIdentifier vcdataID, VtuVarInfo var, double time) throws RemoteProxyException, DataAccessException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public VtuVarInfo[] getVtuVarInfos(OutputContext outputContext, VCDataIdentifier vcDataIdentifier) throws DataAccessException, RemoteProxyException {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public NFSimMolecularConfigurations getNFSimMolecularConfigurations(VCDataIdentifier vcdataID) throws RemoteProxyException, DataAccessException {
            // TODO Auto-generated method stub
            return null;
        }
    };
    DataSetControllerProvider dataSetControllerProvider = new DataSetControllerProvider() {

        @Override
        public DataSetController getDataSetController() throws DataAccessException {
            return dataSetController;
        }
    };
    VCDataManager vcDataManager = new VCDataManager(dataSetControllerProvider);
    OutputContext outputContext = new OutputContext(new AnnotatedFunction[0]);
    VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {

        public User getOwner() {
            return new User("nouser", null);
        }

        public KeyValue getDataKey() {
            return null;
        }

        public String getID() {
            return "mydata";
        }
    };
    PDEDataManager pdeDataManager = new PDEDataManager(outputContext, vcDataManager, vcDataIdentifier);
    ClientPDEDataContext myPdeDataContext = new ClientPDEDataContext(pdeDataManager);
    PDEDataViewer pdeDataViewer = new PDEDataViewer();
    JFrame jframe = new JFrame();
    jframe.setTitle(title);
    jframe.getContentPane().add(pdeDataViewer);
    jframe.setSize(1000, 600);
    jframe.setVisible(true);
    if (windowListener != null) {
        jframe.addWindowListener(windowListener);
    }
    pdeDataViewer.setPdeDataContext(myPdeDataContext);
}
Also used : Origin(org.vcell.util.Origin) VtuVarInfo(org.vcell.vis.io.VtuVarInfo) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) User(org.vcell.util.document.User) TimeSeriesJobSpec(org.vcell.util.document.TimeSeriesJobSpec) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) ExportSpecs(cbit.vcell.export.server.ExportSpecs) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) VCImage(cbit.image.VCImage) PDEDataInfo(cbit.vcell.simdata.PDEDataInfo) DataSetControllerProvider(cbit.vcell.server.DataSetControllerProvider) SimDataBlock(cbit.vcell.simdata.SimDataBlock) SpatialSelection(cbit.vcell.simdata.SpatialSelection) JFrame(javax.swing.JFrame) VCDataManager(cbit.vcell.simdata.VCDataManager) AnnotatedFunction(cbit.vcell.solver.AnnotatedFunction) DataOperation(cbit.vcell.simdata.DataOperation) VariableType(cbit.vcell.math.VariableType) DataSetController(cbit.vcell.server.DataSetController) VCImageUncompressed(cbit.image.VCImageUncompressed) OutputContext(cbit.vcell.simdata.OutputContext) CartesianMesh(cbit.vcell.solvers.CartesianMesh) PDEDataManager(cbit.vcell.simdata.PDEDataManager) RegionImage(cbit.vcell.geometry.RegionImage) ClientPDEDataContext(cbit.vcell.simdata.ClientPDEDataContext) Domain(cbit.vcell.math.Variable.Domain) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) PDEDataViewer(cbit.vcell.client.data.PDEDataViewer)

Aggregations

VariableType (cbit.vcell.math.VariableType)54 CartesianMesh (cbit.vcell.solvers.CartesianMesh)17 DataAccessException (org.vcell.util.DataAccessException)15 File (java.io.File)13 ISize (org.vcell.util.ISize)12 Expression (cbit.vcell.parser.Expression)11 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)11 SinglePoint (cbit.vcell.geometry.SinglePoint)10 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)10 Domain (cbit.vcell.math.Variable.Domain)9 ExpressionException (cbit.vcell.parser.ExpressionException)9 DataIdentifier (cbit.vcell.simdata.DataIdentifier)9 ArrayList (java.util.ArrayList)9 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)8 ReservedVariable (cbit.vcell.math.ReservedVariable)8 Variable (cbit.vcell.math.Variable)8 SimDataBlock (cbit.vcell.simdata.SimDataBlock)8 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)8 Hashtable (java.util.Hashtable)8 MathException (cbit.vcell.math.MathException)7