From 5ea032ee3ed1fb2084baaa9a2a6eab8261adaaf6 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 23 Nov 2016 19:33:05 +0800 Subject: products.py: Add new method "get_product_abspath()" This new method will be used by the "ProductsAJAXHandler" for the "open" and "download" actions. --- fg21sim/products.py | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'fg21sim') diff --git a/fg21sim/products.py b/fg21sim/products.py index 7613c38..6b83c8b 100644 --- a/fg21sim/products.py +++ b/fg21sim/products.py @@ -244,6 +244,40 @@ class Products: def get_product(self, comp_id, freq_id): return self.manifest[comp_id][freq_id] + def get_product_abspath(self, comp_id, freq_id, ptype="healpix"): + """ + Get the absolute path to the specified product. + + Parameters + ---------- + comp_id : str + ID of the component whose product will be checksum'ed + freq_id : int + The frequency ID of the specific product within the component. + ptype : str, optional + The type of product whose path will be retrieved. + Valid values: ``healpix`` (default), ``hpx``. + + Returns + ------- + abspath : str + The absolute path to the specified product + + Raises + ------ + ValueError : + Invalid ``ptype`` other than ``healpix`` and ``hpx``. + KeyError : + The requested product type not available (e.g., the HPX + image is not generated yet) + """ + if ptype not in ["healpix", "hpx"]: + raise ValueError("Invalid ptype: {0}".format(ptype)) + curdir = os.path.dirname(self.manifestfile) + metadata = self.get_product(comp_id, freq_id) + abspath = os.path.join(curdir, metadata[ptype]["path"]) + return abspath + def convert_hpx(self, comp_id, freq_id, clobber=False): """ Convert the specified HEALPix map product to HPX projected FITS image. -- cgit v1.2.2