Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8256453
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T01:52:04+00:00 2026-06-08T01:52:04+00:00

I’d like to learn how to grab information from a FITS file header and

  • 0

I’d like to learn how to grab information from a FITS file header and transfer that information to an ascii table. For example, this is how I would obtain the info.:

import pyfits
a = pyfits.open('data.fits')
header = a[0].header # Which should return something like this (It is  BinHDUlist)
SIMPLE  =                T / conforms to FITS standards                    
                               / institution responsible for creating this file 
TELESCOP= 'Kepler  '           / telescope                                      
INSTRUME= 'Kepler Photometer'  / detector type                                  
OBJECT  = 'KIC 8631743'        / string version of KEPLERID                     
RA_OBJ  =           294.466516 / [deg] right ascension                          
DEC_OBJ =            44.751131 / [deg] declination                              

How could I create an ASCII table that contains RA_OBJ and DEC_OBJ ?

EDIT: I’d like to create a .dat file that contains two columns (RA and DEC) from the headers. Here is an example of what I am trying:

import asciitable
import asciidata
import pyfits
import numpy as np

# Here I have taken all the fits files in my current directory and did the following:
# ls > z.txt so that all the fits files are in one place.

a = asciidata.open('z.txt')
i = 0 #There are 371 fits files in z.txt
while i<=370:
    b = pyfits.open(a[0][i])
    h = b[0].header
    RA = np.array([h['RA_OBJ']])
    DEC = np.array(h['DEC_OBJ']])
    asciitable.write({'RA': RA, 'DEC': DEC}, 'coordinates.dat', names=['RA', 'DEC'])
    i = i+1

I’d like for this to write a .dat file containing something like this:

RA    DEC
###   ###
...   ...
...   ...
...   ...

Instead, my code just writes over the keys of the previous files. Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-08T01:52:05+00:00Added an answer on June 8, 2026 at 1:52 am

    I think you might benefit from reading the pyfits documentation more carefully. The header attribute is a pyfits.header.Header object, which is a dictionary-like object. So you can do something like:

    import pyfits
    
    keys = ['SIMPLE', 'TELESCOP', 'INSTRUME', 'OBJECTS', 'RA_OBJ', 'DEV_OBJ']
    
    hdulist = pyfits.open("data.fits")
    header = hdulist[0].header
    for k in keys:
        print k, "=", header[k]
    

    You can add more fancy outputting, put the resulting string in variable, checking for missing keys, etc.

    EDIT:

    Here’s how this could be coupled with asciitable and numpy:

    import asciitable
    import numpy as np
    
    keys = ['RA', 'DEC']
    data = {}
    
    # Initialize "data" with empty lists for each key
    for k in keys:
        data[k] = []
    
    # Collect all data in the "data" dictionary
    for i in range(0, 50):
        data['RA'].append(np.array(i))
        data['DEC'].append(np.array(i+1))
    
    asciitable.write(data, "coords.dat", names=keys)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I've got a string that has curly quotes in it. I'd like to replace
I am trying to render a haml file in a javascript response like so:
Does anyone know how can I replace this 2 symbol below from the string
I have two tables with like below codes: Table: Accounts id | username |
I have a view passing on information from a database: def serve_article(request, id): served_article
I have some data like this: 1 2 3 4 5 9 2 6

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.