示例#1
0
def parse_beam(header, pixelsize):
    """Read and return the beam properties bmaj, bmin and bpa values from
    the fits header.
    
    Returns: 
      - Beam parameters, (semimajor, semiminor, parallactic angle) 
        in (pixels,pixels, radians)  
    """
    bmaj, bmin, bpa = None, None, None
    try:
        # MIRIAD FITS file
        bmaj = header['BMAJ']
        bmin = header['BMIN']
        bpa = header['BPA']
    except KeyError:

        for i, key in enumerate(header.ascardlist().keys()):
            if key == 'HISTORY':
                results = beam_regex.search(header[i])
                if results:
                    bmaj, bmin, bpa = [float(results.group(key)) for
                                       key in ('bmaj', 'bmin', 'bpa')]
                    break

    beam = degrees2pixels(bmaj, bmin, bpa, pixelsize[0], pixelsize[1])
    return beam
示例#2
0
文件: casaimage.py 项目: hughbg/tkp
    def __init__(self, url, plane=0, beam=None):
        self._url = url
        table = pyrap_table(self.url.encode(), ack=False)
        self._data = parse_data(table, plane)
        self._wcs = parse_coordinates(table)
        self._centre_ra, self._centre_decl = parse_phase_centre(table)
        self._freq_eff, self._freq_bw = parse_frequency(table)

        if beam:
            (bmaj, bmin, bpa) = beam
            self._beam = degrees2pixels(
                bmaj, bmin, bpa, self.pixelsize[0], self.pixelsize[1]
            )
        else:
            self._beam = parse_beam(table, self.pixelsize)
示例#3
0
    def __init__(self, url, plane=0, beam=None):
        super(CasaImage, self).__init__()  # Set defaults
        self.url = url

        self.table = pyrap_table(self.url.encode(), ack=False)
        self.telescope = self.table.getkeyword('coords')['telescope']
        self.data = parse_data(self.table, plane)
        self.wcs = parse_coordinates(self.table)
        self.pixelsize = parse_pixelsize(self.wcs)
        self.centre_ra, self.centre_decl = parse_phase_centre(self.table)
        self.freq_eff, self.freq_bw = parse_frequency(self.table)

        if beam:
            (bmaj, bmin, bpa) = beam
            self.beam = degrees2pixels(bmaj, bmin, bpa,
                                       self.pixelsize[0], self.pixelsize[1])
        else:
            self.beam = parse_beam(self.table, self.pixelsize)
示例#4
0
文件: fitsimage.py 项目: hughbg/tkp
    def __init__(self, url, plane=None, beam=None, hdu=0):
        self._url = url
        header = self._get_header(hdu)
        self._wcs = parse_coordinates(header)
        self._data = read_data(pyfits.open(self.url)[hdu], plane)
        self._taustart_ts, self._tau_time = parse_times(header)
        self._freq_eff, self._freq_bw = parse_frequency(header)
        if beam:
            (bmaj, bmin, bpa) = beam
            self._beam = degrees2pixels(
                bmaj, bmin, bpa, self.pixelsize[0], self.pixelsize[1]
            )
        else:
            self._beam = parse_beam(header, self.pixelsize)

        # Bonus attribute
        if 'TELESCOP' in header:
            # Otherwise, it defaults to None.
            self.telescope = header['TELESCOP']
示例#5
0
文件: casaimage.py 项目: hughbg/tkp
def parse_beam(table, pixelsize):
    """
    Returns:
      - Beam parameters, (semimajor, semiminor, parallactic angle) in
        (pixels,pixels, radians).
    """
    def ensure_degrees(quantity):
        if quantity['unit'] == 'deg':
            return quantity['value']
        elif quantity['unit'] == 'arcsec':
            return quantity['value'] / 3600
        elif quantity['unit'] == 'rad':
            return degrees(quantity['value'])
        else:
            raise Exception("Beam units (%s) unknown" % quantity['unit'])

    restoringbeam = table.getkeyword('imageinfo')['restoringbeam']
    bmaj = ensure_degrees(restoringbeam['major'])
    bmin = ensure_degrees(restoringbeam['minor'])
    bpa = ensure_degrees(restoringbeam['positionangle'])
    beam_pixels = degrees2pixels(bmaj, bmin, bpa, pixelsize[0], pixelsize[1])
    return beam_pixels
示例#6
0
    def __init__(self, url, plane=None, beam=None, hdu=0):
        """
        Args:
          - url: location of FITS file
          - beam: (optional) beam parameters in degrees, in the form
            (bmaj, bmin, bpa). Will attempt to read from header if
            not supplied.
        """
        # NB: pyfits bogs down reading parameters from FITS files with very
        # long headers. This code should run in a fraction of a second on most
        # files, but can take several seconds given a huge header.
        super(FitsImage, self).__init__()  # Set defaults
        self.url = url
        self.beam = beam

        hdulist = pyfits.open(url)
        hdu = hdulist[hdu]
        self.header = hdu.header.copy()
        if 'TELESCOP' in self.header:
            # Otherwise, it defaults to None.
            self.telescope = self.header['TELESCOP']
        self.data = read_data(hdu, plane)
        hdulist.close()

        self.wcs = parse_coordinates(self.header)
        self.pixelsize = parse_pixelsize(self.wcs)
        self.centre_ra, self.centre_decl = calculate_phase_centre(self.data.shape,
                                                                  self.wcs)
        self.freq_eff, self.freq_bw = parse_frequency(self.header)

        if beam:
            (bmaj, bmin, bpa) = beam
            self.beam = degrees2pixels(bmaj, bmin, bpa,
                                       self.pixelsize[0], self.pixelsize[1])
        else:
            self.beam = parse_beam(self.header, self.pixelsize)

        self.taustart_ts, self.tau_time = parse_times(self.header)
示例#7
0
文件: fitsimage.py 项目: hughbg/tkp
def parse_beam(header, pixelsize):
    """Read and return the beam properties bmaj, bmin and bpa values from
    the fits header.

    Returns:
      - Beam parameters, (semimajor, semiminor, position angle)
        in (pixels, pixels, radians)
    """
    bmaj, bmin, bpa = None, None, None
    try:
        # MIRIAD FITS file
        bmaj = header['BMAJ']
        bmin = header['BMIN']
        bpa = header['BPA']
    except KeyError:

        def get_history(hdr):
            """
            Returns all history cards in FITS header hdr as a list of strings.
            """
            # Appropriate method to get the HISTORY from a FITS header varies with
            # PyFITS version. See discussion at
            # <http://pythonhosted.org/pyfits/appendix/header_transition.html>.
            # This is quite ugly, so deliberately limited to this scope.
            if pyfits.__version__ < 3.2:
                return hdr.get_history()
            else:
                return hdr['HISTORY']

        for hist_entry in get_history(header):
            results = beam_regex.search(hist_entry)
            if results:
                bmaj, bmin, bpa = [float(results.group(key)) for
                                   key in ('bmaj', 'bmin', 'bpa')]
                break

    beam = degrees2pixels(bmaj, bmin, bpa, pixelsize[0], pixelsize[1])
    return beam