use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class XmlReader method getParticleJumpProcess.
private ParticleJumpProcess getParticleJumpProcess(Element param, MathDescription md) throws XmlParseException {
// name
String name = unMangle(param.getAttributeValue(XMLTags.NameAttrTag));
ProcessSymmetryFactor processSymmetryFactor = null;
Attribute symmetryFactorAttr = param.getAttribute(XMLTags.ProcessSymmetryFactorAttrTag);
if (symmetryFactorAttr != null) {
processSymmetryFactor = new ProcessSymmetryFactor(Double.parseDouble(symmetryFactorAttr.getValue()));
}
// selected particle
List<ParticleVariable> varList = new ArrayList<ParticleVariable>();
Iterator<Element> iterator = param.getChildren(XMLTags.SelectedParticleTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempelement = (Element) iterator.next();
String varname = unMangle(tempelement.getAttributeValue(XMLTags.NameAttrTag));
Variable var = md.getVariable(varname);
if (!(var instanceof ParticleVariable)) {
throw new XmlParseException("Not a ParticleVariable in ParticleJumpProcess.");
}
varList.add((ParticleVariable) var);
}
// probability rate
JumpProcessRateDefinition jprd = null;
// for old models
Element pb = param.getChild(XMLTags.ParticleProbabilityRateTag, vcNamespace);
if (pb != null) {
Expression exp = unMangleExpression(pb.getText());
jprd = new MacroscopicRateConstant(exp);
} else // for new models
{
pb = param.getChild(XMLTags.MacroscopicRateConstantTag, vcNamespace);
if (// jump process rate defined by macroscopic rate constant
pb != null) {
Expression exp = unMangleExpression(pb.getText());
jprd = new MacroscopicRateConstant(exp);
} else // jump process rate defined by binding radius
{
pb = param.getChild(XMLTags.InteractionRadiusTag, vcNamespace);
if (pb != null) {
Expression exp = unMangleExpression(pb.getText());
jprd = new InteractionRadius(exp);
}
}
}
// add actions
List<Action> actionList = new ArrayList<Action>();
iterator = param.getChildren(XMLTags.ActionTag, vcNamespace).iterator();
while (iterator.hasNext()) {
Element tempelement = (Element) iterator.next();
try {
actionList.add(getAction(tempelement, md));
} catch (MathException e) {
e.printStackTrace();
throw new XmlParseException(e);
} catch (ExpressionException e) {
e.printStackTrace();
throw new XmlParseException(e);
}
}
ParticleJumpProcess jump = new ParticleJumpProcess(name, varList, jprd, actionList, processSymmetryFactor);
return jump;
}
use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class XmlReader method getAction.
/**
* This method returns a Action object from a XML element.
* Creation date: (7/24/2006 5:56:36 PM)
* @return cbit.vcell.math.Action
* @param param org.jdom.Element
* @exception cbit.vcell.xml.XmlParseException The exception description.
*/
private Action getAction(Element param, MathDescription md) throws XmlParseException, MathException, ExpressionException {
// retrieve values
String operation = unMangle(param.getAttributeValue(XMLTags.OperationAttrTag));
String operand = param.getText();
Expression exp = null;
if (operand != null && operand.length() != 0) {
exp = unMangleExpression(operand);
}
String name = unMangle(param.getAttributeValue(XMLTags.VarNameAttrTag));
Variable var = md.getVariable(name);
if (var == null) {
throw new MathFormatException("variable " + name + " not defined");
}
if (!(var instanceof StochVolVariable) && !(var instanceof ParticleVariable)) {
throw new MathFormatException("variable " + name + " not a Stochastic Volume Variable");
}
try {
Action action = new Action(var, operation, exp);
return action;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class StochMathMapping method addJumpProcesses.
private void addJumpProcesses(VariableHash varHash, GeometryClass geometryClass, SubDomain subDomain) throws ExpressionException, ModelException, MappingException, MathException {
// set up jump processes
// get all the reactions from simulation context
// ReactionSpec[] reactionSpecs = simContext.getReactionContext().getReactionSpecs();---need to take a look here!
ModelUnitSystem modelUnitSystem = getSimulationContext().getModel().getUnitSystem();
ReactionSpec[] reactionSpecs = getSimulationContext().getReactionContext().getReactionSpecs();
for (ReactionSpec reactionSpec : reactionSpecs) {
if (reactionSpec.isExcluded()) {
continue;
}
// get the reaction
ReactionStep reactionStep = reactionSpec.getReactionStep();
Kinetics kinetics = reactionStep.getKinetics();
// probability parameter from modelUnitSystem
VCUnitDefinition probabilityParamUnit = modelUnitSystem.getStochasticSubstanceUnit().divideBy(modelUnitSystem.getTimeUnit());
// Different ways to deal with simple reactions and flux reactions
if (// simple reactions
reactionStep instanceof SimpleReaction) {
// check the reaction rate law to see if we need to decompose a reaction(reversible) into two jump processes.
// rate constants are important in calculating the probability rate.
// for Mass Action, we use KForward and KReverse,
// for General Kinetics we parse reaction rate J to see if it is in Mass Action form.
Expression forwardRate = null;
Expression reverseRate = null;
if (kinetics.getKineticsDescription().equals(KineticsDescription.MassAction) || kinetics.getKineticsDescription().equals(KineticsDescription.General)) {
Expression rateExp = new Expression(kinetics.getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate), reactionStep.getNameScope());
Parameter forwardRateParameter = null;
Parameter reverseRateParameter = null;
if (kinetics.getKineticsDescription().equals(KineticsDescription.MassAction)) {
forwardRateParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_KForward);
reverseRateParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_KReverse);
}
MassActionSolver.MassActionFunction maFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, rateExp, reactionStep);
if (maFunc.getForwardRate() == null && maFunc.getReverseRate() == null) {
throw new MappingException("Cannot generate stochastic math mapping for the reaction:" + reactionStep.getName() + "\nLooking for the rate function according to the form of k1*Reactant1^Stoir1*Reactant2^Stoir2...-k2*Product1^Stoip1*Product2^Stoip2.");
} else {
if (maFunc.getForwardRate() != null) {
forwardRate = maFunc.getForwardRate();
}
if (maFunc.getReverseRate() != null) {
reverseRate = maFunc.getReverseRate();
}
}
} else // if it's macro/microscopic kinetics, we'll have them set up as reactions with only forward rate.
if (kinetics.getKineticsDescription().equals(KineticsDescription.Macroscopic_irreversible) || kinetics.getKineticsDescription().equals(KineticsDescription.Microscopic_irreversible)) {
Expression Kon = getIdentifierSubstitutions(new Expression(reactionStep.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_KOn), getNameScope()), reactionStep.getKinetics().getKineticsParameterFromRole(Kinetics.ROLE_Binding_Radius).getUnitDefinition(), geometryClass);
if (Kon != null) {
Expression KonCopy = new Expression(Kon);
try {
MassActionSolver.substituteParameters(KonCopy, true).evaluateConstant();
forwardRate = new Expression(Kon);
} catch (ExpressionException e) {
throw new MathException(VCellErrorMessages.getMassActionSolverMessage(reactionStep.getName(), "Problem with Kon parameter in " + reactionStep.getName() + ": '" + KonCopy.infix() + "', " + e.getMessage()));
}
} else {
throw new MathException(VCellErrorMessages.getMassActionSolverMessage(reactionStep.getName(), "Kon parameter of " + reactionStep.getName() + " is null."));
}
}
boolean isForwardRatePresent = false;
boolean isReverseRatePresent = false;
if (forwardRate != null) {
isForwardRatePresent = true;
}
if (reverseRate != null) {
isReverseRatePresent = true;
}
// we process it as forward reaction
if ((isForwardRatePresent)) /*|| ((forwardRate == null) && (reverseRate == null))*/
{
// get jump process name
String jpName = TokenMangler.mangleToSName(reactionStep.getName());
// get probability
Expression exp = null;
// reactions are of mass action form
exp = getProbabilityRate(reactionStep, forwardRate, true);
ProbabilityParameter probParm = null;
try {
probParm = addProbabilityParameter(PARAMETER_PROBABILITYRATE_PREFIX + jpName, exp, PARAMETER_ROLE_P, probabilityParamUnit, reactionStep);
} catch (PropertyVetoException pve) {
pve.printStackTrace();
throw new MappingException(pve.getMessage());
}
// add probability to function or constant
varHash.addVariable(newFunctionOrConstant(getMathSymbol(probParm, geometryClass), getIdentifierSubstitutions(exp, probabilityParamUnit, geometryClass), geometryClass));
JumpProcess jp = new JumpProcess(jpName, new Expression(getMathSymbol(probParm, geometryClass)));
// actions
ReactionParticipant[] reacPart = reactionStep.getReactionParticipants();
for (int j = 0; j < reacPart.length; j++) {
Action action = null;
SpeciesCountParameter spCountParam = getSpeciesCountParameter(reacPart[j].getSpeciesContext());
if (reacPart[j] instanceof Reactant) {
// check if the reactant is a constant. If the species is a constant, there will be no action taken on this species
if (// not a constant
!simContext.getReactionContext().getSpeciesContextSpec(reacPart[j].getSpeciesContext()).isConstant()) {
int stoi = ((Reactant) reacPart[j]).getStoichiometry();
action = Action.createIncrementAction(varHash.getVariable(getMathSymbol(spCountParam, geometryClass)), new Expression(-stoi));
jp.addAction(action);
}
} else if (reacPart[j] instanceof Product) {
// check if the product is a constant. If the product is a constant, there will be no action taken on this species
if (// not a constant
!simContext.getReactionContext().getSpeciesContextSpec(reacPart[j].getSpeciesContext()).isConstant()) {
int stoi = ((Product) reacPart[j]).getStoichiometry();
action = Action.createIncrementAction(varHash.getVariable(getMathSymbol(spCountParam, geometryClass)), new Expression(stoi));
jp.addAction(action);
}
}
}
// add jump process to compartment subDomain
subDomain.addJumpProcess(jp);
}
if (// one more jump process for a reversible reaction
isReverseRatePresent) {
// get jump process name
String jpName = TokenMangler.mangleToSName(reactionStep.getName()) + PARAMETER_PROBABILITY_RATE_REVERSE_SUFFIX;
Expression exp = null;
// reactions are mass actions
exp = getProbabilityRate(reactionStep, reverseRate, false);
ProbabilityParameter probRevParm = null;
try {
probRevParm = addProbabilityParameter(PARAMETER_PROBABILITYRATE_PREFIX + jpName, exp, PARAMETER_ROLE_P_reverse, probabilityParamUnit, reactionStep);
} catch (PropertyVetoException pve) {
pve.printStackTrace();
throw new MappingException(pve.getMessage());
}
// add probability to function or constant
varHash.addVariable(newFunctionOrConstant(getMathSymbol(probRevParm, geometryClass), getIdentifierSubstitutions(exp, probabilityParamUnit, geometryClass), geometryClass));
JumpProcess jp = new JumpProcess(jpName, new Expression(getMathSymbol(probRevParm, geometryClass)));
// actions
ReactionParticipant[] reacPart = reactionStep.getReactionParticipants();
for (int j = 0; j < reacPart.length; j++) {
Action action = null;
SpeciesCountParameter spCountParam = getSpeciesCountParameter(reacPart[j].getSpeciesContext());
if (reacPart[j] instanceof Reactant) {
// check if the reactant is a constant. If the species is a constant, there will be no action taken on this species
if (// not a constant
!simContext.getReactionContext().getSpeciesContextSpec(reacPart[j].getSpeciesContext()).isConstant()) {
int stoi = ((Reactant) reacPart[j]).getStoichiometry();
action = Action.createIncrementAction(varHash.getVariable(getMathSymbol(spCountParam, geometryClass)), new Expression(stoi));
jp.addAction(action);
}
} else if (reacPart[j] instanceof Product) {
// check if the product is a constant. If the product is a constant, there will be no action taken on this species
if (// not a constant
!simContext.getReactionContext().getSpeciesContextSpec(reacPart[j].getSpeciesContext()).isConstant()) {
int stoi = ((Product) reacPart[j]).getStoichiometry();
action = Action.createIncrementAction(varHash.getVariable(getMathSymbol(spCountParam, geometryClass)), new Expression(-stoi));
jp.addAction(action);
}
}
}
// add jump process to compartment subDomain
subDomain.addJumpProcess(jp);
}
// end of if(isForwardRateNonZero), if(isReverseRateNonRate)
} else if (// flux reactions
reactionStep instanceof FluxReaction) {
// we could set jump processes for general flux rate in forms of p1*Sout + p2*Sin
if (kinetics.getKineticsDescription().equals(KineticsDescription.General) || kinetics.getKineticsDescription().equals(KineticsDescription.GeneralPermeability)) {
Expression fluxRate = new Expression(kinetics.getKineticsParameterFromRole(Kinetics.ROLE_ReactionRate), reactionStep.getNameScope());
// we have to pass the math description para to flux solver, coz somehow math description in simulation context is not updated.
// forward and reverse rate parameters may be null
Parameter forwardRateParameter = null;
Parameter reverseRateParameter = null;
if (kinetics.getKineticsDescription().equals(KineticsDescription.GeneralPermeability)) {
forwardRateParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_Permeability);
reverseRateParameter = kinetics.getKineticsParameterFromRole(Kinetics.ROLE_Permeability);
}
MassActionSolver.MassActionFunction fluxFunc = MassActionSolver.solveMassAction(forwardRateParameter, reverseRateParameter, fluxRate, (FluxReaction) reactionStep);
// create jump process for forward flux if it exists.
Expression rsStructureSize = new Expression(reactionStep.getStructure().getStructureSize(), getNameScope());
VCUnitDefinition probRateUnit = modelUnitSystem.getStochasticSubstanceUnit().divideBy(modelUnitSystem.getAreaUnit()).divideBy(modelUnitSystem.getTimeUnit());
Expression rsRateUnitFactor = getUnitFactor(probRateUnit.divideBy(modelUnitSystem.getFluxReactionUnit()));
if (fluxFunc.getForwardRate() != null && !fluxFunc.getForwardRate().isZero()) {
Expression rate = fluxFunc.getForwardRate();
// get species expression (depend on structure, if mem: Species/mem_Size, if vol: species*KMOLE/vol_size)
if (fluxFunc.getReactants().size() != 1) {
throw new MappingException("Flux " + reactionStep.getName() + " should have only one reactant.");
}
SpeciesContext scReactant = fluxFunc.getReactants().get(0).getSpeciesContext();
Expression scConcExpr = new Expression(getSpeciesConcentrationParameter(scReactant), getNameScope());
Expression probExp = Expression.mult(rate, rsRateUnitFactor, rsStructureSize, scConcExpr);
// jump process name
// +"_reverse";
String jpName = TokenMangler.mangleToSName(reactionStep.getName());
ProbabilityParameter probParm = null;
try {
probParm = addProbabilityParameter(PARAMETER_PROBABILITYRATE_PREFIX + jpName, probExp, PARAMETER_ROLE_P, probabilityParamUnit, reactionStep);
} catch (PropertyVetoException pve) {
pve.printStackTrace();
throw new MappingException(pve.getMessage());
}
// add probability to function or constant
String ms = getMathSymbol(probParm, geometryClass);
Expression is = getIdentifierSubstitutions(probExp, probabilityParamUnit, geometryClass);
Variable nfoc = newFunctionOrConstant(ms, is, geometryClass);
varHash.addVariable(nfoc);
JumpProcess jp = new JumpProcess(jpName, new Expression(getMathSymbol(probParm, geometryClass)));
// actions
Action action = null;
SpeciesContext sc = fluxFunc.getReactants().get(0).getSpeciesContext();
if (!simContext.getReactionContext().getSpeciesContextSpec(sc).isConstant()) {
SpeciesCountParameter spCountParam = getSpeciesCountParameter(sc);
action = Action.createIncrementAction(varHash.getVariable(getMathSymbol(spCountParam, geometryClass)), new Expression(-1));
jp.addAction(action);
}
sc = fluxFunc.getProducts().get(0).getSpeciesContext();
if (!simContext.getReactionContext().getSpeciesContextSpec(sc).isConstant()) {
SpeciesCountParameter spCountParam = getSpeciesCountParameter(sc);
action = Action.createIncrementAction(varHash.getVariable(getMathSymbol(spCountParam, geometryClass)), new Expression(1));
jp.addAction(action);
}
subDomain.addJumpProcess(jp);
}
// create jump process for reverse flux if it exists.
if (fluxFunc.getReverseRate() != null && !fluxFunc.getReverseRate().isZero()) {
// jump process name
String jpName = TokenMangler.mangleToSName(reactionStep.getName()) + PARAMETER_PROBABILITY_RATE_REVERSE_SUFFIX;
Expression rate = fluxFunc.getReverseRate();
// get species expression (depend on structure, if mem: Species/mem_Size, if vol: species*KMOLE/vol_size)
if (fluxFunc.getProducts().size() != 1) {
throw new MappingException("Flux " + reactionStep.getName() + " should have only one product.");
}
SpeciesContext scProduct = fluxFunc.getProducts().get(0).getSpeciesContext();
Expression scConcExpr = new Expression(getSpeciesConcentrationParameter(scProduct), getNameScope());
Expression probExp = Expression.mult(rate, rsRateUnitFactor, rsStructureSize, scConcExpr);
ProbabilityParameter probRevParm = null;
try {
probRevParm = addProbabilityParameter(PARAMETER_PROBABILITYRATE_PREFIX + jpName, probExp, PARAMETER_ROLE_P_reverse, probabilityParamUnit, reactionStep);
} catch (PropertyVetoException pve) {
pve.printStackTrace();
throw new MappingException(pve.getMessage());
}
// add probability to function or constant
varHash.addVariable(newFunctionOrConstant(getMathSymbol(probRevParm, geometryClass), getIdentifierSubstitutions(probExp, probabilityParamUnit, geometryClass), geometryClass));
JumpProcess jp = new JumpProcess(jpName, new Expression(getMathSymbol(probRevParm, geometryClass)));
// actions
Action action = null;
SpeciesContext sc = fluxFunc.getReactants().get(0).getSpeciesContext();
if (!simContext.getReactionContext().getSpeciesContextSpec(sc).isConstant()) {
SpeciesCountParameter spCountParam = getSpeciesCountParameter(sc);
action = Action.createIncrementAction(varHash.getVariable(getMathSymbol(spCountParam, geometryClass)), new Expression(1));
jp.addAction(action);
}
sc = fluxFunc.getProducts().get(0).getSpeciesContext();
if (!simContext.getReactionContext().getSpeciesContextSpec(sc).isConstant()) {
SpeciesCountParameter spCountParam = getSpeciesCountParameter(sc);
action = Action.createIncrementAction(varHash.getVariable(getMathSymbol(spCountParam, geometryClass)), new Expression(-1));
jp.addAction(action);
}
subDomain.addJumpProcess(jp);
}
}
}
// end of if (simplereaction)...else if(fluxreaction)
}
// end of reaction step loop
}
use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class FastSystemAnalyzer method checkLinearity.
/**
* @exception java.lang.Exception The exception description.
*/
private void checkLinearity() throws MathException, ExpressionException {
Enumeration<Variable> enum1 = fastVarList.elements();
while (enum1.hasMoreElements()) {
Variable var = enum1.nextElement();
//
// d invariant
// for each variable, make sure ------------- = constant;
// d Var
//
Enumeration<FastInvariant> enum_fi = fastSystem.getFastInvariants();
while (enum_fi.hasMoreElements()) {
FastInvariant fi = enum_fi.nextElement();
Expression exp = fi.getFunction().differentiate(var.getName());
exp = MathUtilities.substituteFunctions(exp, this).flatten();
if (!exp.isNumeric()) {
// If expression is in terms of 'x','y','z' - then its ok - relax the constant requirement.
String[] symbols = exp.getSymbols();
for (int i = 0; i < symbols.length; i++) {
if (!symbols[i].equals(ReservedVariable.X.getName()) && !symbols[i].equals(ReservedVariable.Y.getName()) && !symbols[i].equals(ReservedVariable.Z.getName()) && !symbols[i].equals(ReservedVariable.TIME.getName())) {
throw new MathException("FastInvariant " + fi.getFunction().toString() + " isn't linear, d/d(" + var.getName() + ") = " + exp.toString());
}
}
}
}
}
}
use of cbit.vcell.math.MathException in project vcell by virtualcell.
the class DataSetControllerImpl method getLineScan.
/**
* This method was created by a SmartGuide.
* @return cbit.plot.PlotData
* @param varName java.lang.String
* @param begin cbit.vcell.math.CoordinateIndex
* @param end cbit.vcell.math.CoordinateIndex
*/
public PlotData getLineScan(OutputContext outputContext, VCDataIdentifier vcdID, String varName, double time, SpatialSelection spatialSelection) throws DataAccessException, MathException {
try {
if (spatialSelection == null) {
throw new IllegalArgumentException("null spatialSelection");
}
if (spatialSelection.isPoint()) {
throw new RuntimeException("'Point' spatialSelection not expected");
}
double[] dataTimes = getDataSetTimes(vcdID);
if (dataTimes == null || dataTimes.length <= 0) {
return null;
}
CartesianMesh mesh = getMesh(vcdID);
// mesh is transient and is null if we got here by a serialized path (e.g. rmi)
spatialSelection.setMesh(mesh);
SimDataBlock simDataBlock = getSimDataBlock(outputContext, vcdID, varName, time);
if (simDataBlock == null) {
return null;
}
DataIdentifier dataIdentifier = null;
try {
DataIdentifier[] dataIdentifiers = getDataIdentifiers(outputContext, vcdID);
for (int i = 0; i < dataIdentifiers.length; i++) {
if (dataIdentifiers[i].getName().equals(varName)) {
dataIdentifier = dataIdentifiers[i];
}
}
} catch (IOException e) {
throw new DataAccessException(e.getMessage());
}
double[] data = simDataBlock.getData();
if (data == null) {
return null;
}
if (spatialSelection instanceof SpatialSelectionVolume) {
SpatialSelectionVolume ssVolume = (SpatialSelectionVolume) spatialSelection;
SpatialSelection.SSHelper ssvHelper = ssVolume.getIndexSamples(0.0, 1.0);
if (dataIdentifier.getVariableType().equals(VariableType.VOLUME)) {
ssvHelper.initializeValues_VOLUME(data);
} else if (dataIdentifier.getVariableType().equals(VariableType.VOLUME_REGION)) {
ssvHelper.initializeValues_VOLUMEREGION(data);
} else {
throw new RuntimeException(SpatialSelectionVolume.class.getName() + " does not support variableType=" + dataIdentifier.getVariableType());
}
try {
if (ssvHelper.getMembraneIndexesInOut() != null && ssvHelper.getMembraneIndexesInOut().length > 0) {
adjustMembraneAdjacentVolumeValues(outputContext, new double[][] { ssvHelper.getSampledValues() }, false, simDataBlock, ssvHelper.getSampledIndexes(), ssvHelper.getMembraneIndexesInOut(), vcdID, varName, mesh, // PostProcess never calls LineScan so send in VCell times
new TimeInfo(vcdID, time, 1, time, getDataSetTimes(vcdID)));
}
} catch (Exception e) {
throw new DataAccessException("Error getLineScan adjustingMembraneValues\n" + e.getMessage(), e);
}
double[] values = ssvHelper.getSampledValues();
if (mesh.isChomboMesh()) {
// convert NaN to 0
for (int i = 0; i < values.length; i++) {
if (Double.isNaN(values[i])) {
values[i] = 0;
}
}
}
return new PlotData(ssvHelper.getWorldCoordinateLengths(), values);
} else if (spatialSelection instanceof SpatialSelectionContour) {
//
// get length of span (in microns)
//
double lengthMicrons = spatialSelection.getLengthInMicrons();
if (lengthMicrons <= 0) {
return null;
}
int sizeScan;
int[] sampleIndexes = null;
double[] lineScan = null;
double[] distance = null;
SpatialSelectionContour ssContour = (SpatialSelectionContour) spatialSelection;
sampleIndexes = ssContour.getIndexSamples();
sizeScan = sampleIndexes.length;
//
if (dataIdentifier.getVariableType().equals(VariableType.CONTOUR_REGION)) {
for (int i = 0; i < sampleIndexes.length; i++) {
sampleIndexes[i] = mesh.getContourRegionIndex(sampleIndexes[i]);
}
}
lineScan = new double[sizeScan];
distance = new double[sizeScan];
for (int i = 0; i < sizeScan; i++) {
lineScan[i] = data[sampleIndexes[i]];
distance[i] = (((double) i) / (sizeScan - 1)) * lengthMicrons;
}
return new PlotData(distance, lineScan);
} else if (spatialSelection instanceof SpatialSelectionMembrane) {
SpatialSelectionMembrane ssMembrane = (SpatialSelectionMembrane) spatialSelection;
SpatialSelection.SSHelper ssmHelper = ssMembrane.getIndexSamples();
if (dataIdentifier.getVariableType().equals(VariableType.MEMBRANE)) {
ssmHelper.initializeValues_MEMBRANE(data);
} else if (dataIdentifier.getVariableType().equals(VariableType.MEMBRANE_REGION)) {
ssmHelper.initializeValues_MEMBRANEREGION(data);
} else {
throw new RuntimeException(SpatialSelectionMembrane.class.getName() + " does not support variableType=" + dataIdentifier.getVariableType());
}
return new PlotData(ssmHelper.getWorldCoordinateLengths(), ssmHelper.getSampledValues());
} else {
throw new RuntimeException("unexpected SpatialSelection type " + spatialSelection.getClass().toString());
}
} catch (DataAccessException e) {
lg.error(e.getMessage(), e);
throw e;
} catch (IOException e) {
lg.error(e.getMessage(), e);
throw new DataAccessException(e.getMessage());
}
}
Aggregations