Search in sources :

Example 36 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class FitTimeSeries method fit.

public FitBleachSpotOpResults fit(ROI bleachROI, FloatImage normImage) {
    // 
    // find initial guess by centroid from bleach ROI and total area of bleach ROI (assuming a circle of radius R)
    // 
    int nonzeroPixelsCount = bleachROI.getNonzeroPixelsCount();
    ISize size = bleachROI.getISize();
    if (size.getZ() > 1) {
        throw new RuntimeException("expecting 2D bleach region ROI");
    }
    short[] pixels = bleachROI.getBinaryPixelsXYZ(1);
    long numPixelsInROI = 0;
    Extent extent = bleachROI.getRoiImages()[0].getExtent();
    double totalX_um = 0.0;
    double totalY_um = 0.0;
    double total_I = 0.0;
    double total_J = 0.0;
    int pixelIndex = 0;
    for (int i = 0; i < size.getX(); i++) {
        double x = extent.getX() * (i + 0.5) / (size.getX() - 1);
        for (int j = 0; j < size.getY(); j++) {
            if (pixels[pixelIndex] != 0) {
                double y = extent.getY() * (j + 0.5) / (size.getY() - 1);
                totalX_um += x;
                totalY_um += y;
                total_I += i;
                total_J += j;
                numPixelsInROI++;
            }
            pixelIndex++;
        }
    }
    Origin origin = bleachROI.getRoiImages()[0].getOrigin();
    double roiCenterX_um = origin.getX() + totalX_um / numPixelsInROI;
    double roiCenterY_um = origin.getY() + totalY_um / numPixelsInROI;
    double roiCenterI_pixelscale = total_I / numPixelsInROI;
    double roiCenterJ_pixelscale = total_J / numPixelsInROI;
    // Area = PI * R^2
    // R = sqrt(Area/PI)
    double roiBleachSpotArea_um2 = (extent.getX() * extent.getY() * numPixelsInROI) / (size.getX() * size.getY());
    double roiBleachRadius_um = Math.sqrt(roiBleachSpotArea_um2 / Math.PI);
    double roiBleachRadius_pixelscale = Math.sqrt(numPixelsInROI / Math.PI);
    FitBleachSpotOpResults results = new FitBleachSpotOpResults();
    results.bleachRadius_ROI = roiBleachRadius_um;
    results.centerX_ROI = roiCenterX_um;
    results.centerY_ROI = roiCenterY_um;
    GaussianFitResults gfresults = fitToGaussian(roiCenterI_pixelscale, roiCenterJ_pixelscale, roiBleachRadius_pixelscale * roiBleachRadius_pixelscale, normImage);
    results.bleachFactorK_GaussianFit = gfresults.K;
    results.bleachRadius_GaussianFit = Math.sqrt(gfresults.radius2);
    results.centerX_GaussianFit = origin.getX() + extent.getX() * (gfresults.centerI + 0.5) / size.getX();
    results.centerY_GaussianFit = origin.getY() + extent.getY() * (gfresults.centerJ + 0.5) / size.getY();
    return results;
}
Also used : Origin(org.vcell.util.Origin) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize)

Example 37 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class Generate2DExpModelOpAbstract method generateModel.

