Created
February 1, 2011 17:00
-
-
Save astrofrog/806152 to your computer and use it in GitHub Desktop.
Create an ATpy table in IRAF hselect style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Create an ATpy table in IRAF hselect style | |
| # Example: | |
| # | |
| # >>> files = glob.glob(os.path.join('.', '*.fits')) | |
| # >>> t = hselect(files) | |
| import glob | |
| import os | |
| import pyfits | |
| import atpy | |
| from atpy.odict import odict | |
| def hselect(files): | |
| # Initialize column holder | |
| cols = odict() | |
| # Loop over files | |
| for i, f in enumerate(files): | |
| # Read in header | |
| header = pyfits.getheader(f) | |
| # Add values | |
| for key in header: | |
| if key.strip() != "": | |
| if key not in cols: | |
| cols[key] = [] | |
| cols[key].append(header[key]) | |
| # Create ATpy table | |
| t = atpy.Table() | |
| for col in cols: | |
| t.add_column(col, cols[col]) | |
| return t |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I updated the code with your suggestion :-)