Exemplo n.º 1
0
    def onRecovery(self, e):
        # Find finished runs and display results
        int_folder = os.path.abspath('{}/integration'.format(os.curdir))

        if not os.path.isdir(int_folder):
            open_dlg = wx.DirDialog(self,
                                    "Choose the integration folder:",
                                    style=wx.DD_DEFAULT_STYLE)
            if open_dlg.ShowModal() == wx.ID_OK:
                int_folder = open_dlg.GetPath()
                open_dlg.Destroy()
            else:
                open_dlg.Destroy()
                return

        paths = [os.path.join(int_folder, p) for p in os.listdir(int_folder)]
        paths = [p for p in paths if os.path.isdir(p)]

        path_dlg = dlg.RecoveryDialog(self)
        path_dlg.insert_paths(paths)

        if path_dlg.ShowModal() == wx.ID_OK:
            self.reset_settings()
            selected = path_dlg.selected
            recovery_mode = path_dlg.recovery_mode
            int_path = selected[1]

            init_file = os.path.join(int_path, 'init.cfg')

            if os.path.isfile(init_file):
                rec_init = ep.load(init_file)
                tmp_phil = inp.master_phil.format(
                    python_object=rec_init.params)
                self.iota_phil = self.iota_phil.fetch(source=tmp_phil)
            else:
                rec_init = InitAll(iver=iota_version)
                rec_init.int_base = int_path
                rec_init.obj_base = os.path.join(int_path, 'image_objects')
                rec_init.fin_base = os.path.join(int_path, 'final')
                rec_init.log_base = os.path.join(int_path, 'logs')
                rec_init.viz_base = os.path.join(int_path, 'visualization')
                rec_init.logfile = os.path.join(int_path, 'iota.log')
                with open(rec_init.logfile, 'r') as lf:
                    lines = lf.readlines()[4:86]
                    log_phil = ip.parse(''.join(lines))
                self.iota_phil = self.iota_phil.fetch(source=log_phil)
                rec_init.params = self.iota_phil.extract()
                input_entries = [i for i in rec_init.params.input if i != None]
                rec_init.input_list = ginp.make_input_list(input_entries)

            self.gparams = self.iota_phil.extract()

            # Re-populate input window with settings from read-in run (check that
            # nothing has been moved)
            rec_target_phil_file = os.path.join(rec_init.int_base,
                                                'target.phil')
            with open(rec_target_phil_file, 'r') as pf:
                rec_target_phil = pf.read()
            self.target_phil = rec_target_phil
            self.update_input_window()

            # Re-open processing window with results of the run
            if recovery_mode == 0:
                self.proc_window = frm.ProcWindow(self,
                                                  -1,
                                                  title='Image Processing',
                                                  target_phil=rec_target_phil,
                                                  phil=self.iota_phil)
                self.proc_window.recover(int_path=rec_init.int_base,
                                         init=rec_init,
                                         status=selected[0],
                                         params=self.gparams)
                self.proc_window.Show(True)
Exemplo n.º 2
0
    def onRecovery(self, e):
        # Find finished runs and display results
        int_folder = os.path.abspath('{}/integration'.format(os.curdir))

        if not os.path.isdir(int_folder):
            open_dlg = wx.DirDialog(self,
                                    "Choose the integration folder:",
                                    style=wx.DD_DEFAULT_STYLE)
            if open_dlg.ShowModal() == wx.ID_OK:
                int_folder = open_dlg.GetPath()
                open_dlg.Destroy()
            else:
                open_dlg.Destroy()
                return

        paths = [os.path.join(int_folder, p) for p in os.listdir(int_folder)]
        paths = [p for p in paths if os.path.isdir(p)]

        path_dlg = dlg.RecoveryDialog(self)
        path_dlg.insert_paths(paths)

        if path_dlg.ShowModal() == wx.ID_OK:
            self.reset_settings()
            selected = path_dlg.selected
            int_path = selected[1]

            init_file = os.path.join(int_path, 'init.cfg')

            if os.path.isfile(init_file):
                rec_init = ep.load(init_file)
                tmp_phil = inp.master_phil.format(
                    python_object=rec_init.params)
                self.iota_phil = self.iota_phil.fetch(source=tmp_phil)
            else:
                rec_init = InitAll(iver=iota_version)
                rec_init.int_base = int_path
                rec_init.obj_base = os.path.join(int_path, 'image_objects')
                rec_init.fin_base = os.path.join(int_path, 'final')
                rec_init.log_base = os.path.join(int_path, 'logs')
                rec_init.viz_base = os.path.join(int_path, 'visualization')
                rec_init.logfile = os.path.join(int_path, 'iota.log')
                with open(rec_init.logfile, 'r') as lf:
                    log_phil = ip.parse(''.join(lf.readlines()[4:86]))
                self.iota_phil = self.iota_phil.fetch(source=log_phil)
                rec_init.params = self.iota_phil.extract()
                input_entries = [i for i in rec_init.params.input if i != None]
                rec_init.input_list = ginp.make_input_list(input_entries)

            self.gparams = self.iota_phil.extract()

            # # Test / fix input folders / files
            # for inp in self.gparams.input:
            #   if not os.path.exists(inp):
            #     error_msg = wx.MessageDialog(None,
            #                                  'INPUT PATH {} NOT FOUND!\n'
            #                                  'Would you like to look for it?'
            #                                  ''.format(inp),
            #                                  wx.YES_NO | wx.ICON_ERROR)
            #     if (error_msg.ShowModal() == wx.ID_YES):
            #       open_dlg = wx.DirDialog(self, "Choose the input folder:",
            #                               style=wx.DD_DEFAULT_STYLE)
            #       if open_dlg.ShowModal() == wx.ID_OK:
            #         path = os.path.abspath(open_dlg.GetPath())
            #         if path not in self.gparams.input:
            #           self.gparams.input.append(path)
            #       else:
            #         return
            #     else:
            #       return
            #
            # # Test / fix output folder
            # if not os.path.isdir(self.gparams.output):
            #   error_msg = wx.MessageDialog(None,
            #                                'OUTPUT FOLDER {} NOT FOUND!\n'
            #                                'Would you like to look for it?'
            #                                ''.format(self.gparams.output),
            #                                wx.YES_NO | wx.ICON_ERROR)
            #   if (error_msg.ShowModal() == wx.ID_YES):
            #     open_dlg = wx.DirDialog(self, "Choose the output folder:",
            #                             style=wx.DD_DEFAULT_STYLE)
            #     if open_dlg.ShowModal() == wx.ID_OK:
            #       self.gparams.output = os.path.abspath(open_dlg.GetPath())
            #       int_no = rec_init.int_base.split('/')[-1]
            #       cnv_no = rec_init.conv_base.split('/')[-1]
            #       rec_init.input_base = self.gparams.input
            #       rec_init.conv_base = os.path.join(self.gparams.output,
            #                                         'converted_pickles', cnv_no)
            #       rec_init.int_base = os.path.join(self.gparams.output,
            #                                        'integration', int_no)
            #       rec_init.fin_base = os.path.join(rec_init.int_base, 'final')
            #       rec_init.log_base = os.path.join(rec_init.int_base, 'logs')
            #       rec_init.obj_base = os.path.join(rec_init.int_base, 'image_objects')
            #       rec_init.viz_base = os.path.join(rec_init.int_base, 'visualization')
            #       rec_init.logfile = os.path.join(int_path, 'iot.log')
            #     else:
            #       return
            #   else:
            #     return

            # Re-populate input window with settings from read-in run (check that
            # nothing has been moved)
            rec_target_phil_file = os.path.join(rec_init.int_base,
                                                'target.phil')
            with open(rec_target_phil_file, 'r') as pf:
                rec_target_phil = pf.read()
            self.target_phil = rec_target_phil

            self.update_input_window()

            # Re-open processing window with results of the run
            self.proc_window = frm.ProcWindow(self,
                                              -1,
                                              title='Image Processing',
                                              target_phil=rec_target_phil,
                                              phil=self.iota_phil)
            self.proc_window.recover(int_path=rec_init.int_base,
                                     init=rec_init,
                                     status=selected[0],
                                     params=self.gparams)
            self.proc_window.Show(True)