public final GeneratedModelResults generateModel(double deltaX, double bleachRadius, double cellRadius, double bleachDuration, double bleachRate, double postbleachDelay, double postbleachDuration, double psfSigma, double outputTimeStep, double primaryDiffusionRate, double primaryFraction, double bleachMonitorRate, double secondaryDiffusionRate, double secondaryFraction, String extracellularName, String cytosolName, Context context) throws PropertyVetoException, ExpressionException, GeometryException, ImageException, ModelException, MappingException, MathException, MatrixException {
    double domainSize = 2.2 * cellRadius;
    Extent extent = new Extent(domainSize, domainSize, 1.0);
    Origin origin = new Origin(-extent.getX() / 2.0, -extent.getY() / 2.0, -extent.getZ() / 2.0);
    String EXTRACELLULAR_NAME = extracellularName;
    String CYTOSOL_NAME = cytosolName;
    AnalyticSubVolume cytosolSubVolume = new AnalyticSubVolume(CYTOSOL_NAME, new Expression("pow(x,2)+pow(y,2)<pow(" + cellRadius + ",2)"));
    AnalyticSubVolume extracellularSubVolume = new AnalyticSubVolume(EXTRACELLULAR_NAME, new Expression(1.0));
    Geometry geometry = new Geometry("geometry", 2);
    geometry.getGeometrySpec().setExtent(extent);
    geometry.getGeometrySpec().setOrigin(origin);
    geometry.getGeometrySpec().addSubVolume(extracellularSubVolume);
    geometry.getGeometrySpec().addSubVolume(cytosolSubVolume, true);
    geometry.getGeometrySurfaceDescription().updateAll();
    BioModel bioModel = new BioModel(null);
    bioModel.setName("unnamed");
    Model model = new Model("model");
    bioModel.setModel(model);
    model.addFeature(EXTRACELLULAR_NAME);
    Feature extracellular = (Feature) model.getStructure(EXTRACELLULAR_NAME);
    model.addFeature(CYTOSOL_NAME);
    Feature cytosol = (Feature) model.getStructure(CYTOSOL_NAME);
    SpeciesContext immobileSC = model.createSpeciesContext(cytosol);
    SpeciesContext primarySC = model.createSpeciesContext(cytosol);
    SpeciesContext secondarySC = model.createSpeciesContext(cytosol);
    // 
    // common bleaching rate for all species
    // 
    double bleachStart = 10 * outputTimeStep - bleachDuration - postbleachDelay;
    double bleachEnd = bleachStart + bleachDuration;
    Expression bleachRateExp = createBleachExpression(bleachRadius, bleachRate, bleachMonitorRate, bleachStart, bleachEnd);
    {
        SimpleReaction immobileBWM = model.createSimpleReaction(cytosol);
        GeneralKinetics immobileBWMKinetics = new GeneralKinetics(immobileBWM);
        immobileBWM.setKinetics(immobileBWMKinetics);
        immobileBWM.addReactant(immobileSC, 1);
        immobileBWMKinetics.getReactionRateParameter().setExpression(Expression.mult(bleachRateExp, new Expression(immobileSC.getName())));
    }
    {
        SimpleReaction primaryBWM = model.createSimpleReaction(cytosol);
        GeneralKinetics primaryBWMKinetics = new GeneralKinetics(primaryBWM);
        primaryBWM.setKinetics(primaryBWMKinetics);
        primaryBWM.addReactant(primarySC, 1);
        primaryBWMKinetics.getReactionRateParameter().setExpression(Expression.mult(bleachRateExp, new Expression(primarySC.getName())));
    }
    {
        SimpleReaction secondaryBWM = model.createSimpleReaction(cytosol);
        GeneralKinetics secondaryBWMKinetics = new GeneralKinetics(secondaryBWM);
        secondaryBWM.setKinetics(secondaryBWMKinetics);
        secondaryBWM.addReactant(secondarySC, 1);
        secondaryBWMKinetics.getReactionRateParameter().setExpression(Expression.mult(bleachRateExp, new Expression(secondarySC.getName())));
    }
    // create simulation context
    SimulationContext simContext = bioModel.addNewSimulationContext("simContext", SimulationContext.Application.NETWORK_DETERMINISTIC);
    simContext.setGeometry(geometry);
    FeatureMapping cytosolFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(cytosol);
    FeatureMapping extracellularFeatureMapping = (FeatureMapping) simContext.getGeometryContext().getStructureMapping(extracellular);
    SubVolume cytSubVolume = geometry.getGeometrySpec().getSubVolume(CYTOSOL_NAME);
    SubVolume exSubVolume = geometry.getGeometrySpec().getSubVolume(EXTRACELLULAR_NAME);
    // unused? SurfaceClass pmSurfaceClass = geometry.getGeometrySurfaceDescription().getSurfaceClass(exSubVolume, cytSubVolume);
    cytosolFeatureMapping.setGeometryClass(cytSubVolume);
    extracellularFeatureMapping.setGeometryClass(exSubVolume);
    cytosolFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    extracellularFeatureMapping.getUnitSizeParameter().setExpression(new Expression(1.0));
    double fixedFraction = 1.0 - primaryFraction - secondaryFraction;
    SpeciesContextSpec immobileSCS = simContext.getReactionContext().getSpeciesContextSpec(immobileSC);
    immobileSCS.getInitialConditionParameter().setExpression(new Expression(fixedFraction));
    immobileSCS.getDiffusionParameter().setExpression(new Expression(0.0));
    SpeciesContextSpec primarySCS = simContext.getReactionContext().getSpeciesContextSpec(primarySC);
    primarySCS.getInitialConditionParameter().setExpression(new Expression(primaryFraction));
    primarySCS.getDiffusionParameter().setExpression(new Expression(primaryDiffusionRate));
    SpeciesContextSpec secondarySCS = simContext.getReactionContext().getSpeciesContextSpec(secondarySC);
    secondarySCS.getInitialConditionParameter().setExpression(new Expression(secondaryFraction));
    secondarySCS.getDiffusionParameter().setExpression(new Expression(secondaryDiffusionRate));
    simContext.getMicroscopeMeasurement().addFluorescentSpecies(immobileSC);
    simContext.getMicroscopeMeasurement().addFluorescentSpecies(primarySC);
    simContext.getMicroscopeMeasurement().addFluorescentSpecies(secondarySC);
    simContext.getMicroscopeMeasurement().setConvolutionKernel(new GaussianConvolutionKernel(new Expression(psfSigma), new Expression(psfSigma)));
    MathMapping mathMapping = simContext.createNewMathMapping();
    MathDescription mathDesc = mathMapping.getMathDescription();
    simContext.setMathDescription(mathDesc);
    User owner = context.getDefaultOwner();
    int meshSize = (int) (domainSize / deltaX);
    if (meshSize % 2 == 0) {
        // want an odd-sized mesh in x and y ... so centered at the origin.
        meshSize = meshSize + 1;
    }
    TimeBounds timeBounds = new TimeBounds(0.0, postbleachDuration);
    // 
    // simulation to use for data generation (output time steps as recorded by the microscope)
    // 
    double bleachBlackoutBegin = bleachStart - postbleachDelay;
    double bleachBlackoutEnd = bleachEnd + postbleachDelay;
    // ArrayList<Double> times = new ArrayList<Double>();
    // double time = 0;
    // while (time<=timeBounds.getEndingTime()){
    // if (time<=bleachBlackoutBegin || time>bleachBlackoutEnd){
    // // postbleachDelay is the time it takes to switch the filters.
    // times.add(time);
    // }
    // time += outputTimeStep.getData();
    // }
    // double[] timeArray = new double[times.size()];
    // for (int i=0;i<timeArray.length;i++){
    // timeArray[i] = times.get(i);
    // }
    // OutputTimeSpec fakeDataSimOutputTimeSpec = new ExplicitOutputTimeSpec(timeArray);
    OutputTimeSpec fakeDataSimOutputTimeSpec = new UniformOutputTimeSpec(outputTimeStep);
    KeyValue fakeDataSimKey = context.createNewKeyValue();
    SimulationVersion fakeDataSimVersion = new SimulationVersion(fakeDataSimKey, "fakeDataSim", owner, new GroupAccessNone(), new KeyValue("0"), new BigDecimal(0), new Date(), VersionFlag.Current, "", null);
    Simulation fakeDataSim = new Simulation(fakeDataSimVersion, mathDesc);
    simContext.addSimulation(fakeDataSim);
    fakeDataSim.getSolverTaskDescription().setTimeBounds(timeBounds);
    fakeDataSim.getMeshSpecification().setSamplingSize(new ISize(meshSize, meshSize, 1));
    fakeDataSim.getSolverTaskDescription().setSolverDescription(SolverDescription.SundialsPDE);
    fakeDataSim.getSolverTaskDescription().setOutputTimeSpec(fakeDataSimOutputTimeSpec);
    // 
    // simulation to use for viewing the protocol (output time steps to understand the physics)
    // 
    KeyValue fullExperimentSimKey = context.createNewKeyValue();
    SimulationVersion fullExperimentSimVersion = new SimulationVersion(fullExperimentSimKey, "fullExperiment", owner, new GroupAccessNone(), new KeyValue("0"), new BigDecimal(0), new Date(), VersionFlag.Current, "", null);
    Simulation fullExperimentSim = new Simulation(fullExperimentSimVersion, mathDesc);
    simContext.addSimulation(fullExperimentSim);
    OutputTimeSpec fullExperimentOutputTimeSpec = new UniformOutputTimeSpec(outputTimeStep / 10.0);
    fullExperimentSim.getSolverTaskDescription().setTimeBounds(timeBounds);
    fullExperimentSim.getMeshSpecification().setSamplingSize(new ISize(meshSize, meshSize, 1));
    fullExperimentSim.getSolverTaskDescription().setSolverDescription(SolverDescription.SundialsPDE);
    fullExperimentSim.getSolverTaskDescription().setOutputTimeSpec(fullExperimentOutputTimeSpec);
    GeneratedModelResults results = new GeneratedModelResults();
    results.bioModel_2D = bioModel;
    results.simulation_2D = fakeDataSim;
    results.bleachBlackoutBeginTime = bleachBlackoutBegin;
    results.bleachBlackoutEndTime = bleachBlackoutEnd;
    return results;
}
Also used : Origin(org.vcell.util.Origin) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) Extent(org.vcell.util.Extent) MathDescription(cbit.vcell.math.MathDescription) ISize(org.vcell.util.ISize) SpeciesContext(cbit.vcell.model.SpeciesContext) GeneralKinetics(cbit.vcell.model.GeneralKinetics) SpeciesContextSpec(cbit.vcell.mapping.SpeciesContextSpec) Feature(cbit.vcell.model.Feature) TimeBounds(cbit.vcell.solver.TimeBounds) GroupAccessNone(org.vcell.util.document.GroupAccessNone) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) OutputTimeSpec(cbit.vcell.solver.OutputTimeSpec) SimulationVersion(org.vcell.util.document.SimulationVersion) FeatureMapping(cbit.vcell.mapping.FeatureMapping) SubVolume(cbit.vcell.geometry.SubVolume) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume) SimpleReaction(cbit.vcell.model.SimpleReaction) UniformOutputTimeSpec(cbit.vcell.solver.UniformOutputTimeSpec) SimulationContext(cbit.vcell.mapping.SimulationContext) GaussianConvolutionKernel(cbit.vcell.mapping.MicroscopeMeasurement.GaussianConvolutionKernel) BigDecimal(java.math.BigDecimal) Date(java.util.Date) Geometry(cbit.vcell.geometry.Geometry) Simulation(cbit.vcell.solver.Simulation) Expression(cbit.vcell.parser.Expression) BioModel(cbit.vcell.biomodel.BioModel) BioModel(cbit.vcell.biomodel.BioModel) Model(cbit.vcell.model.Model) MathMapping(cbit.vcell.mapping.MathMapping) AnalyticSubVolume(cbit.vcell.geometry.AnalyticSubVolume)

Example 38 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class BioformatsImageDatasetReader method getImageDataset.

private ImageDataset getImageDataset(org.vcell.imagedataset.ImageDataset t_imageDataset) throws ImageException {
    List<org.vcell.imagedataset.UShortImage> t_images = t_imageDataset.getImages();
    UShortImage[] images = new UShortImage[t_images.size()];
    for (int i = 0; i < t_images.size(); i++) {
        org.vcell.imagedataset.UShortImage t_image = t_images.get(i);
        short[] pixels = new short[t_image.getPixels().size()];
        for (int p = 0; p < t_image.getPixelsSize(); p++) {
            pixels[p] = t_image.getPixels().get(p);
        }
        Origin origin = new Origin(t_image.getOrigin().x, t_image.getOrigin().y, t_image.getOrigin().z);
        Extent extent = new Extent(t_image.getExtent().x, t_image.getExtent().y, t_image.getExtent().z);
        int numX = t_image.getSize().x;
        int numY = t_image.getSize().y;
        int numZ = t_image.getSize().z;
        UShortImage image = new UShortImage(pixels, origin, extent, numX, numY, numZ);
        images[i] = image;
    }
    ;
    List<Double> t_imageTimeStamps = t_imageDataset.getImageTimeStamps();
    double[] timestamps = new double[t_imageTimeStamps.size()];
    for (int t = 0; t < t_imageTimeStamps.size(); t++) {
        timestamps[t] = t_imageTimeStamps.get(t);
    }
    ImageDataset imageDataset = new ImageDataset(images, timestamps, t_imageDataset.numZ);
    return imageDataset;
}
Also used : Origin(org.vcell.util.Origin) ImageDataset(cbit.vcell.VirtualMicroscopy.ImageDataset) Extent(org.vcell.util.Extent) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage)

