本文整理汇总了Python中pyfits.getheader方法的典型用法代码示例。如果您正苦于以下问题:Python pyfits.getheader方法的具体用法?Python pyfits.getheader怎么用?Python pyfits.getheader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pyfits
的用法示例。
在下文中一共展示了pyfits.getheader方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: write_res
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import getheader [as 别名]
def write_res(filename, datas, extnames, header='', hdrref=None, clobber=False):
if not header and hdrref: header = pyfits.getheader(hdrref)
hdu = pyfits.PrimaryHDU(header=header)
warnings.resetwarnings() # supress nasty overwrite warning http://pythonhosted.org/pyfits/users_guide/users_misc.html
warnings.filterwarnings('ignore', category=UserWarning, append=True)
hdu.writeto(filename, clobber=clobber, output_verify='fix')
warnings.resetwarnings()
warnings.filterwarnings('always', category=UserWarning, append=True)
for i,extname in enumerate(extnames):
data = datas[extname]
if isinstance(data, np.ndarray):
pyfits.append(filename, data)
else:
1/0
pyfits.setval(filename, 'EXTNAME', value=extname, ext=i+1)
#fitsio.write(filename, flux)
示例2: write_template
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import getheader [as 别名]
def write_template(filename, flux, wave, header=None, hdrref=None, clobber=False):
if not header and hdrref: header = pyfits.getheader(hdrref)
hdu = pyfits.PrimaryHDU(header=header)
warnings.resetwarnings() # supress nasty overwrite warning http://pythonhosted.org/pyfits/users_guide/users_misc.html
warnings.filterwarnings('ignore', category=UserWarning, append=True)
hdu.writeto(filename, clobber=clobber, output_verify='fix')
warnings.resetwarnings()
warnings.filterwarnings('always', category=UserWarning, append=True)
if isinstance(flux, np.ndarray):
pyfits.append(filename, flux)
pyfits.append(filename, wave)
else:
# pad arrays with zero to common size
maxpix = max(arr.size for arr in flux if isinstance(arr, np.ndarray))
flux_new = np.zeros((len(flux), maxpix))
wave_new = np.zeros((len(flux), maxpix))
for o,arr in enumerate(flux):
if isinstance(arr, np.ndarray): flux_new[o,:len(arr)] = arr
for o,arr in enumerate(wave):
if isinstance(arr, np.ndarray): wave_new[o,:len(arr)] = arr
pyfits.append(filename, flux_new)
pyfits.append(filename, wave_new)
pyfits.setval(filename, 'EXTNAME', value='SPEC', ext=1)
pyfits.setval(filename, 'EXTNAME', value='WAVE', ext=2)
#fitsio.write(filename, flux)
示例3: write_fits
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import getheader [as 别名]
def write_fits(filename, data, header='', hdrref=None, clobber=True):
if not header and hdrref: header = pyfits.getheader(hdrref)
warnings.resetwarnings() # supress nasty overwrite warning http://pythonhosted.org/pyfits/users_guide/users_misc.html
warnings.filterwarnings('ignore', category=UserWarning, append=True)
pyfits.writeto(filename, data, header, clobber=clobber, output_verify='fix')
warnings.resetwarnings()
warnings.filterwarnings('always', category=UserWarning, append=True)
示例4: bary_harps
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import getheader [as 别名]
def bary_harps(file, ra=None, dec=None, epoch=2000, pma=0.0, pmd=0.0):
''' compute barycentric correction for HARPS spctrum using coordinates from
input or fits header
ra - rammss e.g. -142942.94 (for 14:29:42.94)
dec - demmss e.g. -624046.16 (-62:40:46.16)
pma - [mas/yr] proper motion in alpha (-3775.75)
pmd - [mas/yr] proper motion in delta (765.54)
epoch - epoch of coordinates
'''
head = pyfits.getheader(file)
if ra is None:
ra = head['HIERARCH ESO TEL TARG ALPHA']
dec = head['HIERARCH ESO TEL TARG DELTA']
epoch = head['HIERARCH ESO TEL TARG EPOCH']
pma = head['HIERARCH ESO TEL TARG PMA']*1000
pmd = head['HIERARCH ESO TEL TARG PMD']*1000
exptime = head['EXPTIME'] * 2*head['HIERARCH ESO INS DET1 TMMEAN']
dateobs = head['DATE-OBS']
#bjd = head['HIERARCH ESO DRS BERV']
#berv = head['HIERARCH ESO DRS BJD']
x = str(ra).split('.')
rammss = float(x[0][:-4]), float(x[0][-4:-2]), float(x[0][-2:]+'.'+x[1])
# rammss = divmod(ra,10000); rammss = (rammss[0],) + divmod(rammss[1],100)
x = str(dec).split('.')
demmss = float(x[0][:-4]), float(x[0][-4:-2]), float(x[0][-2:]+'.'+x[1])
#print ra, dec, pma, pmd
return bary(dateobs, rammss, demmss, 14, epoch, exptime, pma, pmd) #, bjd, berv
示例5: load_interaction_matrix
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import getheader [as 别名]
def load_interaction_matrix(self):
"""
Loads the interaction matrix from file
AO interaction matrices can get very big, so its useful to be able to load it frmo file
rather than make it new everytime. It is assumed that the iMat is saved as "FITS" in the
simulation saved directory, with other accompanying FITS files that contain the indices
of actuators which are "valid". Some DMs also use pre made influence functions, which are
also loaded here.
"""
filename = self.sim_config.simName+"/iMat.fits"
imat_header = fits.getheader(filename)
imat_data = fits.getdata(filename)
# Check that imat shape is copatibile with curretn sim
if imat_data.shape != (self.sim_config.totalActs, self.sim_config.totalWfsData):
logger.warning(
"interaction matrix does not match required required size."
)
raise IOError("interaction matrix does not match required required size.")
self.interaction_matrix[:] = imat_data
# Load valid actuators
for i in range(self.n_dms):
valid_acts_filename = self.sim_config.simName+"/active_acts_dm{}.fits".format(i)
valid_acts = fits.getdata(valid_acts_filename)
self.dms[i].valid_actuators = valid_acts
# DM may also have preloaded influence functions
try:
dm_shapes_filename = self.sim_config.simName + "/dmShapes_dm{}.fits".format(i)
dm_shapes = fits.getdata(dm_shapes_filename)
self.dms[i].iMatShapes = dm_shapes
except IOError:
# Found no DM influence funcs
logger.info("DM Influence functions not found. If the DM doesn't use them, this is ok. If not, set 'forceNew=True' when making IMat")
示例6: read_harps_ccf
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import getheader [as 别名]
def read_harps_ccf(s):
ccf = namedtuple('ccf', 'rvc err_rvc bis fwhm contrast mask')
tar = None
if ".tar" in s:
tar = tarfile.open(s)
extr = None
for member in tar.getmembers():
if 'A.fits' in member.name:
if '_ccf_' in member.name and not extr: extr = member
if '_bis_' in member.name: extr = member # prefer bis
if not extr: return ccf(0,0,0,0,0,0)
s = tar.extractfile(extr)
else:
s = glob.glob(s.replace("_e2ds","_bis_*")) + glob.glob(s.replace("_e2ds","_ccf_*"))
if s: s = s[0] # prefer bis
else: return ccf(*[np.nan]*6)
#else: return ccf(0,0,0,0,0,0)
# ccf = namedtuple('ccf', 'rvc err_rvc bis fwhm contrast mask header')
HIERARCH = 'HIERARCH '
if 1:
hdr = imhead(s, HIERARCH+'ESO DRS CCF RVC', HIERARCH+'ESO DRS CCF CONTRAST', HIERARCH+'ESO DRS CCF FWHM', HIERARCH+'ESO DRS CCF MASK', HIERARCH+'ESO DRS DVRMS',HIERARCH+'ESO DRS BIS SPAN')
elif 0:
if ".tar" in s:
s = tar.extractfile(extr)
hdulist = pyfits.open(s)
hdr = hdulist[0].header
tar.close()
#hdr = pyfits.getheader(s) # doesn't work for file like object?
else:
tar.extract(extr, path='tarfits')
os.system('mv tarfits/* tmp.fits ')
data,hdr = fitsio.read('tmp.fits',header=1)
HIERARCH = ''
if tar:
tar.close()
rvc = hdr[HIERARCH+'ESO DRS CCF RVC'] # [km/s]
contrast = hdr.get(HIERARCH+'ESO DRS CCF CONTRAST', np.nan)
fwhm = hdr[HIERARCH+'ESO DRS CCF FWHM']
mask = hdr[HIERARCH+'ESO DRS CCF MASK']
e_rvc = hdr.get(HIERARCH+'ESO DRS DVRMS', np.nan) / 1000. # [km/s]
bis = hdr.get(HIERARCH+'ESO DRS BIS SPAN', np.nan)
return ccf(rvc, e_rvc, bis, fwhm, contrast, mask)
示例7: __init__
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import getheader [as 别名]
def __init__(self, ID, season=None, mission='k2', quiet=False,
clobber=False, cadence='lc', **kwargs):
'''
'''
# Read kwargs
self.ID = ID
self.mission = mission
self.clobber = clobber
if season is not None:
self._season = season
# Initialize preliminary logging
if not quiet:
screen_level = logging.DEBUG
else:
screen_level = logging.CRITICAL
InitLog(None, logging.DEBUG, screen_level, False)
# Check the cadence
if cadence not in ['lc', 'sc']:
raise ValueError("Invalid cadence selected.")
self.cadence = cadence
# Download the FITS file if necessary
self.fitsfile = DownloadFile(
ID, season=season, mission=mission, clobber=clobber,
cadence=cadence)
self.model_name = pyfits.getheader(self.fitsfile, 1)['MODEL']
self._weights = None
# Check the pipeline version. Do we need to upgrade?
subversion = pyfits.getheader(self.fitsfile, 1).get('SUBVER', None)
if subversion is not None:
if LooseVersion(subversion) > LooseVersion(EVEREST_VERSION):
raise Exception("Desired light curve was generated with " +
"EVEREST version %s, but current version " +
"is %s.\n" % (subversion, EVEREST_VERSION) +
"Please upgrade EVEREST by running " +
"`pip install everest-pipeline --upgrade`.")
# Load the FITS file
self.load_fits()
示例8: DetrendFITS
# 需要导入模块: import pyfits [as 别名]
# 或者: from pyfits import getheader [as 别名]
def DetrendFITS(fitsfile, raw=False, season=None, clobber=False, **kwargs):
"""
De-trend a K2 FITS file using :py:class:`everest.detrender.rPLD`.
:param str fitsfile: The full path to the FITS file
:param ndarray aperture: A 2D integer array corresponding to the \
desired photometric aperture (1 = in aperture, 0 = outside \
aperture). Default is to interactively select an aperture.
:param kwargs: Any kwargs accepted by :py:class:`everest.detrender.rPLD`.
:returns: An :py:class:`everest.Everest` instance.
"""
# Get info
EPIC = pyfits.getheader(fitsfile, 0)['KEPLERID']
if season is None:
season = pyfits.getheader(fitsfile, 0)['CAMPAIGN']
if season is None or season == "":
season = 0
everestfile = os.path.join(
everest.missions.k2.TargetDirectory(EPIC, season),
everest.missions.k2.FITSFile(EPIC, season))
# De-trend?
if clobber or not os.path.exists(everestfile):
# Get raw data
data = GetData(fitsfile, EPIC, season, clobber=clobber, **kwargs)
# De-trend
model = everest.rPLD(EPIC,
data=data,
season=season, debug=True,
clobber=clobber, **kwargs)
# Publish it
everest.fits.MakeFITS(model)
shutil.copyfile(os.path.join(model.dir, model.name + '.pdf'),
os.path.join(model.dir,
model._mission.DVSFile(model.ID,
model.season,
model.cadence)))
# Return an Everest instance
return everest.Everest(EPIC, season=season)