Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
parsec_isochrones/merge.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
69 lines (60 sloc)
1.92 KB
This file contains 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
#!/usr/bin/env python3 | |
# -*- coding: utf-8 -*- | |
""" | |
Created on Mon Feb 19 15:16:37 2018 | |
@author: mints | |
""" | |
from __future__ import print_function | |
import os | |
from astropy.io import fits | |
import argparse | |
parser = argparse.ArgumentParser(description=""" | |
Merge photometry from two PARSEC fits files. | |
If band names duplicate, suffixes are added. | |
""", formatter_class=argparse.RawDescriptionHelpFormatter) | |
parser.add_argument('-i1', '--input1', type=str, default=None, | |
help='Filename one') | |
parser.add_argument('-i2', '--input2', type=str, default=None, | |
help='Filename two') | |
parser.add_argument('-o', '--output', type=str, default=None, | |
help='Output filename') | |
parser.add_argument('-s1', '--suffix1', type=str, default=None, | |
help='First suffix') | |
parser.add_argument('-s2', '--suffix2', type=str, default=None, | |
help='Second suffix') | |
args = parser.parse_args() | |
data1 = fits.open(args.input1) | |
data2 = fits.open(args.input2) | |
if args.suffix1 is None: | |
s1 = args.input1[:-5] | |
else: | |
s1 = args.suffix1 | |
if args.suffix2 is None: | |
s2 = args.input2[:-5] | |
else: | |
s2 = args.suffix2 | |
hdu = fits.PrimaryHDU() | |
mark = [] | |
for col1 in data1[1].columns.names[10:-2]: | |
if col1 in data2[1].columns.names[10:]: | |
mark.append(col1) | |
for col2 in data2[1].columns.names[10:-2]: | |
if col2 in data1[1].columns.names[10:]: | |
mark.append(col2) | |
print(mark) | |
for col in data1[1].columns: | |
print(col.name) | |
if col.name in mark: | |
col.name = '%s%s' % (col.name, s1) | |
print('>', col.name) | |
for col in data2[1].columns: | |
if col.name in mark: | |
col.name = '%s%s' % (col.name, s2) | |
print(data1[1].columns.names) | |
columns = data1[1].columns[:-2] + data2[1].columns[10:] | |
hdulist = fits.HDUList([hdu, fits.BinTableHDU.from_columns(columns), | |
data1[2]]) | |
out = args.output | |
if os.path.exists(out): | |
os.remove(out) | |
hdulist.writeto(out) | |