From e6085558dae8594ab309ade6d9772e79b5cc746a Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Sun, 3 Dec 2017 19:46:35 +0800 Subject: astro/make_lightcone.py: allow variables in "outfile" option --- astro/21cm/make_lightcone.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'astro/21cm') diff --git a/astro/21cm/make_lightcone.py b/astro/21cm/make_lightcone.py index 2c428ae..cb38f86 100755 --- a/astro/21cm/make_lightcone.py +++ b/astro/21cm/make_lightcone.py @@ -57,8 +57,8 @@ Lside: Nside: # Filename pattern of the input coeval cubes infiles_pattern: "deltaTb_z{z:05.3f}_N{Nside:d}_L{Lside:.1f}.dat" -# Filename of output light-cone cube (required) -outfile: deltaTb_lightcone.fits +# Filename of output light-cone cube +outfile: "deltaTb_z{zmin:.1f}-{zmax:.1f}_lightcone.fits" --------------------------------------------------------------------------- """ @@ -120,6 +120,12 @@ class Configs: else: raise OSError("requested file does not exists: %s" % filename) + def get_outfile(self): + data = {"zmin": self.zmin, "zmax": self.zmax, "dz": self.dz, + "Nside": self.Nside, "Lside": self.Lside} + filename = self.outfile.format(**data) + return filename + def get_cubepair(self, z): """ Get the consecutive two cubes enclosing the given redshift. @@ -281,7 +287,7 @@ class LightCone: def write(self, outfile=None, clobber=None): if outfile is None: - outfile = self.configs.outfile + outfile = self.get_outfile() if clobber is None: clobber = self.configs.clobber @@ -300,7 +306,7 @@ def main(): args = parser.parse_args() configs = Configs(args.config) - if os.path.exists(configs.outfile) and (not configs.clobber): + if os.path.exists(configs.get_outfile()) and (not configs.clobber): raise OSError("output file already exists: %s" % configs.outfile) cubepair = CubePair(Nside=configs.Nside, dtype=configs.dtype) -- cgit v1.2.2