if mask[y][x] == 1 and (x,y) not in points:
        points.append((x,y))
        mask[y][x] = 0
    else:
        return []
    new_points = []
    if x+1 < mask.shape[1]:
        new_points += recurrent_point_search(x+1, y, points, mask)
    if y+1 < mask.shape[0]:
        new_points += recurrent_point_search(x, y+1, points, mask)
    if x-1 >= 0:
        new_points += recurrent_point_search(x-1, y, points, mask)
    if y-1 >= 0:
        new_points += recurrent_point_search(x, y-1, points, mask)

    for point in new_points:
        if point not in points:
            points.append(point)
    return points


image = read_fits_file('M27_R_60s-001.fit')
# image = np.array([
#     [0,0,0,0],
#     [0,1000,1000,0],
#     [0,1000,1000,0],
#     [0,0,0,0],
#     ])
create_psf_objects(image)
# show_3d_data(image)
Example #2
0
    if args.show_object_fit:
        show_object_fit = True

    show_object_fit_separate = False
    if args.show_object_fit_separate:
        show_object_fit_separate = True

    show_3d = False
    if args.show_3d:
        show_3d = True

    if args.file is None or not os.path.isfile(args.file):
        raise FileNotFoundError('target file not given')
    if args.o is None:
        raise FileNotFoundError('output file not given')
    image = read_fits_file(args.file)
    # image = np.flip(image, axis=0)
    headers = read_fits_file_headers(args.file)

    if show_3d:
        show_3d_data(image)

    segmentation_options = ['fit_threshold', 'sobel']
    extracted_point_clusters = None
    if not args.s:
        raise AttributeError('need segmentation method, -s')
    if args.s in segmentation_options:
        if args.s == 'fit_threshold':
            if not args.sigma_threshold:
                sigma_threshold = 2
            else:
                  bigger.shape[1] - smaller.shape[1])
    first = difference[0] // 2
    second = difference[1] // 2
    print('Fixing sizes of outputs with shapes {} and {}'.format(
        str(bigger.shape), str(smaller.shape)))
    print('Crop {} from edges in 1 dimension and {} in second'.format(
        str(first), str(second)))
    if bigger is a1:
        return a1[first:-first, second:-second], a2
    else:
        return a1, a2[first:-first, second:-second]


for i in range(1, 10):
    input_file = 'generated/Comb_' + str(i) + '/Comb/Comb_' + str(i) + '.fits'
    image = read_fits_file(input_file)

    original_background_input_file = 'generated/Comb_' + str(
        i) + '/Noise/Noise_' + str(i) + '.fits'
    original_background = read_fits_file(original_background_input_file)
    # show_3d_data(original_background, method='matplotlib')

    file_name, extension = os.path.basename(input_file).split('.')
    # extracted_background = sigma_clipper(image, 10, 10)
    extracted_background = sigma_clipper(image)
    # show_3d_data(image, method='matplotlib')
    # show_3d_data(extracted_background, method='matplotlib')

    difference_between_backgrounds = abs(original_background -
                                         extracted_background)
Example #4
0
                        action="store_true")
    parser.add_argument("-o",
                        help="name of background file(default = file + _bg)")
    args = parser.parse_args()
    if '/' not in args.file:
        directory = os.getcwd()
        input_file = directory + '/' + args.file.split('/')[-1]
    else:
        if args.a:
            input_file = args.file
            directory = '/'.join(input_file.split('/')[:-1])
        else:
            directory = os.getcwd()
            input_file = directory + '/' + args.file

    image = read_fits_file(input_file)

    file_name, extension = os.path.basename(input_file).split('.')
    if args.i:
        extracted_background = sigma_clipper(image, iterations=args.i)
        my_comment = "Extracted background with {} iterations".format(args.i)
    else:
        extracted_background = sigma_clipper(image)
        my_comment = "Extracted background with {} iterations".format(5)

    if args.o:
        if '.' in args.o:
            edit_fits_data(input_file,
                           extracted_background,
                           args.o,
                           comment=my_comment)
Example #5
0
    init_vals = [1000., 0., 1000.]

    best_vals, covar = curve_fit(gaussian, [x for x in range(len(hist))], hist, p0=init_vals)

    # Get the fitted curve
    hist_fit = gaussian([x for x in range(len(hist))], *best_vals)

    center = int(best_vals[1])
    sigma = int(best_vals[2])
    if sigma_only:
        return sigma
    threshold = int(center + sigma*threshold_sigma)
    if show:
        fig = plt.figure()
        ax = fig.add_subplot(111)
        # smoothed = smooth(hist,15) ax.bar([x for x in range(len(hist))], hist)
        ax.axvline(threshold, color='green', label='threshold')
        ax.axvline(center, color='brown', label='center')
        ax.axvline(center+sigma, color='yellow', label='center+sigma')
        ax.plot([x for x in range(len(hist))], hist, label='Test data', color='red')
        ax.plot([x for x in range(len(hist))], hist_fit, label='Fitted data', color='blue')
        plt.show()
        return bins[threshold]
    else:
        return bins[threshold]

if __name__ == '__main__':
    image = read_fits_file('data/M27_R_60s-001.fit')
    histogram_threshold(image, True)
        found_spot = False
        for i, point_mesh in enumerate(joined):
            if found_spot:
                break
            for u, point_mesh_point in enumerate(point_mesh):
                if found_spot:
                    break
                if neighbor_check(point_mesh_point, point):
                    found_spot = True
                    joined[i].append(point)
        if not found_spot:
            joined.append([point])
    return joined


def neighbor_check(first_point, second_point):
    dist = np.linalg.norm(np.array(first_point) - np.array(second_point))
    if dist == 1 or dist == math.sqrt(2):
        return True
    return False


# image = read_fits_file('data/M27_R_60s-001.fit')
image = read_fits_file('data/AGO_2017_PR25_R-005.fit')
# image = read_fits_file('data/STREAK_test_1-003.fit')
extracted_point_spread_meshes = []
extract_point_spread_meshes(image)
for point_mash in extracted_point_spread_meshes:
    params = point_mash.fit_curve()
    show_image(point_mash.squared_data, 'point mash')