Search in sources :

Example 31 with FRAPStudy

use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.

the class VirtualFrapBatchRunFrame method saveAs.

public AsynchClientTask[] saveAs() {
    ArrayList<AsynchClientTask> saveAsTasks = new ArrayList<AsynchClientTask>();
    AsynchClientTask beforeSaveTask = new AsynchClientTask("Saving file ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            if (batchRunWorkspace.getFrapStudies() == null || batchRunWorkspace.getFrapStudies().size() < 1) {
                throw new Exception("No FRAP Data exists to save");
            } else {
                File outputFile = null;
                String saveFileName = null;
                int choice = VirtualFrapLoader.saveFileChooser_batchRun.showSaveDialog(VirtualFrapBatchRunFrame.this);
                if (choice != JFileChooser.APPROVE_OPTION) {
                    throw UserCancelException.CANCEL_FILE_SELECTION;
                }
                saveFileName = VirtualFrapLoader.saveFileChooser_batchRun.getSelectedFile().getPath();
                if (saveFileName != null) {
                    File tempOutputFile = new File(saveFileName);
                    if (!VirtualFrapLoader.filter_vfbatch.accept(tempOutputFile)) {
                        if (tempOutputFile.getName().indexOf(".") == -1) {
                            tempOutputFile = new File(tempOutputFile.getParentFile(), tempOutputFile.getName() + "." + VirtualFrapLoader.VFRAP_BATCH_EXTENSION);
                        } else {
                            throw new Exception("Virtual FRAP Batchrun document names must have an extension of ." + VirtualFrapLoader.VFRAP_BATCH_EXTENSION);
                        }
                    }
                    if (tempOutputFile.exists()) {
                        String overwriteChoice = DialogUtils.showWarningDialog(VirtualFrapBatchRunFrame.this, "OverWrite file\n" + tempOutputFile.getAbsolutePath(), new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_CANCEL);
                        if (overwriteChoice.equals(UserMessage.OPTION_CANCEL)) {
                            throw UserCancelException.CANCEL_GENERIC;
                        } else {
                            // Remove single vfrap files in the overwritten batchRun
                            try {
                            // TODO
                            } catch (Exception e) {
                                System.out.println("Error deleting externalData and simulation files for overwritten vfrap document " + tempOutputFile.getAbsolutePath() + "  " + e.getMessage());
                                e.printStackTrace();
                            }
                        }
                    }
                    outputFile = tempOutputFile;
                }
                if (outputFile != null) {
                    updateStatus("Saving file " + outputFile.getAbsolutePath() + " ...");
                    hashTable.put(FRAPStudyPanel.SAVE_FILE_NAME_KEY, outputFile);
                }
            }
        }
    };
    saveAsTasks.add(beforeSaveTask);
    // add saving each single vfrap files in the batchrun
    // to see if users want to overwrite
    String choice = DialogUtils.showWarningDialog(VirtualFrapBatchRunFrame.this, "All \'.vfrap\' files in the batchrun will have to be saved to new copies.\nIf you just want to overwrite the existing \'.vfrap\' files in the batchrun, \nPlease cancel this action and use \'save\' function instead.", new String[] { UserMessage.OPTION_OK, UserMessage.OPTION_CANCEL }, UserMessage.OPTION_OK);
    if (choice.equals(UserMessage.OPTION_OK)) {
        ArrayList<FRAPStudy> frapStudies = batchRunWorkspace.getFrapStudies();
        for (FRAPStudy fStudy : frapStudies) {
            String fileName = fStudy.getXmlFilename();
            VirtualFrapLoader.saveFileChooser_batchRunSaveSingleFileAs.setDialogTitle("Save " + fileName + " as...");
            VirtualFrapLoader.saveFileChooser_batchRunSaveSingleFileAs.setSelectedFile(new File(new File(fileName).getName()));
            int option = VirtualFrapLoader.saveFileChooser_batchRunSaveSingleFileAs.showSaveDialog(VirtualFrapBatchRunFrame.this);
            if (option == JFileChooser.APPROVE_OPTION) {
                String fileStr = VirtualFrapLoader.saveFileChooser_batchRunSaveSingleFileAs.getSelectedFile().getAbsolutePath();
                File tempFile = new File(fileStr);
                if (!VirtualFrapLoader.filter_vfrap.accept(tempFile)) {
                    if (tempFile.getName().indexOf(".") == -1) {
                        tempFile = new File(tempFile.getParentFile(), tempFile.getName() + "." + VirtualFrapLoader.VFRAP_EXTENSION);
                    } else {
                        DialogUtils.showErrorDialog(this, "Virtual FRAP document names must have an extension of ." + VirtualFrapLoader.VFRAP_EXTENSION);
                        // return?
                        throw new RuntimeException("Virtual FRAP document names must have an extension of ." + VirtualFrapLoader.VFRAP_EXTENSION);
                    }
                }
                fStudy.setXmlFilename(tempFile.getAbsolutePath());
            } else {
                throw UserCancelException.CANCEL_GENERIC;
            }
        }
        saveAsTasks.add(batchRunWorkspace.getSaveSingleFilesTask());
    } else {
        throw UserCancelException.CANCEL_GENERIC;
    }
    // write batch run file
    saveAsTasks.add(batchRunWorkspace.getSaveBatchRunFileTask());
    AsynchClientTask afterSaveAsTask = new AsynchClientTask("Saving file ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            // update tree
            getBatchRunDetailsPanel().updateViewTreeForNewBatchRunFile(batchRunWorkspace);
            // update title bar and status bar
            File outFile = (File) hashTable.get(FRAPStudyPanel.SAVE_FILE_NAME_KEY);
            VirtualFrapBatchRunFrame.updateStatus("File " + outFile.getAbsolutePath() + " has been saved.");
            VirtualFrapLoader.mf.setBatchRunFrameTitle(outFile.getName());
        }
    };
    saveAsTasks.add(afterSaveAsTask);
    return saveAsTasks.toArray(new AsynchClientTask[saveAsTasks.size()]);
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) File(java.io.File) UserCancelException(org.vcell.util.UserCancelException)

