diff --git a/csst_dfs_api/common/ephem.py b/csst_dfs_api/common/ephem.py index 3b7a2c453de72faf426834159c44d02c3c948444..4eebd9dfc76e11521ee73155b5c10985fe33e361 100644 --- a/csst_dfs_api/common/ephem.py +++ b/csst_dfs_api/common/ephem.py @@ -1,7 +1,18 @@ +from .delegate import Delegate class EphemSearchApi(object): def __init__(self): - pass + self.module = Delegate().load(sub_module = "common") + self.stub = getattr(self.module, "EphemSearchApi")() - def search(self, ra: float, dec: float, radius: float, limit: int): - pass + def gaia_query(self, ra: float, dec: float, radius: float, mag: float, limit: int = 1000): + ''' retivial GAIA DR 2 + args: + ra: in deg + dec: in deg + radius: in deg + mag: + limit: limits on the number of returns + return: a dict as {success: true, totalCount: 100, records:[.....]} + ''' + return self.stub.gaia_query(ra, dec, radius, mag, limit) diff --git a/examples/ifs_rss_pipeline.py b/examples/ifs_rss_pipeline.py index c21cb3e9cc1cb579a1dabb4cd98884ab857a53ee..e0f7a6f59715d378fb7d46ab42d84d0cad948e9f 100644 --- a/examples/ifs_rss_pipeline.py +++ b/examples/ifs_rss_pipeline.py @@ -23,9 +23,11 @@ class RSS(object): try: self.raw = self.fitsApi.find(file_name=file_name) self.raw = self.raw[0] if self.raw else None - log.info("find raw fits: %s,%s"%(self.raw["id"], self.raw["filename"])) if self.raw is None: log.error('raw %s not found' %(file_name,)) + else: + log.info("find raw fits: %s,%s"%(self.raw["id"], self.raw["filename"])) + except Exception as e: log.error('raw %s not found' %(file_name,),e) @@ -33,10 +35,11 @@ class RSS(object): try: self.bias = self.refFitsApi.find(file_name=file_name, ref_type=RefFitsApi.REF_FITS_BIAS) self.bias = self.bias[0] if self.bias else None - log.info("find ref bias fits: %s,%s"%(self.bias["id"], self.bias["filename"])) - + if self.bias is None: log.error('bias %s not found' %(file_name,)) + else: + log.info("find ref bias fits: %s,%s"%(self.bias["id"], self.bias["filename"])) except Exception as e: log.error('bias %s not found' %(file_name,),e) @@ -44,10 +47,11 @@ class RSS(object): try: self.flat = self.refFitsApi.find(file_name=file_name, ref_type=RefFitsApi.REF_FITS_FLAT) self.flat = self.flat[0] if self.flat else None - log.info("find ref flat fits: %s,%s"%(self.flat["id"], self.flat["filename"])) - + if self.flat is None: log.error('flat %s not found' %(file_name,)) + else: + log.info("find ref flat fits: %s,%s"%(self.flat["id"], self.flat["filename"])) except Exception as e: log.error('flat %s not found' %(file_name,),e) @@ -55,10 +59,11 @@ class RSS(object): try: self.arc = self.refFitsApi.find(file_name=file_name, ref_type=RefFitsApi.REF_FITS_ARC) self.arc = self.arc[0] if self.arc else None - log.info("find ref arc fits: %s,%s"%(self.arc["id"], self.arc["filename"])) if self.arc is None: log.error('arc %s not found' %(file_name,)) + else: + log.info("find ref arc fits: %s,%s"%(self.arc["id"], self.arc["filename"])) except Exception as e: log.error('arc %s not found' %(file_name,),e) @@ -66,17 +71,30 @@ class RSS(object): try: self.sky = self.refFitsApi.find(file_name=file_name, ref_type=RefFitsApi.REF_FITS_SKY) self.sky = self.sky[0] if self.sky else None - log.info("find ref sky fits: %s,%s"%(self.sky["id"], self.sky["filename"])) if self.sky is None: log.error('sky %s not found' %(file_name,)) + else: + log.info("find ref sky fits: %s,%s"%(self.sky["id"], self.sky["filename"])) except Exception as e: log.error('sky %s not found' %(file_name,),e) def makecube(self, outfile): - hdul_raw = fits.open(os.path.join(self.root_dir, self.raw['file_path'])) + if self.raw is None: + log.error('raw not found') + return + if self.arc is None: + log.error('arc not found') + return + if self.flat is None: + log.error('flat not found') + return + if self.sky is None: + log.error('sky not found') + return + hdul_raw = fits.open(os.path.join(self.root_dir, self.raw['file_path'])) hdul_arc = fits.open(os.path.join(self.root_dir, self.arc['file_path'])) hdul_flat = fits.open(os.path.join(self.root_dir, self.flat['file_path'])) hdul_sky = fits.open(os.path.join(self.root_dir, self.sky['file_path'])) diff --git a/tests/test_common_ephem.py b/tests/test_common_ephem.py new file mode 100644 index 0000000000000000000000000000000000000000..c6d0295d1995e5b4343a5cc5dda11c7d9bc98d3a --- /dev/null +++ b/tests/test_common_ephem.py @@ -0,0 +1,14 @@ +import os +import unittest +from astropy.io import fits + +from csst_dfs_api.common.ephem import EphemSearchApi + +class CommonEphemTestCase(unittest.TestCase): + + def setUp(self): + self.api = EphemSearchApi() + + def test_gaia_query(self): + recs = self.api.gaia_query(ra=260, dec=-27, radius=0.01, mag=0.01, limit=2) + print('find:', recs)