use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.
the class BatchRunDisplayPanel method getFRAPDataPanel.
public FRAPDataPanel getFRAPDataPanel() {
if (frapDataPanel == null) {
// the frap data panel in the main frame is not editable
frapDataPanel = new FRAPDataPanel(false);
// set display mode
frapDataPanel.adjustComponents(VFrap_OverlayEditorPanelJAI.DISPLAY_WITH_ROIS);
Hashtable<String, Cursor> cursorsForROIsHash = new Hashtable<String, Cursor>();
cursorsForROIsHash.put(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name(), FRAPStudyPanel.ROI_CURSORS[FRAPStudyPanel.CURSOR_CELLROI]);
cursorsForROIsHash.put(FRAPData.VFRAP_ROI_ENUM.ROI_BLEACHED.name(), FRAPStudyPanel.ROI_CURSORS[FRAPStudyPanel.CURSOR_BLEACHROI]);
cursorsForROIsHash.put(FRAPData.VFRAP_ROI_ENUM.ROI_BACKGROUND.name(), FRAPStudyPanel.ROI_CURSORS[FRAPStudyPanel.CURSOR_BACKGROUNDROI]);
frapDataPanel.getOverlayEditorPanelJAI().setCursorsForROIs(cursorsForROIsHash);
VFrap_OverlayEditorPanelJAI.CustomROIImport importVFRAPROI = new VFrap_OverlayEditorPanelJAI.CustomROIImport() {
public boolean importROI(File inputFile) throws Exception {
try {
if (!VirtualFrapLoader.filter_vfrap.accept(inputFile)) {
return false;
}
String xmlString = XmlUtil.getXMLString(inputFile.getAbsolutePath());
MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
FRAPStudy importedFrapStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), null);
VirtualFrapMainFrame.updateProgress(0);
ROI roi = getBatchRunWorkspace().getWorkingSingleWorkspace().getWorkingFrapStudy().getFrapData().getCurrentlyDisplayedROI();
ROI[] importedROIs = importedFrapStudy.getFrapData().getRois();
if (importedFrapStudy.getFrapData() != null && importedROIs != null) {
if (!importedROIs[0].getISize().compareEqual(roi.getISize())) {
throw new Exception("Imported ROI mask size (" + importedROIs[0].getISize().getX() + "," + importedROIs[0].getISize().getY() + "," + importedROIs[0].getISize().getZ() + ")" + " does not match current Frap DataSet size (" + roi.getISize().getX() + "," + roi.getISize().getY() + "," + roi.getISize().getZ() + ")");
}
for (int i = 0; i < importedROIs.length; i++) {
getBatchRunWorkspace().getWorkingSingleWorkspace().getWorkingFrapStudy().getFrapData().addReplaceRoi(importedROIs[i]);
}
// undoableEditSupport.postEdit(FRAPStudyPanel.CLEAR_UNDOABLE_EDIT);
}
return true;
} catch (Exception e1) {
throw new Exception("VFRAP ROI Import - " + e1.getMessage());
}
}
};
frapDataPanel.getOverlayEditorPanelJAI().setCustomROIImport(importVFRAPROI);
}
return frapDataPanel;
}
use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.
the class DefineROI_SummaryDescriptor method preNextProcess.
// save the startingIndex before the panel disappears
public ArrayList<AsynchClientTask> preNextProcess() {
// create AsynchClientTask arraylist
ArrayList<AsynchClientTask> taskArrayList = new ArrayList<AsynchClientTask>();
AsynchClientTask verifyLoadedDataTask = new AsynchClientTask("", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
String msg = ((DefineROI_SummaryPanel) getPanelComponent()).checkInputValidity();
if (msg.equals("")) {
int startIndex = ((DefineROI_SummaryPanel) getPanelComponent()).getStartingIndex();
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
// check ROI void/discontinuous location
Point internalVoidLocation = ROI.findInternalVoid(fStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()));
if (internalVoidLocation != null) {
throw new Exception("CELL ROI has unfilled internal void area at image location " + "x=" + internalVoidLocation.x + ",y=" + internalVoidLocation.y + "\n" + "Use ROI editing tools to completely define the CELL ROI");
}
Point[] distinctCellAreaLocations = ROI.checkContinuity(fStudy.getFrapData().getRoi(FRAPData.VFRAP_ROI_ENUM.ROI_CELL.name()));
if (distinctCellAreaLocations != null) {
throw new Exception("CELL ROI has at least 2 discontinuous areas at image locations \n" + "x=" + distinctCellAreaLocations[0].x + ",y=" + distinctCellAreaLocations[0].y + " and " + "x=" + distinctCellAreaLocations[1].x + ",y=" + distinctCellAreaLocations[1].y + "\n" + "Use ROI editing tools to define a single continuous CELL ROI");
}
/**
* check for conflicts of background and bleach ROIs against CellROI.
*/
boolean bViolationBleachROI = fStudy.getFrapData().checkBleachROIViolatesConstraints();
boolean bViolationBackgroundROI = fStudy.getFrapData().checkBackgroundROIViolatesConstraints();
if (bViolationBleachROI || bViolationBackgroundROI) {
final String FIX_AUTO = "Fix Automatically";
final String NO_THANKS = "No, Thanks";
String result = DialogUtils.showWarningDialog(imgPanel, (bViolationBleachROI ? "Bleach ROI extends beyond Cell ROI" : "") + (bViolationBackgroundROI && bViolationBleachROI ? " and" : "") + (bViolationBackgroundROI ? "Background ROI overlaps Cell ROI" : "") + ". Ensure that the Bleach ROI is completely inside the Cell ROI and the Background ROI is completely outside the Cell ROI.\nDo you want Virtual Frap to fix it automatically?", new String[] { FIX_AUTO, NO_THANKS }, FIX_AUTO);
if (result != null && result.equals(FIX_AUTO)) {
if (fStudy.getFrapData().fixROIConstraints()) {
fStudy.setStartingIndexForRecovery(startIndex);
getFrapWorkspace().setFrapStudy(fStudy, true);
// generate ROI rings
fStudy.refreshDependentROIs();
} else {
throw new Exception("Please fix the ROI problem or cancel the wizard.");
}
}
}
} else {
throw new Exception(msg);
}
}
};
taskArrayList.add(verifyLoadedDataTask);
return taskArrayList;
}
use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.
the class EstParams_OneDiffComponentDescriptor method aboutToDisplayPanel.
public void aboutToDisplayPanel() {
FRAPStudy fStudy = frapWorkspace.getWorkingFrapStudy();
Parameter[] params = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters();
try {
if (params == null) {
params = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], fStudy.getStartingIndexForRecovery());
}
((EstParams_OneDiffComponentPanel) getPanelComponent()).setData(fStudy.getFrapOptData(), fStudy.getFrapData(), params, fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
} catch (Exception ex) {
ex.printStackTrace(System.out);
DialogUtils.showErrorDialog((getPanelComponent()), "Error getting parameters for diffusion with one diffusing component model.");
}
}
use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.
the class EstParams_ReacBindingPanel method simulateWithCurrentParameters.
private // used by reaction binding panel only. not used by VFRAP 1.1 though
void simulateWithCurrentParameters() {
fStudy = getFrapWorkspace().getWorkingFrapStudy();
// save external files if needed
AsynchClientTask saveTask = new AsynchClientTask("Preparing to run simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
// check external data before running simulation
if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo())) {
// if external files are missing/currupt or ROIs are changed, create keys and save them
fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.IMAGE_EXTDATA_NAME));
fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(getLocalWorkspace(), FRAPStudy.ROI_EXTDATA_NAME));
try {
fStudy.saveROIsAsExternalData(getLocalWorkspace(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
fStudy.saveImageDatasetAsExternalData(getLocalWorkspace(), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
};
// run simulation task
AsynchClientTask runSimTask = new AsynchClientTask("Running simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
BioModel bioModel = null;
KeyValue simKey = null;
// }
try {
bioModel = FRAPStudy.createNewSimBioModel(fStudy, getCurrentParameters(), null, LocalWorkspace.createNewKeyValue(), LocalWorkspace.getDefaultOwner(), fStudy.getStartingIndexForRecovery());
// we don't have to set the bioModel to frap study, we just need the results.
// change time bound and time step
// Simulation sim = bioModel.getSimulations()[0];
// sim.getSolverTaskDescription().setTimeBounds(getRefTimeBounds());
// sim.getSolverTaskDescription().setTimeStep(getRefTimeStep());
// sim.getSolverTaskDescription().setOutputTimeSpec(getRefTimeSpec());
// System.out.println("run FRAP Reference Simulation...");
// final double RUN_REFSIM_PROGRESS_FRACTION = 1.0;
// DataSetControllerImpl.ProgressListener runRefSimProgressListener =
// new DataSetControllerImpl.ProgressListener(){
// public void updateProgress(double progress) {
// if(progressListener != null){
// //To run to the steady state the time length is unpredictable. Progress increase 10 times
// //because we manually set ending time to 1000 and usually it will reach steady state in less than 100 seconds.
// //max allowed progress is 80%. this is heuristic.
// progressListener.updateProgress(Math.min(0.8, (progress*10)*RUN_REFSIM_PROGRESS_FRACTION));
// }
// }
// public void updateMessage(String message){
// if(progressListener != null){
// progressListener.updateMessage(message);
// }
// }
// };
// run simulation
FRAPStudy.runFVSolverStandalone(new File(getLocalWorkspace().getDefaultSimDataDirectory()), bioModel.getSimulation(0), fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), this.getClientTaskStatusSupport(), false);
/*//prepare to run native FV solver
Simulation simulation = bioModel.getSimulations()[0];
// clone and resample geometry
Geometry resampledGeometry = null;
try {
resampledGeometry = (Geometry) BeanUtils.cloneSerializable(simulation.getMathDescription().getGeometry());
GeometrySurfaceDescription geoSurfaceDesc = resampledGeometry.getGeometrySurfaceDescription();
ISize newSize = simulation.getMeshSpecification().getSamplingSize();
geoSurfaceDesc.setVolumeSampleSize(newSize);
geoSurfaceDesc.updateAll();
} catch (Exception e) {
e.printStackTrace();
throw new SolverException(e.getMessage());
}
SimulationJob simJob = new SimulationJob(simulation, 0, null); //fielddata ID?
StringWriter simulationInputStringWriter = new StringWriter();
FiniteVolumeFileWriter fvFileWriter = new FiniteVolumeFileWriter(new PrintWriter(simulationInputStringWriter,true), simJob, resampledGeometry, new File(getLocalWorkspace().getDefaultSimDataDirectory())); //need dir?
fvFileWriter.write(null); //what are parameter names?
simulationInputStringWriter.close();
String fvInputStr = simulationInputStringWriter.getBuffer().toString();
//run simulation with native FV solver
double[][][] rawSimResults = new NativeFVSolver().solve(fvInputStr);*/
simKey = bioModel.getSimulations()[0].getVersion().getVersionKey();
} catch (Exception e) {
if (bioModel != null && bioModel.getSimulations() != null) {
FRAPStudy.removeExternalDataAndSimulationFiles(bioModel.getSimulations()[0].getVersion().getVersionKey(), null, null, getLocalWorkspace());
}
throw e;
}
// push sim key into hash table
// for all loaded file
hashTable.put(FRAPStudyPanel.SIMULATION_KEY, simKey);
}
};
// generate dimension reduced sim data
AsynchClientTask readDataTask = new AsynchClientTask("Reading simulation data ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
KeyValue simulationKey = (KeyValue) hashTable.get(FRAPStudyPanel.SIMULATION_KEY);
if (simulationKey != null) {
VCSimulationIdentifier vcSimID = new VCSimulationIdentifier(simulationKey, LocalWorkspace.getDefaultOwner());
VCSimulationDataIdentifier vcSimDataID = new VCSimulationDataIdentifier(vcSimID, FieldDataFileOperationSpec.JOBINDEX_DEFAULT);
double[] rawSimTimePoints = getLocalWorkspace().getVCDataManager().getDataSetTimes(vcSimDataID);
// to store time points in frap model (simulation time points may be slightly different with exp time points)
setCurrentRawSimTimePoints(rawSimTimePoints);
// refDataTimePoints = timeShiftForBaseDiffRate(rawRefDataTimePoints);
// System.out.println("simulation done...");
// DataSetControllerImpl.ProgressListener reducedRefDataProgressListener =
// new DataSetControllerImpl.ProgressListener(){
// public void updateProgress(double progress) {
// if(progressListener != null){
// progressListener.setProgress((int)((.5+progress*(1-RUNSIM_PROGRESS_FRACTION))*100));
// }
// }
// public void updateMessage(String message){
// if(progressListener != null){
// progressListener.setMessage(message);
// }
// }
// };
double[][] results = FRAPOptimizationUtils.dataReduction(getLocalWorkspace().getVCDataManager(), vcSimDataID, rawSimTimePoints, fStudy.getFrapData().getRois(), this.getClientTaskStatusSupport(), false);
// to store data in frap model.
setCurrentSimResults(results);
System.out.println("generating dimension reduced ref data, done ....");
// remove reference simulation files
FRAPStudy.removeSimulationFiles(simulationKey, getLocalWorkspace());
}
}
};
// plot task
AsynchClientTask plotTask = new AsynchClientTask("Generating plots ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {
public void run(Hashtable<String, Object> hashTable) throws Exception {
FRAPStudy fStudy = getFrapWorkspace().getWorkingFrapStudy();
try {
setData(fStudy.getFrapData(), getCurrentParameters(), fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace(System.out);
}
}
};
// dispatch
ClientTaskDispatcher.dispatch(EstParams_ReacBindingPanel.this, new Hashtable<String, Object>(), new AsynchClientTask[] { saveTask, runSimTask, readDataTask, plotTask }, false);
}
use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.
the class EstParams_TwoDiffComponentDescriptor method aboutToDisplayPanel.
public void aboutToDisplayPanel() {
FRAPStudy fStudy = frapWorkspace.getWorkingFrapStudy();
Parameter[] params = fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters();
try {
if (params == null) {
params = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], fStudy.getStartingIndexForRecovery());
}
((EstParams_TwoDiffComponentPanel) getPanelComponent()).setData(fStudy.getFrapOptData(), fStudy.getFrapData(), params, fStudy.getFrapData().getImageDataset().getImageTimeStamps(), fStudy.getStartingIndexForRecovery(), fStudy.getSelectedROIsForErrorCalculation());
} catch (Exception ex) {
ex.printStackTrace(System.out);
DialogUtils.showErrorDialog((getPanelComponent()), "Error getting parameters for diffusion with one diffusing component model.");
}
}
Aggregations