catalog.py 1.65 KB
Newer Older
Shoulin Wei's avatar
gaia3  
Shoulin Wei committed
1
from .delegate import Delegate
Wei Shoulin's avatar
ephem    
Wei Shoulin committed
2
from csst_dfs_commons.models import Result
Wei Shoulin's avatar
Wei Shoulin committed
3
from csst_dfs_api.common.utils import to_table as to_fits_table
Wei Shoulin's avatar
Wei Shoulin committed
4

Shoulin Wei's avatar
gaia3  
Shoulin Wei committed
5
6
7
8
9
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
10
    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
11
12
13
14
15
        ''' retrieval catalog

        :param ra: in deg
        :param dec:  in deg
        :param radius:  in deg
Wei Shoulin's avatar
C9    
Wei Shoulin committed
16
        :param catalog_name: one of ['gaia3','sim']
Wei Shoulin's avatar
Wei Shoulin committed
17
        :param columns: tuple of str, like ('ra','dec','phot_g_mean_mag')
Wei Shoulin's avatar
docs    
Wei Shoulin committed
18
19
20
21
22
23
        :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
24
        '''
Wei Shoulin's avatar
C9    
Wei Shoulin committed
25
26
27
28
29
30
31
32
33
34
35
36
37
        if not catalog_name or catalog_name not in ('gaia3', 'sim'):
            raise Exception("catalog_name is not allowed")
        if not columns:
            raise Exception("columns is empty")
        return self.catalog_query(ra = ra,
                                dec = dec, 
                                radius = radius, 
                                catalog_name = catalog_name,
                                columns = columns, 
                                min_mag = min_mag, 
                                max_mag = max_mag, 
                                obstime = obstime, 
                                limit = limit)
Wei Shoulin's avatar
Wei Shoulin committed
38

Wei Shoulin's avatar
Wei Shoulin committed
39
    def to_table(self, query_result):
Wei Shoulin's avatar
Wei Shoulin committed
40
        return to_fits_table(query_result)