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


Python fits.open方法代码示例

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


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

示例1: __init__

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

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def parse_input_healpix_data(input_data, field=0, hdu_in=None, nested=None):
    """
    Parse input HEALPIX data to return a Numpy array and coordinate frame object.
    """

    if isinstance(input_data, (TableHDU, BinTableHDU)):
        data = input_data.data
        header = input_data.header
        coordinate_system_in = parse_coord_system(header['COORDSYS'])
        array_in = data[data.columns[field].name].ravel()
        if 'ORDERING' in header:
            nested = header['ORDERING'].lower() == 'nested'
    elif isinstance(input_data, str):
        hdu = fits.open(input_data)[hdu_in or 1]
        return parse_input_healpix_data(hdu, field=field)
    elif isinstance(input_data, tuple) and isinstance(input_data[0], np.ndarray):
        array_in = input_data[0]
        coordinate_system_in = parse_coord_system(input_data[1])
    else:
        raise TypeError("input_data should either be an HDU object or a tuple of (array, frame)")

    return array_in, coordinate_system_in, nested 
开发者ID:astropy,项目名称:astropy-healpix,代码行数:24,代码来源:utils.py

示例3: main

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def main(infile, xypadsize):
    """Pad a fits image with zeros to padsize"""
    pad_xsize, pad_ysize = [int(s) for s in xypadsize.split(' ')]

    hdu = pyfits.open(infile)
    imdata = hdu[0].data[0, 0]
    (ysize, xsize) = imdata.shape
    if xsize > pad_xsize or ysize > pad_ysize:
        raise ValueError('pad_image: padded size is smaller than current size!')
    if xsize == pad_xsize and ysize == pad_ysize:
        return()

    xoffset = (pad_xsize - xsize) / 2
    yoffset = (pad_ysize - ysize) / 2
    newdata=np.zeros((1, 1, pad_ysize, pad_xsize))

    newdata[0, 0, yoffset:yoffset+ysize, xoffset:xoffset+xsize] = imdata
    hdu[0].data = newdata
    hdu[0].header['CRPIX1'] += xoffset
    hdu[0].header['CRPIX2'] += yoffset
    hdu.writeto(infile, clobber=True) 
开发者ID:lofar-astron,项目名称:prefactor,代码行数:23,代码来源:pad_image.py

示例4: load_allstar_dr5

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def load_allstar_dr5():
    """
    Open LAMOST DR5 allstar

    :return: fits file opened by astropy
    :rtype: astropy.io.fits.hdu.hdulist.HDUList
    :History: 2018-Jun-17 - Written - Henry Leung (University of Toronto)
    """
    import os
    from astropy.io import fits

    file_name = "LAMO5_2MS_AP9_SD14_UC4_PS1_AW_Carlin_M.fits"
    _lamost_dr5_allsta_path = os.path.join(lamost_env(), "DR5", file_name)
    if not os.path.isfile(_lamost_dr5_allsta_path):
        raise FileNotFoundError(f'{file_name} file not found')
    return fits.open(_lamost_dr5_allsta_path) 
开发者ID:henrysky,项目名称:astroNN,代码行数:18,代码来源:__init__.py

示例5: test_frame_type_invalid

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def test_frame_type_invalid(self) -> None:

        with fits.open(self.fitsfile) as hdulist:
            hdulist[10].header['ESO DET FRAM TYPE'] = 'Test'
            hdulist.writeto(self.fitsfile, overwrite=True)

        module = NearReadingModule(name_in='read5',
                                   input_dir=self.test_dir+'near',
                                   chopa_out_tag=self.positions[0],
                                   chopb_out_tag=self.positions[1])

        self.pipeline.add_module(module)

        with pytest.raises(ValueError) as error:
            self.pipeline.run_module('read5')

        assert str(error.value) == 'Frame type (Test) not a valid value. Expecting HCYCLE1 or ' \
                                   'HCYCLE2 as value for ESO DET FRAM TYPE.' 
开发者ID:PynPoint,项目名称:PynPoint,代码行数:20,代码来源:test_nearreading.py

