def worker(reporter, task, queue):
     register_reporter(reporter)
     while True:
         args = queue.get()
         if args is None:
             queue.task_done()
             break
         task(*args)
         queue.task_done()
Esempio n. 2
0
 def init_progressbar(reporter):
     atpbar.register_reporter(reporter)
Esempio n. 3
0
    def process_pressures(self,
                          pressures,
                          p_0=ps.peep,
                          con=None,
                          reporter=None):
        """
        Maps data points from pressure to enumerated states
        
        Parameters
        ----------
        pressures : array like of real
            Pressure data points
        p_0 : PressureStates enum, optional
            The initial pressure state the program assumes it is in. Defaults to peep
        con : Queue object, optional
            The queue object to use for transferring data back to main cpu if multiprocessing is used. Defaults to None
        reporter : reporter object, optional
            The reporter object used to update the main cpu on the progress of the analysis. Defaults to None
        
        Returns
        -------
        None
        """
        if len(pressures) < self.w_len and con is None:
            con.put(np.array([]))
        elif len(pressures) < self.w_len:
            return

        output = np.array([ps(p_0)] * len(pressures))
        pressures = np.array(pressures).reshape(-1, self.w_len)
        pressure_means = np.mean(pressures, axis=1)
        pressure_mean_deltas = pressure_means[1:] - pressure_means[:-1]
        pressure_stds = np.std(pressures, axis=1)
        prev_label = ps(p_0)
        prev_pressure_hold = self.p_base
        if reporter != None:
            register_reporter(reporter)
        for i in atpbar(range(len(pressure_means) - 1),
                        name="Labelling pressure states"):
            if pressure_stds[i] < 0.1 * self.p_base:
                w_std_i = 0.05 * self.p_base
            else:
                w_std_i = pressure_stds[i]
            w_mean_delta = pressure_mean_deltas[i]
            w_mean_i_1 = pressure_means[i + 1]
            curpos = (i + 1) * self.w_len
            # If standard deviation is too small, set it to a minimum threshold
            if w_std_i < 0.1 * self.p_base:
                w_std_i = self.p_base * 0.05

            # Process stationary states
            if abs(w_mean_delta) < 2 * w_std_i:
                # Process for PIP
                if w_mean_i_1 > (self.p_base +
                                 prev_pressure_hold) / 2 + 2 * w_std_i:
                    if prev_label is not ps.pip:
                        output[curpos:curpos + self.w_len] = ps.pip
                        prev_pressure_hold = pressure_means[i + 1]
                        prev_label = ps.pip
                    else:
                        output[curpos:curpos + self.w_len] = ps.pip
                        prev_label = ps.pip
                else:
                    # Process PEEP
                    if prev_label is not ps.peep:
                        output[curpos:curpos + self.w_len] = ps.peep
                        prev_pressure_hold = pressure_means[i + 1]
                        prev_label = ps.peep
                    else:
                        output[curpos:curpos + self.w_len] = ps.peep
                        prev_label = ps.peep
            elif w_mean_delta > 0:
                # Process pressure rise
                output[curpos:curpos + self.w_len] = ps.pressure_rise
                prev_label = ps.pressure_rise
            else:
                # Process pressure drop
                output[curpos:curpos + self.w_len] = ps.pressure_drop
                prev_label = ps.pressure_drop
        if con is not None:
            con.put(output)
        else:
            self.p_labels = np.concatenate([self.p_labels, output])
Esempio n. 4
0
 def _configure_progressbar(self):
     atpbar.register_reporter(self.progress_reporter)
Esempio n. 5
0
 def process_flows(self, flows, f_0=fs.no_flow, con=None, reporter=None):
     """
     Maps data points from pressure to enumerated states
     
      Parameters
     ----------
     flows : array like of real
         Flow data points
     f_0 : FlowStates enum, optional
         The initial flow state the program assumes it is in. Defaults to no flow.
     con : Queue object, optional
         The queue object to use for transferring data back to main cpu if multiprocessing is used. Defaults to None
     reporter : reporter object, optional
         The reporter object used to update the main cpu on the progress of the analysis. Defaults to None
     
     Returns
     -------
     None
     """
     if len(flows) < self.w_len and con is None:
         con.put(np.array([]))
     elif len(flows) < self.w_len:
         return
     output = np.array([fs(f_0)] * len(flows))
     flows = np.array(flows).reshape(-1, self.w_len)
     flow_means = np.mean(flows, axis=1)
     flow_mean_deltas = flow_means[1:] - flow_means[:-1]
     flow_stds = np.std(flows, axis=1)
     if reporter != None:
         register_reporter(reporter)
     for i in atpbar(range(len(flow_means) - 1),
                     name="Labelling flow states"):
         if flow_stds[i] < self.f_thresh:
             w_std_i = 0.5 * self.f_thresh
         else:
             w_std_i = flow_stds[i]
         w_mean_delta = flow_mean_deltas[i]
         w_mean_i_1 = flow_means[i + 1]
         curpos = (i + 1) * self.w_len
         if abs(w_mean_delta) < 2 * w_std_i:
             if w_mean_i_1 > self.f_base + 2 * w_std_i:
                 # Process Peak Inspiratory Flow
                 output[curpos:curpos +
                        self.w_len] = fs.peak_inspiratory_flow
             elif w_mean_i_1 < self.f_base - 2 * w_std_i:
                 # Process Peak Expiratory Flow
                 output[curpos:curpos +
                        self.w_len] = fs.peak_expiratory_flow
             else:
                 # Process No Flow
                 output[curpos:curpos + self.w_len] = fs.no_flow
         elif w_mean_i_1 > self.f_base:
             if w_mean_delta > 0:
                 # Process Inspiration Initiation
                 output[curpos:curpos +
                        self.w_len] = fs.inspiration_initiation
             else:
                 # Process Inspiration Termination
                 output[curpos:curpos +
                        self.w_len] = fs.inspiration_termination
         else:
             if w_mean_delta < 0:
                 # Process Expiration Initiation
                 output[curpos:curpos +
                        self.w_len] = fs.expiration_initiation
             else:
                 # Process Expiration Termination
                 output[curpos:curpos +
                        self.w_len] = fs.expiration_termination
     if con is not None:
         con.put(output)
     else:
         self.f_labels = np.concatenate([self.f_labels, output])