use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class FRAPStudy method getROIDataGenerator.
public ROIDataGenerator getROIDataGenerator(LocalWorkspace localWorkspace) {
// create ROI image
short[] roiFieldData = null;
ROI[] rois = getFrapData().getRois();
if (rois.length > 0) {
Extent extent = rois[0].getRoiImages()[0].getExtent();
ISize isize = rois[0].getISize();
int numROIX = rois[0].getISize().getX();
int numROIY = rois[0].getISize().getY();
roiFieldData = new short[numROIX * numROIY];
short regionCounter = 1;
for (int roiIdx = FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED_RING1.ordinal(); roiIdx < rois.length; roiIdx++) {
short[] roiImg = rois[roiIdx].getPixelsXYZ();
for (int pixelIdx = 0; pixelIdx < (numROIX * numROIY); pixelIdx++) {
if (roiImg[pixelIdx] > 0) {
roiFieldData[pixelIdx] = regionCounter;
}
}
regionCounter++;
}
// create field data
int NumTimePoints = 1;
// 8 rois integrated into 1 image
int NumChannels = 1;
short[][][] pixData = new short[NumTimePoints][NumChannels][];
pixData[0][0] = roiFieldData;
// get extental data id
ExternalDataIdentifier newROIExtDataID = FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_SUMDATA_NAME).getExternalDataIdentifier();
CartesianMesh cartesianMesh;
try {
cartesianMesh = getCartesianMesh();
Origin origin = new Origin(0, 0, 0);
FieldDataFileOperationSpec fdos = new FieldDataFileOperationSpec();
fdos.opType = FieldDataFileOperationSpec.FDOS_ADD;
fdos.cartesianMesh = cartesianMesh;
fdos.shortSpecData = pixData;
fdos.specEDI = newROIExtDataID;
fdos.varNames = new String[] { "roiSumDataVar" };
fdos.owner = LocalWorkspace.getDefaultOwner();
fdos.times = new double[] { 0.0 };
fdos.variableTypes = new VariableType[] { VariableType.VOLUME };
fdos.origin = origin;
fdos.extent = extent;
fdos.isize = isize;
localWorkspace.getDataSetControllerImpl().fieldDataFileOperation(fdos);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return new ROIDataGenerator(ROI_EXTDATA_NAME, /*name*/
new int[] { 0 }, /* volumePoints*/
new int[0], /* membranePoints*/
regionCounter, /*numRegions*/
0, /*zSlice*/
newROIExtDataID.getKey(), /* fieldDataKey, sample image*/
new FieldFunctionArguments(FRAPStudy.ROI_SUMDATA_NAME, "roiSumDataVar", new Expression(0), VariableType.VOLUME), /*FieldFunctionArguments, sample image*/
false);
}
return null;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class ROIDataGenerator method getSampleImageFieldData.
public FieldDataIdentifierSpec getSampleImageFieldData(User user) {
// key
String key = fieldDataKey.toString();
String fieldInput = fieldFuncArguments.infix();
StringTokenizer st = null;
int index = fieldInput.indexOf(FieldFunctionDefinition.FUNCTION_name);
if (index >= 0) {
st = new StringTokenizer(fieldInput.substring(index), "\n");
if (st.hasMoreTokens()) {
String fieldFunction = st.nextToken();
try {
Expression exp = new Expression(fieldFunction);
FieldFunctionArguments[] ffa = FieldUtilities.getFieldFunctionArguments(exp);
return new FieldDataIdentifierSpec(ffa[0], new ExternalDataIdentifier(KeyValue.fromString(key), user, ffa[0].getFieldName()));
} catch (ExpressionException e) {
e.printStackTrace();
throw new RuntimeException(e.getMessage());
} catch (Exception e) {
e.printStackTrace();
throw new RuntimeException("Failed to load data processing script.");
}
}
}
return null;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class ReactionDominantTest method solve.
private OptimizationResultSet solve() throws ExpressionException, IOException {
Expression Fbleached_bleachFastExp = new Expression(Fbleached_bleachFast);
Expression OmegaExp = new Expression(strOmega);
Expression Omega_cExp = new Expression(strOmega_c);
Expression WExp = new Expression(strW);
Fbleached_bleachFastExp.substituteInPlace(OmegaExp, new Expression(Omega));
Fbleached_bleachFastExp.substituteInPlace(Omega_cExp, new Expression(Omega_c));
Fbleached_bleachFastExp.substituteInPlace(WExp, new Expression(W));
Parameter[] parameters = new Parameter[] { para_alpha, para_Kon_star, para_Koff };
// Expression Fbleached_bleachFast = Fbleached_bleachFastExp.flatten();
// choose optimization solver, currently we have Powell and CFSQP
PowellOptimizationSolver optService = new PowellOptimizationSolver();
OptimizationSpec optSpec = new OptimizationSpec();
// create simple reference data
double[][] realData = new double[2][t.length];
for (int i = 0; i < t.length; i++) {
realData[0][i] = t[i];
realData[1][i] = data_bleached[i];
}
String[] colNames = new String[] { "t", "intensity" };
double[] weights = new double[] { 1.0, 1.0 };
SimpleReferenceData refData = new SimpleReferenceData(colNames, weights, realData);
// send to optimization service
ExplicitFitObjectiveFunction.ExpressionDataPair oneExpDataPair = new ExplicitFitObjectiveFunction.ExpressionDataPair(Fbleached_bleachFastExp.flatten(), 1);
ExplicitFitObjectiveFunction.ExpressionDataPair[] expDataPairs = new ExplicitFitObjectiveFunction.ExpressionDataPair[] { oneExpDataPair };
optSpec.setObjectiveFunction(new ExplicitFitObjectiveFunction(expDataPairs, refData));
optSpec.setComputeProfileDistributions(true);
// get the initial guess to send it to the f() function. ....
for (int i = 0; i < parameters.length; i++) {
optSpec.addParameter(parameters[i]);
}
// Parameters in OptimizationSolverSpec are solver type and objective function change tolerance.
OptimizationSolverSpec optSolverSpec = new OptimizationSolverSpec(OptimizationSolverSpec.SOLVERTYPE_POWELL, 0.000001);
OptSolverCallbacks optSolverCallbacks = new DefaultOptSolverCallbacks();
OptimizationResultSet optResultSet = null;
optResultSet = optService.solve(optSpec, optSolverSpec, optSolverCallbacks);
String[] paramNames = optResultSet.getOptSolverResultSet().getParameterNames();
ArrayList<ProfileDistribution> profileDistributionList = optResultSet.getOptSolverResultSet().getProfileDistributionList();
for (int i = 0; i < profileDistributionList.size(); i++) {
outputProfileLikelihood(profileDistributionList.get(i), i, paramNames[i], new File(fileDir));
}
return optResultSet;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class AbstractMathMapping method getFluxCorrectionParameter.
/**
* This method was created in VisualAge.
* @return Expression
*/
public KFluxParameter getFluxCorrectionParameter(StructureMapping sourceStructureMapping, StructureMapping targetStructureMapping) throws MappingException, ExpressionException {
for (int i = 0; i < fieldMathMappingParameters.length; i++) {
if (fieldMathMappingParameters[i] instanceof KFluxParameter) {
KFluxParameter kfluxParameter = (KFluxParameter) fieldMathMappingParameters[i];
if (kfluxParameter.getSourceStructureMapping() == sourceStructureMapping && kfluxParameter.getTargetStructureMapping() == targetStructureMapping) {
return kfluxParameter;
}
}
}
//
// not found, add new parameter
//
String sourceName = sourceStructureMapping.getStructure().getNameScope().getName();
String targetName = targetStructureMapping.getStructure().getNameScope().getName();
Parameter sourceSizeParameter = null;
Parameter targetSizeParameter = null;
if (sourceStructureMapping.getGeometryClass() instanceof CompartmentSubVolume) {
sourceSizeParameter = sourceStructureMapping.getSizeParameter();
} else {
sourceSizeParameter = sourceStructureMapping.getUnitSizeParameter();
}
if (targetStructureMapping.getGeometryClass() instanceof CompartmentSubVolume) {
targetSizeParameter = targetStructureMapping.getSizeParameter();
if (targetSizeParameter == null || targetSizeParameter.getExpression() == null) {
throw new MappingException("structure mapping sizes not set for application " + simContext.getName());
}
} else {
targetSizeParameter = targetStructureMapping.getUnitSizeParameter();
}
Expression fluxCorrectionExp = Expression.div(new Expression(sourceSizeParameter, simContext.getNameScope()), new Expression(targetSizeParameter, simContext.getNameScope()));
VCUnitDefinition sourceSizeUnit = sourceSizeParameter.getUnitDefinition();
VCUnitDefinition targetSizeUnit = targetSizeParameter.getUnitDefinition();
VCUnitDefinition unit = sourceSizeUnit.divideBy(targetSizeUnit);
fluxCorrectionExp.bindExpression(this);
String parameterName = PARAMETER_K_FLUX_PREFIX + sourceName + "_" + targetName;
KFluxParameter kFluxParameter = new KFluxParameter(parameterName, fluxCorrectionExp, unit, sourceStructureMapping, targetStructureMapping);
MathMappingParameter[] newMathMappingParameters = (MathMappingParameter[]) BeanUtils.addElement(this.fieldMathMappingParameters, kFluxParameter);
try {
setMathMapppingParameters(newMathMappingParameters);
} catch (java.beans.PropertyVetoException e) {
e.printStackTrace(System.out);
throw new RuntimeException(e.getMessage());
}
return kFluxParameter;
}
use of cbit.vcell.parser.Expression in project vcell by virtualcell.
the class AbstractMathMapping method substituteGlobalParameters.
private Expression substituteGlobalParameters(Expression exp) throws ExpressionException {
Expression exp2 = new Expression(exp);
//
// do until no more globals to substitute
//
int count = 0;
ModelParameter[] modelParams = simContext.getModel().getModelParameters();
while (true) {
if (count++ > 30) {
throw new ExpressionBindingException("infinite loop in eliminating function nesting");
}
//
// get all symbols (identifiers), make list of globals used
//
String[] symbols = exp2.getSymbols();
Vector<ModelParameter> globalsVector = new Vector<ModelParameter>();
if (symbols != null) {
for (int i = 0; i < symbols.length; i++) {
for (int j = 0; j < modelParams.length; j++) {
if (symbols[i].equals(modelParams[j].getName())) {
globalsVector.addElement(modelParams[j]);
}
}
}
}
//
if (globalsVector.size() == 0) {
break;
}
//
for (int i = 0; i < globalsVector.size(); i++) {
ModelParameter mp = globalsVector.elementAt(i);
Expression mpExp = new Expression(mp.getName());
exp2.substituteInPlace(mpExp, mp.getExpression());
}
}
// exp2.bindExpression(simContext.getModel());
return exp2;
}
Aggregations