示例6: test_frame_type_missing

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def test_frame_type_missing(self) -> None:

        with fits.open(self.fitsfile) as hdulist:
            hdulist[10].header.remove('ESO DET FRAM TYPE')
            hdulist.writeto(self.fitsfile, overwrite=True)

        module = NearReadingModule(name_in='read6',
                                   input_dir=self.test_dir+'near',
                                   chopa_out_tag=self.positions[0],
                                   chopb_out_tag=self.positions[1])

        self.pipeline.add_module(module)

        with pytest.raises(ValueError) as error:
            self.pipeline.run_module('read6')

        assert str(error.value) == 'Frame type not found in the FITS header. Image number: 9.' 
开发者ID:PynPoint,项目名称:PynPoint,代码行数:19,代码来源:test_nearreading.py

示例7: test_odd_number_images

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def test_odd_number_images(self) -> None:

        with fits.open(self.fitsfile) as hdulist:
            del hdulist[11]
            hdulist.writeto(self.fitsfile, overwrite=True)

        module = NearReadingModule(name_in='read8',
                                   input_dir=self.test_dir+'near',
                                   chopa_out_tag=self.positions[0],
                                   chopb_out_tag=self.positions[1])

        self.pipeline.add_module(module)

        with pytest.warns(UserWarning) as warning:
            self.pipeline.run_module('read8')

        assert len(warning) == 2

        assert warning[0].message.args[0] == f'FITS file contains odd number of images: ' \
                                             f'{self.fitsfile}'

        assert warning[1].message.args[0] == 'The number of chop cycles (5) is not equal to ' \
                                             'half the number of available HDU images (4).' 
开发者ID:PynPoint,项目名称:PynPoint,代码行数:25,代码来源:test_nearreading.py

示例8: test_header_attribute

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def test_header_attribute(self) -> None:

        with fits.open(self.test_dir+'fits/images_0.fits') as hdu:
            header = hdu[0].header
            header['PARANG'] = 1.0
            hdu.writeto(self.test_dir+'fits/images_0.fits', overwrite=True)

        with fits.open(self.test_dir+'fits/images_1.fits') as hdu:
            header = hdu[0].header
            header['PARANG'] = 2.0
            header['HIERARCH ESO DET DIT'] = 0.1
            hdu.writeto(self.test_dir+'fits/images_1.fits', overwrite=True)

        module = FitsReadingModule(name_in='read5',
                                   input_dir=self.test_dir+'fits',
                                   image_tag='input',
                                   overwrite=True,
                                   check=True)

        self.pipeline.add_module(module)
        self.pipeline.run_module('read5') 
开发者ID:PynPoint,项目名称:PynPoint,代码行数:23,代码来源:test_fitsreading.py

示例9: test_fits_read_textfile_exists

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def test_fits_read_textfile_exists(self) -> None:

        with open(self.test_dir+'filenames.dat', 'w') as file_obj:
            file_obj.write(self.test_dir+'fits/images_0.fits\n')
            file_obj.write(self.test_dir+'fits/images_2.fits\n')

        module = FitsReadingModule(name_in='read10',
                                   input_dir=None,
                                   image_tag='files',
                                   overwrite=True,
                                   check=True,
                                   filenames=self.test_dir+'filenames.dat')

        self.pipeline.add_module(module)

        with pytest.raises(ValueError) as error:
            self.pipeline.run_module('read10')

        assert str(error.value) == f'The file {self.test_dir}fits/images_2.fits does not exist. ' \
                                   f'Please check that the path is correct.' 
开发者ID:PynPoint,项目名称:PynPoint,代码行数:22,代码来源:test_fitsreading.py

示例10: load_spectrum

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def load_spectrum(filename, grid):
    """
    Load a single spectrum
    """
    file_in = pyfits.open(filename)
    wl = np.array(file_in[0].data[2])
    flux = np.array(file_in[0].data[0])
    ivar = np.array((file_in[0].data[1]))
    # correct for radial velocity of star
    redshift = file_in[0].header['Z']
    wl_shifted = wl - redshift * wl
    # resample
    flux_rs = (interpolate.interp1d(wl_shifted, flux))(grid)
    ivar_rs = (interpolate.interp1d(wl_shifted, ivar))(grid)
    ivar_rs[ivar_rs < 0] = 0. # in interpolating you can end up with neg
    return flux_rs, ivar_rs 
