Commit e81bfd8d authored by Wei Shoulin's avatar Wei Shoulin
Browse files

add pipeline_id

parent 650b8f74
...@@ -2,7 +2,7 @@ from astropy.table import Table ...@@ -2,7 +2,7 @@ from astropy.table import Table
from .delegate import Delegate from .delegate import Delegate
from csst_dfs_commons.models import Result from csst_dfs_commons.models import Result
from csst_dfs_api.common.utils import to_table as to_fits_table
class CatalogApi(object): class CatalogApi(object):
def __init__(self): def __init__(self):
...@@ -29,32 +29,8 @@ class CatalogApi(object): ...@@ -29,32 +29,8 @@ class CatalogApi(object):
else: else:
return Result.error(message="%s catalog search not yet implemented" %(catalog_name, )) return Result.error(message="%s catalog search not yet implemented" %(catalog_name, ))
def _fields_dtypes(self, rec):
fields = tuple(rec.__dataclass_fields__.keys())
dtypes = []
for _, f in rec.__dataclass_fields__.items():
if f.type == int:
dtypes.append('i8')
elif f.type == float:
dtypes.append('f8')
elif f.type == str:
dtypes.append('S2')
else:
dtypes.append('S2')
dtypes = tuple(dtypes)
return fields, dtypes
def to_table(self, query_result): def to_table(self, query_result):
if not query_result.success or not query_result.data: return to_fits_table(query_result)
return Table()
fields, dtypes = self._fields_dtypes(query_result.data[0])
t = Table(names = fields, dtype = dtypes)
t.meta['comments'] = [str(query_result.data[0].__class__)]
t.meta['total'] = query_result['totalCount']
for rec in query_result.data:
t.add_row(tuple([rec.__getattribute__(k) for k in fields]))
return t
def gaia3_query(self, ra: float, dec: float, radius: float, min_mag: float, max_mag: float, obstime: int, limit: int): def gaia3_query(self, ra: float, dec: float, radius: float, min_mag: float, max_mag: float, obstime: int, limit: int):
"""retrieval GAIA EDR 3 """retrieval GAIA EDR 3
......
from datetime import datetime from datetime import datetime
from astropy.table import Table
import time import time
def format_datetime(dt): def format_datetime(dt):
...@@ -61,3 +62,32 @@ def revoke(cmd, desc=''): ...@@ -61,3 +62,32 @@ def revoke(cmd, desc=''):
return self.func(*args, **kw) return self.func(*args, **kw)
return Wrapper(cmd, desc, func) return Wrapper(cmd, desc, func)
return decorator return decorator
def fields_dtypes(rec):
fields = tuple(rec.__dataclass_fields__.keys())
dtypes = []
for _, f in rec.__dataclass_fields__.items():
if f.type == int:
dtypes.append('i8')
elif f.type == float:
dtypes.append('f8')
elif f.type == str:
dtypes.append('S2')
elif f.type == list:
dtypes.append('(12,)f8')
else:
dtypes.append('S2')
dtypes = tuple(dtypes)
return fields, dtypes
def to_table(query_result):
if not query_result.success or not query_result.data:
return Table()
fields, dtypes = fields_dtypes(query_result.data[0])
t = Table(names = fields, dtype = dtypes)
t.meta['comments'] = [str(query_result.data[0].__class__)]
t.meta['total'] = query_result['totalCount']
for rec in query_result.data:
t.add_row(tuple([rec.__getattribute__(k) for k in fields]))
return t
\ No newline at end of file
...@@ -41,35 +41,6 @@ class Level2DataApi(object): ...@@ -41,35 +41,6 @@ class Level2DataApi(object):
''' '''
return self.stub.catalog_query(**kwargs) return self.stub.catalog_query(**kwargs)
def _fields_dtypes(self, rec):
fields = tuple(rec.__dataclass_fields__.keys())
dtypes = []
for _, f in rec.__dataclass_fields__.items():
if f.type == int:
dtypes.append('i8')
elif f.type == float:
dtypes.append('f8')
elif f.type == str:
dtypes.append('S2')
elif f.type == list:
dtypes.append('(12,)f8')
else:
dtypes.append('S2')
dtypes = tuple(dtypes)
return fields, dtypes
def to_table(self, query_result):
if not query_result.success or not query_result.data:
return Table()
fields, dtypes = self._fields_dtypes(query_result.data[0])
t = Table(names = fields, dtype = dtypes)
t.meta['comments'] = [str(query_result.data[0].__class__)]
t.meta['total'] = query_result['totalCount']
for rec in query_result.data:
t.add_row(tuple([rec.__getattribute__(k) for k in fields]))
return t
def get(self, **kwargs): def get(self, **kwargs):
''' fetch a record from database ''' fetch a record from database
...@@ -93,7 +64,7 @@ class Level2DataApi(object): ...@@ -93,7 +64,7 @@ class Level2DataApi(object):
return self.stub.update_proc_status(**kwargs) return self.stub.update_proc_status(**kwargs)
def update_qc2_status(self, **kwargs): def update_qc2_status(self, **kwargs):
''' update the status of QC0 ''' update the status of QC2
:param kwargs: Parameter dictionary, key items support: :param kwargs: Parameter dictionary, key items support:
id = [int], id = [int],
...@@ -113,6 +84,7 @@ class Level2DataApi(object): ...@@ -113,6 +84,7 @@ class Level2DataApi(object):
file_path : [str] file_path : [str]
prc_status : [int] prc_status : [int]
prc_time : [str] prc_time : [str]
pipeline_id : [str]
:returns: csst_dfs_common.models.Result :returns: csst_dfs_common.models.Result
''' '''
......
from ..common.delegate import Delegate
class Level2CoApi(object):
"""
Level2 Merge Catalog Operation Class
"""
def __init__(self):
self.pymodule = Delegate().load(sub_module = "msc")
self.stub = getattr(self.pymodule, "Level2CoApi")()
def find(self, **kwargs):
''' retrieve level2 Merge Catalog records from database
:param kwargs: Parameter dictionary, key items support:
data_type: [str]
create_time : (start, end),
qc2_status : [int],
prc_status : [int],
filename: [str]
limit: limits returns the number of records,default 0:no-limit
:returns: csst_dfs_common.models.Result
'''
return self.stub.find(**kwargs)
def catalog_query(self, **kwargs):
''' retrieve level2 Merge catalog
:param kwargs: Parameter dictionary, key items support:
obs_id: [str]
detector_no: [str]
min_mag: [float]
max_mag: [float]
obs_time: (start, end),
limit: limits returns the number of records,default 0:no-limit
:returns: csst_dfs_common.models.Result
'''
return self.stub.catalog_query(**kwargs)
def get(self, **kwargs):
''' fetch a record from database
:param kwargs: Parameter dictionary, key items support:
id : [int]
:returns: csst_dfs_common.models.Result
'''
return self.stub.get(**kwargs)
def update_proc_status(self, **kwargs):
''' update the status of reduction
:param kwargs: Parameter dictionary, key items support:
id = [int],
status = [int]
:returns: csst_dfs_common.models.Result
'''
return self.stub.update_proc_status(**kwargs)
def update_qc2_status(self, **kwargs):
''' update the status of QC2
:param kwargs: Parameter dictionary, key items support:
id = [int],
status = [int]
:returns: csst_dfs_common.models.Result
'''
return self.stub.update_qc2_status(**kwargs)
def write(self, **kwargs):
''' insert a level2 record after merge into database
:param kwargs: Parameter dictionary, key items support:
data_type : [str]
filename : [str]
file_path : [str]
prc_status : [int]
prc_time : [str]
pipeline_id : [str]
:returns: csst_dfs_common.models.Result
'''
return self.stub.write(**kwargs)
...@@ -13,8 +13,8 @@ class CommonCatalogTestCase(unittest.TestCase): ...@@ -13,8 +13,8 @@ class CommonCatalogTestCase(unittest.TestCase):
def test_catalog_query(self): def test_catalog_query(self):
t= time.time() t= time.time()
result = self.api.catalog_query( result = self.api.catalog_query(
ra=128, # 15415 ra=193.2990269, # 15415
dec=-40, dec=0.038331050065405756,
radius=2, radius=2,
catalog_name='gaia3', catalog_name='gaia3',
min_mag=-1, min_mag=-1,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment