當前位置: 首頁>>代碼示例>>Python>>正文


Python wcs.WCS屬性代碼示例

本文整理匯總了Python中astropy.wcs.WCS屬性的典型用法代碼示例。如果您正苦於以下問題:Python wcs.WCS屬性的具體用法?Python wcs.WCS怎麽用?Python wcs.WCS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在astropy.wcs的用法示例。


在下文中一共展示了wcs.WCS屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: __init__

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def __init__(self, base_fname):
        """
        Args:
            base_fname (str): The map should be stored in two FITS files, named
                ``base_fname + '_' + X + '.fits'``, where ``X`` is ``'ngp'`` and
                ``'sgp'``.
        """
        self._data = {}

        for pole in self.poles:
            fname = '{}_{}.fits'.format(base_fname, pole)
            try:
                with fits.open(fname) as hdulist:
                    self._data[pole] = [hdulist[0].data, wcs.WCS(hdulist[0].header)]
            except IOError as error:
                print(dustexceptions.data_missing_message(self.map_name,
                                                          self.map_name_long))
                raise error 
開發者ID:gregreen,項目名稱:dustmaps,代碼行數:20,代碼來源:sfd.py

示例2: __init__

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def __init__(self, input, output, origin=1):
        """Sample class to demonstrate how to define a coordinate transformation

        Modified from `drizzlepac.wcs_functions.WCSMap` to use full SIP header
        in the `forward` and `backward` methods. Use this class to drizzle to
        an output distorted WCS, e.g.,

            >>> drizzlepac.astrodrizzle.do_driz(..., wcsmap=SIP_WCSMap)
        """

        # Verify that we have valid WCS input objects
        self.checkWCS(input, 'Input')
        self.checkWCS(output, 'Output')

        self.input = input
        self.output = copy.deepcopy(output)
        #self.output = output

        self.origin = origin
        self.shift = None
        self.rot = None
        self.scale = None 
開發者ID:gbrammer,項目名稱:grizli,代碼行數:24,代碼來源:combine.py

示例3: get_data

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def get_data(self, filter='f140w', catfile=None, segfile=None):
        import glob

        sci_file = glob.glob('{0}-{1}_dr?_sci.fits'.format(self.root, filter))

        sci = pyfits.open(sci_file[0])
        wht = pyfits.open(sci_file[0].replace('sci', 'wht'))

        if segfile is None:
            segfile = sci_file[0].split('_dr')[0]+'_seg.fits'

        seg = pyfits.open(segfile)

        if catfile is None:
            catfile = '{0}-{1}.cat.fits'.format(self.root, filter)

        cat = utils.GTable.gread(catfile)

        wcs = pywcs.WCS(sci[0].header, relax=True)
        return sci, wht, seg, cat, wcs 
開發者ID:gbrammer,項目名稱:grizli,代碼行數:22,代碼來源:galfit.py

示例4: update_wcs_fits_log

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def update_wcs_fits_log(file, wcs_ref, xyscale=[0, 0, 0, 1], initialize=True, replace=('.fits', '.wcslog.fits'), wcsname='SHIFT'):
    """
    Make FITS log when updating WCS
    """
    new_hdu = wcs_ref.to_fits(relax=True)[0]
    new_hdu.header['XSHIFT'] = xyscale[0]
    new_hdu.header['YSHIFT'] = xyscale[1]
    new_hdu.header['ROT'] = xyscale[2], 'WCS fit rotation, degrees'
    new_hdu.header['SCALE'] = xyscale[3], 'WCS fit scale'
    new_hdu.header['WCSNAME'] = wcsname

    wcs_logfile = file.replace(replace[0], replace[1])

    if os.path.exists(wcs_logfile):
        if initialize:
            os.remove(wcs_logfile)
            hdu = pyfits.HDUList([pyfits.PrimaryHDU()])
        else:
            hdu = pyfits.open(wcs_logfile)
    else:
        hdu = pyfits.HDUList([pyfits.PrimaryHDU()])

    hdu.append(new_hdu)
    hdu.writeto(wcs_logfile, overwrite=True, output_verify='fix') 
開發者ID:gbrammer,項目名稱:grizli,代碼行數:26,代碼來源:prep.py

示例5: make_SEP_FLT_catalog

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def make_SEP_FLT_catalog(flt_file, ext=1, column_case=str.upper, **kwargs):
    import astropy.io.fits as pyfits
    import astropy.wcs as pywcs

    im = pyfits.open(flt_file)
    sci = im['SCI', ext].data - im['SCI', ext].header['MDRIZSKY']
    err = im['ERR', ext].data
    mask = im['DQ', ext].data > 0

    ZP = utils.calc_header_zeropoint(im, ext=('SCI', ext))

    try:
        wcs = pywcs.WCS(im['SCI', ext].header, fobj=im)
    except:
        wcs = None

    tab, seg = make_SEP_catalog_from_arrays(sci, err, mask, wcs=wcs, ZP=ZP, **kwargs)
    tab.meta['ABZP'] = ZP
    tab.meta['FILTER'] = utils.get_hst_filter(im[0].header)
    tab['mag_auto'] = ZP - 2.5*np.log10(tab['flux'])

    for c in tab.colnames:
        tab.rename_column(c, column_case(c))

    return tab, seg 
