def test_max_magnitude(): from all_sky_cloud_detection.catalog import read_catalog catalog = read_catalog(max_magnitude=6) assert np.all(catalog['v_mag'] <= 6) catalog = read_catalog(max_magnitude=3) assert np.all(catalog['v_mag'] <= 3)
def main(): args = parser.parse_args() catalog = read_catalog( max_magnitude=args.max_magnitude, max_variability=None, ) img = cam.read(args.inputfile) # create catalog of possibly visible stars and planets stars_catalog, magnitude = transform_catalog( catalog, img.timestamp, cam, min_altitude=args.min_altitude) # find blobs in the image r, c, s = find_stars(img.data, threshold=args.threshold) found_altaz = cam.pixel2horizontal(r, c, img.timestamp) # only use blobs with alt > min_altitude mask = found_altaz.alt.deg > args.min_altitude idx, found = find_matching_stars(stars_catalog, found_altaz[mask]) print('Simple: ', calculate_cloudiness_simple(found)) print('Weighted:', calculate_cloudiness_weighted(magnitude, found)) # plot that stuff fig, ax, plot = plot_img(img) add_blobs( *cam.horizontal2pixel(stars_catalog[found]), np.full(len(stars_catalog), 1.5), color='C2', ax=ax, ) add_blobs( *cam.horizontal2pixel(stars_catalog[~found]), np.full(len(stars_catalog), 1.5), color='C1', ax=ax, ) plt.legend([ plt.Circle((0, 0), 0, edgecolor='C2', fill=False), plt.Circle((0, 0), 0, edgecolor='C1', fill=False), ], ['Found Catalog Stars', 'Catalog stars without match']) add_zenith_lines(cam, ax=ax) add_direction_labels(cam, ax=ax, color='crimson', weight='bold', size=14) plt.show()
def test_images(): from all_sky_cloud_detection.cameras import cta_la_palma as cam from all_sky_cloud_detection.catalog import read_catalog, transform_catalog from all_sky_cloud_detection.star_detection import find_stars, find_matching_stars from all_sky_cloud_detection.calculate_cloudiness import calculate_cloudiness_simple images = [ 'tests/resources/cta_images/starry_nomoon.fits.gz', 'tests/resources/cta_images/starry.fits.gz', 'tests/resources/cta_images/partly_cloudy.fits.gz', 'tests/resources/cta_images/cloudy.fits.gz', ] limits = [ (0, 0.1), (0, 0.2), (0.3, 0.7), (0.9, 1.0), ] catalog = read_catalog( max_magnitude=cam.max_magnitude, max_variability=None, ) for (a, b), path in zip(limits, images): img = cam.read(path) # create catalog of possibly visible stars and planets stars_catalog, magnitude = transform_catalog( catalog, img.timestamp, cam, min_altitude=20, ) r, c, s = find_stars(img.data, threshold=cam.threshold) found_altaz = cam.pixel2horizontal(r, c, img.timestamp) mask = found_altaz.alt.deg > 20 idx, found = find_matching_stars( stars_catalog, found_altaz[mask], max_sep=0.25 * u.deg ) cl = calculate_cloudiness_simple(found) assert a <= cl <= b
from astropy.coordinates import concatenate, match_coordinates_sky import astropy.units as u import pandas as pd from tqdm import tqdm from all_sky_cloud_detection.cameras import magic_2018 from all_sky_cloud_detection.catalog import read_catalog, transform_catalog, get_planets from all_sky_cloud_detection.star_detection import find_stars from all_sky_cloud_detection.plotting import add_blobs, add_zenith_lines parser = ArgumentParser() parser.add_argument('inputdir') args = parser.parse_args() catalog = read_catalog( max_magnitude=2.5, max_variability=None, ) write_header = True for path in tqdm(sorted(os.listdir(args.inputdir))): img = magic_2018.read(os.path.join(args.inputdir, path)) if img.data.mean() > 0.030: continue stars_altaz = transform_catalog(catalog, img.timestamp, magic_2018) objects = concatenate( [stars_altaz, get_planets(img.timestamp, magic_2018)]) objects = objects[objects.alt.deg > 5]
def main(): args = parser.parse_args() catalog = read_catalog( max_magnitude=args.max_magnitude, max_variability=None, ) for path in images: img = cam.read(path) # create catalog of possibly visible stars and planets stars_catalog, magnitude = transform_catalog( catalog, img.timestamp, cam, min_altitude=args.min_altitude ) # img.smoothed = gaussian(img.data, sigma=1.5) # find blobs in the image r, c, s = find_stars(img.data, threshold=args.threshold) found_altaz = cam.pixel2horizontal(r, c, img.timestamp) # only use blobs with alt > min_altitude mask = found_altaz.alt.deg > args.min_altitude idx, found = find_matching_stars( stars_catalog, found_altaz[mask], max_sep=0.25 * u.deg ) print('Simple: ', calculate_cloudiness_simple(found)) print('Weighted:', calculate_cloudiness_weighted(magnitude, found)) img.data[np.isnan(img.data)] = np.nanmin(img.data) img.data = adjust_gamma(rescale_intensity(img.data, (0, 1)), gamma=0.7) # plot that stuff fig, ax, plot = plot_img(img) fig.colorbar(plot) add_blobs( r[mask], c[mask], s[mask], color='C0', ax=ax, ) add_blobs( *cam.horizontal2pixel(stars_catalog[found]), np.full(len(stars_catalog), 1.5), color='C2', ax=ax, ) add_blobs( *cam.horizontal2pixel(stars_catalog[~found]), np.full(len(stars_catalog), 1.5), color='C1', ax=ax, ) plt.legend([ plt.Circle((0, 0), 0, edgecolor='C2', fill=False), plt.Circle((0, 0), 0, edgecolor='C1', fill=False), ], [ 'Found Catalog Stars', 'Catalog stars without match' ]) add_zenith_lines(cam, ax=ax) add_direction_labels(cam, ax=ax, color='crimson', weight='bold', size=14) plt.show()
# coding: utf-8 from all_sky_cloud_detection.cameras import magic_2018 from all_sky_cloud_detection.catalog import read_catalog from all_sky_cloud_detection.plotting import add_direction_labels, add_zenith_lines from astropy.coordinates import SkyCoord, AltAz import astropy.units as u import matplotlib.pyplot as plt from argparse import ArgumentParser parser = ArgumentParser() parser.add_argument('inputfile') parser.add_argument('-o', '--output') args = parser.parse_args() c = read_catalog( max_magnitude=magic_2018.max_magnitude, max_variability=None, ) img = magic_2018.read(args.inputfile) big_dipper = [54061, 53910, 58001, 59774, 62956, 65378, 67301] dipper_mask = [row['HIP'] in big_dipper for row in c] stars = SkyCoord(ra=c['ra'], dec=c['dec']) altaz = AltAz(obstime=img.timestamp, location=magic_2018.location) stars_altaz = stars.transform_to(altaz) mask = (stars_altaz.alt.deg > 15) & (c['v_mag'] <= 3.5) fig = plt.figure(figsize=(12, 9)) ax = fig.add_axes([0, 0, 1, 1]) ax.set_axis_off()
def test_read(): from all_sky_cloud_detection.catalog import read_catalog catalog = read_catalog() assert catalog.colnames == ['HIP', 'ra', 'dec', 'v_mag', 'variability']
def test_max_variability(): from all_sky_cloud_detection.catalog import read_catalog catalog = read_catalog(max_variability=2) assert np.any(catalog['variability'] >= 1) assert np.all(catalog['variability'] <= 2)
# coding: utf-8 from all_sky_cloud_detection.cameras import cta_la_palma from all_sky_cloud_detection.catalog import read_catalog from astropy.coordinates import SkyCoord, AltAz import astropy.units as u import matplotlib.pyplot as plt c = read_catalog( max_magnitude=cta_la_palma.max_magnitude, max_variability=None, ) img = cta_la_palma.read('tests/resources/cta_images/starry.fits.gz') big_dipper = [54061, 53910, 58001, 59774, 62956, 65378, 67301] dipper_mask = [row['HIP'] in big_dipper for row in c] stars = SkyCoord(ra=c['ra'], dec=c['dec']) altaz = AltAz(obstime=img.timestamp, location=cta_la_palma.location) stars_altaz = stars.transform_to(altaz) mask = (stars_altaz.alt.deg > 15) & (c['v_mag'] <= 5) fig = plt.figure(figsize=(8, 8)) ax = fig.add_axes([0, 0, 1, 1]) ax.set_axis_off() ax.imshow(img.data, cmap='gray', vmax=0.2) for m in (mask, dipper_mask): row, col = cta_la_palma.horizontal2pixel(stars_altaz[m]) ax.plot(col, row, 'o', ms=8, mfc='none')
from all_sky_cloud_detection.cameras import iceact from all_sky_cloud_detection.catalog import read_catalog from astropy.coordinates import SkyCoord, AltAz import astropy.units as u import matplotlib.pyplot as plt c = read_catalog( max_magnitude=iceact.max_magnitude, max_variability=None, ) img = iceact.read('tests/resources/iceact_images/starry.fits') stars = SkyCoord(ra=c['ra'], dec=c['dec']) altaz = AltAz(obstime=img.timestamp, location=iceact.location) stars_altaz = stars.transform_to(altaz) mask = (stars_altaz.alt.deg > 15) & (c['v_mag'] <= 2.5) fig = plt.figure(figsize=(8, 8)) ax = fig.add_axes([0, 0, 1, 1]) ax.set_axis_off() ax.imshow(img.data, cmap='gray', vmax=0.2) row, col = iceact.horizontal2pixel(stars_altaz[mask]) ax.plot( col, row, 'o', ms=8,