catalog.py 2.11 KB
Newer Older
Wei Shoulin's avatar
level2    
Wei Shoulin committed
1
from astropy.table import Table
Wei Shoulin's avatar
Wei Shoulin committed
2

Shoulin Wei's avatar
gaia3  
Shoulin Wei committed
3
from .delegate import Delegate
Wei Shoulin's avatar
ephem    
Wei Shoulin committed
4
from csst_dfs_commons.models import Result
Wei Shoulin's avatar
Wei Shoulin committed
5
from csst_dfs_api.common.utils import to_table as to_fits_table
Wei Shoulin's avatar
Wei Shoulin committed
6

Shoulin Wei's avatar
gaia3  
Shoulin Wei committed
7
8
9
10
11
class CatalogApi(object):
    def __init__(self):
        self.module = Delegate().load(sub_module = "common")
        self.stub = getattr(self.module, "CatalogApi")()
    
Wei Shoulin's avatar
Wei Shoulin committed
12
    def catalog_query(self, ra: float, dec: float, radius: float, catalog_name: str, columns: tuple, min_mag: float,  max_mag: float,  obstime: int, limit: int):
Wei Shoulin's avatar
docs    
Wei Shoulin committed
13
14
15
16
17
18
        ''' retrieval catalog

        :param ra: in deg
        :param dec:  in deg
        :param radius:  in deg
        :param catalog_name: one of ['gaia3','','']
Wei Shoulin's avatar
Wei Shoulin committed
19
        :param columns: tuple of str, like ('ra','dec','phot_g_mean_mag')
Wei Shoulin's avatar
docs    
Wei Shoulin committed
20
21
22
23
24
25
        :param min_mag: minimal magnitude
        :param max_mag: maximal magnitude
        :param obstime: seconds  
        :param limit: limits returns the number of records

        :returns: csst_dfs_common.models.Result
Shoulin Wei's avatar
gaia3  
Shoulin Wei committed
26
27
28
29
30
        '''

        if catalog_name == "gaia3":
            return self.gaia3_query(ra, dec, radius, min_mag, max_mag, obstime, limit)
        else:
Wei Shoulin's avatar
ephem    
Wei Shoulin committed
31
            return Result.error(message="%s catalog search not yet implemented" %(catalog_name, ))
Wei Shoulin's avatar
Wei Shoulin committed
32

Wei Shoulin's avatar
Wei Shoulin committed
33
    def to_table(self, query_result):
Wei Shoulin's avatar
Wei Shoulin committed
34
        return to_fits_table(query_result)
Shoulin Wei's avatar
gaia3  
Shoulin Wei committed
35

Wei Shoulin's avatar
Wei Shoulin committed
36
    def gaia3_query(self, ra: float, dec: float, radius: float, columns: tuple,min_mag: float,  max_mag: float,  obstime: int, limit: int):
Wei Shoulin's avatar
docs    
Wei Shoulin committed
37
38
39
40
41
        """retrieval GAIA EDR 3
        
        :param ra: in deg
        :param dec:  in deg
        :param radius:  in deg
Wei Shoulin's avatar
Wei Shoulin committed
42
        :param columns: tuple of str, like ('ra','dec','phot_g_mean_mag')
Wei Shoulin's avatar
docs    
Wei Shoulin committed
43
44
45
46
47
48
49
        :param min_mag: minimal magnitude
        :param max_mag: maximal magnitude
        :param obstime: seconds  
        :param limit: limits returns the number of records

        :returns: csst_dfs_common.models.Result
        """ 
Wei Shoulin's avatar
ephem    
Wei Shoulin committed
50
        try:
Wei Shoulin's avatar
Wei Shoulin committed
51
52
53
            if not columns:
                raise Exception("columns is empty")
            return self.stub.gaia3_query(ra, dec, radius, columns, min_mag, max_mag, obstime, limit)
Wei Shoulin's avatar
ephem    
Wei Shoulin committed
54
55
        except Exception as e:
            return Result.error(message=repr(e))