本文整理匯總了Python中pyfits.open方法的典型用法代碼示例。如果您正苦於以下問題:Python pyfits.open方法的具體用法?Python pyfits.open怎麽用?Python pyfits.open使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyfits
的用法示例。
在下文中一共展示了pyfits.open方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_spectrum
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits 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
示例2: load_data
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def load_data():
direc = "/Users/annaho/Data/LAMOST/Mass_And_Age"
hdulist = pyfits.open("%s/catalog_paper.fits" %direc)
tbdata = hdulist[1].data
hdulist.close()
snr = tbdata.field("snr")
chisq = tbdata.field("chisq")
teff = tbdata.field("cannon_teff")
in_martig_range = tbdata.field("in_martig_range")
choose = np.logical_and(in_martig_range, snr > 80)
print(sum(choose))
mh = tbdata.field("cannon_mh")[choose]
afe = tbdata.field("cannon_am")[choose]
age = tbdata.field("cannon_age")[choose]
age_err = tbdata.field("cannon_age_err")[choose]
return mh, afe, age, age_err
示例3: load_comparison
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def load_comparison():
direc = "/Users/annaho/Data/LAMOST/Mass_And_Age"
hdulist = pyfits.open("%s/age_vs_age_catalog.fits" %direc)
tbdata = hdulist[1].data
hdulist.close()
snr = tbdata.field("snr")
mass_raw = tbdata.field("cannon_mass")
choose = np.logical_and(snr > 30, mass_raw > 0)
mass = np.log10(tbdata.field("cannon_mass")[choose])
age = tbdata.field("cannon_age")[choose]
age_err = tbdata.field("cannon_age_err")[choose]
mass_err = tbdata.field("cannon_mass_err")[choose]
ness_age = np.log10(np.exp(tbdata.field("lnAge")[choose]))
ness_age_err = tbdata.field("e_logAge")[choose]
ness_mass = np.log10(np.exp(tbdata.field("lnM")[choose]))
ness_mass_err = tbdata.field("e_logM")[choose]
return mass, age, ness_mass, ness_age
示例4: find_colors
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def find_colors(ref_id, ref_flux, ref_ivar):
# Find colors
print("Finding colors")
a = pyfits.open(DATA_DIR + "/lamost_catalog_colors.fits")
data = a[1].data
a.close()
all_ids = data['LAMOST_ID_1']
all_ids = np.array([val.strip() for val in all_ids])
ref_id_col = np.intersect1d(all_ids, ref_id)
inds = np.array([np.where(all_ids==val)[0][0] for val in ref_id_col])
all_col, all_col_ivar = get_colors(
DATA_DIR + "/lamost_catalog_colors.fits")
col = all_col[:,inds]
col_ivar = all_col_ivar[:,inds]
bad_ivar = np.logical_or(np.isnan(col_ivar), col_ivar==np.inf)
col_ivar[bad_ivar] = 0.0
bad_flux = np.logical_or(np.isnan(col), col==np.inf)
col[bad_flux] = 1.0
col_ivar[bad_flux] = 0.0
# add them to the wl, flux and ivar arrays
inds = np.array([np.where(ref_id==val)[0][0] for val in ref_id_col])
ref_flux_col = np.hstack((ref_flux[inds], col.T))
ref_ivar_col = np.hstack((ref_ivar[inds], col_ivar.T))
return ref_id_col, ref_flux_col, ref_ivar_col
示例5: load_all_ref_label
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def load_all_ref_label():
DATA_DIR = "/Users/annaho/Data/LAMOST/Abundances"
a = pyfits.open(
DATA_DIR + "/casey_lamost_paper_one_cross_match_with_colors.fits")
tbl = a[1].data
a.close()
ref_id = tbl['lamost_id']
ref_id = np.array(ref_id)
ref_id = np.array([val.strip() for val in ref_id])
snrg = tbl['snrg']
labels = ['TEFF', 'LOGG', 'AK_WISE',
'AL_H', 'CA_H', 'C_H', 'FE_H', 'MG_H', 'MN_H',
'NI_H', 'N_H', 'O_H', 'SI_H', 'TI_H']
np.savez("label_names.npz", labels)
nlabel = len(labels)
nobj = len(ref_id)
ref_label = np.zeros((nobj, nlabel))
for ii,label in enumerate(labels):
ref_label[:,ii] = tbl[label]
np.savez("ref_id.npz", ref_id)
np.savez("ref_label.npz", ref_label)
return ref_id
示例6: find_colors
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def find_colors(ref_id, ref_flux, ref_ivar):
# Find colors
DATA_DIR = "/Users/annaho/Data/LAMOST/Mass_And_Age"
print("Finding colors")
a = pyfits.open(DATA_DIR + "/lamost_catalog_colors.fits")
data = a[1].data
a.close()
all_ids = data['LAMOST_ID_1']
all_ids = np.array([val.strip() for val in all_ids])
ref_id_col = np.intersect1d(all_ids, ref_id)
inds = np.array([np.where(all_ids==val)[0][0] for val in ref_id_col])
all_id, all_col, all_col_ivar = get_colors(
DATA_DIR + "/lamost_catalog_colors.fits")
col = all_col[:,inds]
col_ivar = all_col_ivar[:,inds]
bad_ivar = np.logical_or(np.isnan(col_ivar), col_ivar==np.inf)
col_ivar[bad_ivar] = 0.0
bad_flux = np.logical_or(np.isnan(col), col==np.inf)
col[bad_flux] = 1.0
col_ivar[bad_flux] = 0.0
# add them to the wl, flux and ivar arrays
inds = np.array([np.where(ref_id==val)[0][0] for val in ref_id_col])
ref_flux_col = np.hstack((ref_flux[inds], col.T))
ref_ivar_col = np.hstack((ref_ivar[inds], col_ivar.T))
return ref_id_col, ref_flux_col, ref_ivar_col
示例7: get_labels
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def get_labels(ids_find):
""" Labels to make Cannon model spectra """
a = pyfits.open("%s/lamost_catalog_full.fits" %LAB_DIR)
data = a[1].data
a.close()
id_all = data['lamost_id']
id_all = np.array(id_all)
id_all = np.array([val.strip() for val in id_all])
snr_all = data['cannon_snrg']
chisq_all = data['cannon_chisq']
teff = data['cannon_teff']
logg = data['cannon_logg']
feh = data['cannon_m_h']
afe = data['cannon_alpha_m']
ak = data['cannon_a_k']
labels = np.vstack((teff,logg,feh,afe,ak))
choose = np.in1d(id_all, ids_find)
id_choose = id_all[choose]
label_choose = labels[:,choose]
snr_choose = snr_all[choose]
chisq_choose = chisq_all[choose]
inds = np.array([np.where(id_choose==val)[0][0] for val in ids_find])
print(id_choose[inds][100])
print(ids_find[100])
return label_choose[:,inds], snr_choose[inds], chisq_choose[inds]
示例8: readphoenix
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def readphoenix(fitsphoe, wmin=3500, wmax=8000):
#fitsphoe = '/home/astro56/husser/PhoenixModels/HiResFITS/PHOENIX-ACES-AGSS-COND-2011/Z-0.0/lte03900-4.00-0.0.PHOENIX-ACES-AGSS-COND-2011-HiRes.fits'
#fitsphoe = '/home/astro115/carmenes/serval/phoenix_tmp/lte03400-5.00-0.0_carm.fits'
#fitsphoe = '/home/astro115/carmenes/serval/phoenix_tmp/lte03400-5.00-0.0_carm.fits'
print 'readphoenix', fitsphoe
hdulist = pyfits.open(fitsphoe)
flux = hdulist[0].data
#hdulist = pyfits.open('/home/astro56/husser/PhoenixModels/HiResFITS/WAVE_PHOENIX-ACES-AGSS-COND-2011.fits')
hdulist = pyfits.open(os.path.dirname(fitsphoe)+os.sep+'/WAVE_PHOENIX-ACES-AGSS-COND-2011.fits')
wave = hdulist[0].data
hdulist.close()
#if flux.shape!=wave.shape:
#flux = flux.T
imap = (wmin<wave) * (wave<wmax)
w = wave[imap]
f = flux[imap]
return w, f
示例9: StatsToCSV
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def StatsToCSV(campaign, model='nPLD'):
'''
Generate the CSV file used in the search database for the documentation.
'''
statsfile = os.path.join(EVEREST_SRC, 'missions', 'k2',
'tables', 'c%02d_%s.cdpp' % (campaign, model))
csvfile = os.path.join(os.path.dirname(EVEREST_SRC), 'docs',
'c%02d.csv' % campaign)
epic, kp, cdpp6r, cdpp6, _, _, _, _, saturated = \
np.loadtxt(statsfile, unpack=True, skiprows=2)
with open(csvfile, 'w') as f:
print('c%02d' % campaign, file=f)
for i in range(len(epic)):
print('%09d,%.3f,%.3f,%.3f,%d' % (epic[i], kp[i],
cdpp6r[i], cdpp6[i],
int(saturated[i])),
file=f)
示例10: load_all_broadband_images
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def load_all_broadband_images(filename,camera=0,openlist=None):
if (not os.path.exists(filename)):
print "file not found:", filename
sys.exit()
camera_string = 'CAMERA'+str(camera)+'-BROADBAND-NONSCATTER'
if openlist is None:
openlist = fits.open(filename,memmap=False)
data = openlist[camera_string].data
#openlist.close()
print "### Sunpy: opening broadband list: ", openlist.filename()
else:
openfn = openlist.filename()
assert openfn==filename
data = openlist[camera_string].data
data[ data < 1e-20 ] = 1e-20
return data,openlist
示例11: apply_gain
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def apply_gain(self):
"""
Applies the gains set for each DM to the DM actuator commands.
Also applies different control law if DM is in "closed" or "open" loop mode
"""
# Loop through DMs and apply gain
n_act1 = 0
for dm_i, dm in self.dms.items():
n_act2 = n_act1 + dm.n_valid_actuators
# If loop is closed, only add residual measurements onto old
# actuator values
if dm.dmConfig.closed:
self.actuator_values[n_act1: n_act2] += (dm.dmConfig.gain * self.new_actuator_values[n_act1: n_act2])
else:
self.actuator_values[n_act1: n_act2] = ((dm.dmConfig.gain * self.new_actuator_values[n_act1: n_act2])
+ ( (1. - dm.dmConfig.gain) * self.actuator_values[n_act1: n_act2]) )
n_act1 += dm.n_valid_actuators
示例12: runSciCams
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def runSciCams(self, dmShape=None):
"""
Runs a single frame of the science Cameras
Calculates the image recorded by all science cameras in the system for the current phase over the telescope one frame. If a dmShape is present (which it usually will be in AO!) this correction is applied to the science phase before the image is calculated.
Args:
correction (list or ndarray, optional): An array of the combined system DM shape to correct the science path. If not given science cameras are in open loop.
"""
t = time.time()
self.sciImgNo +=1
for sci in xrange(self.config.sim.nSci):
self.sciImgs[sci] += self.sciCams[sci].frame(self.scrns, dmShape)
# Normalise long exposure psf
#self.sciImgs[sci] /= self.sciImgs[sci].sum()
self.sciCams[sci].longExpStrehl = (
self.sciImgs[sci].max()/
self.sciImgs[sci].sum()/
self.sciCams[sci].psfMax)
self.Tsci +=time.time()-t
示例13: readin
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def readin(self):
"""
readin()
"""
inf = open(self.archive, 'r')
(self.data, self.time_data, self.cadence, self.labels) = pickle.load(inf)
inf.close()
# Use hours from 0 as x axis scale
self.xvals = self.time_data - self.time_data[0]
#print self.data
#_______________________________________________________________________________
#_____________________________________plot_item_________________________________
#
示例14: make_kepler_label_file
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def make_kepler_label_file():
""" using the values made by The Cannon """
lamost_key = np.loadtxt('lamost_sorted_by_ra.txt',dtype=str)
apogee_key = np.loadtxt('apogee_sorted_by_ra.txt', dtype=str)
apogee_key_short = np.array(
[(item.split('v603-')[-1]).split('.fits')[0]
for item in apogee_key])
nstars = len(lamost_key)
direc = "/home/annaho/TheCannon/examples/example_apokasc/test_is_lamost_apogee_overlap"
kepler_ids = np.load("%s/test_ids.npz" %direc)['arr_0']
kepler_ids = np.array([a.split('/')[-1] for a in kepler_ids])
kepler_labels = np.load("%s/test_labels.npz" %direc)['arr_0']
inds = np.array(
[np.where(apogee_key==a)[0][0] for a in kepler_ids])
teff = kepler_labels[:,0][inds]
logg = kepler_labels[:,1][inds]
feh = kepler_labels[:,2][inds]
alpha = kepler_labels[:,3][inds]
outputf = open("apogee_cannon_labels.csv", "w")
header = "#lamost_id,apogee_id,teff,logg,feh,alpha,snr,vscatter,starflag\n"
outputf.write(header)
for i in range(nstars):
line = lamost_key[i]+','+apogee_key[i]+','+\
str(teff[i])+','+str(logg[i])+','+str(feh[i])+','+\
str(alpha[i])+',0'+',0'+',0'+'\n'
outputf.write(line)
示例15: make_tr_file_list
# 需要導入模塊: import pyfits [as 別名]
# 或者: from pyfits import open [as 別名]
def make_tr_file_list(frac_cut=0.94, snr_cut=100):
""" make a list of training objects, given cuts
Parameters
----------
frac_cut: float
the fraction of pix in the spectrum that must be good
snr_cut: float
the snr that the spec
Returns
-------
tr_files: np array
list of file names of training objects
"""
allfiles = np.loadtxt(
"apogee_dr12_labels.csv", delimiter=',', usecols=(0,),
dtype=str)
allfiles_apogee= np.loadtxt(
"apogee_dr12_labels.csv", delimiter=',', usecols=(1,),
dtype=str)
starflags = np.loadtxt(
"apogee_dr12_labels.csv", delimiter=',', usecols=(8,), dtype=str)
good = starflags == "False"
tr_files = allfiles[good]
tr_files_apogee = allfiles_apogee[good]
outputf = open("PAPER_training_step/tr_files.txt", "w")
for tr_file in tr_files:
outputf.write(tr_file + '\n')
outputf.close()
outputf = open("PAPER_training_step/tr_files_apogee.txt", "w")
for tr_file in tr_files_apogee:
outputf.write(tr_file + '\n')
outputf.close()
return tr_files