當前位置: 首頁>>代碼示例>>Python>>正文


Python pyfits.getheader方法代碼示例

本文整理匯總了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) 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:20,代碼來源:read_spec.py

示例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) 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:29,代碼來源:read_spec.py

示例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) 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:9,代碼來源:read_spec.py

示例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 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:31,代碼來源:bary.py

示例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") 
開發者ID:AOtools,項目名稱:soapy,代碼行數:42,代碼來源:reconstruction.py

示例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) 
開發者ID:mzechmeister,項目名稱:serval,代碼行數:47,代碼來源:read_spec.py

示例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() 
開發者ID:rodluger,項目名稱:everest,代碼行數:46,代碼來源:user.py

示例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) 
開發者ID:rodluger,項目名稱:everest,代碼行數:47,代碼來源:standalone.py


注:本文中的pyfits.getheader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。