aboutsummaryrefslogtreecommitdiffstats
path: root/fg21sim/webui/handlers/products.py
diff options
context:
space:
mode:
authorAaron LI <aaronly.me@outlook.com>2016-11-22 20:43:25 +0800
committerAaron LI <aaronly.me@outlook.com>2016-11-22 20:43:25 +0800
commit8215466fbfce7c3c48dcde64f1d8093369c88a2c (patch)
treec4d7f5ce0e7d6486e27b646f43d4048ab041e4ce /fg21sim/webui/handlers/products.py
parentb73e9b03d2370c1e199f39988b22cbe0a3e7b200 (diff)
downloadfg21sim-8215466fbfce7c3c48dcde64f1d8093369c88a2c.tar.bz2
webui: products: Implement HPX conversion function
Diffstat (limited to 'fg21sim/webui/handlers/products.py')
-rw-r--r--fg21sim/webui/handlers/products.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/fg21sim/webui/handlers/products.py b/fg21sim/webui/handlers/products.py
index 5c9e0c8..f68fa5d 100644
--- a/fg21sim/webui/handlers/products.py
+++ b/fg21sim/webui/handlers/products.py
@@ -78,6 +78,7 @@ class ProductsAJAXHandler(BaseRequestHandler):
request = json_decode(self.request.body)
logger.debug("Received request: {0}".format(request))
action = request.get("action")
+ response = {"action": action}
if action == "load":
# Load the manifest from supplied file
try:
@@ -98,14 +99,22 @@ class ProductsAJAXHandler(BaseRequestHandler):
success = self._reset_products()
elif action == "convert":
# Convert the product from HEALPix map to HPX image
- raise NotImplementedError("TODO")
+ try:
+ comp_id = request["compID"]
+ freq_id = request["freqID"]
+ success, reason = self._convert_hpx(comp_id, freq_id)
+ data = self.products.get_product(comp_id, freq_id)
+ response["data"] = data
+ except KeyError:
+ success = False
+ reason = "'compID' or 'freqID' is missing"
else:
# ERROR: bad action
success = False
reason = "Bad request action: {0}".format(action)
#
if success:
- response = {"action": action, "success": success}
+ response["success"] = success
logger.debug("Response: {0}".format(response))
self.set_header("Content-Type", "application/json; charset=UTF-8")
self.write(json_encode(response))
@@ -171,3 +180,18 @@ class ProductsAJAXHandler(BaseRequestHandler):
except (ValueError, OSError) as e:
error = str(e)
return (success, error)
+
+ def _convert_hpx(self, comp_id, freq_id):
+ """
+ Convert the HEALPix map of the product to HPX projected FITS image.
+
+ FIXME/TODO: make this non-blocking!
+ """
+ success = False
+ error = None
+ try:
+ self.products.convert_hpx(comp_id, freq_id, clobber=True)
+ success = True
+ except IOError as e:
+ error = str(e)
+ return (success, error)