当前位置: 首页>>代码示例>>Python>>正文


Python fits.HDUList方法代码示例

本文整理汇总了Python中astropy.io.fits.HDUList方法的典型用法代码示例。如果您正苦于以下问题:Python fits.HDUList方法的具体用法?Python fits.HDUList怎么用?Python fits.HDUList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在astropy.io.fits的用法示例。


在下文中一共展示了fits.HDUList方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_is_fits_image_file_table_img

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def test_is_fits_image_file_table_img(self, dp_mock):
        with tempfile.TemporaryDirectory() as tmpdir:
            with self.settings(MEDIA_ROOT=tmpdir):
                img_file = os.path.join(tmpdir, 'img.blah')  # file name should be irrelevant
                img = fits.PrimaryHDU(np.arange(100))
                img.header['EXTNAME'] = 'SCI'
                hdul = fits.HDUList([img])
                hdul.writeto(img_file)

                tabimg_file = os.path.join(tmpdir, 'both.fits')
                table = fits.BinTableHDU.from_columns([
                    fits.Column(name='col1', format='I', array=np.array([1, 2, 3])),
                    fits.Column(name='col2', format='I', array=np.array([4, 5, 6]))
                ])
                hdul = fits.HDUList([img, table])
                hdul.writeto(tabimg_file)
                self.data_product.data = tabimg_file
                self.assertTrue(is_fits_image_file(self.data_product.data.file)) 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:20,代码来源:tests.py

示例2: write_fits

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def write_fits(data, header, file_name):
    """
    Combine data and a fits header to write a fits file.

    Parameters
    ----------
    data : numpy.ndarray
        The data to be written.

    header : astropy.io.fits.hduheader
        The header for the fits file.

    file_name : string
        The file to write

    Returns
    -------
    None
    """
    hdu = fits.PrimaryHDU(data)
    hdu.header = header
    hdulist = fits.HDUList([hdu])
    hdulist.writeto(file_name, overwrite=True)
    logging.info("Wrote {0}".format(file_name))
    return 
开发者ID:PaulHancock,项目名称:Aegean,代码行数:27,代码来源:BANE.py

示例3: load_file_or_hdu

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def load_file_or_hdu(filename):
    """
    Load a file from disk and return an HDUList
    If filename is already an HDUList return that instead

    Parameters
    ----------
    filename : str or HDUList
        File or HDU to be loaded

    Returns
    -------
    hdulist : HDUList
    """
    if isinstance(filename, fits.HDUList):
        hdulist = filename
    else:
        hdulist = fits.open(filename, ignore_missing_end=True)
    return hdulist 
开发者ID:PaulHancock,项目名称:Aegean,代码行数:21,代码来源:fits_interp.py

示例4: test_compress

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def test_compress():
    """Test the compression functionality"""
    # return None when the factor is not a positive integer
    if not (fits_interp.compress(None, factor=-1) is None): raise AssertionError()
    if not (fits_interp.compress(None, factor=0.3) is None): raise AssertionError()
    if not (fits_interp.compress(None, factor=0) is None): raise AssertionError()
    # test with factor = 10 for speed
    fname = 'tests/test_files/1904-66_AIT.fits'
    hdulist = fits.open(fname)
    cd1 = hdulist[0].header['CDELT1']
    cd2 = hdulist[0].header['CDELT2']
    # compress using CDELT1 and CDELT2
    if not (isinstance(fits_interp.compress(hdulist, factor=10), fits.HDUList)): raise AssertionError()
    hdulist[0].header['CD1_1'] = cd1
    del hdulist[0].header['CDELT1']
    hdulist[0].header['CD2_2'] = cd2
    del hdulist[0].header['CDELT2']
    # compress using CD1_1 and CDELT2_2 instead
    if not (isinstance(fits_interp.compress(hdulist, factor=10), fits.HDUList)): raise AssertionError()
    # now strip CD2_2 and we should get error
    del hdulist[0].header['CD2_2']
    if not (fits_interp.compress(hdulist, factor=10) is None): raise AssertionError()
    # same for CD1_1
    del hdulist[0].header['CD1_1']
    if not (fits_interp.compress(hdulist, factor=10) is None): raise AssertionError() 
开发者ID:PaulHancock,项目名称:Aegean,代码行数:27,代码来源:test_fits_interp.py

