Search in sources :

Example 31 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.

the class FunctionRangeGenerator method main.

public static void main(String[] args) {
    try {
        Expression exp = new Expression("a+log(b)+c");
        VarStatistics[] varStats = new VarStatistics[3];
        varStats[0] = new VarStatistics("a", new double[] { 1.0, 2.0, 3.0 }, new double[] { 1.0, 2.0, 3.0 });
        varStats[1] = new VarStatistics("b", new double[] { 1.0, 2.0, 3.0 }, new double[] { 1.0, 2.0, 3.0 });
        varStats[2] = new VarStatistics("c", new double[] { 1.0, 2.0, 3.0 }, new double[] { 1.0, 2.0, 3.0 });
        double[] times = new double[] { 0.0, 1.0, 2.0 };
        Extent extent = new Extent(5, 5, 5);
        Origin origin = new Origin(0, 0, 0);
        // int numSamplesPerDim = 10;
        byte[] pixels = new byte[3 * 3 * 3];
        BitSet indomain = new BitSet(pixels.length);
        for (int i = 0; i < pixels.length; i++) {
            indomain.set(i);
        }
        VCImageUncompressed vcImage = new VCImageUncompressed(null, pixels, extent, 3, 3, 3);
        RegionImage regionImage = new RegionImage(vcImage, 3, extent, origin, RegionImage.NO_SMOOTHING);
        CartesianMesh mesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, new ISize(regionImage.getNumX(), regionImage.getNumY(), regionImage.getNumZ()), regionImage, true);
        FunctionStatistics results = FunctionRangeGenerator.getFunctionStatistics(exp, varStats, times, mesh, indomain, VariableType.VOLUME);
        System.out.println(results.getDefaultDatasetRange().toString());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) BitSet(java.util.BitSet) VCImageUncompressed(cbit.image.VCImageUncompressed) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Expression(cbit.vcell.parser.Expression) RegionImage(cbit.vcell.geometry.RegionImage)

Example 32 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.

the class FRAPStudy method getPSFFieldData.

public static FieldDataIdentifierSpec getPSFFieldData(LocalWorkspace localWorkspace) {
    // create ROI image
    short[] psfFieldData = null;
    psfFieldData = new short[9];
    psfFieldData[4] = (short) 1;
    // create field data
    int NumTimePoints = 1;
    // 8 rois integrated into 1 image
    int NumChannels = 1;
    short[][][] pixData = new short[NumTimePoints][NumChannels][1];
    pixData[0][0] = psfFieldData;
    // get extental data id
    ExternalDataIdentifier newPsfExtDataID = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.PSF_DATA_NAME).getExternalDataIdentifier();
    CartesianMesh cartesianMesh;
    try {
        Origin origin = new Origin(0, 0, 0);
        Extent ext = new Extent(1, 1, 1);
        ISize isize = new ISize(3, 3, 1);
        cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, ext, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], ext, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
        FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
        fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
        fdos.cartesianMesh = cartesianMesh;
        fdos.shortSpecData = pixData;
        fdos.specEDI = newPsfExtDataID;
        fdos.varNames = new String[] { "psfVar" };
        fdos.owner = LocalWorkspace.getDefaultOwner();
        fdos.times = new double[] { 0.0 };
        fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
        fdos.origin = origin;
        fdos.extent = ext;
        fdos.isize = isize;
        localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
        FieldFunctionArguments psfFieldFunc = new FieldFunctionArguments(PSF_DATA_NAME, "psfVar", new Expression(0.0), VariableType.VOLUME);
        FieldDataIdentifierSpec fdis = new FieldDataIdentifierSpec(psfFieldFunc, newPsfExtDataID);
        return fdis;
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return null;
    }
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) FieldFunctionArguments(cbit.vcell.field.FieldFunctionArguments) ISize(org.vcell.util.ISize) FieldDataFileOperationSpec(cbit.vcell.field.io.FieldDataFileOperationSpec) VCImageUncompressed(cbit.image.VCImageUncompressed) ImageException(cbit.image.ImageException) UserCancelException(org.vcell.util.UserCancelException) CartesianMesh(cbit.vcell.solvers.CartesianMesh) Expression(cbit.vcell.parser.Expression) FieldDataIdentifierSpec(cbit.vcell.field.FieldDataIdentifierSpec) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) RegionImage(cbit.vcell.geometry.RegionImage)

Example 33 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.

the class FRAPStudy method getCartesianMesh.

public CartesianMesh getCartesianMesh() throws Exception {
    CartesianMesh cartesianMesh = null;
    ImageDataset imgDataSet = getFrapData().getImageDataset();
    Extent extent = imgDataSet.getExtent();
    ISize isize = imgDataSet.getISize();
    Origin origin = new Origin(0, 0, 0);
    if (getBioModel() == null) {
        cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, new RegionImage(new VCImageUncompressed(null, new byte[isize.getXYZ()], extent, isize.getX(), isize.getY(), isize.getZ()), 0, null, null, RegionImage.NO_SMOOTHING));
    } else {
        RegionImage regionImage = getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().getRegionImage();
        if (regionImage == null) {
            getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().updateAll();
            regionImage = getBioModel().getSimulationContexts()[0].getGeometry().getGeometrySurfaceDescription().getRegionImage();
        }
        cartesianMesh = CartesianMesh.createSimpleCartesianMesh(origin, extent, isize, regionImage);
    }
    return cartesianMesh;
}
Also used : Origin(org.vcell.util.Origin) CartesianMesh(cbit.vcell.solvers.CartesianMesh) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) RegionImage(cbit.vcell.geometry.RegionImage) VCImageUncompressed(cbit.image.VCImageUncompressed)

Example 34 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh 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 35 with CartesianMesh

use of cbit.vcell.solvers.CartesianMesh in project vcell by virtualcell.

the class DataSetControllerImpl method getMesh.

/**
 * This method was created in VisualAge.
 * @return CartesianMesh
 */
public CartesianMesh getMesh(VCDataIdentifier vcdID) throws DataAccessException, IOException, MathException {
    VCMongoMessage.sendTrace("DataSetControllerImpl.getMesh(" + vcdID.getID() + ")  <<EXIT>>");
    if (lg.isTraceEnabled())
        lg.trace("DataSetControllerImpl.getMesh(" + vcdID.getOwner().getName() + "," + vcdID.getID() + ")");
    VCData simData = null;
    try {
        simData = getVCData(vcdID);
    } catch (DataAccessException e) {
    }
    if (simData == null) {
        throw new DataAccessException("no simResults for user " + vcdID.getOwner().getName() + " with simID=" + vcdID.getID());
    }
    CartesianMesh mesh = simData.getMesh();
    if (mesh == null) {
        if (lg.isWarnEnabled())
            lg.warn("DataSetControllerImpl.getMesh(): creating dummy CartesianMesh");
        try {
            int[] size = simData.getVolumeSize();
            if (size == null) {
                VCMongoMessage.sendTrace("DataSetControllerImpl.getMesh(" + vcdID.getID() + ")  <<EXIT size==null>>");
                return null;
            }
            VCMongoMessage.sendTrace("DataSetControllerImpl.getMesh(" + vcdID.getID() + ")  <<EXIT size not null but can't read>>");
            throw new RuntimeException("DataSetControllerImpl.getMesh(): size not null but couldn't read Mesh");
        } catch (Throwable e2) {
            lg.error(e2.getMessage(), e2);
            if (lg.isWarnEnabled())
                lg.warn("DataSetControllerImpl.getMesh(): error creating dummy mesh: " + e2.getMessage());
            VCMongoMessage.sendTrace("DataSetControllerImpl.getMesh(" + vcdID.getID() + ")  <<EXIT null>>");
            return null;
        }
    } else {
        VCMongoMessage.sendTrace("DataSetControllerImpl.getMesh(" + vcdID.getID() + ")  <<EXIT non-null>>");
        return mesh;
    }
}
Also used : CartesianMesh(cbit.vcell.solvers.CartesianMesh) DataAccessException(org.vcell.util.DataAccessException)

Aggregations

CartesianMesh (cbit.vcell.solvers.CartesianMesh)49 ISize (org.vcell.util.ISize)24 Extent (org.vcell.util.Extent)19 Origin (org.vcell.util.Origin)18 VariableType (cbit.vcell.math.VariableType)17 VCImageUncompressed (cbit.image.VCImageUncompressed)15 RegionImage (cbit.vcell.geometry.RegionImage)15 DataAccessException (org.vcell.util.DataAccessException)15 VCDataIdentifier (org.vcell.util.document.VCDataIdentifier)14 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)13 File (java.io.File)13 ExternalDataIdentifier (org.vcell.util.document.ExternalDataIdentifier)12 IOException (java.io.IOException)11 DataIdentifier (cbit.vcell.simdata.DataIdentifier)9 SimDataBlock (cbit.vcell.simdata.SimDataBlock)9 VCSimulationDataIdentifier (cbit.vcell.solver.VCSimulationDataIdentifier)9 VCImage (cbit.image.VCImage)8 UserCancelException (org.vcell.util.UserCancelException)8 Expression (cbit.vcell.parser.Expression)7 Vector (java.util.Vector)7