Exemple #1
0
def task_func(t):
    progress = ProgressDialog(title="progress",
                              message="counting to %d",
                              max=t,
                              show_time=True,
                              can_cancel=True)
    progress.open()
Exemple #2
0
    def _get_misc_data(self):
        if not self.raw:
            return
        if self.show_gui:
            # progress dialog with indefinite progress bar
            prog = ProgressDialog(title="Loading SQD data...",
                                  message="Loading stim channel data from SQD "
                                  "file ...")
            prog.open()
            prog.update(0)
        else:
            prog = None

        try:
            data, times = self.raw[self.misc_chs]
        except Exception as err:
            if self.show_gui:
                error(
                    None, "Error reading SQD data file: %s (Check the "
                    "terminal output for details)" % str(err),
                    "Error Reading SQD File")
            raise
        finally:
            if self.show_gui:
                prog.close()
        return data
Exemple #3
0
 def __init__(self, title, max_n):
     self.max_n = max_n
     self.progress = ProgressDialog(max=max_n,
                                    title=title,
                                    show_time=False,
                                    can_cancel=False,
                                    show_percent=True)
     self.progress.open()
Exemple #4
0
    def _create_fsaverage_fired(self):
        # progress dialog with indefinite progress bar
        title = "Creating FsAverage ..."
        message = "Copying fsaverage files ..."
        prog = ProgressDialog(title=title, message=message)
        prog.open()
        prog.update(0)

        try:
            self.model.create_fsaverage()
        except Exception as err:
            error(None, str(err), "Error Creating FsAverage")
            raise
        finally:
            prog.close()
def task_func(t):
    progress = ProgressDialog(title="progress",
                              message="counting to %d" % t,
                              max=t,
                              show_time=True,
                              can_cancel=True)
    progress.open()

    for i in range(0, t + 1):
        time.sleep(1)
        print(i)
        (cont, skip) = progress.update(i)
        if not cont or skip:
            break

    progress.update(t)
Exemple #6
0
 def run_model(self, modeldata):
     self.simulation = True
     self.md = modeldata
     self.c_stock = numpy.empty(shape=(0, 10), dtype=numpy.float32)
     self.c_change = numpy.empty(shape=(0, 10), dtype=numpy.float32)
     self.co2_yield = numpy.empty(shape=(0, 3), dtype=numpy.float32)
     self.timemap = defaultdict(list)
     self.area_timemap = defaultdict(list)
     samplesize = self.md.sample_size
     msg = "Simulating %d samples for %d timesteps" % (
         samplesize, self.md.simulation_length)
     progress = ProgressDialog(title="Simulation",
                               message=msg,
                               max=samplesize,
                               show_time=True,
                               can_cancel=True)
     progress.open()
     timesteps = self.md.simulation_length
     self.timestep_length = self.md.timestep_length
     self.ml_run = True
     self.infall = {}
     self.initial_mode = self.md.initial_mode
     if self.initial_mode == 'steady state':
         self.initial_def = self.md.steady_state
     else:
         self.initial_def = self.md.initial_litter
     timemsg = None
     for j in range(samplesize):
         (cont, skip) = progress.update(j)
         if not cont or skip:
             break
         self.draw = True
         self.curr_yr_ind = 0
         self.curr_month_ind = 0
         for k in range(timesteps):
             self._predict_timestep(j, k)
         self.ml_run = False
     self._fill_moment_results()
     progress.update(samplesize)
     if timemsg is not None:
         error(timemsg, title='Error handling timesteps', buttons=['OK'])
     return self.c_stock, self.c_change, self.co2_yield
Exemple #7
0
    def _render_animation_fired(self):
        self.stop = True
        n_frames_render = self.render_to_frame - self.render_from_frame
        # prepare the render window
        renwin = self._figure.scene.render_window
        aa_frames = renwin.aa_frames
        renwin.aa_frames = 8
        renwin.alpha_bit_planes = 1
        # turn on off screen rendering
        #renwin.off_screen_rendering = True
        # set size of window
        if self.fix_image_size:
            orig_size = renwin.size
            renwin.size = self.image_size
        # render the frames
        progress = ProgressDialog(title="Rendering", max=n_frames_render, 
                                  show_time=True, can_cancel=True)
        progress.open()
        self.is_rendering_animation = True
        for frame in range(self.render_from_frame, self.render_to_frame + 1):
            # move animation to desired frame, this will also render the scene
            self.current_frame = frame
            # prepare window to image writer
            render = tvtk.WindowToImageFilter(input=renwin, magnification=1)#, input_buffer_type='rgba')
            if not self.fix_image_size:
                render.magnification = self.magnification
            exporter = tvtk.PNGWriter(file_name=path.join(self.render_directory, self.render_name_pattern % frame))

            configure_input(exporter,render)
            exporter.write()
            do_continue, skip = progress.update(frame - self.render_from_frame)
            if not do_continue:
                break
        # reset the render window to old values
        renwin.aa_frames = aa_frames
        if self.fix_image_size:
            renwin.size = orig_size
        #renwin.off_screen_rendering = False
        self.is_rendering_animation = False
        progress.close()
Exemple #8
0
    def _get_misc_data(self):
        if not self.raw:
            return
        if self.show_gui:
            # progress dialog with indefinite progress bar
            prog = ProgressDialog(title="Loading SQD data...",
                                  message="Loading stim channel data from SQD "
                                  "file ...")
            prog.open()
            prog.update(0)
        else:
            prog = None

        try:
            data, times = self.raw[self.misc_chs]
        except Exception as err:
            if self.show_gui:
                error(None, str(err), "Error Creating FsAverage")
            raise
        finally:
            if self.show_gui:
                prog.close()
        return data