示例5: pack

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def pack(uncompressed_hdulist: fits.HDUList) -> fits.HDUList:
    if uncompressed_hdulist[0].data is None:
        primary_hdu = fits.PrimaryHDU(header=uncompressed_hdulist[0].header)
        hdulist = [primary_hdu]
    else:
        primary_hdu = fits.PrimaryHDU()
        compressed_hdu = fits.CompImageHDU(data=np.ascontiguousarray(uncompressed_hdulist[0].data),
                                           header=uncompressed_hdulist[0].header, quantize_level=64,
                                           dither_seed=2048, quantize_method=1)
        hdulist = [primary_hdu, compressed_hdu]

    for hdu in uncompressed_hdulist[1:]:
        if isinstance(hdu, fits.ImageHDU):
            compressed_hdu = fits.CompImageHDU(data=np.ascontiguousarray(hdu.data), header=hdu.header,
                                               quantize_level=64, quantize_method=1)
            hdulist.append(compressed_hdu)
        else:
            hdulist.append(hdu)
    return fits.HDUList(hdulist) 
开发者ID:LCOGT,项目名称:banzai,代码行数:21,代码来源:fits_utils.py

示例6: to_fits

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def to_fits(self, context) -> Union[fits.HDUList, list]:
        hdu = fits.BinTableHDU(self.data)
        hdu.name = self.name
        # For all TTYPE header keywords, set the header comment
        # from the table column's description.
        for k in self.meta.keys():
            if 'TTYPE' in k:
                column_name = self.meta[k]
                description = self.data[column_name].description
                hdu.header[k] = (column_name.upper(), description)
                # Get the value of n in TTYPEn
                n = k[5:]
                # Also add the TCOMMn header keyword with the description of the table column
                hdu.header['TCOMM{0}'.format(n)] = description

        return [hdu] 
开发者ID:LCOGT,项目名称:banzai,代码行数:18,代码来源:data.py

示例7: save_single_fits

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def save_single_fits(image, name, key_dict=None, image2=None, image2type=None):
        # Save an array into the first extension of a fits file
        h0 = fits.PrimaryHDU()
        h1 = fits.ImageHDU(image, name='DATA')
        if image2 is not None:
            h2 = fits.ImageHDU(image2)
            if image2type is not None:
                h2.header['EXTNAME'] = image2type

        # if a keyword dictionary is provided, put the
        # keywords into the 0th and 1st extension headers
        if key_dict is not None:
            for key in key_dict:
                h0.header[key] = key_dict[key]
                h1.header[key] = key_dict[key]

        if image2 is None:
            hdulist = fits.HDUList([h0, h1])
        else:
            hdulist = fits.HDUList([h0, h1, h2])
        hdulist.writeto(name, overwrite=True) 
开发者ID:spacetelescope,项目名称:mirage,代码行数:23,代码来源:save_seed.py

示例8: _load_cube_from_file

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [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: __init__

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def __init__(self, primary_hdu=None, fits_extensions=None):

        hdu_list = []

        if primary_hdu is None:

            primary_hdu = fits.PrimaryHDU()

        else:

            assert isinstance(primary_hdu, fits.PrimaryHDU)

        hdu_list.append(primary_hdu)

        if fits_extensions is not None:

            fits_extensions = list(fits_extensions)

            hdu_list.extend([x.hdu for x in fits_extensions])

        # We embed instead of subclassing because the HDUList class has some weird interaction with the
        # __init__ and __new__ methods which makes difficult to do so (we couldn't figure it out)

        self._hdu_list = fits.HDUList(hdus=hdu_list) 
开发者ID:threeML,项目名称:threeML,代码行数:26,代码来源:fits_file.py

示例10: saveScrns

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def saveScrns(self, DIR):
        """
        Saves the currently loaded phase screens to file,
        saving the r0 value in the fits header (in units of pixels). 
        Saved phase data is in radians @500nm

        Args:
            DIR (string): The directory to save the screens
        """

        for scrn in range(self.scrnNo):
            logger.info("Write Sreen {}....".format(scrn))
            hdu = fits.PrimaryHDU(self.wholeScrns[scrn])
            hdu.header["R0"] = self.wholeScrnR0 / self.pixel_scale
            hdulist = fits.HDUList([hdu])
            hdulist.writeto(DIR+"/scrn{}.fits".format(scrn))
            hdulist.close()

            logger.info("Done!") 
开发者ID:AOtools,项目名称:soapy,代码行数:21,代码来源:atmosphere.py

示例11: from_tree

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def from_tree(cls, data, ctx):
        hdus = []
        first = True
        for hdu_entry in data:
            header = fits.Header([fits.Card(*x) for x in hdu_entry['header']])
            data = hdu_entry.get('data')
            if data is not None:
                try:
                    data = data.__array__()
                except ValueError:
                    data = None
            if first:
                hdu = fits.PrimaryHDU(data=data, header=header)
                first = False
            elif data.dtype.names is not None:
                hdu = fits.BinTableHDU(data=data, header=header)
            else:
                hdu = fits.ImageHDU(data=data, header=header)
            hdus.append(hdu)
        hdulist = fits.HDUList(hdus)
        return hdulist 
开发者ID:holzschu,项目名称:Carnets,代码行数:23,代码来源:fits.py

示例12: save_unwrapped

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def save_unwrapped(self, fname):

        imarr = np.array(self.profiles).T

        header = fits.Header()
        header['CTYPE1'] = 'RA---SIN'
        header['CTYPE2'] = 'DEC--SIN'
        header['CDELT1'] = 2*np.pi/float(len(self.profiles))
        header['CDELT2'] = np.max(self.rs)/float(len(self.rs))
        header['BUNIT'] = 'K'
        hdu = fits.PrimaryHDU(imarr, header=header)
        hdulist = [hdu]
        hdulist = fits.HDUList(hdulist)
        hdulist.writeto(fname, overwrite=True) 
开发者ID:achael,项目名称:eht-imaging,代码行数:16,代码来源:rex.py

示例13: test_read_cst_write_read_fits_intensity

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def test_read_cst_write_read_fits_intensity(cst_power_1freq, tmp_path):
    # set up power beam
    beam_in = cst_power_1freq
    beam_out = UVBeam()

    write_file = str(tmp_path / "outtest_beam.fits")
    write_file2 = str(tmp_path / "outtest_beam2.fits")
    beam_in.write_beamfits(write_file, clobber=True)

    # now replace 'power' with 'intensity' for btype
    fname = fits.open(write_file)
    data = fname[0].data
    primary_hdr = fname[0].header
    primary_hdr["BTYPE"] = "Intensity"
    hdunames = uvutils._fits_indexhdus(fname)
    bandpass_hdu = fname[hdunames["BANDPARM"]]

    prihdu = fits.PrimaryHDU(data=data, header=primary_hdr)
    hdulist = fits.HDUList([prihdu, bandpass_hdu])

    hdulist.writeto(write_file2, overwrite=True)
    hdulist.close()

    beam_out.read_beamfits(write_file2)
    assert beam_in == beam_out

    return 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:29,代码来源:test_beamfits.py

示例14: test_read_cst_write_read_fits_no_coordsys

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def test_read_cst_write_read_fits_no_coordsys(cst_power_1freq, tmp_path):
    # set up power beam
    beam_in = cst_power_1freq
    beam_out = UVBeam()

    write_file = str(tmp_path / "outtest_beam.fits")
    write_file2 = str(tmp_path / "outtest_beam2.fits")
    beam_in.write_beamfits(write_file, clobber=True)

    # now remove coordsys but leave ctypes 1 & 2
    fname = fits.open(write_file)
    data = fname[0].data
    primary_hdr = fname[0].header
    primary_hdr.pop("COORDSYS")
    hdunames = uvutils._fits_indexhdus(fname)
    bandpass_hdu = fname[hdunames["BANDPARM"]]

    prihdu = fits.PrimaryHDU(data=data, header=primary_hdr)
    hdulist = fits.HDUList([prihdu, bandpass_hdu])

    hdulist.writeto(write_file2, overwrite=True)
    hdulist.close()

    beam_out.read_beamfits(write_file2)
    assert beam_in == beam_out

    return 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:29,代码来源:test_beamfits.py

示例15: test_read_cst_write_read_fits_change_freq_units

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import HDUList [as 别名]
def test_read_cst_write_read_fits_change_freq_units(cst_power_1freq, tmp_path):
    # set up power beam
    beam_in = cst_power_1freq
    beam_out = UVBeam()

    write_file = str(tmp_path / "outtest_beam.fits")
    write_file2 = str(tmp_path / "outtest_beam2.fits")
    beam_in.write_beamfits(write_file, clobber=True)

    # now change frequency units
    fname = fits.open(write_file)
    data = fname[0].data
    primary_hdr = fname[0].header
    primary_hdr["CUNIT3"] = "MHz"
    primary_hdr["CRVAL3"] = primary_hdr["CRVAL3"] / 1e6
    primary_hdr["CDELT3"] = primary_hdr["CRVAL3"] / 1e6
    hdunames = uvutils._fits_indexhdus(fname)
    bandpass_hdu = fname[hdunames["BANDPARM"]]

    prihdu = fits.PrimaryHDU(data=data, header=primary_hdr)
    hdulist = fits.HDUList([prihdu, bandpass_hdu])

    hdulist.writeto(write_file2, overwrite=True)
    hdulist.close()

    beam_out.read_beamfits(write_file2)
    assert beam_in == beam_out

    return 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:31,代码来源:test_beamfits.py


注:本文中的astropy.io.fits.HDUList方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。