开发者ID:annayqho,项目名称:TheCannon,代码行数:18,代码来源:lamost.py

示例11: test_fine_channels

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def test_fine_channels(tmp_path):
    """
    Break read_mwa_corr_fits by submitting files with different fine channels.

    Test that error is raised if files with different numbers of fine channels
    are submitted.
    """
    mwa_uv = UVData()
    bad_fine = str(tmp_path / "bad_gpubox06_01.fits")
    with fits.open(filelist[2]) as mini6:
        mini6[1].data = np.concatenate((mini6[1].data, mini6[1].data))
        mini6.writeto(bad_fine)
    with pytest.raises(ValueError) as cm:
        mwa_uv.read([bad_fine, filelist[1]])
    assert str(cm.value).startswith("files submitted have different fine")
    del mwa_uv 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:18,代码来源:test_mwa_corr_fits.py

示例12: test_diff_obs

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def test_diff_obs(tmp_path):
    """
    Break read_mwa_corr_fits by submitting files from different observations.

    Test that error is raised if files from different observations are
    submitted in the same file list.
    """
    mwa_uv = UVData()
    bad_obs = str(tmp_path / "bad2_gpubox06_01.fits")
    with fits.open(filelist[2]) as mini6:
        mini6[0].header["OBSID"] = "1131733555"
        mini6.writeto(bad_obs)
    with pytest.raises(ValueError) as cm:
        mwa_uv.read([bad_obs, filelist[0], filelist[1]])
    assert str(cm.value).startswith("files from different observations")
    del mwa_uv 
开发者ID:RadioAstronomySoftwareGroup,项目名称:pyuvdata,代码行数:18,代码来源:test_mwa_corr_fits.py

示例13: find_fits_img_size

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def find_fits_img_size(filename):
    """
    Returns the size of a FITS image, given a valid FITS image file

    :param filename: The fully-qualified path of the FITS image file
    :type filename: str

    :returns: Tuple of horizontal/vertical dimensions
    :rtype: tuple
    """

    try:
        return settings.THUMBNAIL_MAX_SIZE
    except AttributeError:
        hdul = fits.open(filename)
        xsize = 0
        ysize = 0
        for hdu in hdul:
            try:
                xsize = max(xsize, hdu.header['NAXIS1'])
                ysize = max(ysize, hdu.header['NAXIS2'])
            except KeyError:
                pass
        return (xsize, ysize) 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:26,代码来源:models.py

示例14: is_fits_image_file

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def is_fits_image_file(file):
    """
    Checks if a file is a valid FITS image by checking if any header contains 'SCI' in the 'EXTNAME'.

    :param file: The file to be checked.
    :type file:

    :returns: True if the file is a FITS image, False otherwise
    :rtype: boolean
    """

    with file.open() as f:
        try:
            hdul = fits.open(f)
        except OSError:  # OSError is raised if file is not FITS format
            return False
        for hdu in hdul:
            if hdu.header.get('EXTNAME') == 'SCI':
                return True
    return False 
开发者ID:TOMToolkit,项目名称:tom_base,代码行数:22,代码来源:models.py

示例15: add_all_spectra

# 需要导入模块: from astropy.io import fits [as 别名]
# 或者: from astropy.io.fits import open [as 别名]
def add_all_spectra():

    from grizli.aws import db as grizli_db

    roots = grizli_db.from_sql("select root,count(root) as n from redshift_fit group BY root order by n DESC", engine)

    o = 1

    for root in roots['root'][::o]:
        existing = open('log').readlines()
        if root+'\n' in existing:
            print('Skip', root)
            continue

        fp = open('log', 'a')
        fp.write(root+'\n')
        fp.close()
        try:
            grizli_db.add_oned_spectra(root=root, engine=engine)
        except:
            pass 
开发者ID:gbrammer,项目名称:grizli,代码行数:23,代码来源:db.py


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