Exemple #9
0
    def read_data(self):
        """ Obtain x_locations, y_locations, data_locations, traces in a context

            Returns:
            ---------
            context: DataContext

        """

        # Check if the filename is valid for reading data
        if not self.file_handle:
            return None

        # Set the file reader at the first char.
        if self.file_handle.closed:
            self.file_handle = file(self.filename, 'rb')

        # Setup a progress dialog
        progress = ProgressDialog(title='Reading Segy Files',
                                  message='Reading Segy Files',
                                  max=100,
                                  show_time=True,
                                  can_cancel=True)
        progress.open()

        # Skip the card_image_header and binary header
        self.file_handle.seek(Segy.CARD_IMAGE_HEADER_LEN +
                              Segy.BINARY_HEADER_LEN)
        progress.update(1)

        # Check if data lengths are correct.
        x_data_len = struct.calcsize(self.x_format)
        y_data_len = struct.calcsize(self.y_format)
        inline_data_len = struct.calcsize(self.inline_format)
        crossline_data_len = struct.calcsize(self.crossline_format)

        if not (x_data_len == y_data_len and y_data_len == inline_data_len
                and inline_data_len == crossline_data_len):
            logger.error('SegyReader: Mismatch in format lengths')
            return None

        if self.scale_format != '':
            scale_data_len = struct.calcsize(self.scale_format)
            if scale_data_len != x_data_len:
                logger.error('SegyReader: Mismatch in format lengths')
                return None

        # Get trace header data of 240 bytes.
        header_data = self.file_handle.read(Segy.TRACE_HEADER_LEN)
        traces, read_error = [], False
        previous_update = 1
        while header_data != '' and not read_error:
            trace = self._read_trace(header_data, x_data_len)
            if trace is None:
                logger.error('SegyReader: Error in reading a trace')
                read_error = True
            else:
                traces.append(trace)
                header_data = self.file_handle.read(Segy.TRACE_HEADER_LEN)

            progress_pc = 1 + int(
                98.0 * float(len(traces)) / float(self.trace_count))
            if progress_pc - previous_update > 1:
                cont_val, skip_val = progress.update(progress_pc)
                previous_update = progress_pc

                # If the user has cancelled the action then stop the import
                # immediately
                if skip_val or not cont_val:
                    del traces
                    self.file_handle.close()
                    return None

        self.file_handle.close()
        progress.update(100)

        if read_error:
            del traces
            return None
        else:
            arr_descriptor = {
                'names':
                ('x', 'y', 'inline', 'crossline', 'scale_factor', 'trace'),
                'formats': ('f4', 'f4', 'f4', 'f4', 'f4',
                            str(self.samples_per_trace) + 'f4')
            }
            traces = array(traces, dtype=arr_descriptor)
            filesplit = os.path.split(self.filename)
            name = str(os.path.splitext(
                filesplit[1])[0]).translate(trans_table)
            return DataContext(name=name,
                               _bindings={
                                   'traces': traces['trace'],
                                   'x_locations': traces['x'],
                                   'y_locations': traces['y'],
                                   'inline_values': traces['inline'],
                                   'crossline_values': traces['crossline'],
                                   'scale_factors': traces['scale_factor']
                               })
        return
Exemple #10
0
 def initialize(self, title, max_index):
     self.progress = ProgressDialog(title="Characterizing %d peaks on current image"%max_index, 
                       max=int(max_index), show_time=True, can_cancel=False)
     self.progress.open()
Exemple #11
0
 def _progress_dialog_default(self):
     return ProgressDialog(
         min=0,
         max=100,
     )
Exemple #12
0
    def __getitem__(self, factor_slices):
        '''
        Access to the output_array using factor level indices.

        This method enables access to the values using the syntax

        output_sub_array = pstudy[ f1_level_idx, f2_level_idx, ... ]

        Here the standard numpy indices including slice and elipses can be used. 
        '''

        # map the slices within the levels2run array
        # to the indices of the expanded input_table
        #
        n_sims = self._get_slice_n_sims(factor_slices)
        progress = ProgressDialog(title='simulation progress',
                                  message='running %d simulations' % n_sims,
                                  max=n_sims,
                                  show_time=True,
                                  can_cancel=True)
        progress.open()

        run_idx_list = self.levels2run[factor_slices].flatten()
        runs_levels = self.input_table[run_idx_list]
        runs_levels_idx = self.run2levels[run_idx_list]

        # start the computation for each of the runs
        #
        sim_idx = 0
        for run_levels, run_levels_idx in zip(runs_levels, runs_levels_idx):

            # check to see if this run is already in the cache
            #
            outputs = self._output_cache.get(tuple(run_levels), None)
            if outputs == None:

                print 'new simulation', sim_idx

                # Set the factor values of the run in
                # the simulation model
                #
                for factor_name, factor, level in zip(self.factor_names,
                                                      self.factor_list,
                                                      run_levels):
                    level = factor.get_level_value(level)
                    setattr(self.sim_model, factor_name, level)

                # Perform the simulation
                #
                outputs = self.sim_model.peval()

                self.output_array[tuple(run_levels_idx)] = outputs
                self._output_cache[tuple(run_levels)] = outputs

            else:
                print 'cached simulation', sim_idx

            # let the progress bar interfere
            #
            (cont, skip) = progress.update(sim_idx)
            if not cont or skip:
                break
            sim_idx += 1

        progress.update(n_sims)
        return self.output_array[factor_slices]