Created
September 30, 2015 15:52
-
-
Save wkerzendorf/35e4991433e5eb8bc3f5 to your computer and use it in GitHub Desktop.
concatenating decam tables
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
import argparse | |
from astropy.io import fits | |
from astropy import wcs | |
import os | |
from glob import glob | |
import pandas as pd | |
parser = argparse.ArgumentParser(description='Convert DECAM photometry to Tables') | |
parser.add_argument('decam_path') | |
def read_decam_chip_dir(decam_chip_dir): | |
all_data = {} | |
for fname in glob(os.path.join(decam_chip_dir, '*.dcmp')): | |
header = fits.getheader(fname) | |
columns = header['col*'].values() | |
current_wcs = wcs.WCS(header) | |
data = pd.read_csv(fname, delim_whitespace=True, skiprows=1, | |
header=None, converters={6:lambda x: int(x, 0), 19:lambda x: int(x, 0), 20:lambda x:int(x,0)}) | |
data.columns = columns | |
radec = current_wcs.wcs_pix2world(data[['Xpos', 'Ypos']].values, 1) | |
data['RA'] = radec[:,0] | |
data['Dec'] = radec[:, 1] | |
data['mag'] = data['M'] + header['ZPTMAG'] | |
all_data[os.path.basename(fname).split('.')[1]] = data | |
return all_data | |
def concatenate_tables(table_list): | |
np.sum([len(item) for item in table_list]) | |
if __name__ == '__main__': | |
args = parser.parse_args() | |
print "Analyzing path {0}".format(args.decam_path) | |
all_data = {} | |
for decam_chip_dir in glob(os.path.join(args.decam_path, '*')): | |
if not os.path.isdir(decam_chip_dir): | |
print "{0} not a directory - skipping".format(decam_chip_dir) | |
continue | |
else: | |
print "Analyzing {0}".format(decam_chip_dir) | |
chip_data = read_decam_chip_dir(decam_chip_dir) | |
for filter_name in chip_data: | |
if filter_name not in all_data: | |
all_data[filter_name] = [] | |
all_data[filter_name].append(chip_data[filter_name]) | |
for filter_name in all_data: | |
table = pd.concat(all_data[filter_name]) | |
table.to_csv('{0}_filter.dat'.format(filter_name)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment