Skip to content

Commit

Permalink
add a nocreate option to prevent spurious outdir creation when we jus…
Browse files Browse the repository at this point in the history
…t want the objname and outdir path
  • Loading branch information
gnarayan committed Sep 23, 2018
1 parent bab541b commit afe790c
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
7 changes: 5 additions & 2 deletions WDmodel/io.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ def make_outdirs(dirname, redo=False, resume=False):
raise OSError(message)


def set_objname_outdir_for_specfile(specfile, outdir=None, outroot=None, redo=False, resume=False):
def set_objname_outdir_for_specfile(specfile, outdir=None, outroot=None, redo=False, resume=False, nocreate=False):
"""
Sets the short human readable object name and output directory
Expand All @@ -891,6 +891,8 @@ def set_objname_outdir_for_specfile(specfile, outdir=None, outroot=None, redo=Fa
If ``False`` the directory will not be created if it already exists, and an error is raised
resume : bool, optional
If ``False`` the directory will not be created if it already exists, and an error is raised
nocreate: bool, optional
If ``True`` then creation of output directories is not even attempted
Returns
-------
Expand All @@ -912,7 +914,8 @@ def set_objname_outdir_for_specfile(specfile, outdir=None, outroot=None, redo=Fa
dirname = os.path.join(outroot, objname, basespec)
else:
dirname = outdir
make_outdirs(dirname, redo=redo, resume=resume)
if not nocreate:
make_outdirs(dirname, redo=redo, resume=resume)
return objname, dirname


Expand Down
4 changes: 2 additions & 2 deletions bin/print_WDmodel_residual_table
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def main(inargs=None):
pbs = pbs.split(',')

for specfile in specfiles:
objname, outdir = WDmodel.io.set_objname_outdir_for_specfile(specfile, outroot=args.outroot, outdir=args.outdir, resume=True)
objname, outdir = WDmodel.io.set_objname_outdir_for_specfile(specfile, outroot=args.outroot, outdir=args.outdir, nocreate=True)
outfile = WDmodel.io.get_outfile(outdir, specfile, '_phot_model.dat')
try:
phot = WDmodel.io.read_phot(outfile)
Expand Down Expand Up @@ -91,7 +91,7 @@ def main(inargs=None):
precision = [None, None] + [4,4,4,4]*len(pbs)
with open('residual_table.dat', 'w') as f:
f.write(rec2txt(out, precision=precision )+'\n')




Expand Down
4 changes: 2 additions & 2 deletions bin/print_WDmodel_result_table
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def main(inargs=None):
colbool = False

for specfile in specfiles:
objname, outdir = WDmodel.io.set_objname_outdir_for_specfile(specfile, outroot=args.outroot, outdir=args.outdir, resume=True)
objname, outdir = WDmodel.io.set_objname_outdir_for_specfile(specfile, outroot=args.outroot, outdir=args.outdir, nocreate=True)
outfile = WDmodel.io.get_outfile(outdir, specfile, '_result.json')
try:
params = WDmodel.io.read_params(outfile)
Expand Down Expand Up @@ -78,7 +78,7 @@ def main(inargs=None):
out.sort()
precision = [None, None] + [2,2,2]*7 + [5,5,5] + [2,2,2] + [4,4,4]
print(rec2txt(out, precision=precision ))


if __name__=='__main__':
main(sys.argv[1:])
2 changes: 1 addition & 1 deletion bin/print_WDmodel_synmags_table
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def main(inargs=None):

out = []
for specfile in specfiles:
objname, outdir = WDmodel.io.set_objname_outdir_for_specfile(specfile, outroot=args.outroot, outdir=args.outdir, resume=True)
objname, outdir = WDmodel.io.set_objname_outdir_for_specfile(specfile, outroot=args.outroot, outdir=args.outdir, nocreate=True)
sedfile = WDmodel.io.get_outfile(outdir, specfile, '_full_model.hdf5')
try:
fullsed = WDmodel.io.read_full_model(sedfile)
Expand Down

0 comments on commit afe790c

Please sign in to comment.