当前位置: 首页>>代码示例>>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;未经允许,请勿转载。