From d00427046e3a50148a0f40ad41ab550b62431965 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Mon, 17 Oct 2016 18:19:02 +0800 Subject: galactic/snr.py: Create dir if necessary and adhere clobber config --- fg21sim/galactic/snr.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'fg21sim/galactic') 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) -- cgit v1.2.2