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


Python fits.getdata方法代碼示例

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


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

示例1: test_quantitative

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def test_quantitative():
    """Test that the images are equal to a pre-calculated version"""
    fbase = 'tests/test_files/1904-66_SIN'
    outbase = 'dlme'
    BANE.filter_image(fbase+'.fits', out_base=outbase, cores=2, nslice=2)

    rms = outbase + '_rms.fits'
    bkg = outbase + '_bkg.fits'
    ref_rms = fbase + '_rms.fits'
    ref_bkg = fbase + '_bkg.fits'

    r1 = fits.getdata(rms)
    r2 = fits.getdata(ref_rms)
    b1 = fits.getdata(bkg)
    b2 = fits.getdata(ref_bkg)
    os.remove(rms)
    os.remove(bkg)

    if not np.allclose(r1, r2, atol=0.01, equal_nan=True):
        raise AssertionError("rms is wrong")

    if not np.allclose(b1, b2, atol=0.003, equal_nan=True):
        raise AssertionError("bkg is wrong")

    return 
開發者ID:PaulHancock,項目名稱:Aegean,代碼行數:27,代碼來源:test_BANE.py

示例2: loadCMat

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def loadCMat(self):

        super(LearnAndApply, self).loadCMat()

        #Load tomo reconstructor
        tomoFilename = self.sim_config.simName+"/tomoMat.fits"
        tomoMat = fits.getdata(tomoFilename)

        #And check its the right size
        if tomoMat.shape != (
                2*self.wfss[0].activeSubaps,
                self.sim_config.totalWfsData - 2*self.wfss[0].activeSubaps):
            logger.warning("Loaded Tomo matrix not the expected shape - gonna make a new one..." )
            raise Exception
        else:
            self.tomoRecon = tomoMat 
開發者ID:AOtools,項目名稱:soapy,代碼行數:18,代碼來源:reconstruction.py

示例3: test_fortran_array

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def test_fortran_array(self):
        # Test that files are being correctly written+read for "C" and "F" order arrays
        a = np.arange(21).reshape(3,7)
        b = np.asfortranarray(a)

        afits = self.temp('a_str.fits')
        bfits = self.temp('b_str.fits')
        # writting to str specified files
        fits.PrimaryHDU(data=a).writeto(afits)
        fits.PrimaryHDU(data=b).writeto(bfits)
        np.testing.assert_array_equal(fits.getdata(afits), a)
        np.testing.assert_array_equal(fits.getdata(bfits), a)

        # writting to fileobjs
        aafits = self.temp('a_fileobj.fits')
        bbfits = self.temp('b_fileobj.fits')
        with open(aafits, mode='wb') as fd:
            fits.PrimaryHDU(data=a).writeto(fd)
        with open(bbfits, mode='wb') as fd:
            fits.PrimaryHDU(data=b).writeto(fd)
        np.testing.assert_array_equal(fits.getdata(aafits), a)
        np.testing.assert_array_equal(fits.getdata(bbfits), a) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:24,代碼來源:test_image.py

示例4: test_fortran_array_non_contiguous

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def test_fortran_array_non_contiguous(self):
        # Test that files are being correctly written+read for 'C' and 'F' order arrays
        a = np.arange(105).reshape(3,5,7)
        b = np.asfortranarray(a)

        # writting to str specified files
        afits = self.temp('a_str_slice.fits')
        bfits = self.temp('b_str_slice.fits')
        fits.PrimaryHDU(data=a[::2, ::2]).writeto(afits)
        fits.PrimaryHDU(data=b[::2, ::2]).writeto(bfits)
        np.testing.assert_array_equal(fits.getdata(afits), a[::2, ::2])
        np.testing.assert_array_equal(fits.getdata(bfits), a[::2, ::2])

        # writting to fileobjs
        aafits = self.temp('a_fileobj_slice.fits')
        bbfits = self.temp('b_fileobj_slice.fits')
        with open(aafits, mode='wb') as fd:
            fits.PrimaryHDU(data=a[::2, ::2]).writeto(fd)
        with open(bbfits, mode='wb') as fd:
            fits.PrimaryHDU(data=b[::2, ::2]).writeto(fd)
        np.testing.assert_array_equal(fits.getdata(aafits), a[::2, ::2])
        np.testing.assert_array_equal(fits.getdata(bbfits), a[::2, ::2]) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:24,代碼來源:test_image.py

示例5: test_fileobj_not_closed

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def test_fileobj_not_closed(self):
        """
        Tests that file-like objects are not closed after being passed
        to convenience functions.

        Regression test for https://github.com/astropy/astropy/issues/5063
        """

        f = open(self.data('test0.fits'), 'rb')
        _ = fits.getdata(f)
        assert not f.closed

        f.seek(0)
        _ = fits.getheader(f)
        assert not f.closed

        f.close()  # Close it now 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:19,代碼來源:test_convenience.py

