aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-10-17 18:19:02 +0800
committerAaron LI <aaronly.me@outlook.com>2016-10-17 18:19:02 +0800
commitd00427046e3a50148a0f40ad41ab550b62431965 (patch)
treea5aa410bfacfc86762c5c68f4069b3309a35bda9 /fg21sim
parent294bb17b01e0fc895d9ac283d21d2fa23eb3460f (diff)
downloadfg21sim-d00427046e3a50148a0f40ad41ab550b62431965.tar.bz2
galactic/snr.py: Create dir if necessary and adhere clobber config
Diffstat (limited to 'fg21sim')
-rw-r--r--fg21sim/galactic/snr.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/fg21sim/galactic/snr.py b/fg21sim/galactic/snr.py
index 087e022..4f3d548 100644
--- a/fg21sim/galactic/snr.py
+++ b/fg21sim/galactic/snr.py
@@ -113,10 +113,21 @@ class SuperNovaRemnants:
if self.catalog_outfile is None:
logger.warning("Catalog output file not set, so do NOT save.")
return
+ # Create directory if necessary
+ dirname = os.path.dirname(self.catalog_outfile)
+ if os.path.exists(dirname):
+ os.mkdir(dirname)
+ logger.info("Created directory: {0}".format(dirname))
# Save catalog data
colnames = ["name", "glon", "glat", "ra", "dec",
"size_major", "size_minor", "flux",
"specindex", "rotation"]
+ if os.path.exists(self.catalog_outfile):
+ if self.clobber:
+ os.remove(self.catalog_outfile)
+ else:
+ raise OSError("Output file already exists: {0}".format(
+ self.catalog_outfile))
self.catalog.to_csv(self.catalog_outfile, columns=colnames,
header=True, index=False)
logger.info("Save SNRs catalog in use to: %s" % self.catalog_outfile)