本文整理汇总了Python中linetools.spectra.xspectrum1d.XSpectrum1D.from_spec1d方法的典型用法代码示例。如果您正苦于以下问题:Python XSpectrum1D.from_spec1d方法的具体用法?Python XSpectrum1D.from_spec1d怎么用?Python XSpectrum1D.from_spec1d使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类linetools.spectra.xspectrum1d.XSpectrum1D
的用法示例。
在下文中一共展示了XSpectrum1D.from_spec1d方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: parse_linetools_spectrum_format
# 需要导入模块: from linetools.spectra.xspectrum1d import XSpectrum1D [as 别名]
# 或者: from linetools.spectra.xspectrum1d.XSpectrum1D import from_spec1d [as 别名]
def parse_linetools_spectrum_format(hdulist):
""" Parse an old linetools-format spectrum from an hdulist
Parameters
----------
hdulist : FITS HDU list
Returns
-------
xspec1d : XSpectrum1D
Parsed spectrum
"""
if 'WAVELENGTH' not in hdulist:
pdb.set_trace()
#spec1d = spec_read_fits.read_fits_spectrum1d(
# os.path.expanduser(datfil), dispersion_unit='AA')
xspec1d = XSpectrum1D.from_spec1d(spec1d)
else:
wave = hdulist['WAVELENGTH'].data * u.AA
fx = hdulist['FLUX'].data
# Error array
if 'ERROR' in hdulist:
sig = hdulist['ERROR'].data
else:
sig = None
if 'CONTINUUM' in hdulist:
co = hdulist['CONTINUUM'].data
else:
co = None
xspec1d = XSpectrum1D.from_tuple((wave, fx, sig, co))
if 'METADATA' in hdulist[0].header:
# import pdb; pdb.set_trace()
# patch for reading continuum metadata; todo: should be fixed properly!!!
if "contpoints" in hdulist[0].header['METADATA']:
aux_s = hdulist[0].header['METADATA']
if aux_s.endswith("}\' /"):
aux_s = aux_s[:-3] # delete these extra characters
hdulist[0].header['METADATA'] = aux_s
xspec1d.meta.update(json.loads(hdulist[0].header['METADATA']))
return xspec1d
示例2: parse_linetools_spectrum_format
# 需要导入模块: from linetools.spectra.xspectrum1d import XSpectrum1D [as 别名]
# 或者: from linetools.spectra.xspectrum1d.XSpectrum1D import from_spec1d [as 别名]
def parse_linetools_spectrum_format(hdulist, **kwargs):
""" Parse an old linetools-format spectrum from an hdulist
Parameters
----------
hdulist : FITS HDU list
Returns
-------
xspec1d : XSpectrum1D
Parsed spectrum
"""
if 'WAVELENGTH' not in hdulist:
pdb.set_trace()
xspec1d = XSpectrum1D.from_spec1d(spec1d)
else:
wave = hdulist['WAVELENGTH'].data * u.AA
fx = hdulist['FLUX'].data
# Error array
if 'ERROR' in hdulist:
sig = hdulist['ERROR'].data
else:
sig = None
if 'CONTINUUM' in hdulist:
co = hdulist['CONTINUUM'].data
else:
co = None
xspec1d = XSpectrum1D.from_tuple((wave, fx, sig, co), **kwargs)
if 'METADATA' in hdulist[0].header:
# Prepare for JSON (bug fix of sorts)
metas = hdulist[0].header['METADATA']
ipos = metas.rfind('}')
xspec1d.meta.update(json.loads(metas[:ipos+1]))
return xspec1d
示例3: parse_linetools_spectrum_format
# 需要导入模块: from linetools.spectra.xspectrum1d import XSpectrum1D [as 别名]
# 或者: from linetools.spectra.xspectrum1d.XSpectrum1D import from_spec1d [as 别名]
def parse_linetools_spectrum_format(hdulist):
""" Parse an old linetools-format spectrum from an hdulist
Parameters
----------
hdulist : FITS HDU list
Returns
-------
xspec1d : XSpectrum1D
Parsed spectrum
"""
if 'WAVELENGTH' not in hdulist:
pdb.set_trace()
#spec1d = spec_read_fits.read_fits_spectrum1d(
# os.path.expanduser(datfil), dispersion_unit='AA')
xspec1d = XSpectrum1D.from_spec1d(spec1d)
else:
wave = hdulist['WAVELENGTH'].data * u.AA
fx = hdulist['FLUX'].data
# Error array
if 'ERROR' in hdulist:
sig = hdulist['ERROR'].data
else:
sig = None
if 'CONTINUUM' in hdulist:
co = hdulist['CONTINUUM'].data
else:
co = None
xspec1d = XSpectrum1D.from_tuple((wave, fx, sig, co))
if 'METADATA' in hdulist[0].header:
xspec1d.meta.update(json.loads(hdulist[0].header['METADATA']))
return xspec1d
示例4: test_from_spec1d
# 需要导入模块: from linetools.spectra.xspectrum1d import XSpectrum1D [as 别名]
# 或者: from linetools.spectra.xspectrum1d.XSpectrum1D import from_spec1d [as 别名]
def test_from_spec1d():
spec = Spectrum1D.from_array(np.array([1,2,3]), np.array([1,1,1]))
xspec = XSpectrum1D.from_spec1d(spec)
示例5: readspec
# 需要导入模块: from linetools.spectra.xspectrum1d import XSpectrum1D [as 别名]
# 或者: from linetools.spectra.xspectrum1d.XSpectrum1D import from_spec1d [as 别名]
#.........这里部分代码省略.........
if ipos < 0:
# Becker XShooter style
ipos = specfil.find('.fits')
efil,chk = chk_for_gz(specfil[0:ipos]+'e.fits')
else:
if specfil.find('F.fits') > 0:
efil,chk = chk_for_gz(specfil[0:ipos]+'E.fits')
else:
efil,chk = chk_for_gz(specfil[0:ipos]+'e.fits')
if efil is None:
efil,chk = chk_for_gz(specfil[0:ipos]+'err.fits')
if efil is not None:
efil = os.path.expanduser(efil)
# Error file
if efil is not None:
sig = fits.getdata(efil)
uncertainty = StdDevUncertainty(sig)
else:
uncertainty = None
#Log-Linear?
try:
dc_flag = head0['DC-FLAG']
except KeyError:
# The following is necessary for Becker's XShooter output
cdelt1, dc_flag = get_cdelt_dcflag(head0)
# Read
if dc_flag == 0:
# Read FITS file
spec1d = spec_read_fits.read_fits_spectrum1d(os.path.expanduser(datfil), dispersion_unit='AA')
spec1d.uncertainty = uncertainty
xspec1d = XSpectrum1D.from_spec1d(spec1d)
elif dc_flag == 1: # Generate wavelengths and use array approach
fx = hdulist[0].data
# Generate wave
wave = setwave(head0)
else:
raise ValueError('DC-FLAG has unusual value {:d}'.format(dc_flag))
elif hdulist[0].name == 'FLUX':
# NEW SCHOOL (one file for flux and error)
if 'WAVELENGTH' not in hdulist:
spec1d = spec_read_fits.read_fits_spectrum1d(
os.path.expanduser(datfil), dispersion_unit='AA')
xspec1d = XSpectrum1D.from_spec1d(spec1d)
else:
wave = hdulist['WAVELENGTH'].data * u.AA
fx = hdulist['FLUX'].data
xspec1d = XSpectrum1D.from_tuple((wave, fx))
# Error array
if 'ERROR' in hdulist:
sig = hdulist['ERROR'].data
xspec1d.uncertainty = StdDevUncertainty(sig)
else:
sig = None
if 'CONTINUUM' in hdulist:
xspec1d.co = hdulist['CONTINUUM'].data
if 'METADATA' in head0:
xspec1d.meta.update(json.loads(head0['METADATA']))
else: # ASSUMING MULTI-EXTENSION
示例6: parse_two_file_format
# 需要导入模块: from linetools.spectra.xspectrum1d import XSpectrum1D [as 别名]
# 或者: from linetools.spectra.xspectrum1d.XSpectrum1D import from_spec1d [as 别名]
def parse_two_file_format(specfil, hdulist, efil=None):
""" Parse old two file format (one for flux, another for error).
Parameters
----------
specfil : str
Flux filename
hdulist : FITS HDU list
efil : str, optional
Error filename. By default this is inferred from the flux
filename.
Returns
-------
xspec1d : XSpectrum1D
Parsed spectrum
"""
head0 = hdulist[0].header
# Error
if efil is None:
ipos = max(specfil.find('F.fits'),
specfil.find('f.fits'), specfil.find('flx.fits'))
if ipos < 0:
# Becker XShooter style
ipos = specfil.find('.fits')
efil,chk = chk_for_gz(specfil[0:ipos]+'e.fits')
else:
if specfil.find('F.fits') > 0:
efil,chk = chk_for_gz(specfil[0:ipos]+'E.fits')
else:
efil,chk = chk_for_gz(specfil[0:ipos]+'e.fits')
if efil is None:
efil,chk = chk_for_gz(specfil[0:ipos]+'err.fits')
# Error file
if efil is not None:
efil = os.path.expanduser(efil)
sig = fits.getdata(efil)
else:
sig = None
#Log-Linear?
try:
dc_flag = head0['DC-FLAG']
except KeyError:
# The following is necessary for Becker's XShooter output
cdelt1, dc_flag = get_cdelt_dcflag(head0)
# Read
if dc_flag == 0:
# Read FITS file
pdb.set_trace()
#spec1d = spec_read_fits.read_fits_spectrum1d(
# os.path.expanduser(specfil), dispersion_unit='AA')
#spec1d.uncertainty = uncertainty
xspec1d = XSpectrum1D.from_spec1d(spec1d)
elif dc_flag == 1: # Generate wavelengths and use array approach
fx = hdulist[0].data
# Generate wave
wave = setwave(head0)
else:
raise ValueError('DC-FLAG has unusual value {:d}'.format(dc_flag))
# Finish
xspec1d = XSpectrum1D.from_tuple((wave, fx, sig, None))
return xspec1d