Example 32 with FRAPStudy

use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.

the class VirtualFrapBatchRunFrame method getBatchRunTasks.

private ArrayList<AsynchClientTask> getBatchRunTasks() {
    // to run batch files
    ArrayList<AsynchClientTask> batchRunTaskList = new ArrayList<AsynchClientTask>();
    for (int i = 0; i < batchRunWorkspace.getFrapStudies().size(); i++) {
        final int finalIdx = i;
        AsynchClientTask message1Task = new AsynchClientTask("Preparing for parameter estimation ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                appendJobStatus("<html><br>Running " + (batchRunWorkspace.getFrapStudies().get(finalIdx)).getXmlFilename() + "</html>", false);
            }
        };
        AsynchClientTask saveTask = new AsynchClientTask("Preparing for parameter estimation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                if (fStudy.hasDiffusionOnlyModel()) {
                    // check external data info. If not existing,  we have to run ref simulation.
                    if (!FRAPWorkspace.areExternalDataOK(localWorkspace, fStudy.getFrapDataExternalDataInfo(), fStudy.getRoiExternalDataInfo())) {
                        // if external files are missing/currupt or ROIs are changed, create keys and save them
                        fStudy.setFrapDataExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.IMAGE_EXTDATA_NAME));
                        fStudy.setRoiExternalDataInfo(FRAPStudy.createNewExternalDataInfo(localWorkspace, FRAPStudy.ROI_EXTDATA_NAME));
                        fStudy.saveROIsAsExternalData(localWorkspace, fStudy.getRoiExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
                        fStudy.saveImageDatasetAsExternalData(localWorkspace, fStudy.getFrapDataExternalDataInfo().getExternalDataIdentifier(), fStudy.getStartingIndexForRecovery());
                    }
                }
            }
        };
        AsynchClientTask message2Task = new AsynchClientTask("Running reference simulation ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                if (fStudy.hasDiffusionOnlyModel()) {
                    MessagePanel msgPanel = appendJobStatus("Running reference simulation ...", true);
                    hashTable.put("runRefStatus", msgPanel);
                } else if (fStudy.hasReactionOnlyOffRateModel()) {
                // MessagePanel msgPanel = appendJobStatus("...", true);
                // hashTable.put("runRefStatus", msgPanel);
                }
            }
        };
        AsynchClientTask runRefSimTask = new AsynchClientTask("Running reference simulation ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                if (fStudy.hasDiffusionOnlyModel()) {
                    MessagePanel msgPanel = (MessagePanel) hashTable.get("runRefStatus");
                    // run ref sim
                    if (// if ref data is stored ,we don't have to re-run
                    fStudy.getStoredRefData() != null) {
                        fStudy.setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, fStudy.getStoredRefData()));
                    } else {
                        fStudy.setFrapOptData(new FRAPOptData(fStudy, FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF, localWorkspace, msgPanel));
                    }
                } else if (fStudy.hasReactionOnlyOffRateModel()) {
                    if (fStudy.getFrapOptFunc() == null) {
                        fStudy.setFrapOptFunc(new FRAPOptFunctions(fStudy));
                    }
                }
            }
        };
        AsynchClientTask message3Task = new AsynchClientTask("Running optimization ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                if (fStudy.hasDiffusionOnlyModel()) {
                    MessagePanel msgPanel = (MessagePanel) hashTable.get("runRefStatus");
                    msgPanel.setProgressCompleted();
                }
                MessagePanel msgPanel1 = appendJobStatus("Running optimization ...", true);
                hashTable.put("optimizationStatus", msgPanel1);
            }
        };
        AsynchClientTask runOptTask = new AsynchClientTask("Running optimization ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                ArrayList<Integer> models = fStudy.getSelectedModels();
                if (models.size() == 1) {
                    for (int i = 0; i < models.size(); i++) {
                        int model = (models.get(i)).intValue();
                        if (model == batchRunWorkspace.getSelectedModel()) {
                            if (model == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
                                // if(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() == null)
                                // {//always run
                                fStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_ONE_DIFF);
                                Parameter[] initialParams = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT], fStudy.getStartingIndexForRecovery());
                                // set model parameters and data
                                Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
                                double[][] fitData = fStudy.getFrapOptData().getFitData(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setModelParameters(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].setData(fitData);
                            // }
                            } else if (model == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
                                // if(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() == null)
                                // {//always run
                                fStudy.getFrapOptData().setNumEstimatedParams(FRAPModel.NUM_MODEL_PARAMETERS_TWO_DIFF);
                                Parameter[] initialParams = FRAPModel.getInitialParameters(fStudy.getFrapData(), FRAPModel.MODEL_TYPE_ARRAY[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS], fStudy.getStartingIndexForRecovery());
                                // set model parameters and data
                                Parameter[] bestParameters = fStudy.getFrapOptData().getBestParamters(initialParams, fStudy.getSelectedROIsForErrorCalculation());
                                double[][] fitData = fStudy.getFrapOptData().getFitData(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setModelParameters(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].setData(fitData);
                            // }
                            } else if (model == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
                                Parameter[] bestParameters = fStudy.getFrapOptFunc().getBestParamters(fStudy.getFrapData(), null, true);
                                double[][] fitData = fStudy.getFrapOptFunc().getFitData(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].setModelParameters(bestParameters);
                                fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].setData(fitData);
                            }
                        } else {
                            throw new Exception("Selected model for batch run is not the same as selected model in FRAP doc " + fStudy.getXmlFilename());
                        }
                    }
                } else {
                    throw new Exception("Selected model size exceed 1");
                }
            }
        };
        AsynchClientTask message4Task = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                MessagePanel msgPanel = (MessagePanel) hashTable.get("optimizationStatus");
                msgPanel.setProgressCompleted();
                MessagePanel msgPanel2 = appendJobStatus("Evaluating confidence intervals for parameters ...", true);
                hashTable.put("evaluateCI", msgPanel2);
            }
        };
        AsynchClientTask evaluateCITask = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                FRAPStudy fStudy = (batchRunWorkspace.getFrapStudies().get(finalIdx));
                MessagePanel msgPanel = (MessagePanel) hashTable.get("evaluateCI");
                // evaluate confidence intervals
                ArrayList<Integer> models = fStudy.getSelectedModels();
                if (models.size() == 1) {
                    for (int i = 0; i < models.size(); i++) {
                        int model = (models.get(i)).intValue();
                        if (model == batchRunWorkspace.getSelectedModel()) {
                            if (model == FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT) {
                                if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters() != null) {
                                    ProfileData[] profileData = fStudy.getFrapOptData().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT].getModelParameters(), msgPanel);
                                    fStudy.setProfileData_oneDiffComponent(profileData);
                                }
                            } else if (model == FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS) {
                                if (fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters() != null) {
                                    ProfileData[] profileData = fStudy.getFrapOptData().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS].getModelParameters(), msgPanel);
                                    fStudy.setProfileData_twoDiffComponents(profileData);
                                }
                            } else if (model == FRAPModel.IDX_MODEL_REACTION_OFF_RATE) {
                                if (fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters() != null) {
                                    ProfileData[] profileData = fStudy.getFrapOptFunc().evaluateParameters(fStudy.getModels()[FRAPModel.IDX_MODEL_REACTION_OFF_RATE].getModelParameters(), msgPanel);
                                    fStudy.setProfileData_reactionOffRate(profileData);
                                }
                            }
                        } else {
                            throw new Exception("Selected model for batch run is not the same as selected model in FRAP doc " + fStudy.getXmlFilename());
                        }
                    }
                } else {
                    throw new Exception("Selected model size exceed 1");
                }
            }
        };
        AsynchClientTask message5Task = new AsynchClientTask("Evaluating confidence intervals for parameters ...", AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

            public void run(Hashtable<String, Object> hashTable) throws Exception {
                MessagePanel msgPanel = (MessagePanel) hashTable.get("evaluateCI");
                msgPanel.setProgressCompleted();
            }
        };
        batchRunTaskList.add(message1Task);
        batchRunTaskList.add(saveTask);
        batchRunTaskList.add(message2Task);
        batchRunTaskList.add(runRefSimTask);
        batchRunTaskList.add(message3Task);
        batchRunTaskList.add(runOptTask);
        batchRunTaskList.add(message4Task);
        batchRunTaskList.add(evaluateCITask);
        batchRunTaskList.add(message5Task);
    }
    return batchRunTaskList;
}
Also used : AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) FRAPOptFunctions(cbit.vcell.microscopy.FRAPOptFunctions) ArrayList(java.util.ArrayList) ProfileData(org.vcell.optimization.ProfileData) UserCancelException(org.vcell.util.UserCancelException) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) FRAPOptData(cbit.vcell.microscopy.FRAPOptData) Parameter(cbit.vcell.opt.Parameter)

