def query_des_fits(ra,
                   dec,
                   size=10.0,
                   output_file='DES_TMP.fits',
                   xpix=500,
                   ypix=500,
                   projection='AIT'):

    coord = SkyCoord(ra, dec, unit='deg', frame='icrs')
    fov = str(round(size / 60 * 100) / 100) + ' deg'
    geometry = WCSGeometry.create(skydir=coord,
                                  width=xpix,
                                  height=ypix,
                                  fov=fov,
                                  coordsys='icrs',
                                  projection=projection)

    hips_survey_base = 'CDS/P/DES-DR1/'

    #Split string in a list and search for fits image URLs & band names
    bands_list = ['g', 'r', 'i', 'z', 'Y']
    for i in range(0, len(bands_list)):
        try:
            print("Downloading band " + bands_list[i] + ": " + bands_list[i] +
                  '_' + output_file)
            hips_survey = hips_survey_base + bands_list[i]
            result = make_sky_image(geometry, hips_survey, 'fits')
            result.write_image(bands_list[i] + '_' + output_file)
        except:
            print("Failed")
Beispiel #2
0
    def __init__(self):
        #projections support http://docs.astropy.org/en/stable/wcs/#supported-projections

        ra = 214.641841
        dec = 51.2152

        geometry = WCSGeometry.create(
            skydir=SkyCoord(ra, dec, unit='deg'),
            width=100,
            height=100,
            fov="0.03 deg",
            coordsys='icrs',
            projection='SIN',
        )
        coor = SkyCoord(ra, dec, unit='deg', frame='galactic')
        print(coor.to_string('hmsdms'))
        # geometry = WCSGeometry.create(
        #     skydir=SkyCoord(280.4652, -32.8884, unit='deg', frame='galactic'),
        #     width=1600, height=1000, fov="2 deg",
        #     coordsys='icrs', projection='SIN',
        # )

        #        hips_survey = HipsSkyMaps.getMap("CFHT")

        hips_survey = 'CDS/P/SPITZER/MIPS2'
        hips_survey = 'CDS/P/CFHTLS/W/r'
        #"P/CFHTLS/W/r) 14 18 42.36 +51 25 56.7 0.5 deg"
        #result = make_sky_image(geometry, hips_survey, 'jpeg')

        result = make_sky_image(geometry,
                                hips_survey,
                                'fits',
                                progress_bar=False)
        image = result.image
        plt.clf()
        fig1 = plt.gcf()
        w = h = 3.125  # 300pixel = 3.125inches (1in == 2.54cm) 1 inch = 96 pixel
        fig1.set_size_inches(w, h)

        plt.imshow(result.image,
                   origin='lower',
                   interpolation='none',
                   cmap=plt.get_cmap("Greys"),
                   norm=matplotlib.colors.LogNorm(vmin=0.1,
                                                  vmax=result.image.max()))
        plt.axis("off")

        #plt.figure(figsize=(20, 10))

        result.plot()
        plt.show()
Beispiel #3
0
"""Basic example how to plot a sky image with the hips package"""
from astropy.coordinates import SkyCoord
from hips import WCSGeometry, make_sky_image

# Compute the sky image
geometry = WCSGeometry.create(
    skydir=SkyCoord(0, 0, unit='deg', frame='galactic'),
    width=2000, height=1000, fov="3 deg",
    coordsys='galactic', projection='AIT',
)
hips_survey = 'CDS/P/DSS2/red'
result = make_sky_image(geometry=geometry, hips_survey=hips_survey, tile_format='fits')
result.plot()

# Draw the sky image
# import matplotlib.pyplot as plt
# from astropy.visualization.mpl_normalize import simple_norm
# ax = plt.subplot(projection=geometry.wcs)
# norm = simple_norm(result.image, 'sqrt', min_percent=1, max_percent=99)
# ax.imshow(result.image, origin='lower', norm=norm, cmap='gray')

# import matplotlib.pyplot as plt
# plt.show()
Beispiel #4
0
hips_survey_property = HipsSurveyProperties.fetch(url)

# In[ ]:

geometry = WCSGeometry.create(skydir=SkyCoord(217.9,
                                              -2.3,
                                              unit='deg',
                                              frame='fk5'),
                              width=180,
                              height=180,
                              fov='0.02 deg',
                              coordsys='icrs',
                              projection='TAN')
from hips import make_sky_image
result = make_sky_image(geometry, hips_survey_property, 'fits')

# In[ ]:

result.plot()

# In[ ]:

#result.image

# In[ ]:

import matplotlib.pyplot as plt

# In[ ]:
Beispiel #5
0
def plot_hips_sky_image(ra: float, dec: float, sig_p: float, sigma1: float,
                        hips_surveys: List, outpath: str, name: str,
                        label: int, res: int):
    """ Plot sky image using hips

    : ra : ra of the pixel
    : dec : dec of the pixel
    : sig_p : sig_poisson of the pixel
    : sigma1 : sigma1 of the map
    : hips_surveys : list of surveys
    : outpath : output dir path
    : name : name of the system (dwarf and more info)
    : label : label of a cluster pixels
    : res : resolution of the image (number of pixels for the image)
    """
    width = WIDTH_FAC * sigma1

    # Compute the sky image
    geometry = WCSGeometry.create(skydir=SkyCoord(ra,
                                                  dec,
                                                  unit='deg',
                                                  frame='icrs'),
                                  width=res,
                                  height=res,
                                  fov="%f deg" % width,
                                  coordsys='icrs',
                                  projection='AIT')

    name_split = name.split('-')
    short_name = name_split[0]
    data = np.load('results/{}'.format(
        name.replace('-poisson' or '-gaussian', '/queried-data.npy'))).item()

    ra_data, dec_data = data['ra'], data['dec']
    pmra_data, pmdec_data = data['pmra'], data['pmdec']
    bp_rp_data, g_mag_data = data['bp_rp'], data['phot_g_mean_mag']

    data = None  # free memory

    ra_min = ra - 0.5 * width
    ra_max = ra + 0.5 * width
    dec_min = dec - 0.5 * width
    dec_max = dec + 0.5 * width

    mask1 = (ra_min < ra_data) & (ra_data < ra_max)
    mask2 = (dec_min < dec_data) & (dec_data < dec_max)
    mask = mask1 & mask2

    ra_data, dec_data = ra_data[mask], dec_data[mask]
    pmra_data, pmdec_data = pmra_data[mask], pmdec_data[mask]
    bp_rp_data, g_mag_data = bp_rp_data[mask], g_mag_data[mask]

    is_in = dist2(ra_data, dec_data, ra, dec) <= sigma1**2
    n_star_in = len(ra_data[is_in])

    if n_star_in < NSTAR_MIN:
        _s1 = 'skipping image for %s ' % short_name
        _s2 = 'because there are only %d stars in the kernel' % n_star_in
        print(_s1 + _s2)
        return  # skip plotting image with fewer than NSTAR_MIN stars

    print('plotting image for %s' % short_name)
    sns.set(style="white", color_codes=True, font_scale=1)

    if 'gaia' in short_name:
        fig, axes = plt.subplots(2, 3, figsize=(15, 10))

        name_hue = ['inside' if i else 'outside' for i in is_in]
        ms = 20

        circle = plt.Circle((ra, dec),
                            sigma1,
                            color='k',
                            fill=False,
                            lw=2,
                            alpha=0.6)
        axes[0, 0].add_artist(circle)

        sns.scatterplot(x=ra_data,
                        y=dec_data,
                        s=ms,
                        hue=name_hue,
                        ax=axes[0, 0])
        sns.scatterplot(x=bp_rp_data,
                        y=g_mag_data,
                        s=ms,
                        hue=name_hue,
                        ax=axes[0, 1])
        sns.scatterplot(x=pmra_data,
                        y=pmdec_data,
                        s=ms,
                        hue=name_hue,
                        ax=axes[0, 2])

        sns.scatterplot(x=ra_data[is_in],
                        y=dec_data[is_in],
                        s=ms,
                        ax=axes[0, 0])
        sns.scatterplot(x=bp_rp_data[is_in],
                        y=g_mag_data[is_in],
                        s=ms,
                        ax=axes[0, 1])
        sns.scatterplot(x=pmra_data[is_in],
                        y=pmdec_data[is_in],
                        s=ms,
                        ax=axes[0, 2])

        axes[0, 0].set_title('stellar distribution')
        axes[0, 0].set_xlabel('ra (deg)')
        axes[0, 0].set_ylabel('dec (deg)')
        axes[0, 0].set_xlim([ra_min, ra_max])
        axes[0, 0].set_ylim([dec_min, dec_max])
        axes[0, 0].invert_xaxis()

        axes[0, 1].set_title('color mag diagram (CMD)')
        axes[0, 1].invert_yaxis()
        axes[0, 1].set_xlabel('Bp-Rp (mag)')
        axes[0, 1].set_ylabel('G (mag)')

        axes[0, 2].set_title('proper motions')
        axes[0, 2].set_xlabel('pmra (mas/yr)')
        axes[0, 2].set_ylabel('pmdec (mas/yr)')

        for u in range(3):
            for v in range(2):
                _asp = np.diff(axes[0, u].get_xlim())[0]
                _asp /= np.diff(axes[0, u].get_ylim())[0]
                axes[1, u].set_aspect(np.abs(_asp))

        cnt = 0  # counter for how many images have been plotted
        for hips_survey in hips_surveys:
            try:
                result = make_sky_image(geometry=geometry,
                                        hips_survey=hips_survey,
                                        tile_format='jpg',
                                        progress_bar=False)
                axes[1, cnt].imshow(result.image, origin='lower')
                axes[1, cnt].set_title(hips_survey)
                cnt += 1
            except:
                pass

            if cnt == 3:
                break

        for u in range(3):
            axes[1, u].tick_params(axis='both',
                                   which='both',
                                   labelleft=False,
                                   labelbottom=False)
    else:
        fig, axes = plt.subplots(1, 4, figsize=(15, 5))

        # plot sources
        axes[0].set_title(short_name)
        sns.scatterplot(ra_data, dec_data, ax=axes[0])
        axes[0].set_xlim([ra_min, ra_max])
        axes[0].set_ylim([dec_min, dec_max])
        _asp = np.diff(axes[0].get_xlim())[0] / np.diff(axes[0].get_ylim())[0]
        axes[0].set_aspect(_asp)
        axes[0].set_xlim(axes[0].set_xlim([ra_min, ra_max])[::-1])  # flipping

        # plot circle of the size of sigma1
        circle = plt.Circle((ra, dec),
                            sigma1,
                            color='orange',
                            fill=False,
                            lw=2)
        axes[0].add_artist(circle)

        cnt = 0  # counter for how many images have been plotted
        for hips_survey in hips_surveys:
            try:
                result = make_sky_image(geometry=geometry,
                                        hips_survey=hips_survey,
                                        tile_format='jpg',
                                        progress_bar=False)
                cnt += 1
                axes[cnt].imshow(result.image, origin='lower')
                axes[cnt].set_title(hips_survey)
            except:
                pass

            if cnt == 3:
                break

        for i in range(4):
            axes[i].tick_params(axis='both',
                                which='both',
                                labelleft=False,
                                labelbottom=False)

    _st1 = '{}-label{}-sigp%0.2f-'.format(short_name, label) % sig_p
    _st2 = '-width{}'.format(width)
    fig.suptitle('{}(%0.4f,%0.4f){}'.format(_st1, _st2) % (ra, dec))

    _str = '{}/{}-target{}-'.format(outpath, name, label)
    _str = '{}ra%0.4f-dec%0.4f-sigp%0.2f.jpg'.format(_str) % (ra, dec, sig_p)
    plt.savefig(_str, bbox_inches='tight', dpi=300)