use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.
the class EstParams_OneDiffComponentPanel method plotDerivedSimulationResults.
private void plotDerivedSimulationResults(AnalysisParameters[] anaParams) {
try {
String description = null;
int totalROIlen = FRAPData.VFRAP_ROI_ENUM.values().length;
boolean[] wantsROITypes = new boolean[totalROIlen];
System.arraycopy(frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation(), 0, wantsROITypes, 0, totalROIlen);
ODESolverResultSet fitOdeSolverResultSet = new ODESolverResultSet();
fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
for (int j = 0; j < totalROIlen; j++) {
if (!wantsROITypes[j]) {
continue;
}
String currentROIName = FRAPData.VFRAP_ROI_ENUM.values()[j].name();
String name = (description == null ? /*"sim D="+diffusionRates[diffusionRateIndex]+"::"*/
"" : description) + currentROIName;
fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
}
int totalWantedROIlen = 0;
for (int i = 0; i < wantsROITypes.length; i++) {
if (wantsROITypes[i]) {
totalWantedROIlen++;
}
}
//
// populate time
//
double[] shiftedSimTimes = frapOptData.getReducedExpTimePoints();
int startIndexRecovery = frapOptData.getExpFrapStudy().getStartingIndexForRecovery();
for (int j = 0; j < shiftedSimTimes.length; j++) {
double[] row = new double[totalWantedROIlen + 1];
row[0] = shiftedSimTimes[j] + frapOptData.getExpFrapStudy().getFrapData().getImageDataset().getImageTimeStamps()[startIndexRecovery];
fitOdeSolverResultSet.addRow(row);
}
// populate values
double[][] currentOptFitData = getPureDiffusionPanel().getCurrentFitData();
// store results
setCurrentEstimationResults(currentOptFitData);
if (allDataHash != null && currentOptFitData != null) {
// populate optimization data
int columncounter = 0;
for (int j = 0; j < totalROIlen; j++) {
if (!wantsROITypes[j]) {
continue;
}
// if(!isSimData) //opt data
// {
double[] values = currentOptFitData[j];
for (int k = 0; k < values.length; k++) {
fitOdeSolverResultSet.setValue(k, columncounter + 1, values[k]);
}
// }
columncounter++;
}
// boolean hasSimData = false;
// anaParams[0] is the key in allDataHash to get the dataSource[]:exp & sim
DataSource[] selectedRowDataSourceArr = allDataHash.get(anaParams[0]);
if (selectedRowDataSourceArr != null) {
// referenceData is the exp data
// ReferenceData referenceData = (ReferenceData)selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
// new DataSource.DataSourceReferenceData("exp", referenceData);
final DataSource expDataSource = selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
DataSource optDataSource = new DataSource.DataSourceRowColumnResultSet("opt", fitOdeSolverResultSet);
DataSource[] newDataSourceArr = new DataSource[2];
newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_SIMDATASOURCE] = optDataSource;
if (currentOptFitData == null) {
multisourcePlotPane.setDataSources(null);
} else {
// the following paragraph of code is just to get selected color for selected ROIs
// and make them the same as we show on ChooseModel_RoiForErrorPanel/RoiForErrorPanel
// double valid ROI colors (not include cell and background)
int validROISize = FRAPData.VFRAP_ROI_ENUM.values().length - 2;
Color[] fullColors = ColorUtil.generateAutoColor(validROISize * 2, getBackground(), new Integer(0));
boolean[] selectedROIs = frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation();
int selectedROICounter = 0;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i]) {
selectedROICounter++;
}
}
// double the size, each ROI is a comparison of exp and sim
Color[] selectedColors = new Color[selectedROICounter * 2];
int selectedColorIdx = 0;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i] && i == 0) {
selectedColors[selectedColorIdx] = fullColors[i];
selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i + validROISize];
selectedColorIdx++;
}
if (// skip cell and background ROIs
selectedROIs[i] && i > 2) {
selectedColors[selectedColorIdx] = fullColors[i - 2];
selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i - 2 + validROISize];
selectedColorIdx++;
}
}
int[] selectedIndices = multisourcePlotPane.getUnsortedSelectedIndices();
multisourcePlotPane.setDataSources(newDataSourceArr, selectedColors);
if (selectedIndices.length == 0) {
multisourcePlotPane.selectAll();
} else {
multisourcePlotPane.setUnsortedSelectedIndices(selectedIndices);
}
}
}
}
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(this, "Error graphing Optimizer data " + e2.getMessage());
}
}
use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.
the class EstParams_ReacBindingPanel method plotDerivedSimulationResults.
private void plotDerivedSimulationResults(AnalysisParameters[] anaParams) {
try {
if (getCurrentSimResults() == null || getCurrentRawSimTimePoints() == null || allDataHash == null || allDataHash.get(anaParams[0]) == null || (allDataHash.get(anaParams[0])[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE]) == null) {
multisourcePlotPane.setDataSources(null);
return;
}
String description = null;
int totalROIlen = FRAPData.VFRAP_ROI_ENUM.values().length;
boolean[] wantsROITypes = new boolean[totalROIlen];
System.arraycopy(frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation(), 0, wantsROITypes, 0, totalROIlen);
ODESolverResultSet simSolverResultSet = new ODESolverResultSet();
simSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
for (int j = 0; j < totalROIlen; j++) {
if (!wantsROITypes[j]) {
continue;
}
String currentROIName = FRAPData.VFRAP_ROI_ENUM.values()[j].name();
String name = (description == null ? /*"sim D="+diffusionRates[diffusionRateIndex]+"::"*/
"" : description) + currentROIName;
simSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(name));
}
int totalWantedROIlen = 0;
for (int i = 0; i < wantsROITypes.length; i++) {
if (wantsROITypes[i]) {
totalWantedROIlen++;
}
}
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
//
// populate time
//
double[] shiftedSimTimes = getCurrentRawSimTimePoints();
int startIndexRecovery = fStudy.getStartingIndexForRecovery();
for (int j = 0; j < shiftedSimTimes.length; j++) {
double[] row = new double[totalWantedROIlen + 1];
row[0] = shiftedSimTimes[j] + fStudy.getFrapData().getImageDataset().getImageTimeStamps()[startIndexRecovery];
simSolverResultSet.addRow(row);
}
//
// populate values
//
double[][] currentSimData = getCurrentSimResults();
// populate sim data
int columncounter = 0;
for (int j = 0; j < totalROIlen; j++) {
if (!wantsROITypes[j]) {
continue;
}
double[] values = currentSimData[j];
for (int k = 0; k < values.length; k++) {
simSolverResultSet.setValue(k, columncounter + 1, values[k]);
}
columncounter++;
}
// get exp data and generate datasource to display
// anaParams[0] is the key in allDataHash to get the dataSource[]:exp & sim
DataSource[] selectedRowDataSourceArr = allDataHash.get(anaParams[0]);
if (selectedRowDataSourceArr != null) {
// referenceData is the exp data
// ReferenceData referenceData = (ReferenceData)selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE].getSource();
final DataSource expDataSource = /*new DataSource(referenceData,"exp")*/
selectedRowDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE];
// from simulation
final DataSource simDataSource = new DataSource.DataSourceRowColumnResultSet("sim", simSolverResultSet);
DataSource[] newDataSourceArr = new DataSource[2];
newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
newDataSourceArr[SpatialAnalysisResults.ARRAY_INDEX_SIMDATASOURCE] = simDataSource;
// the following paragraph of code is just to get selected color for selected ROIs
// and make them the same as we show on ChooseModel_RoiForErrorPanel/RoiForErrorPanel
// double valid ROI colors (not include cell and background)
int validROISize = FRAPData.VFRAP_ROI_ENUM.values().length - 2;
Color[] fullColors = ColorUtil.generateAutoColor(validROISize * 2, getBackground(), new Integer(0));
boolean[] selectedROIs = frapWorkspace.getWorkingFrapStudy().getSelectedROIsForErrorCalculation();
int selectedROICounter = 0;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i]) {
selectedROICounter++;
}
}
// double the size, each ROI is a comparison of exp and sim
Color[] selectedColors = new Color[selectedROICounter * 2];
int selectedColorIdx = 0;
for (int i = 0; i < selectedROIs.length; i++) {
if (selectedROIs[i] && i == 0) {
selectedColors[selectedColorIdx] = fullColors[i];
selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i + validROISize];
selectedColorIdx++;
}
if (// skip cell and background ROIs
selectedROIs[i] && i > 2) {
selectedColors[selectedColorIdx] = fullColors[i - 2];
selectedColors[selectedColorIdx + selectedROICounter] = fullColors[i - 2 + validROISize];
selectedColorIdx++;
}
}
multisourcePlotPane.setDataSources(newDataSourceArr, selectedColors);
multisourcePlotPane.selectAll();
}
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(this, "Error graphing Optimizer data " + e2.getMessage());
}
}
use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.
the class OptModelParamPanel method plotDerivedSimulationResults.
private void plotDerivedSimulationResults() {
try {
RowColumnResultSet simulatedData = optContext.computeSolution(getCurrentParameterValues(), fittedROIs, optContext.getExperimentalTimePoints());
RowColumnResultSet experimentalData = optContext.getExperimentalData(fittedROIs);
DataSource simDataSource = new DataSource.DataSourceRowColumnResultSet("opt", simulatedData, false);
DataSource expDataSource = new DataSource.DataSourceRowColumnResultSet("exp", experimentalData, true);
DataSource[] newDataSourceArr = new DataSource[2];
newDataSourceArr[ARRAY_INDEX_EXPDATASOURCE] = expDataSource;
newDataSourceArr[ARRAY_INDEX_SIMDATASOURCE] = simDataSource;
// double valid ROI colors (not include cell and background)
int roiSize = fittedROIs.length;
Color[] uniqueColors = ColorUtil.generateAutoColor(roiSize, getBackground(), new Integer(0));
Color[] colors = new Color[roiSize * 2];
for (int i = 0; i < roiSize; i++) {
colors[i] = uniqueColors[i];
colors[i + roiSize] = uniqueColors[i];
}
int[] selectedIndices = multisourcePlotPane.getUnsortedSelectedIndices();
multisourcePlotPane.setDataSources(newDataSourceArr, colors);
if (selectedIndices.length == 0) {
multisourcePlotPane.selectAll();
} else {
multisourcePlotPane.setUnsortedSelectedIndices(selectedIndices);
}
} catch (Exception e2) {
e2.printStackTrace();
DialogUtils.showErrorDialog(this, "Error graphing Optimizer data " + e2.getMessage());
}
}
use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.
the class FRAPEstimationPanel_NotUsed method displayFit.
private void displayFit(FrapDataAnalysisResults.DiffusionOnlyAnalysisRestults diffAnalysisResults, double[] frapDataTimeStamps, int startIndexForRecovery) {
if (diffAnalysisResults == null) {
FRAPParameterEstimateEnum.DIFFUSION_RATE.value = null;
FRAPParameterEstimateEnum.MOBILE_FRACTION.value = null;
FRAPParameterEstimateEnum.IMMOBILE_FRATION.value = null;
FRAPParameterEstimateEnum.START_TIME_RECOVERY.value = null;
FRAPParameterEstimateEnum.BLEACH_RATE_MONITOR.value = null;
multisourcePlotPane.setDataSources(null);
} else {
FRAPParameterEstimateEnum.DIFFUSION_RATE.value = (diffAnalysisResults.getRecoveryDiffusionRate() == null ? null : diffAnalysisResults.getRecoveryDiffusionRate());
FRAPParameterEstimateEnum.MOBILE_FRACTION.value = (diffAnalysisResults.getMobilefraction() == null ? null : diffAnalysisResults.getMobilefraction());
FRAPParameterEstimateEnum.IMMOBILE_FRATION.value = (FRAPParameterEstimateEnum.MOBILE_FRACTION.value == null ? null : 1.0 - FRAPParameterEstimateEnum.MOBILE_FRACTION.value);
FRAPParameterEstimateEnum.BLEACH_RATE_MONITOR.value = (diffAnalysisResults.getBleachWhileMonitoringTau() == null ? null : diffAnalysisResults.getBleachWhileMonitoringTau());
// int startIndexForRecovery = FRAPDataAnalysis.getRecoveryIndex(initFRAPData);
//
// Experiment - Cell ROI Average
//
double[] temp_background = initFRAPData.getAvgBackGroundIntensity();
double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(initFRAPData, startIndexForRecovery);
double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(initFRAPData, initFRAPData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()), preBleachAvgXYZ, temp_background);
ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { "t", "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, cellRegionData });
DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("expCellAvg", expCellAvgData);
//
// Analytic - Cell ROI Average with Bleach while monitor
//
ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
try {
bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(diffAnalysisResults.getFitBleachWhileMonitorExpression(), "CellROI_BleachWhileMonitor", null, "bleachWhileMonitorFit", true));
} catch (ExpressionException e) {
e.printStackTrace();
}
for (int i = startIndexForRecovery; i < frapDataTimeStamps.length; i++) {
bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
}
//
// extend if necessary to plot theoretical curve to 4*tau
//
{
double T = frapDataTimeStamps[frapDataTimeStamps.length - 1];
double deltaT = frapDataTimeStamps[frapDataTimeStamps.length - 1] - frapDataTimeStamps[frapDataTimeStamps.length - 2];
while (T + deltaT < 6 * diffAnalysisResults.getRecoveryTau()) {
bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { T });
T += deltaT;
}
}
DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceRowColumnResultSet("bleachwm", bleachWhileMonitorOdeSolverResultSet);
// Recovery curve
double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(initFRAPData, initFRAPData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
;
ReferenceData expRefData = new SimpleReferenceData(new String[] { "t", "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
DataSource expDataSource = new DataSource.DataSourceReferenceData("experiment", expRefData);
ODESolverResultSet fitOdeSolverResultSet = new ODESolverResultSet();
fitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription("t"));
try {
fitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(diffAnalysisResults.getDiffFitExpression(), // "('"+FrapDataAnalysisResults.BLEACH_TYPE_NAMES[bleachEstimationComboBox.getSelectedIndex()]+"')",
"BleachROI_Recovery", null, "recoveryFit", true));
} catch (ExpressionException e) {
e.printStackTrace();
}
for (int i = startIndexForRecovery; i < frapDataTimeStamps.length; i++) {
fitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
}
//
// extend if necessary to plot theoretical curve to 4*tau
//
double T = frapDataTimeStamps[frapDataTimeStamps.length - 1];
double deltaT = frapDataTimeStamps[frapDataTimeStamps.length - 1] - frapDataTimeStamps[frapDataTimeStamps.length - 2];
while (T + deltaT < 6 * diffAnalysisResults.getRecoveryTau()) {
fitOdeSolverResultSet.addRow(new double[] { T });
T += deltaT;
}
DataSource fitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", fitOdeSolverResultSet);
multisourcePlotPane.setDataSources(new DataSource[] { expDataSource, fitDataSource, expCellAvgDataSource, bleachWhileMonitorDataSource });
multisourcePlotPane.selectAll();
}
table.repaint();
}
use of cbit.vcell.modelopt.DataSource in project vcell by virtualcell.
the class EstParams_ReactionOffRatePanel method displayResults.
private void displayResults(FRAPData frapData, int startIndexRecovery) throws ExpressionException, DivideByZeroException {
Parameter[] currentParams = offRateParamPanel.getCurrentParameters();
if (frapData == null || currentParams == null) {
multisourcePlotPane.setDataSources(null);
} else {
double[] frapDataTimeStamps = frapData.getImageDataset().getImageTimeStamps();
// Experiment - Cell ROI Average
double[] temp_background = frapData.getAvgBackGroundIntensity();
double[] preBleachAvgXYZ = FrapDataUtils.calculatePreBleachAverageXYZ(frapData, startIndexRecovery);
/*double[] cellRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()),preBleachAvgXYZ,temp_background);
ReferenceData expCellAvgData = new SimpleReferenceData(new String[] { ReservedSymbol.TIME.getName(), "CellROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] {frapDataTimeStamps, cellRegionData });
DataSource expCellAvgDataSource = new DataSource.DataSourceReferenceData("exp", expCellAvgData);
//Analytic - Cell ROI Average with Bleach while monitor
ODESolverResultSet bleachWhileMonitorOdeSolverResultSet = new ODESolverResultSet();
bleachWhileMonitorOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedSymbol.TIME.getName()));
Expression cellAvgExp = new Expression(FRAPOptFunctions.FUNC_CELL_INTENSITY);
// substitute parameter values
cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_I_inicell), new Expression(cellRegionData[startIndexRecovery]));
cellAvgExp.substituteInPlace(new Expression(FRAPOptFunctions.SYMBOL_BWM_RATE), new Expression(currentParams[FRAPModel.INDEX_BLEACH_MONITOR_RATE].getInitialGuess()));
// time shift
cellAvgExp.substituteInPlace(new Expression(ReservedSymbol.TIME.getName()), new Expression(ReservedSymbol.TIME.getName()+"-"+frapDataTimeStamps[startIndexRecovery]));
try {
bleachWhileMonitorOdeSolverResultSet.addFunctionColumn(
new FunctionColumnDescription(
cellAvgExp,
"CellROIAvg",
null,"bleachWhileMonitorFit",true));
} catch (ExpressionException e) {
e.printStackTrace();
}
for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++)
{
bleachWhileMonitorOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
}
DataSource bleachWhileMonitorDataSource = new DataSource.DataSourceOdeSolverResultSet("fit", bleachWhileMonitorOdeSolverResultSet);*/
// experimental bleach region average intensity curve
double[] bleachRegionData = FRAPDataAnalysis.getAverageROIIntensity(frapData, frapData.getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name()), preBleachAvgXYZ, temp_background);
;
ReferenceData expRefData = new SimpleReferenceData(new String[] { ReservedVariable.TIME.getName(), "BleachROIAvg" }, new double[] { 1.0, 1.0 }, new double[][] { frapDataTimeStamps, bleachRegionData });
DataSource expBleachDataSource = new DataSource.DataSourceReferenceData("exp", expRefData);
// Analytic - bleach region average intensity with bleach while monitoring rate
ODESolverResultSet koffFitOdeSolverResultSet = new ODESolverResultSet();
koffFitOdeSolverResultSet.addDataColumn(new ODESolverResultSetColumnDescription(ReservedVariable.TIME.getName()));
Expression bleachedAvgExp = frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().getRecoveryExpressionWithCurrentParameters(currentParams);
try {
koffFitOdeSolverResultSet.addFunctionColumn(new FunctionColumnDescription(bleachedAvgExp, "BleachROIAvg", null, "recoveryFit", true));
} catch (ExpressionException e) {
e.printStackTrace();
}
double[] truncatedTimes = new double[frapDataTimeStamps.length - startIndexRecovery];
for (int i = startIndexRecovery; i < frapDataTimeStamps.length; i++) {
koffFitOdeSolverResultSet.addRow(new double[] { frapDataTimeStamps[i] });
truncatedTimes[i - startIndexRecovery] = frapDataTimeStamps[i];
}
setCurrentEstimationResults(frapWorkspace.getWorkingFrapStudy().getFrapOptFunc().createData(bleachedAvgExp.flatten(), truncatedTimes));
DataSource koffFitDataSource = new DataSource.DataSourceRowColumnResultSet("fit", koffFitOdeSolverResultSet);
multisourcePlotPane.setDataSources(new DataSource[] { expBleachDataSource, koffFitDataSource /*, expCellAvgDataSource , bleachWhileMonitorDataSource*/
});
multisourcePlotPane.selectAll();
}
}
Aggregations