示例6: test_table_from_bool_fields

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def test_table_from_bool_fields(self):
        """
        Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/113

        Tests creating a table from a recarray containing numpy.bool columns.
        """

        array = np.rec.array([(True, False), (False, True)], formats='|b1,|b1')
        thdu = fits.BinTableHDU.from_columns(array)
        assert thdu.columns.formats == ['L', 'L']
        assert comparerecords(thdu.data, array)

        # Test round trip
        thdu.writeto(self.temp('table.fits'))
        data = fits.getdata(self.temp('table.fits'), ext=1)
        assert thdu.columns.formats == ['L', 'L']
        assert comparerecords(data, array) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:19,代碼來源:test_table.py

示例7: test_dim_column_byte_order_mismatch

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def test_dim_column_byte_order_mismatch(self):
        """
        When creating a table column with non-trivial TDIMn, and
        big-endian array data read from an existing FITS file, the data
        should not be unnecessarily byteswapped.

        Regression test for https://github.com/astropy/astropy/issues/3561
        """

        data = fits.getdata(self.data('random_groups.fits'))['DATA']
        col = fits.Column(name='TEST', array=data, dim='(3,1,128,1,1)',
                          format='1152E')
        thdu = fits.BinTableHDU.from_columns([col])
        thdu.writeto(self.temp('test.fits'))

        with fits.open(self.temp('test.fits')) as hdul:
            assert np.all(hdul[1].data['TEST'] == data) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:19,代碼來源:test_table.py

示例8: test_getdata_vla

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def test_getdata_vla(self):
        """Regression test for https://aeon.stsci.edu/ssb/trac/pyfits/ticket/200"""

        def test(format_code):
            col = fits.Column(name='QUAL_SPE', format=format_code,
                              array=[np.arange(1572)] * 225)
            tb_hdu = fits.BinTableHDU.from_columns([col])
            pri_hdu = fits.PrimaryHDU()
            hdu_list = fits.HDUList([pri_hdu, tb_hdu])
            with ignore_warnings():
                hdu_list.writeto(self.temp('toto.fits'), overwrite=True)

            data = fits.getdata(self.temp('toto.fits'))

            # Need to compare to the original data row by row since the FITS_rec
            # returns an array of _VLA objects
            for row_a, row_b in zip(data['QUAL_SPE'], col.array):
                assert (row_a == row_b).all()

        for code in ('PJ()', 'QJ()'):
            test(code) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:23,代碼來源:test_table.py

示例9: __init__

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def __init__(self, wcs, catalog_source, src_find_filters=None, **kwargs):
        # 'src_find_filters' - None or a dictionary. The dictionary
        # MUST contain keys 'region_file' and 'region_file_mode':
        # - 'region_file': the name of the region file that indicates regions
        #   of the image that should be used for source finding
        #   ("include" regions) or regions of the image that should NOT be used
        #   for source finding ("exclude" regions). If it is None - the entire
        #   image will be used for source finding.
        # - 'region_file_mode': 'exclude only' or 'normal' - if 'exclude only' then regular regions are
        #   interpretted as 'exclude' regions and exclude regions (with '-' in front)
        #   are ignored. If 'region_file_mode' = 'normal' then normal DS9 interpretation
        #   of the regions will be applied.
        self.src_find_filters = src_find_filters
        super().__init__(wcs, catalog_source, **kwargs)
        extind = self.fname.rfind('[')
        self.fnamenoext = self.fname if extind < 0 else self.fname[:extind]
        if self.wcs.extname == ('',None):
            self.wcs.extname = (0)
        self.source = fits.getdata(self.wcs.filename,ext=self.wcs.extname, memmap=False)
        self.nbright = None # No GUI parameter defined yet for this filtering 
開發者ID:spacetelescope,項目名稱:drizzlepac,代碼行數:22,代碼來源:catalogs.py

示例10: read_fits

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def read_fits(filename):
	'''Read an array from a fits file.

	Parameters
	----------
	filename : string
		The filename of the file to read. This can include a path.

	Returns
	-------
	ndarray
		The ndarray read from the fits file.
	'''
	from astropy.io import fits
	return fits.getdata(filename).copy() 
開發者ID:ehpor,項目名稱:hcipy,代碼行數:17,代碼來源:io.py

示例11: getdata

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def getdata(self, extname=None, o=np.s_[:]):
      if extname is None:  # search first extension with data
         extname = 0
         while not self[extname].NAXIS: extname += 1
      ext = self[extname]
      dtype = {-32: '>f4', -64: '>f8'}[ext.BITPIX]
      dsize = {-32: 4, -64: 8}[ext.BITPIX]
      was_open = True
      if isinstance(self.fileobj, (tarfile.ExFileObject, file)):
         funit = self.fileobj
      else:
         funit = open(self.fileobj)
         was_open = False