開發者ID:gbrammer,項目名稱:grizli,代碼行數:27,代碼來源:prep.py

示例6: _get_fits_mbr

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def _get_fits_mbr(fin, row_ignore_factor=10):
    hdulist = pyfits.open(fin)
    data = hdulist[0].data
    wcs = pywcs.WCS(hdulist[0].header)
    width = data.shape[1]
    height = data.shape[0]

    bottom_left = [0, 0, 0, 0]
    top_left = [0, height - 1, 0, 0]
    top_right = [width - 1, height - 1, 0, 0]
    bottom_right = [width - 1, 0, 0, 0]

    def pix2sky(pix_coord):
        return wcs.wcs_pix2world([pix_coord], 0)[0][0:2]

    ret = np.zeros([4, 2])
    ret[0, :] = pix2sky(bottom_left)
    ret[1, :] = pix2sky(top_left)
    ret[2, :] = pix2sky(top_right)
    ret[3, :] = pix2sky(bottom_right)
    RA_min, DEC_min, RA_max, DEC_max = np.min(ret[:, 0]),   np.min(ret[:, 1]),  np.max(ret[:, 0]),  np.max(ret[:, 1])
    
    # http://pgsphere.projects.pgfoundry.org/types.html
    sqlStr = "SELECT sbox '((%10fd, %10fd), (%10fd, %10fd))'" % (RA_min, DEC_min, RA_max, DEC_max)
    return sqlStr 
開發者ID:chenwuperth,項目名稱:rgz_rcnn,代碼行數:27,代碼來源:parse_output.py

示例7: get_header

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def get_header(self, ext=0):
        """Returns the metadata embedded in the file.

        Target Pixel Files contain embedded metadata headers spread across three
        different FITS extensions:

        1. The "PRIMARY" extension (``ext=0``) provides a metadata header
           providing details on the target and its CCD position.
        2. The "PIXELS" extension (``ext=1``) provides details on the
           data column and their coordinate system (WCS).
        3. The "APERTURE" extension (``ext=2``) provides details on the
           aperture pixel mask and the expected coordinate system (WCS).

        Parameters
        ----------
        ext : int or str
            FITS extension name or number.

        Returns
        -------
        header : `~astropy.io.fits.header.Header`
            Header object containing metadata keywords.
        """
        return self.hdu[ext].header 
開發者ID:KeplerGO,項目名稱:lightkurve,代碼行數:26,代碼來源:targetpixelfile.py

示例8: _load_cube_from_file

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def _load_cube_from_file(self, data=None):
        """Initialises a cube from a file."""

        if data is not None:
            assert isinstance(data, fits.HDUList), 'data is not an HDUList object'
        else:
            try:
                with gunzip(self.filename) as gg:
                    self.data = fits.open(gg.name)
            except (IOError, OSError) as err:
                raise OSError('filename {0} cannot be found: {1}'.format(self.filename, err))

        self.header = self.data[1].header
        self.wcs = WCS(self.header)

        self._check_file(self.data[0].header, self.data, 'Cube')

        self._wavelength = self.data['WAVE'].data
        self._shape = (self.header['NAXIS2'], self.header['NAXIS1'])

        self._do_file_checks(self) 
開發者ID:sdss,項目名稱:marvin,代碼行數:23,代碼來源:cube.py

示例9: _load_cube_from_api

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def _load_cube_from_api(self):
        """Calls the API and retrieves the necessary information to instantiate the cube."""

        url = marvin.config.urlmap['api']['getCube']['url']

        try:
            response = self._toolInteraction(url.format(name=self.plateifu))
        except Exception as ee:
            raise MarvinError('found a problem when checking if remote cube '
                              'exists: {0}'.format(str(ee)))

        data = response.getData()

        self.header = fits.Header.fromstring(data['header'])
        self.wcs = WCS(fits.Header.fromstring(data['wcs_header']))
        self._wavelength = data['wavelength']
        self._shape = data['shape']

        if self.plateifu != data['plateifu']:
            raise MarvinError('remote cube has a different plateifu!')

        return 
開發者ID:sdss,項目名稱:marvin,代碼行數:24,代碼來源:cube.py

示例10: _load_modelcube_from_api

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def _load_modelcube_from_api(self):
        """Initialises a model cube from the API."""

        url = marvin.config.urlmap['api']['getModelCube']['url']
        url_full = url.format(name=self.plateifu, bintype=self.bintype.name,
                              template=self.template.name)

        try:
            response = self._toolInteraction(url_full)
        except Exception as ee:
            raise MarvinError('found a problem when checking if remote model cube '
                              'exists: {0}'.format(str(ee)))

        data = response.getData()

        self.header = fits.Header.fromstring(data['header'])
        self.wcs = WCS(fits.Header.fromstring(data['wcs_header']))
        self._wavelength = np.array(data['wavelength'])
        self._redcorr = np.array(data['redcorr'])
        self._shape = tuple(data['shape'])

        self.plateifu = str(self.header['PLATEIFU'].strip())
        self.mangaid = str(self.header['MANGAID'].strip()) 
