Exemple #1
0
def construct_circular(n_radii, n_bdy, n_sensor):
    shell_radii = np.linspace(0, 1, n_radii + 2)[1:-1]
    interior = construct_shell(shell_radii)

    bdy_theta = np.linspace(0, 2 * np.pi, n_bdy + 1)
    design_bdy = pol2cart(np.c_[np.ones(n_bdy), bdy_theta[:-1]])

    bdy_sensor_skip = (int)(n_bdy / n_sensor)

    sensor_ixs = np.concatenate(
        [np.arange(0, len(design_bdy), bdy_sensor_skip)[1:], [0]])
    is_sensor_flags = np.in1d(np.arange(len(design_bdy)), sensor_ixs)

    sensor_xy = design_bdy[sensor_ixs]
    non_sensor_xy = design_bdy[~is_sensor_flags]

    return EITGrid(interior, non_sensor_xy, sensor_xy)
 def show_directions(self):
     fig, ax = plt.subplots(nrows=1, ncols=1)
     plot_data = []
     for cell in self.map.cells_data:
         for m in cell.clustering_results.mean_values:
             u, v = he.pol2cart(m[0], m[1])
             row = [
                 cell.corner[0] + self.map.grid_step / 2,
                 cell.corner[1] + self.map.grid_step / 2, u, v
             ]
             plot_data.append(row)
     plot_data = np.array(plot_data)
     ax.quiver(plot_data[:, 0],
               plot_data[:, 1],
               plot_data[:, 2],
               plot_data[:, 3],
               units='xy')
     plt.show()
Exemple #3
0
 def get_headingXY(self):
     # Remember to convert to radians!
     x, y = helpers.pol2cart(self.speed * 1000 / 60 / 60, math.radians(self.heading + 90))
     return [
         -x, y
     ]