#      with open(self.fileobj) as funit:
      if 1:
         if o == np.s_[:]: # read all
            funit.seek(ext.EXTDATA)
            data = np.fromfile(funit, dtype=dtype, count=ext.NAXIS1*ext.NAXIS2).reshape((ext.NAXIS2,ext.NAXIS1))
         else:
            funit.seek(ext.EXTDATA+o*ext.NAXIS1*dsize)
            data = np.fromfile(funit, dtype=dtype, count=ext.NAXIS1)

      if not was_open:
         funit.close()
      return data 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:28,代碼來源:read_spec.py

示例12: fromfile

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def fromfile(name, *args):
   chi2map =  np.array(pyfits.getdata(name), np.float)
   hdr = pyfits.getheader(name)
   vrange = hdr['CRVAL1'], hdr['CDELT1'] # -15, 0.1
   return Chi2Map(chi2map, vrange, *args, name=name) 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:7,代碼來源:chi2map.py

示例13: find_ipc_file

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def find_ipc_file(self, inputipc):
        """Given a list of potential IPC kernel files for a given
        detector, select the most appropriate one, and check to see
        whether the kernel needs to be inverted, in order to populate
        the invertIPC field. This is not intended to be terribly smart.
        The first inverted kernel found will be used. If none are found,
        the first kernel will be used and set to be inverted.

        Parameters
        ----------
        inputipc : list
           List of fits files containing IPC kernels for a single detector

        Returns
        -------
        (ipcfile, invstatus) : tup
           ipcfile is the name of the IPC kernel file to use, and invstatus
           lists whether the kernel needs to be inverted or not.
        """
        for ifile in inputipc:
            kernel = fits.getdata(ifile)
            kshape = kernel.shape

            # If kernel is 4 dimensional, extract the 3x3 kernel associated
            # with a single pixel
            if len(kernel.shape) == 4:
                kernel = kernel[:, :, np.int(kshape[2]/2), np.int(kshape[2]/2)]

            if kernel[1, 1] < 1.0:
                return (ifile, False)
        # If no inverted kernel was found, just return the first file
        return (inputipc[0], True) 
開發者ID:spacetelescope,項目名稱:mirage,代碼行數:34,代碼來源:yaml_generator.py

示例14: simple_get_image

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def simple_get_image(self, name):
        """Read in an array from a fits file and crop using subarray_bounds

        Parameters
        ----------
        name : str
            Name of fits file to be read in

        Returns
        -------
        image : numpy.ndarray
            Array populated with the file contents
        """
        try:
            image, header = fits.getdata(name, header=True)
        except:
            raise FileNotFoundError('WARNING: unable to read in {}'.format(name))

        # assume that the input is 2D, since we are using it to build a signal rate frame
        imageshape = image.shape
        if len(imageshape) != 2:
            self.printfunc("Error: image %s is not two-dimensional" % (name))
            return None, None

        imageshape = image.shape

        try:
            image = image[self.subarray_bounds[1]:self.subarray_bounds[3]+1,
                          self.subarray_bounds[0]:self.subarray_bounds[2]+1]
        except:
            raise ValueError("Unable to crop image from {}".format(name))

        return image 
開發者ID:spacetelescope,項目名稱:mirage,代碼行數:35,代碼來源:obs_generator.py

示例15: _load_itm_library

# 需要導入模塊: from astropy.io import fits [as 別名]
# 或者: from astropy.io.fits import getdata [as 別名]
def _load_itm_library(library_file):
    """Load ITM FITS file

    Parameters
    ----------
    library_path : str
        Path pointing to the location of the PSF library

    Returns
    -------
    library : photutils.griddedPSFModel
        Object containing PSF library
    """
    data = fits.getdata(library_file)
    hdr = fits.getheader(library_file)
    if data.shape == (2048, 2048):
        # Normalize the data
        data /= np.sum(data)

        # Add PSF location and oversampling keywords
        hdr['DET_YX0'] = ('(1023, 1023)', "The #0 PSF's (y,x) detector pixel position")
        hdr['OVERSAMP'] = (1, 'Oversampling factor for FFTs in computation')

        # Convert to HDUList and create library
        phdu = fits.PrimaryHDU(data, hdr)
        hdulist = fits.HDUList(phdu)
        library = to_griddedpsfmodel(hdulist)

        return library
    else:
        raise ValueError('Expecting ITM data of size (2048, 2048), not {}'.format(data.shape)) 
開發者ID:spacetelescope,項目名稱:mirage,代碼行數:33,代碼來源:psf_selection.py


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