Example 33 with FRAPStudy

use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.

the class ModelTypesDescriptor method aboutToDisplayPanel.

public void aboutToDisplayPanel() {
    FRAPStudy fStudy = batchRunWorkspace.getWorkingFrapStudy();
    // if there are models selected and saved, load the model types. otherwise, apply default(diffusion with one component is selected).
    if (fStudy.getModels() != null && fStudy.getModels().length > 0 && fStudy.getSelectedModels().size() > 0) {
        modelTypesPanel.clearAllSelected();
        FRAPModel[] models = fStudy.getModels();
        if (models[FRAPModel.IDX_MODEL_DIFF_ONE_COMPONENT] != null) {
            modelTypesPanel.setDiffOneSelected(true);
        }
        if (models[FRAPModel.IDX_MODEL_DIFF_TWO_COMPONENTS] != null) {
            modelTypesPanel.setDiffTwoSelected(true);
        }
        if (models[FRAPModel.IDX_MODEL_REACTION_OFF_RATE] != null) {
            modelTypesPanel.setReactionOffRateSelected(true);
        }
    } else // new frap document
    {
        modelTypesPanel.clearAllSelected();
        modelTypesPanel.setDiffOneSelected(true);
    }
}
Also used : FRAPStudy(cbit.vcell.microscopy.FRAPStudy) FRAPModel(cbit.vcell.microscopy.FRAPModel)