Exemple #4
0
for chunk in pd.read_csv(file_name, chunksize=chunksize):
    cl_map.load_data(chunk)
    loop_number = loop_number + 1
    plot_data = []
    if loop_number % refresh_ratio == 0:
        ax0.clear()
        ax0.set_aspect('equal')
        ax0.set_xlim(x_min, x_max)
        ax0.set_ylim(y_min, y_max)
        cl_map.cluster_data()

        p_array_vis = np.zeros(p_shape)
        # visualisation
        for cell in cl_map.cells_data:
            for m in cell.clustering_results.mean_values:
                u, v = he.pol2cart(m[0], m[1])
                row = [
                    cell.corner[0] + cl_map.grid_step / 2,
                    cell.corner[1] + cl_map.grid_step / 2, u, v
                ]
                plot_data.append(row)
                p_array_vis[
                    int((cell.corner[1] - y_min) / step),
                    int(
                        (cell.corner[0] - x_min) / step
                    )] = cell.count[0] / cl_map.total_number_of_observations
        plot_data = np.array(plot_data)
        ax0.quiver(plot_data[:, 0],
                   plot_data[:, 1],
                   plot_data[:, 2],
                   plot_data[:, 3],
    def process_map(self):
        self.__compute_fft()
        self.__get_dominant_directions()

        ti = time.time()
        if not self.comp:
            pass
        else:
            diag = 10
            mask_all = np.zeros(self.norm_ft_image.shape)

            min_l = (self.binary_map.shape[0] if self.binary_map.shape[0] < self.binary_map.shape[1] else
                     self.binary_map.shape[1]) / 2 - (self.binary_map.shape[0] if self.binary_map.shape[0] >
                                                                                  self.binary_map.shape[1] else
                                                      self.binary_map.shape[1])
            max_l = (self.binary_map.shape[0] if self.binary_map.shape[0] > self.binary_map.shape[1] else
                     self.binary_map.shape[1]) / 2 + (self.binary_map.shape[0] if self.binary_map.shape[0] >
                                                                                  self.binary_map.shape[1] else
                                                      self.binary_map.shape[1])
            for p in self.comp:
                x1, y1 = he.pol2cart(diag, self.angles[p[0]] + np.pi / 2.0)
                x2, y2 = he.pol2cart(diag, self.angles[p[1]] + np.pi / 2.0)

                x1 = x1 + self.binary_map.shape[0] / 2.0
                x2 = x2 + self.binary_map.shape[0] / 2.0

                y1 = y1 + self.binary_map.shape[1] / 2.0
                y2 = y2 + self.binary_map.shape[1] / 2.0

                a = y2 - y1
                b = x1 - x2
                c = a * x1 + b * y1
                c1 = c + self.par
                c2 = c - self.par

                ######
                X1_l = min_l
                Y1_l = (c - a * X1_l) / b
                X2_l = max_l
                Y2_l = (c - a * X2_l) / b
                ######
                X1 = 0
                Y1 = (c - a * X1) / b
                X2 = self.binary_map.shape[0]
                Y2 = (c - a * X2) / b
                ###
                X1_1 = 0
                Y1_1 = (c1 - a * X1_1) / b
                X2_1 = self.binary_map.shape[0]
                Y2_1 = (c1 - a * X2_1) / b
                ###
                X1_2 = 0
                Y1_2 = (c2 - a * X1_2) / b
                X2_2 = self.binary_map.shape[0]
                Y2_2 = (c2 - a * X2_2) / b
                ###
                Y_org = Y1
                if np.abs(Y_org) > 3 * np.max(self.binary_map.shape):
                    ###
                    Y1_l = min_l
                    X1_l = (c - b * Y1_l) / a
                    Y2_l = max_l
                    X2_l = (c - b * Y2_l) / a
                    ###
                    Y1 = 0
                    X1 = (c - b * Y1) / a
                    Y2 = self.binary_map.shape[1]
                    X2 = (c - b * Y2) / a
                    ###
                    Y1_1 = 0
                    X1_1 = (c1 - b * Y1_1) / a
                    Y2_1 = self.binary_map.shape[1]
                    X2_1 = (c1 - b * Y2_1) / a
                    ###
                    Y1_2 = 0
                    X1_2 = (c2 - b * Y1_2) / a
                    Y2_2 = self.binary_map.shape[1]
                    X2_2 = (c2 - b * Y2_2) / a
                    ###
                if max(X1_l, X2_l) < max(Y1_l, Y2_l):
                    self.lines_long_v.append([X1_l, Y1_l, X2_l, Y2_l])
                else:
                    self.lines_long_h.append([X1_l, Y1_l, X2_l, Y2_l])

                self.lines.append([X1, Y1, X2, Y2])
                mask_l = self.__generate_mask(X1_1, Y1_1, X2_1, Y2_1, X1_2, Y1_2, X2_2, Y2_2, Y_org)
                if not np.any(mask_l == 1):
                    mask_l = self.__generate_mask(X1_2, Y1_2, X2_2, Y2_2, X1_1, Y1_1, X2_1, Y2_1, Y_org)

                self.part_mask.append(mask_l)
                l_mask_ftimage = self.ft_image * mask_l
                l_mask_iftimage = np.fft.ifft2(l_mask_ftimage)
                self.part_reconstruction.append(np.abs(l_mask_iftimage))
                l_map_scored_good = np.abs(l_mask_iftimage) * (self.binary_map * 1)
                self.part_score.append(l_map_scored_good)

                mask_all = np.logical_or(mask_all, mask_l)
                # mask_ftimage_l = self.ft_image * mask_l
                # mask_iftimage_l = np.fft.ifft2(mask_ftimage_l)
                # sm_l = np.abs(mask_iftimage_l) * (self.binary_map * 1)
                # sm_l = sm_l / np.max(sm_l)

            mask_all = np.flipud(mask_all)
            mask_all_inv = np.ones(mask_all.shape)
            mask_all_inv[mask_all == 1] = 0
            logging.debug("Map scored in : %.2f s", time.time() - ti)

            #################
            # legacy experiemntation stuff let us see what we need to keep
            #################

            self.mask_ft_image = self.ft_image * mask_all
            mask_iftimage = np.fft.ifft2(self.mask_ft_image)

            # self.mask_inv_ft_image = self.ft_image * mask_all_inv
            # mask_inv_iftimage = np.fft.ifft2(self.mask_inv_ft_image)

            self.map_scored_good = np.abs(mask_iftimage) * (self.binary_map * 1)