開發者ID:sdss,項目名稱:marvin,代碼行數:25,代碼來源:modelcube.py

示例11: pixel_to_world_values

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def pixel_to_world_values(self, *pixel_arrays):
        """
        Convert pixel coordinates to world coordinates.

        This method takes `~astropy.wcs.wcsapi.BaseLowLevelWCS.pixel_n_dim` scalars or arrays as
        input, and pixel coordinates should be zero-based. Returns
        `~astropy.wcs.wcsapi.BaseLowLevelWCS.world_n_dim` scalars or arrays in units given by
        `~astropy.wcs.wcsapi.BaseLowLevelWCS.world_axis_units`. Note that pixel coordinates are
        assumed to be 0 at the center of the first pixel in each dimension. If a
        pixel is in a region where the WCS is not defined, NaN can be returned.
        The coordinates should be specified in the ``(x, y)`` order, where for
        an image, ``x`` is the horizontal coordinate and ``y`` is the vertical
        coordinate.

        If `~astropy.wcs.wcsapi.BaseLowLevelWCS.world_n_dim` is ``1``, this
        method returns a single scalar or array, otherwise a tuple of scalars or
        arrays is returned.
        """ 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:20,代碼來源:low_level_api.py

示例12: pixel_shape

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def pixel_shape(self):
        """
        The shape of the data that the WCS applies to as a tuple of length
        `~astropy.wcs.wcsapi.BaseLowLevelWCS.pixel_n_dim` in ``(x, y)``
        order (where for an image, ``x`` is the horizontal coordinate and ``y``
        is the vertical coordinate).

        If the WCS is valid in the context of a dataset with a particular
        shape, then this property can be used to store the shape of the
        data. This can be used for example if implementing slicing of WCS
        objects. This is an optional property, and it should return `None`
        if a shape is not known or relevant.

        If you are interested in getting a shape that is comparable to that of
        a Numpy array, you should use
        `~astropy.wcs.wcsapi.BaseLowLevelWCS.array_shape` instead.
        """
        return None 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:20,代碼來源:low_level_api.py

示例13: test_dist

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def test_dist():
    with get_pkg_data_fileobj(
            os.path.join("data", "dist.fits"), encoding='binary') as test_file:
        hdulist = fits.open(test_file)
        # The use of ``AXISCORR`` for D2IM correction has been deprecated
        with pytest.warns(AstropyDeprecationWarning):
            wcs1 = wcs.WCS(hdulist[0].header, hdulist)
        assert wcs1.det2im2 is not None
        with pytest.warns(VerifyWarning):
            s = pickle.dumps(wcs1)
        with pytest.warns(FITSFixedWarning):
            wcs2 = pickle.loads(s)

        with NumpyRNGContext(123456789):
            x = np.random.rand(2 ** 16, wcs1.wcs.naxis)
            world1 = wcs1.all_pix2world(x, 1)
            world2 = wcs2.all_pix2world(x, 1)

        assert_array_almost_equal(world1, world2) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:21,代碼來源:test_pickle.py

示例14: test_sip

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def test_sip():
    with get_pkg_data_fileobj(
            os.path.join("data", "sip.fits"), encoding='binary') as test_file:
        hdulist = fits.open(test_file, ignore_missing_end=True)
        with pytest.warns(FITSFixedWarning):
            wcs1 = wcs.WCS(hdulist[0].header)
        assert wcs1.sip is not None
        s = pickle.dumps(wcs1)
        with pytest.warns(FITSFixedWarning):
            wcs2 = pickle.loads(s)

        with NumpyRNGContext(123456789):
            x = np.random.rand(2 ** 16, wcs1.wcs.naxis)
            world1 = wcs1.all_pix2world(x, 1)
            world2 = wcs2.all_pix2world(x, 1)

        assert_array_almost_equal(world1, world2) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:19,代碼來源:test_pickle.py

示例15: test_sip2

# 需要導入模塊: from astropy import wcs [as 別名]
# 或者: from astropy.wcs import WCS [as 別名]
def test_sip2():
    with get_pkg_data_fileobj(
            os.path.join("data", "sip2.fits"), encoding='binary') as test_file:
        hdulist = fits.open(test_file, ignore_missing_end=True)
        with pytest.warns(FITSFixedWarning):
            wcs1 = wcs.WCS(hdulist[0].header)
        assert wcs1.sip is not None
        s = pickle.dumps(wcs1)
        with pytest.warns(FITSFixedWarning):
            wcs2 = pickle.loads(s)

        with NumpyRNGContext(123456789):
            x = np.random.rand(2 ** 16, wcs1.wcs.naxis)
            world1 = wcs1.all_pix2world(x, 1)
            world2 = wcs2.all_pix2world(x, 1)

        assert_array_almost_equal(world1, world2)


# Ignore "PV2_2 = 0.209028857410973 invalid keyvalue" warning seen on Windows. 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:22,代碼來源:test_pickle.py


注:本文中的astropy.wcs.WCS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。