Skip to content

Commit 393723c

Browse files
committed
Remove rec2txt:
1 parent ccfacc6 commit 393723c

File tree

2 files changed

+31
-18
lines changed

2 files changed

+31
-18
lines changed

bin/print_WDmodel_residual_table

+14-10
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,10 @@ from __future__ import unicode_literals
99
import sys
1010
import argparse
1111
import warnings
12-
warnings.simplefilter('once')
1312
import glob
1413
import numpy as np
15-
from matplotlib.mlab import rec2txt
1614
import WDmodel.io
17-
15+
import astropy.table as at
1816

1917
def get_options(args=None):
2018
"""
@@ -28,6 +26,8 @@ def get_options(args=None):
2826
help="Specify a custom output root directory. Directories go under outroot/objname/subdir.")
2927
parser.add_argument('-o', '--outdir', required=False,\
3028
help="Specify a custom output directory. Default is CWD+objname/ subdir")
29+
parser.add_argument('-v', '--verbose', help="print warnings",
30+
action="store_true")
3131
args = parser.parse_args(args=args)
3232
return args
3333

@@ -43,6 +43,8 @@ def main(inargs=None):
4343
else:
4444
specfiles = args.specfiles
4545

46+
verbose = args.verbose
47+
4648
out = []
4749
colnames = []
4850
colbool = False
@@ -55,8 +57,9 @@ def main(inargs=None):
5557
try:
5658
phot = WDmodel.io.read_phot(outfile)
5759
except IOError as e:
58-
message = 'Could not get results for {}({}) from outfile {}'.format(objname, specfile, outfile)
59-
warnings.warn(message)
60+
if verbose:
61+
message = 'Could not get results for {}({}) from outfile {}'.format(objname, specfile, outfile)
62+
warnings.warn(message)
6063
params = None
6164
continue
6265
this_out = []
@@ -86,11 +89,12 @@ def main(inargs=None):
8689
colbool=True
8790
out.append(this_out)
8891
colnames = [str(x) for x in colnames]
89-
out = np.rec.fromrecords(out, names=colnames)
90-
out.sort()
91-
precision = [None, None] + [4,4,4,4]*len(pbs)
92-
with open('residual_table.dat', 'w') as f:
93-
f.write(rec2txt(out, precision=precision )+'\n')
92+
out = at.Table(rows=out, names=colnames)
93+
out.sort('obj')
94+
for col in colnames[2:]:
95+
out[col].format = '%0.4f'
96+
out.write('residual_table.dat', format='ascii', overwrite=True)
97+
print(out)
9498

9599

96100

bin/print_WDmodel_result_table

+17-8
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,9 @@ from __future__ import unicode_literals
99
import sys
1010
import argparse
1111
import warnings
12-
warnings.simplefilter('once')
1312
import glob
1413
import numpy as np
15-
from matplotlib.mlab import rec2txt
14+
import astropy.table as at
1615
import WDmodel.io
1716

1817

@@ -28,6 +27,8 @@ def get_options(args=None):
2827
help="Specify a custom output root directory. Directories go under outroot/objname/subdir.")
2928
parser.add_argument('-o', '--outdir', required=False,\
3029
help="Specify a custom output directory. Default is CWD+objname/ subdir")
30+
parser.add_argument('-v', '--verbose', help="print warnings",
31+
action="store_true")
3132
args = parser.parse_args(args=args)
3233
return args
3334

@@ -43,6 +44,8 @@ def main(inargs=None):
4344
else:
4445
specfiles = args.specfiles
4546

47+
verbose = args.verbose
48+
4649
out = []
4750
colnames = []
4851
colbool = False
@@ -53,8 +56,9 @@ def main(inargs=None):
5356
try:
5457
params = WDmodel.io.read_params(outfile)
5558
except IOError as e:
56-
message = 'Could not get results for {}({}) from outfile {}'.format(objname, specfile, outfile)
57-
warnings.warn(message)
59+
if verbose:
60+
message = 'Could not get results for {}({}) from outfile {}'.format(objname, specfile, outfile)
61+
warnings.warn(message)
5862
params = None
5963
continue
6064
this_out = []
@@ -74,10 +78,15 @@ def main(inargs=None):
7478
colbool=True
7579
out.append(this_out)
7680
colnames = [str(x) for x in colnames]
77-
out = np.rec.fromrecords(out, names=colnames)
78-
out.sort()
79-
precision = [None, None] + [2,2,2]*7 + [5,5,5] + [2,2,2] + [4,4,4]
80-
print(rec2txt(out, precision=precision ))
81+
82+
out = at.Table(rows=out, names=colnames)
83+
out.sort('obj')
84+
85+
collengths = [2,2,2]*7 + [5,5,5] + [2,2,2] + [4,4,4]
86+
for i, col in enumerate(colnames[2:]):
87+
out[col].format = '%0.{}f'.format(collengths[i])
88+
out.write('result_table.dat', format='ascii', overwrite=True)
89+
print(out)
8190

8291

8392
if __name__=='__main__':

0 commit comments

Comments
 (0)