Example 39 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class MicroscopyXmlReader method getUShortImage.

/**
 * This method returns a VCIMage object from a XML representation.
 * Creation date: (3/16/2001 3:41:24 PM)
 * @param param org.jdom.Element
 * @return VCImage
 * @throws XmlParseException
 */
private UShortImage getUShortImage(Element param) throws XmlParseException {
    // get the attributes
    Element tempelement = param.getChild(XMLTags.ImageDataTag);
    int aNumX = Integer.parseInt(tempelement.getAttributeValue(XMLTags.XAttrTag));
    int aNumY = Integer.parseInt(tempelement.getAttributeValue(XMLTags.YAttrTag));
    int aNumZ = Integer.parseInt(tempelement.getAttributeValue(XMLTags.ZAttrTag));
    int compressSize = Integer.parseInt(tempelement.getAttributeValue(XMLTags.CompressedSizeTag));
    final int BYTES_PER_SHORT = 2;
    int UNCOMPRESSED_SIZE_BYTES = aNumX * aNumY * aNumZ * BYTES_PER_SHORT;
    // getpixels
    String hexEncodedBytes = tempelement.getText();
    byte[] rawBytes = org.vcell.util.Hex.toBytes(hexEncodedBytes);
    ByteArrayInputStream rawByteArrayInputStream = new ByteArrayInputStream(rawBytes);
    InputStream rawInputStream = rawByteArrayInputStream;
    if (compressSize != UNCOMPRESSED_SIZE_BYTES) {
        rawInputStream = new InflaterInputStream(rawByteArrayInputStream);
    }
    byte[] shortsAsBytes = new byte[UNCOMPRESSED_SIZE_BYTES];
    int readCount = 0;
    try {
        while ((readCount += rawInputStream.read(shortsAsBytes, readCount, shortsAsBytes.length - readCount)) != shortsAsBytes.length) {
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new XmlParseException("error reading image pixels: ", e);
    } finally {
        if (rawInputStream != null) {
            try {
                rawInputStream.close();
            } catch (Exception e2) {
                e2.printStackTrace();
            }
        }
    }
    ByteBuffer byteBuffer = ByteBuffer.wrap(shortsAsBytes);
    short[] shortPixels = new short[aNumX * aNumY * aNumZ];
    for (int i = 0; i < shortPixels.length; i++) {
        shortPixels[i] = byteBuffer.getShort();
    }
    Element extentElement = param.getChild(XMLTags.ExtentTag);
    Extent extent = null;
    if (extentElement != null) {
        extent = vcellXMLReader.getExtent(extentElement);
    }
    Element originElement = param.getChild(XMLTags.OriginTag);
    Origin origin = null;
    if (originElement != null) {
        origin = vcellXMLReader.getOrigin(originElement);
    }
    // //set attributes
    // String name = this.unMangle( param.getAttributeValue(XMLTags.NameAttrTag) );
    // String annotation = param.getChildText(XMLTags.AnnotationTag);
    UShortImage newimage;
    try {
        newimage = new UShortImage(shortPixels, origin, extent, aNumX, aNumY, aNumZ);
    } catch (ImageException e) {
        e.printStackTrace();
        throw new XmlParseException("error reading image: ", e);
    }
    return newimage;
}
Also used : Origin(org.vcell.util.Origin) ImageException(cbit.image.ImageException) Extent(org.vcell.util.Extent) InflaterInputStream(java.util.zip.InflaterInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) InflaterInputStream(java.util.zip.InflaterInputStream) Element(org.jdom.Element) UShortImage(cbit.vcell.VirtualMicroscopy.UShortImage) XmlParseException(cbit.vcell.xml.XmlParseException) ByteBuffer(java.nio.ByteBuffer) XmlParseException(cbit.vcell.xml.XmlParseException) ImageException(cbit.image.ImageException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 40 with Extent

use of org.vcell.util.Extent in project vcell by virtualcell.

the class VFrapXmlHelper method LoadVFrapSpecialImages.

// // load and compute prebleach average and first postbleach images
// public void LoadVFrapSpecialImages(AnnotatedImageDataset annotatedImages, int startingIndexRecovery)
// {
// // unnormalized prebleach average
// prebleachAvg = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// for(int j = 0; j < prebleachAvg.length; j++)
// {
// double pixelTotal = 0;
// for(int i = 0 ; i < startingIndexRecovery; i++)
// {
// pixelTotal = pixelTotal + (annotatedImages.getImageDataset().getImage(0, 0, i).getPixels()[j] & 0x0000FFFF);
// }
// prebleachAvg[j] = pixelTotal/startingIndexRecovery;
// }
// 
// // unnormalized first post bleach
// firstPostBleach = new double[annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getNumXYZ()];
// short[] pixels = annotatedImages.getImageDataset().getImage(0, 0, startingIndexRecovery).getPixels();
// for(int i = 0; i< pixels.length; i++)
// {
// firstPostBleach[i] = pixels[i] & 0x0000FFFF;
// }
// }
// 
// Locate the special images within the vFrap files and load them in memory
// 
public static boolean LoadVFrapSpecialImages(Hashtable<String, Object> hashTable, Element vFrapRoot) throws IOException, DataAccessException, MathException, ImageException {
    // ------ parse the vfrap file and the log/zip files referred within -----
    // many channels of 1 timepoint each
    int NumTimePoints = 1;
    // the channels: prebleach, postbleach, roi1, roi2 ... roiN
    int NumChannels = tokenNames.length;
    String[] channelNames = new String[NumChannels];
    VariableType[] channelTypes = new VariableType[NumChannels];
    DataSymbolType[] channelVFrapImageType = new DataSymbolType[NumChannels];
    double[][][] pixData = new double[NumTimePoints][NumChannels][];
    // get the path of the file tagged with "ROIExternalDataInfoTag" and open it
    Element roiExternalDataInfoElement = vFrapRoot.getChild(MicroscopyXMLTags.ROIExternalDataInfoTag);
    if (roiExternalDataInfoElement == null) {
        // can't load FieldData for some reason, fall back to importing the biomodel only
        return false;
    }
    // <ROIExternalDataInfo Filename="c:\vFrap\VirtualMicroscopy\SimulationData\SimID_1282941232246_0_.log">
    // <ExternalDataIdentifier Name="timeData" KeyValue="1282941232246" OwnerName="SimulationData" OwnerKey="0" />
    // </ImageDatasetExternalDataInfo>
    // c:\VirtualMicroscopy\SimulationData\SimID_1284149203811_0_.log
    String filename = (roiExternalDataInfoElement).getAttributeValue("Filename");
    Element childElement = (roiExternalDataInfoElement).getChild("ExternalDataIdentifier");
    if (childElement == null) {
        // can't load FieldData for some reason, fall back to importing the biomodel only
        return false;
    }
    StringTokenizer tokens = new StringTokenizer(filename, "/\\.");
    final ArrayList<String> tokenArray = new ArrayList<String>();
    while (tokens.hasMoreElements()) {
        tokenArray.add(tokens.nextToken());
    }
    final String dataID = tokenArray.get(tokenArray.size() - 2);
    final String userName = tokenArray.get(tokenArray.size() - 3);
    VCDataIdentifier vcDataIdentifier = new VCDataIdentifier() {

        public String getID() {
            return dataID;
        }

        public KeyValue getDataKey() {
            return null;
        }

        public User getOwner() {
            return new User(userName, new KeyValue("123345432334"));
        }
    };
    // ------- recover simulation data for this user name, load the images in memory ------------
    // ex  c:\\VirtualMicroscopy\\SimulationData
    String userDirName = filename.substring(0, filename.indexOf(dataID) - 1);
    File userDir = new File(userDirName);
    SimulationData.SimDataAmplistorInfo simDataAmplistorInfo = AmplistorUtils.getSimDataAmplistorInfoFromPropertyLoader();
    SimulationData simData = new SimulationData(vcDataIdentifier, userDir, null, simDataAmplistorInfo);
    // build a valid mesh in 2 steps, what we have in simData is incomplete
    CartesianMesh incompleteMesh = simData.getMesh();
    Extent extent = incompleteMesh.getExtent();
    ISize isize = new ISize(incompleteMesh.getSizeX(), incompleteMesh.getSizeY(), incompleteMesh.getSizeZ());
    Origin origin = new Origin(0, 0, 0);
    CartesianMesh mesh = 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));
    DataIdentifier[] dataIdentifiers = simData.getVarAndFunctionDataIdentifiers(null);
    double[] times = simData.getDataTimes();
    for (int i = 0; i < dataIdentifiers.length; i++) {
        // ex: prebleach_avg, postbleach_first, postbleach_last, bleached_mask, cell_mask, ring1_mask,... ring8_mask
        System.out.println(dataIdentifiers[i].getName());
        for (double time : times) {
            // this loops only once, we have just 1 timepoint for each "special" image
            SimDataBlock simDataBlock = simData.getSimDataBlock(null, dataIdentifiers[i].getName(), time);
            channelNames[i] = dataIdentifiers[i].getName();
            channelTypes[i] = VariableType.VOLUME;
            channelVFrapImageType[i] = SymbolEquivalence.typeFromToken(dataIdentifiers[i].getName());
            pixData[0][i] = simDataBlock.getData();
            // var = prebleach_avg, time = 0.0, data = { 1.0832530361887216 1.0832530361887216 1.0832530361887216 1.0 .... }
            System.out.print("var = " + dataIdentifiers[i].getName() + ", time = " + time + ", data = { ");
            // show a few
            for (int j = 0; j < 5; j++) {
                System.out.print(pixData[0][i][j] + " ");
            }
            // show a few
            ;
            // show a few
            System.out.println(" ... ");
        }
    }
    hashTable.put("mesh", mesh);
    hashTable.put("pixData", pixData);
    hashTable.put("channelNames", channelNames);
    hashTable.put("channelTypes", channelTypes);
    hashTable.put("channelVFrapImageType", channelVFrapImageType);
    return true;
}
Also used : Origin(org.vcell.util.Origin) User(org.vcell.util.document.User) KeyValue(org.vcell.util.document.KeyValue) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) DataIdentifier(cbit.vcell.simdata.DataIdentifier) ExternalDataIdentifier(org.vcell.util.document.ExternalDataIdentifier) Extent(org.vcell.util.Extent) ISize(org.vcell.util.ISize) Element(org.jdom.Element) ArrayList(java.util.ArrayList) SimDataBlock(cbit.vcell.simdata.SimDataBlock) VariableType(cbit.vcell.math.VariableType) VCImageUncompressed(cbit.image.VCImageUncompressed) StringTokenizer(java.util.StringTokenizer) CartesianMesh(cbit.vcell.solvers.CartesianMesh) SimulationData(cbit.vcell.simdata.SimulationData) DataSymbolType(cbit.vcell.data.DataSymbol.DataSymbolType) RegionImage(cbit.vcell.geometry.RegionImage) VCDataIdentifier(org.vcell.util.document.VCDataIdentifier) File(java.io.File)

Aggregations

Extent (org.vcell.util.Extent)96 Origin (org.vcell.util.Origin)58 ISize (org.vcell.util.ISize)52 VCImageUncompressed (cbit.image.VCImageUncompressed)23 ImageException (cbit.image.ImageException)19 VCImage (cbit.image.VCImage)19 CartesianMesh (cbit.vcell.solvers.CartesianMesh)19 RegionImage (cbit.vcell.geometry.RegionImage)17 Geometry (cbit.vcell.geometry.Geometry)16 Expression (cbit.vcell.parser.Expression)16 FieldDataFileOperationSpec (cbit.vcell.field.io.FieldDataFileOperationSpec)15 IOException (java.io.IOException)15 UShortImage (cbit.vcell.VirtualMicroscopy.UShortImage)13 BioModel (cbit.vcell.biomodel.BioModel)13 SubVolume (cbit.vcell.geometry.SubVolume)13 File (java.io.File)12 ArrayList (java.util.ArrayList)12 UserCancelException (org.vcell.util.UserCancelException)12 ExpressionException (cbit.vcell.parser.ExpressionException)10 ImageDataset (cbit.vcell.VirtualMicroscopy.ImageDataset)9