Example 34 with FRAPStudy

use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.

the class FRAPDataPanel method initialize.

/**
 * This method initializes this
 *
 * @return void
 */
private void initialize() {
    GridBagConstraints gridBagConstraints1 = new GridBagConstraints();
    gridBagConstraints1.gridx = 0;
    gridBagConstraints1.ipadx = 0;
    gridBagConstraints1.ipady = 0;
    gridBagConstraints1.fill = GridBagConstraints.BOTH;
    gridBagConstraints1.weighty = 1.0D;
    gridBagConstraints1.weightx = 1.0D;
    gridBagConstraints1.gridy = 0;
    this.setSize(653, 492);
    this.setLayout(new GridBagLayout());
    this.add(getOverlayEditorPanelJAI(), gridBagConstraints1);
    getOverlayEditorPanelJAI().addPropertyChangeListener(new PropertyChangeListener() {

        public void propertyChange(PropertyChangeEvent evt) {
            if (evt.getPropertyName().equals(VFrap_OverlayEditorPanelJAI.FRAP_DATA_TIMEPLOTROI_PROPERTY)) {
                try {
                    plotROI();
                } catch (Exception e) {
                    DialogUtils.showErrorDialog(FRAPDataPanel.this, "Error Time Plot ROI:\n" + e.getMessage());
                }
            } else if (evt.getPropertyName().equals(VFrap_OverlayEditorPanelJAI.FRAP_DATA_CURRENTROI_PROPERTY)) {
                try {
                    String roiName = (String) evt.getNewValue();
                    if (roiName != null) {
                        getFrapWorkspace().getWorkingFrapStudy().getFrapData().setCurrentlyDisplayedROI(getFrapWorkspace().getWorkingFrapStudy().getFrapData().getRoi(roiName), false);
                    }
                } catch (Exception e) {
                    DialogUtils.showErrorDialog(FRAPDataPanel.this, "Error Setting Current ROI:\n" + e.getMessage());
                }
            } else if (evt.getPropertyName().equals(VFrap_OverlayEditorPanelJAI.FRAP_DATA_UNDOROI_PROPERTY)) {
                try {
                    ROI undoableROI = (ROI) evt.getNewValue();
                    getFrapWorkspace().getWorkingFrapStudy().getFrapData().addReplaceRoi(undoableROI);
                } catch (Exception e) {
                    PopupGenerator.showErrorDialog(FRAPDataPanel.this, "Error Setting Current ROI:\n" + e.getMessage());
                }
            }
        }
    });
    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 = getFrapWorkspace().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++) {
                        getFrapWorkspace().getWorkingFrapStudy().getFrapData().addReplaceRoi(importedROIs[i]);
                    }
                // undoableEditSupport.postEdit(FRAPStudyPanel.CLEAR_UNDOABLE_EDIT);
                }
                return true;
            } catch (Exception e1) {
                throw new Exception("VFRAP ROI Import - " + e1.getMessage());
            }
        }
    };
    getOverlayEditorPanelJAI().setCustomROIImport(importVFRAPROI);
}
Also used : GridBagConstraints(java.awt.GridBagConstraints) PropertyChangeEvent(java.beans.PropertyChangeEvent) GridBagLayout(java.awt.GridBagLayout) PropertyChangeListener(java.beans.PropertyChangeListener) ROI(cbit.vcell.VirtualMicroscopy.ROI) ImageException(cbit.image.ImageException) MicroscopyXmlReader(cbit.vcell.microscopy.MicroscopyXmlReader) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) File(java.io.File)

