Exemple #1
0
def define_wcs(skypos, skyrange, verbose=0, pixsz=0.000416666666666667):
    """
    Define the world coordinate system (WCS).

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param skyrange: Extent of the region of interest, in degrees.

    :type skyrange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param pixsz: Size of a GALEX pixel, in degrees.

    :type pixsz: float

    :returns: astropy.wcs WCS Object -- The WCS information.
    """

    if verbose:
        mc.print_inline('Defining World Coordinate System (WCS).')

    # NAXIS = 2
    wcs = pywcs.WCS(naxis=2)

    imsz = gxt.deg2pix(skypos, skyrange)

    wcs.wcs.cdelt = np.array([-pixsz, pixsz])
    wcs.wcs.ctype = ['RA---TAN', 'DEC--TAN']
    wcs.wcs.crpix = [(imsz[1]/2.)+0.5, (imsz[0]/2.)+0.5]
    wcs.wcs.crval = skypos

    return wcs
def define_wcs(skypos, skyrange, verbose=0, pixsz=0.000416666666666667):
    """
    Define the world coordinate system (WCS).

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param skyrange: Extent of the region of interest, in degrees.

    :type skyrange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param pixsz: Size of a GALEX pixel, in degrees.

    :type pixsz: float

    :returns: astropy.wcs WCS Object -- The WCS information.
    """

    if verbose:
        mc.print_inline('Defining World Coordinate System (WCS).')

    # NAXIS = 2
    wcs = pywcs.WCS(naxis=2)

    imsz = gxt.deg2pix(skypos, skyrange)

    wcs.wcs.cdelt = np.array([-pixsz, pixsz])
    wcs.wcs.ctype = ['RA---TAN', 'DEC--TAN']
    wcs.wcs.crpix = [(imsz[1]/2.)+0.5, (imsz[0]/2.)+0.5]
    wcs.wcs.crval = skypos

    return wcs
Exemple #3
0
def integrate_map(band, skypos, tranges, skyrange, verbose=0, memlight=None,
                  hdu=None, retries=100, response=False, detsize=1.1):
    """
    Integrate an image over some number of time ranges. Use a reduced
	    memory optimization (at the expense of more web queries) if requested.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param tranges: Set of time ranges to retrieve the photon events, in
        GALEX time seconds.

    :type tranges: list

    :param skyrange: RA and Dec extents of the region of interest in degrees.

    :type skyrange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param memlight: Reduce memory usage by breaking query into smaller
        segments of this size in seconds.

    :type memlight: float

    :param hdu: An existing HDU to modify.

    :type hdu: bool

    :param retries: Number of query retries to attempt before giving up.

    :type retries: int

    :param response: Apply the response correction.

    :type response: bool

    :param detsize: Effective diameter, in degrees, of the field-of-view.

    :type detsize: float

    :returns: numpy.ndarray - The integrated image.
    """

    imsz = gxt.deg2pix(skypos, skyrange)
    img = np.zeros(np.array(imsz, dtype='int32'))

    for trange in tranges:
        img += makemap(band, skypos, trange, skyrange,
            response=response, verbose=verbose, detsize=detsize)

    if response: # Intensity maps == average countrate maps.
        expt=np.sum([dbt.compute_exptime(band,trange) for trange in tranges])
        if expt>0:
            img/=expt

    return img
Exemple #4
0
def makemap(band, skypos, trange, skyrange, response=False, verbose=0,
            detsize=1.1):
    """
    Generate a single image frame.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param trange: Minimum and maximum time to use, in GALEX time seconds.

    :type trange: list

    :param skyrange: RA and Dec extent of the region of interest in degrees.

    :type skyrange: list

    :param response: Apply the response correction.

    :type response: bool

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param detsize: Effective diameter, in degrees, of the field-of-view.

    :type detsize: float

    :returns: numpy.ndarray - The bi-dimensional histogram of ra and dec.
    """

    imsz = gxt.deg2pix(skypos, skyrange)

    photons = np.array(gQuery.getArray(
        gQuery.skyrect(band, skypos[0], skypos[1], trange[0], trange[1],
                       skyrange[0], skyrange[1]), verbose=verbose),
                       dtype='float64')
    try:
        events = {'t':photons[:, 0]/tscale, 'ra':photons[:, 1],
                  'dec':photons[:, 2], 'xi':photons[:, 3], 'eta':photons[:, 4],
                  'x':photons[:, 5], 'y':photons[:, 6]}
    except IndexError:
        if verbose > 2:
            print('No events found at {s} +/- {r} in {t}.'.format(
                s=skypos, r=skyrange, t=trange))
        return np.zeros(np.array(imsz, dtype='int32'))

    # Trim the data on detsize
    col, row = ct.xieta2colrow(events['xi'], events['eta'], band)
    ix = np.where(gxt.aper2deg(4)*mc.distance(col, row, 400, 400) <= detsize)
    n = len(ix[0])
    m = len(col)

    if n == 0:
        return np.zeros(np.int(imsz))

    for k in list(events.keys()):
        events[k] = events[k][ix]

    events = ct.hashresponse(band, events)
    wcs = define_wcs(skypos, skyrange)
    coo = list(zip(events['ra'], events['dec']))
    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(coo, 1), 1)
    weights = 1./events['response'] if response else None
    H, xedges, yedges = np.histogram2d(foc[:, 1]-0.5, foc[:, 0]-0.5, bins=imsz,
                                       range=([[0, imsz[0]], [0, imsz[1]]]),
                                       weights=weights)

    return H
