catalog.py 2.27 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
16
        ''' 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
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
25
26
        '''

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

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

Wei Shoulin's avatar
Wei Shoulin committed
34
    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
Wei Shoulin committed
35
36
        """retrieval GAIA DR 3, all column name must be lowercase. columns specification at https://gea.esac.esa.int/archive/documentation/GDR3/Gaia_archive/chap_datamodel/sec_dm_main_source_catalogue/ssec_dm_gaia_source.html

Wei Shoulin's avatar
docs    
Wei Shoulin committed
37
38
39
        :param ra: in deg
        :param dec:  in deg
        :param radius:  in deg
Wei Shoulin's avatar
Wei Shoulin committed
40
        :param columns: tuple of str, like ('ra','dec','phot_g_mean_mag')
Wei Shoulin's avatar
docs    
Wei Shoulin committed
41
42
43
44
45
46
47
        :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
48
        try:
Wei Shoulin's avatar
Wei Shoulin committed
49
50
51
            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
52
53
        except Exception as e:
            return Result.error(message=repr(e))