diff options
author | Aaron LI <aaronly.me@outlook.com> | 2016-11-22 17:59:18 +0800 |
---|---|---|
committer | Aaron LI <aaronly.me@outlook.com> | 2016-11-22 17:59:18 +0800 |
commit | 37f0ab05c94ab9409746ba7eacc4358f35331e3d (patch) | |
tree | fc7d285ac9b7a6a23e3c3e7fa415635b91ab9c9a | |
parent | 788219377f44e9d6246077e4486cfd51f0e0e730 (diff) | |
download | fg21sim-37f0ab05c94ab9409746ba7eacc4358f35331e3d.tar.bz2 |
products: Support frequency unit; Add "reset()" method
-rw-r--r-- | fg21sim/foregrounds.py | 2 | ||||
-rw-r--r-- | fg21sim/products.py | 28 |
2 files changed, 26 insertions, 4 deletions
diff --git a/fg21sim/foregrounds.py b/fg21sim/foregrounds.py index e004a52..a64f21c 100644 --- a/fg21sim/foregrounds.py +++ b/fg21sim/foregrounds.py @@ -182,7 +182,7 @@ class Foregrounds: def preprocess(self): """Perform the preparation procedures for the final simulations.""" - self.products.frequencies = self.frequencies + self.products.frequencies = (self.frequencies, str(self.freq_unit)) logger.info("Perform preprocessing for all enabled components ...") for comp_obj in self.components.values(): comp_obj.preprocess() diff --git a/fg21sim/products.py b/fg21sim/products.py index d524901..7613c38 100644 --- a/fg21sim/products.py +++ b/fg21sim/products.py @@ -37,6 +37,7 @@ class Products: "frequency" : { "frequencies" : [ <list of frequencies> ], "id" : [ <id/index of each frequency> ], + "unit": <frequency unit>, }, <component> : [ { @@ -80,12 +81,26 @@ class Products: Set the frequencies of the products and store in the manifest. Each frequency has an ID (also its index in the frequencies list). + + Parameters + ---------- + value : list[float], or tuple(list[float], str) + The list of simulation frequencies, or a tuple of the frequencies + and its unit (default: MHz). """ + if isinstance(value, tuple) and len(value) == 2: + frequencies, unit = value + else: + frequencies = value + unit = "MHz" + # self.manifest["frequency"] = { - "frequencies": list(value), - "id": list(range(len(value))), + "frequencies": list(frequencies), + "id": list(range(len(frequencies))), + "unit": unit, } - logger.info("Number of frequencies: {0}".format(len(value))) + logger.info("Number of frequencies: {0}, ".format(len(frequencies)) + + "unit: {0}".format(unit)) def find_frequency_id(self, frequency, atol=1e-3): """ @@ -268,6 +283,11 @@ class Products: } return (outfile, size, md5sum) + def reset(self): + self.manifest = OrderedDict() + self.manifestfile = None + logger.warning("Reset products manifest") + def dump(self, outfile=None, clobber=False, backup=True): """ Dump the manifest as a JSON file. @@ -340,6 +360,8 @@ class Products: infile = os.path.expanduser(infile) if not os.path.isabs(infile): raise ValueError("Not an absolute path: {0}".format(infile)) + # Reset existing manifest + self.reset() # Keep the order of keys self.manifest = json.load(open(infile), object_pairs_hook=OrderedDict) self.manifestfile = infile |