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
I updated the code with your suggestion :-)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I thought that
odict()was a subclass ofdict. I looked at the code only now and see that it is not.But one could still do something like:
I am sure that you must have thought of these; I am just saying it loud!