Example 35 with FRAPStudy

use of cbit.vcell.microscopy.FRAPStudy in project vcell by virtualcell.

the class FRAPStudyPanel method open.

// open .vfrap document
public AsynchClientTask[] open(final File inFile) {
    final String LOADING_MESSAGE = "Loading " + inFile.getAbsolutePath() + "...";
    ArrayList<AsynchClientTask> totalTasks = new ArrayList<AsynchClientTask>();
    // check if save is needed before loading data
    if (getFrapWorkspace().getWorkingFrapStudy().isSaveNeeded()) {
        String choice = DialogUtils.showWarningDialog(FRAPStudyPanel.this, "There are unsaved changes. Save current document before loading new document?", new String[] { SAVE_CONTINUE_MSG, NO_THANKS_MSG }, SAVE_CONTINUE_MSG);
        if (choice.equals(SAVE_CONTINUE_MSG)) {
            AsynchClientTask[] saveTasks = save();
            for (int i = 0; i < saveTasks.length; i++) {
                totalTasks.add(saveTasks[i]);
            }
        }
    }
    AsynchClientTask preOpenTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            VirtualFrapMainFrame.updateStatus(LOADING_MESSAGE);
        }
    };
    totalTasks.add(preOpenTask);
    AsynchClientTask loadTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_NONSWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy newFRAPStudy = null;
            String newVFRAPFileName = null;
            if (// .vfrap
            inFile.getName().endsWith("." + VirtualFrapLoader.VFRAP_EXTENSION) || inFile.getName().endsWith(".xml")) {
                String xmlString = XmlUtil.getXMLString(inFile.getAbsolutePath());
                MicroscopyXmlReader xmlReader = new MicroscopyXmlReader(true);
                newFRAPStudy = xmlReader.getFrapStudy(XmlUtil.stringToXML(xmlString, null).getRootElement(), this.getClientTaskStatusSupport());
                if (!FRAPWorkspace.areExternalDataOK(getLocalWorkspace(), newFRAPStudy.getFrapDataExternalDataInfo(), newFRAPStudy.getRoiExternalDataInfo())) {
                    newFRAPStudy.setFrapDataExternalDataInfo(null);
                    newFRAPStudy.setRoiExternalDataInfo(null);
                }
                newVFRAPFileName = inFile.getAbsolutePath();
                // for loaded file
                newFRAPStudy.setXmlFilename(newVFRAPFileName);
                hashTable.put(FRAPStudyPanel.NEW_FRAPSTUDY_KEY, newFRAPStudy);
            } else {
                throw new Exception("Invalid Virtual Frap file name!");
            }
        }
    };
    totalTasks.add(loadTask);
    AsynchClientTask updateUIAfterLoadingTask = new AsynchClientTask(LOADING_MESSAGE, AsynchClientTask.TASKTYPE_SWING_BLOCKING) {

        public void run(Hashtable<String, Object> hashTable) throws Exception {
            FRAPStudy fStudy = (FRAPStudy) hashTable.get(FRAPStudyPanel.NEW_FRAPSTUDY_KEY);
            getFrapWorkspace().setFrapStudy(fStudy, true);
            String fName = "";
            if (fStudy != null && fStudy.getXmlFilename() != null && fStudy.getXmlFilename().length() > 0) {
                fName = fStudy.getXmlFilename();
                VirtualFrapLoader.mf.setMainFrameTitle(fName);
                VirtualFrapMainFrame.updateStatus("Loaded " + fName);
            } else {
                VirtualFrapMainFrame.updateStatus(LOADING_MESSAGE + " Failed.");
            }
            VirtualFrapMainFrame.updateProgress(0);
            // clear movie buffer
            clearMovieBuffer();
            // clear plot selected indices
            if (diffOneDescriptor != null && diffTwoDescriptor != null) {
                diffOneDescriptor.clearSelectedPlotIndices();
                diffTwoDescriptor.clearSelectedPlotIndices();
            }
        }
    };
    totalTasks.add(updateUIAfterLoadingTask);
    return totalTasks.toArray(new AsynchClientTask[totalTasks.size()]);
}
Also used : MicroscopyXmlReader(cbit.vcell.microscopy.MicroscopyXmlReader) AsynchClientTask(cbit.vcell.client.task.AsynchClientTask) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) FRAPStudy(cbit.vcell.microscopy.FRAPStudy) Point(java.awt.Point) IOException(java.io.IOException) CannotUndoException(javax.swing.undo.CannotUndoException) ImageException(cbit.image.ImageException) FileNotFoundException(java.io.FileNotFoundException) UserCancelException(org.vcell.util.UserCancelException)

Aggregations

FRAPStudy (cbit.vcell.microscopy.FRAPStudy)51 Hashtable (java.util.Hashtable)19 AsynchClientTask (cbit.vcell.client.task.AsynchClientTask)18 File (java.io.File)17 ArrayList (java.util.ArrayList)13 Parameter (cbit.vcell.opt.Parameter)11 Point (java.awt.Point)8 FRAPModel (cbit.vcell.microscopy.FRAPModel)7 UserCancelException (org.vcell.util.UserCancelException)7 ImageException (cbit.image.ImageException)6 MicroscopyXmlReader (cbit.vcell.microscopy.MicroscopyXmlReader)5 FRAPData (cbit.vcell.microscopy.FRAPData)4 FRAPOptData (cbit.vcell.microscopy.FRAPOptData)4 FRAPOptFunctions (cbit.vcell.microscopy.FRAPOptFunctions)4 FileNotFoundException (java.io.FileNotFoundException)4 IOException (java.io.IOException)4 CannotUndoException (javax.swing.undo.CannotUndoException)4 PDEDataManager (cbit.vcell.simdata.PDEDataManager)3 Simulation (cbit.vcell.solver.Simulation)3 Wizard (org.vcell.wizard.Wizard)3