def integrate_map(band, skypos, tranges, skyrange, verbose=0, memlight=None,
                  hdu=None, retries=100, response=False, detsize=1.1):
    """
    Integrate an image over some number of time ranges. Use a reduced
	    memory optimization (at the expense of more web queries) if requested.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param tranges: Set of time ranges to retrieve the photon events, in
        GALEX time seconds.

    :type tranges: list

    :param skyrange: RA and Dec extents of the region of interest in degrees.

    :type skyrange: list

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param memlight: Reduce memory usage by breaking query into smaller
        segments of this size in seconds.

    :type memlight: float

    :param hdu: An existing HDU to modify.

    :type hdu: bool

    :param retries: Number of query retries to attempt before giving up.

    :type retries: int

    :param response: Apply the response correction.

    :type response: bool

    :param detsize: Effective diameter, in degrees, of the field-of-view.

    :type detsize: float

    :returns: numpy.ndarray - The integrated image.
    """

    imsz = gxt.deg2pix(skypos, skyrange)
    img = np.zeros(np.array(imsz, dtype='int32'))

    for trange in tranges:
        img += makemap(band, skypos, trange, skyrange,
            response=response, verbose=verbose, detsize=detsize)

    if response: # Intensity maps == average countrate maps.
        expt=np.sum([dbt.compute_exptime(band,trange) for trange in tranges])
        if expt>0:
            img/=expt

    return img
def makemap(band, skypos, trange, skyrange, response=False, verbose=0,
            detsize=1.1):
    """
    Generate a single image frame.

    :param band: The band to use, either 'FUV' or 'NUV'.

    :type band: str

    :param skypos: The right ascension and declination, in degrees.

    :type skypos: list

    :param trange: Minimum and maximum time to use, in GALEX time seconds.

    :type trange: list

    :param skyrange: RA and Dec extent of the region of interest in degrees.

    :type skyrange: list

    :param response: Apply the response correction.

    :type response: bool

    :param verbose: Verbosity level, a value of 0 is minimum verbosity.

    :type verbose: int

    :param detsize: Effective diameter, in degrees, of the field-of-view.

    :type detsize: float

    :returns: numpy.ndarray - The bi-dimensional histogram of ra and dec.
    """

    imsz = gxt.deg2pix(skypos, skyrange)

    photons = np.array(gQuery.getArray(
        gQuery.skyrect(band, skypos[0], skypos[1], trange[0], trange[1],
                       skyrange[0], skyrange[1]), verbose=verbose),
                       dtype='float64')
    try:
        events = {'t':photons[:, 0]/tscale, 'ra':photons[:, 1],
                  'dec':photons[:, 2], 'xi':photons[:, 3], 'eta':photons[:, 4],
                  'x':photons[:, 5], 'y':photons[:, 6]}
    except IndexError:
        if verbose > 2:
            print('No events found at {s} +/- {r} in {t}.'.format(
                s=skypos, r=skyrange, t=trange))
        return np.zeros(np.array(imsz, dtype='int32'))

    # Trim the data on detsize
    col, row = ct.xieta2colrow(events['xi'], events['eta'], band)
    ix = np.where(gxt.aper2deg(4)*mc.distance(col, row, 400, 400) <= detsize)
    n = len(ix[0])
    m = len(col)

    if n == 0:
        return np.zeros(np.int(imsz))

    for k in list(events.keys()):
        events[k] = events[k][ix]

    events = ct.hashresponse(band, events)
    wcs = define_wcs(skypos, skyrange)
    coo = list(zip(events['ra'], events['dec']))
    foc = wcs.sip_pix2foc(wcs.wcs_world2pix(coo, 1), 1)
    weights = 1./events['response'] if response else None
    H, xedges, yedges = np.histogram2d(foc[:, 1]-0.5, foc[:, 0]-0.5, bins=imsz,
                                       range=([[0, imsz[0]], [0, imsz[1]]]),
                                       weights=weights)

    return H
Exemple #7
0
 def test_deg2pix_pole(self):
     skypos,skyrange=[90.,90.],[1.,1.]
     pix = gt.deg2pix(skypos,skyrange)
     self.assertAlmostEqual(pix[0],2400.)
     self.assertAlmostEqual(pix[1],21.)
Exemple #8
0
 def test_deg2pix_equator(self):
     skypos,skyrange=[0.,0.],[1.,1.]
     pix = gt.deg2pix(skypos,skyrange)
     self.assertAlmostEqual(pix[0],2400.)
     self.assertAlmostEqual(pix[1],2400.)