Exemplo n.º 1
0
def create_blank_image(ra_deg,
                       dec_deg,
                       fov_deg,
                       px_scale,
                       rot_deg,
                       cdbase=[1, 1],
                       dtype=None,
                       logger=None,
                       pfx='dp'):

    # ra and dec in traditional format
    ra_txt = wcs.raDegToString(ra_deg, format='%02d:%02d:%06.3f')
    dec_txt = wcs.decDegToString(dec_deg, format='%s%02d:%02d:%05.2f')

    # Create an empty image
    imagesize = int(round(fov_deg / px_scale))
    # round to an even size
    if imagesize % 2 != 0:
        imagesize += 1
    ## # round to an odd size
    ## if imagesize % 2 == 0:
    ##     imagesize += 1
    width = height = imagesize

    if dtype is None:
        dtype = numpy.float32
    data = numpy.zeros((height, width), dtype=dtype)

    crpix = float(imagesize // 2)
    header = OrderedDict((
        ('SIMPLE', True),
        ('BITPIX', -32),
        ('EXTEND', True),
        ('NAXIS', 2),
        ('NAXIS1', imagesize),
        ('NAXIS2', imagesize),
        ('RA', ra_txt),
        ('DEC', dec_txt),
        ('EQUINOX', 2000.0),
        ('OBJECT', 'MOSAIC'),
        ('LONPOLE', 180.0),
    ))

    # Add basic WCS keywords
    wcshdr = wcs.simple_wcs(crpix,
                            crpix,
                            ra_deg,
                            dec_deg,
                            px_scale,
                            rot_deg,
                            cdbase=cdbase)
    header.update(wcshdr)

    # Create image container
    image = AstroImage.AstroImage(data, logger=logger)
    image.update_keywords(header)
    # give the image a name
    get_image_name(image, pfx=pfx)

    return image
Exemplo n.º 2
0
Arquivo: dp.py Projeto: rajul/ginga
def recycle_image(image, ra_deg, dec_deg, fov_deg, px_scale, rot_deg,
                  cdbase=[1, 1], logger=None, pfx='dp'):

    # ra and dec in traditional format
    ra_txt = wcs.raDegToString(ra_deg, format='%02d:%02d:%06.3f')
    dec_txt = wcs.decDegToString(dec_deg, format='%s%02d:%02d:%05.2f')

    header = image.get_header()
    pointing = OrderedDict((('RA', ra_txt),
                            ('DEC', dec_txt),
                            ))
    header.update(pointing)

    # Update WCS keywords and internal wcs objects
    wd, ht = image.get_size()
    crpix1 = wd // 2
    crpix2 = ht // 2
    wcshdr = wcs.simple_wcs(crpix1, crpix2, ra_deg, dec_deg, px_scale,
                            rot_deg, cdbase=cdbase)
    header.update(wcshdr)
    # this should update the wcs
    image.update_keywords(header)

    # zero out data array
    data = image.get_data()
    data.fill(0)

    ## # Create new image container sharing same data
    ## new_image = AstroImage.AstroImage(data, logger=logger)
    ## new_image.update_keywords(header)
    ## # give the image a name
    ## get_image_name(new_image, pfx=pfx)
    new_image = image

    return new_image
Exemplo n.º 3
0
 def _get_hdu(self):
     data = np.random.randint(0, 10000, (10, 10))
     ra_deg, dec_deg = 10.0, -10.0
     px_scale_deg_px = 0.000026044
     rot_deg = 90.0
     ht, wd = data.shape
     kwds = wcs.simple_wcs(wd / 2.0, ht / 2.0, ra_deg, dec_deg,
                           px_scale_deg_px, rot_deg)
     hdu = fits.PrimaryHDU(data)
     hdu.header.update(kwds)
     assert isinstance(hdu, fits.PrimaryHDU)
     return hdu
Exemplo n.º 4
0
 def _get_hdu(self):
     data = np.random.randint(0, 10000, (10, 10))
     ra_deg, dec_deg = 10.0, -10.0
     px_scale_deg_px = 0.000026044
     rot_deg = 90.0
     ht, wd = data.shape
     kwds = wcs.simple_wcs(wd / 2.0, ht / 2.0, ra_deg, dec_deg,
                           px_scale_deg_px, rot_deg)
     hdu = fits.PrimaryHDU(data)
     hdu.header.update(kwds)
     assert isinstance(hdu, fits.PrimaryHDU)
     return hdu
Exemplo n.º 5
0
Arquivo: dp.py Projeto: hdfeos/ginga
def create_blank_image(ra_deg, dec_deg, fov_deg, px_scale, rot_deg,
                       cdbase=[1, 1], dtype=None, logger=None, pfx='dp'):

    # ra and dec in traditional format
    ra_txt = wcs.raDegToString(ra_deg, format='%02d:%02d:%06.3f')
    dec_txt = wcs.decDegToString(dec_deg, format='%s%02d:%02d:%05.2f')

    # Create an empty image
    imagesize = int(round(fov_deg / px_scale))
    # round to an even size
    if imagesize % 2 != 0:
        imagesize += 1
    ## # round to an odd size
    ## if imagesize % 2 == 0:
    ##     imagesize += 1
    width = height = imagesize

    if dtype is None:
        dtype = numpy.float32
    data = numpy.zeros((height, width), dtype=dtype)

    crpix = float(imagesize // 2)
    header = OrderedDict((('SIMPLE', True),
                          ('BITPIX', -32),
                          ('EXTEND', True),
                          ('NAXIS', 2),
                          ('NAXIS1', imagesize),
                          ('NAXIS2', imagesize),
                          ('RA', ra_txt),
                          ('DEC', dec_txt),
                          ('EQUINOX', 2000.0),
                          ('OBJECT', 'MOSAIC'),
                          ('LONPOLE', 180.0),
                          ))

    # Add basic WCS keywords
    wcshdr = wcs.simple_wcs(crpix, crpix, ra_deg, dec_deg, px_scale,
                            rot_deg, cdbase=cdbase)
    header.update(wcshdr)

    # Create image container
    image = AstroImage.AstroImage(data, logger=logger)
    image.update_keywords(header)
    # give the image a name
    get_image_name(image, pfx=pfx)

    return image
Exemplo n.º 6
0
def create_blank_image(ra_deg,
                       dec_deg,
                       fov_deg,
                       px_scale,
                       rot_deg,
                       cdbase=[1, 1],
                       dtype=None,
                       logger=None,
                       pfx='dp',
                       mmap_path=None,
                       mmap_mode='w+'):

    # ra and dec in traditional format
    ra_txt = wcs.raDegToString(ra_deg, format='%02d:%02d:%06.3f')
    dec_txt = wcs.decDegToString(dec_deg, format='%s%02d:%02d:%05.2f')

    if np.isscalar(px_scale):
        px_wd_scale, px_ht_scale = (px_scale, px_scale)
    else:
        px_wd_scale, px_ht_scale = px_scale

    # Create an empty image
    if np.isscalar(fov_deg):
        fov_wd_deg, fov_ht_deg = (fov_deg, fov_deg)
    else:
        fov_wd_deg, fov_ht_deg = fov_deg

    width = int(round(fov_wd_deg / px_wd_scale))
    height = int(round(fov_ht_deg / px_ht_scale))
    # round to an even size
    if width % 2 != 0:
        width += 1
    if height % 2 != 0:
        height += 1

    if dtype is None:
        dtype = np.float32
    if mmap_path is None:
        data = np.zeros((height, width), dtype=dtype)

    else:
        data = np.memmap(mmap_path,
                         dtype=dtype,
                         mode=mmap_mode,
                         shape=(height, width))

    crpix1 = float(width // 2)
    crpix2 = float(height // 2)
    header = OrderedDict((
        ('SIMPLE', True),
        ('BITPIX', -32),
        ('EXTEND', True),
        ('NAXIS', 2),
        ('NAXIS1', width),
        ('NAXIS2', height),
        ('RA', ra_txt),
        ('DEC', dec_txt),
        ('EQUINOX', 2000.0),
        ('OBJECT', 'MOSAIC'),
        ('LONPOLE', 180.0),
    ))

    # Add basic WCS keywords
    wcshdr = wcs.simple_wcs(crpix1,
                            crpix2,
                            ra_deg,
                            dec_deg, (px_wd_scale, px_ht_scale),
                            rot_deg,
                            cdbase=cdbase)
    header.update(wcshdr)

    # Create image container
    image = AstroImage.AstroImage(data, logger=logger)
    image.update_keywords(header)
    # give the image a name
    get_image_name(image, pfx=pfx)

    return image
Exemplo n.º 7
0
def create_blank_image(ra_deg, dec_deg, fov_deg, px_scale, rot_deg,
                       cdbase=[1, 1], dtype=None, logger=None, pfx='dp',
                       mmap_path=None, mmap_mode='w+'):

    # ra and dec in traditional format
    ra_txt = wcs.raDegToString(ra_deg, format='%02d:%02d:%06.3f')
    dec_txt = wcs.decDegToString(dec_deg, format='%s%02d:%02d:%05.2f')

    if np.isscalar(px_scale):
        px_wd_scale, px_ht_scale = (px_scale, px_scale)
    else:
        px_wd_scale, px_ht_scale = px_scale

    # Create an empty image
    if np.isscalar(fov_deg):
        fov_wd_deg, fov_ht_deg = (fov_deg, fov_deg)
    else:
        fov_wd_deg, fov_ht_deg = fov_deg

    width = int(round(fov_wd_deg / px_wd_scale))
    height = int(round(fov_ht_deg / px_ht_scale))
    # round to an even size
    if width % 2 != 0:
        width += 1
    if height % 2 != 0:
        height += 1

    if dtype is None:
        dtype = np.float32
    if mmap_path is None:
        data = np.zeros((height, width), dtype=dtype)

    else:
        data = np.memmap(mmap_path, dtype=dtype, mode=mmap_mode,
                         shape=(height, width))

    crpix1 = float(width // 2)
    crpix2 = float(height // 2)
    header = OrderedDict((('SIMPLE', True),
                          ('BITPIX', -32),
                          ('EXTEND', True),
                          ('NAXIS', 2),
                          ('NAXIS1', width),
                          ('NAXIS2', height),
                          ('RA', ra_txt),
                          ('DEC', dec_txt),
                          ('EQUINOX', 2000.0),
                          ('OBJECT', 'MOSAIC'),
                          ('LONPOLE', 180.0),
                          ))

    # Add basic WCS keywords
    wcshdr = wcs.simple_wcs(crpix1, crpix2, ra_deg, dec_deg,
                            (px_wd_scale, px_ht_scale),
                            rot_deg, cdbase=cdbase)
    header.update(wcshdr)

    # Create image container
    image = AstroImage.AstroImage(data, logger=logger)
    image.update_keywords(header)
    # give the image a name
    get_image_name(image, pfx=pfx)

    return image