コード例 #1
0
    def save_data(self):
        """
        Dialog for saving an data as a nifti file
        """
        if self.ivm.current_data is None:
            QtGui.QMessageBox.warning(self, "No data",
                                      "No current data to save",
                                      QtGui.QMessageBox.Close)
        else:
            if hasattr(self.ivm.current_data,
                       "fname") and self.ivm.current_data.fname is not None:
                fname = self.ivm.current_data.fname
            else:
                fname = os.path.join(default_save_dir(),
                                     self.ivm.current_data.name + ".nii")

            fname, _ = QtGui.QFileDialog.getSaveFileName(
                self,
                'Save file',
                dir=fname,
                filter="NIFTI files (*.nii *.nii.gz)")
            if fname != '':
                save(self.ivm.current_data, fname)
            else:  # Cancelled
                pass
コード例 #2
0
    def run(self, options):
        exceptions = list(options.keys())
        for k in exceptions: options.pop(k)

        for name, qpdata in self.ivm.data.items():
            if name in exceptions: 
                continue
            try:
                save(qpdata, name, outdir=self.outdir)
            except QpException as exc:
                self.warn("Failed to save %s: %s" % (name, str(exc)))
            except:
                import traceback
                traceback.print_exc()
コード例 #3
0
 def save_roi(self):
     """
     Dialog for saving an ROI as a nifti file
     """
     if self.ivm.current_roi is None:
         QtGui.QMessageBox.warning(self, "No ROI", "No current ROI to save",
                                   QtGui.QMessageBox.Close)
     else:
         fname, _ = QtGui.QFileDialog.getSaveFileName(
             self,
             'Save file',
             dir=self.default_directory,
             filter="NIFTI files (*.nii *.nii.gz)")
         if fname != '':
             save(self.ivm.current_roi, fname)
         else:  # Cancelled
             pass
コード例 #4
0
 def _save(self):
     if self.data_list.selected is not None:
         name = self.data_list.selected.name
         data = self.ivm.data[name]
         if hasattr(data, "fname") and data.fname is not None:
             fname = data.fname
         else:
             fname = os.path.join(default_save_dir(), name + ".nii")
         fname, _ = QtGui.QFileDialog.getSaveFileName(
             self,
             'Save file',
             dir=fname,
             filter="NIFTI files (*.nii *.nii.gz)")
         if fname != '':
             save(self.ivm.data[name], fname)
         else:  # Cancelled
             pass
コード例 #5
0
    def save_output(self, save_folder):
        """
        Save process output to a folder

        In practice this is very process dependent and this method may well need to be
        overridden. The default implementation uses the ``output_data_items()`` to
        get the names of the data items the process has created and writes these
        plus the logfile to the output folder
        """
        data_to_save = self.output_data_items()
        self.debug("Data to save: %s", data_to_save)    
        for d in data_to_save:
            qpdata = self.ivm.data.get(d, None)
            if qpdata is not None:
                save(qpdata, os.path.join(save_folder, d + ".nii"))
        logfile = open(os.path.join(save_folder, "logfile"), "w")
        logfile.write(self._log)
        logfile.close()
コード例 #6
0
    def run(self, options):
        # Note that output-grid is not a valid data name so will not clash
        output_grid = None
        output_grid_name = options.pop("output-grid", None)
        if output_grid_name is not None:
            output_grid_data = self.ivm.data.get(output_grid_name, self.ivm.rois.get(output_grid_name, None))
            if output_grid_data is None:
                raise QpException("No such data found as source of grid: %s" % output_grid_name)
            else:
                output_grid = output_grid_data.grid

        for name in list(options.keys()):
            try:
                fname = options.pop(name, name)
                qpdata = self.ivm.data.get(name, None)
                if qpdata is not None:
                    save(qpdata, fname, grid=output_grid, outdir=self.outdir)
                else:
                    self.warn("Failed to save %s - no such data or ROI found" % name)
            except QpException as exc:
                self.warn("Failed to save %s: %s" % (name, str(exc)))
コード例 #7
0
 def add(self, data_name):
     """
     Add a data item to the working directory from the IVM
     """
     fname = os.path.join(self.workdir, data_name)
     save(self.ivm.data[data_name], fname)