def reset(self):
        self.path = 'error'
        self.index = 0
        self.current_state = None  # current state
        # loop to generate a new map with a feasible path
        while self.path == 'error':
            # create map
            self.map_class = create_map.generate_map()
            # run JPS algorithm
            self.path = jps.run(self.map_class.get_start_node(),
                                self.map_class.get_target_node(),
                                self.map_class.get_map_size()[0],
                                self.map_class.get_map_size()[1],
                                self.map_class.get_map())
        # print('generate a new map and path!')
        # print('path:', self.path)
        # print('-' * 30)

        # fill up the path
        index = 0
        while True:
            # print(index)
            if index >= len(self.path) - 1:
                break
            dx = int(
                np.ceil(
                    abs(self.path[index + 1][0] - self.path[index][0]) /
                    self.k))
            dy = int(
                np.ceil(
                    abs(self.path[index + 1][1] - self.path[index][1]) /
                    self.k))
            print(dx, dy)

            num = 0
            if dx > 1 or dy > 1:
                x_list = np.linspace(self.path[index][0],
                                     self.path[index + 1][0],
                                     max(dx, dy) + 1,
                                     endpoint=True)
                y_list = np.linspace(self.path[index][1],
                                     self.path[index + 1][1],
                                     max(dx, dy) + 1,
                                     endpoint=True)
                for i in range(len(x_list) - 2, 0, -1):
                    self.path.insert(index + 1, [x_list[i], y_list[i]])
                num = len(x_list) - 2
            print(num)
            index = index + 1 + num
        # interpolate for fourth B-spline.
        self.path.insert(0, self.path[0])
        self.path.insert(0, self.path[0])
        self.path.append(self.path[-1])
        self.path.append(self.path[-1])
        # print('filling up path finished!', self.path)
        # print('-'*30)

        # slide first time
        state, _ = self.slide()
        return self.flatten_state(state)
    model = np.zeros_like(ccd_image)
    for row in catalogue:
        model += gaussian_2d(yy, xx, row['y'], row['x'], row['width'],
                             row['flux'])
    return model, ccd_image - model


def find_stars(ccd_image, sigma):
    mask, background, background_err = sigma_clip(ccd_image, sigma)
    segments, label_mask = segment_image(image - background, mask)
    return fit_gaussian_to_segments(image, segments, label_mask)


if __name__ == '__main__':
    image, data = generate_map((20, 20),
                               5,
                               noise=0.,
                               real_stars=True,
                               allow_blended=True,
                               allow_bordered=True,
                               seed=10)
    # plot_map(image, data[0])
    # plt.figure()
    table = find_stars(image, 2)
    # model, residual = model_map(image, table)
    plot_map(image, table[['y', 'x']])
    # # plot_positions(, edgecolor='y')
    # print(table)
    # print(data)
    plt.show()
Exemple #3
0
    t = Table(data=pos, names=['y', 'x'])
    t['flux'] = 1
    return t


if __name__ == '__main__':
    shape = (500, 500)
    nstars = 50
    noise = 0.001

    print 'generating map ...',
    image, (positions, fluxes,
            widths) = generate_map(shape,
                                   nstars,
                                   noise=noise,
                                   real_stars=True,
                                   allow_blended=False,
                                   allow_bordered=True,
                                   min_snr=3,
                                   max_snr=10)  # change these options!
    print ' done'

    print 'looking for the stars ...',
    catalogue = find_stars(image, noise)
    print ' done'

    print 'verifying stars ...',
    verify(catalogue, image, positions, fluxes)
    print ' done'

    plt.show()
Exemple #4
0
        plot_positions(missed, edgecolors='r', label='missed')
    s = '{:.0f}/{:.0f} missed. {:.0f} fake sources found'.format(len(missed), len(star_catalogue),
                                                                 len(positions) - len(star_catalogue))
    plt.title(s)
    print(s)

    diff_flux = true_fluxes - star_catalogue['flux']
    plt.figure()
    plt.hist(diff_flux, bins=int(len(true_fluxes) / 3))
    plt.xlabel(r'$\Delta flux$')
    plt.ylabel('N')
    print("flux deviation from true flux = {}+-{}".format(np.nanmean(diff_flux), np.nanstd(diff_flux)))


def shitty_find_stars(array):
    pos = np.asarray(list(zip(*np.where(array > 0))))
    t = Table(data=pos, names=['y', 'x'])
    t['flux'] = 1
    return t


if __name__ == '__main__':
    shape = (500, 500)
    nstars = 50
    image, (positions, fluxes, widths) = generate_map(shape, nstars, noise=0, real_stars=False,
                                                      allow_blended=False, allow_bordered=False,
                                                      min_snr=3, max_snr=10)  # change these options!
    catalogue = find_stars(image)
    verify(catalogue, image, positions, fluxes)

    plt.show()