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

add filter

parent fd7a071c
...@@ -2,7 +2,6 @@ import os ...@@ -2,7 +2,6 @@ import os
import importlib import importlib
import logging import logging
from csst_dfs_commons.models.errors import * from csst_dfs_commons.models.errors import *
from .constants import * from .constants import *
...@@ -12,9 +11,9 @@ API_MODULE_PREFIX = "csst_dfs_api_" ...@@ -12,9 +11,9 @@ API_MODULE_PREFIX = "csst_dfs_api_"
class Delegate(object): class Delegate(object):
def __init__(self): def __init__(self):
self.mode = os.getenv("CSST_DFS_API_MODE",'local') self.mode = os.getenv("CSST_DFS_API_MODE", 'cluster')
self.check_env() self.check_env()
def check_env(self): def check_env(self):
if self.mode == MODE_LOCAL: if self.mode == MODE_LOCAL:
self.local_path = os.getenv("CSST_LOCAL_FILE_ROOT") self.local_path = os.getenv("CSST_LOCAL_FILE_ROOT")
......
...@@ -2,6 +2,8 @@ from datetime import datetime ...@@ -2,6 +2,8 @@ from datetime import datetime
from astropy.table import Table from astropy.table import Table
import time import time
from .delegate import Delegate
def format_datetime(dt): def format_datetime(dt):
return dt.strftime('%Y-%m-%d %H:%M:%S') return dt.strftime('%Y-%m-%d %H:%M:%S')
...@@ -14,7 +16,6 @@ def format_time_ms(float_time): ...@@ -14,7 +16,6 @@ def format_time_ms(float_time):
data_secs = (float_time - int(float_time)) * 1000 data_secs = (float_time - int(float_time)) * 1000
return "%s.%03d" % (data_head, data_secs) return "%s.%03d" % (data_head, data_secs)
def get_parameter(kwargs, key, default=None): def get_parameter(kwargs, key, default=None):
""" Get a specified named value for this (calling) function """ Get a specified named value for this (calling) function
...@@ -40,7 +41,6 @@ def to_int(s, default_value = 0): ...@@ -40,7 +41,6 @@ def to_int(s, default_value = 0):
except: except:
return default_value return default_value
def singleton(cls): def singleton(cls):
_instance = {} _instance = {}
...@@ -117,4 +117,8 @@ def object_list_to_table(query_result): ...@@ -117,4 +117,8 @@ def object_list_to_table(query_result):
for rec in query_result.data: for rec in query_result.data:
t.add_row(tuple([rec.__getattribute__(k) for k in fields])) t.add_row(tuple([rec.__getattribute__(k) for k in fields]))
return t return t
\ No newline at end of file
def get_nextId_by_prefix(prefix):
pymodule = Delegate().load(sub_module = "common.utils")
return getattr(pymodule, "get_nextId_by_prefix")(prefix)
\ No newline at end of file
...@@ -13,9 +13,10 @@ class Level0DataApi(object): ...@@ -13,9 +13,10 @@ class Level0DataApi(object):
''' retrieve level0 records from database ''' retrieve level0 records from database
:param kwargs: Parameter dictionary, key items support: :param kwargs: Parameter dictionary, key items support:
obs_id: [str] obs_id: [str],
detector_no: [str] detector_no: [str],
obs_type: [str] obs_type: [str],
filter: [str],
obs_time : (start, end), obs_time : (start, end),
qc0_status : [int], qc0_status : [int],
prc_status : [int], prc_status : [int],
......
...@@ -93,7 +93,7 @@ class Level2DataApi(object): ...@@ -93,7 +93,7 @@ class Level2DataApi(object):
def write(self, **kwargs): def write(self, **kwargs):
''' insert a level2 record into database ''' insert a level2 record into database
:param kwargs: Parameter dictionary, key items support: :param kwargs: Parameter dictionary, key items support:
level1_id: [int] level1_id: [int]
data_type : [str] data_type : [str]
......
...@@ -61,7 +61,7 @@ class Level2SpectraApi(object): ...@@ -61,7 +61,7 @@ class Level2SpectraApi(object):
def write(self, **kwargs): def write(self, **kwargs):
''' insert a level1 record into database ''' insert a level1 record into database
:param kwargs: Parameter dictionary, key items support: :param kwargs: Parameter dictionary, key items support:
level0_id: [str] level0_id: [str]
level1_id: [int] level1_id: [int]
......
import unittest
import time
from csst_dfs_api.common.utils import get_nextId_by_prefix
class CommonUtilsTestCase(unittest.TestCase):
def setUp(self):
pass
def test_get_nextId_by_prefix(self):
t= time.time()
result = get_nextId_by_prefix("MBI")
print(result)
assert type(result.data) == int
...@@ -9,7 +9,7 @@ class CPICLevel1TestCase(unittest.TestCase): ...@@ -9,7 +9,7 @@ class CPICLevel1TestCase(unittest.TestCase):
def test_find(self): def test_find(self):
recs = self.api.find( recs = self.api.find(
level0_id='0000223', level0_id='400001223',
create_time = ("2021-06-01 11:12:13","2021-06-08 11:12:13") create_time = ("2021-06-01 11:12:13","2021-06-08 11:12:13")
) )
print('find:', recs) print('find:', recs)
...@@ -33,8 +33,8 @@ class CPICLevel1TestCase(unittest.TestCase): ...@@ -33,8 +33,8 @@ class CPICLevel1TestCase(unittest.TestCase):
prc_params = "/opt/dddasd.params", prc_params = "/opt/dddasd.params",
prc_status = 3, prc_status = 3,
prc_time = '2021-10-22 11:12:13', prc_time = '2021-10-22 11:12:13',
filename = "MSC_MS_210525121500_100000001_09_raw", filename = "CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
file_path = "/opt/temp/csst/MSC_MS_210525121500_100000001_09_raw.fits", file_path = "/opt/temp/csst/CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
pipeline_id = "P2", pipeline_id = "P2",
refs = {'dark': 1, 'bias': 2, 'flat': 3 }) refs = {'dark': 1, 'bias': 2, 'flat': 3 })
print('write:', rec) print('write:', rec)
\ No newline at end of file
...@@ -13,7 +13,7 @@ class FacilityBrickTestCase(unittest.TestCase): ...@@ -13,7 +13,7 @@ class FacilityBrickTestCase(unittest.TestCase):
print('find:', recs) print('find:', recs)
def test_get(self): def test_get(self):
rec = self.api.get(id=17) rec = self.api.get(id=1)
print('get:', rec) print('get:', rec)
def test_write(self): def test_write(self):
...@@ -26,4 +26,4 @@ class FacilityBrickTestCase(unittest.TestCase): ...@@ -26,4 +26,4 @@ class FacilityBrickTestCase(unittest.TestCase):
def test_find_level1_data(self): def test_find_level1_data(self):
rec = self.api.find_level1_data(brick_id=1, level1_id = 1, module = 'msc') rec = self.api.find_level1_data(brick_id=1, level1_id = 1, module = 'msc')
print('find_level1_data:', rec) print('find_level1_data:', rec)
...@@ -13,7 +13,7 @@ class Level0DataTestCase(unittest.TestCase): ...@@ -13,7 +13,7 @@ class Level0DataTestCase(unittest.TestCase):
def test_find_by_brick_ids(self): def test_find_by_brick_ids(self):
recs = self.api.find_by_brick_ids(brick_ids = [1,2,3,4]) recs = self.api.find_by_brick_ids(brick_ids = [1,2,3,4])
print('find:', recs) print('find_by_brick_ids:', recs)
def test_get(self): def test_get(self):
rec = self.api.get(id = 3) rec = self.api.get(id = 3)
...@@ -35,6 +35,7 @@ class Level0DataTestCase(unittest.TestCase): ...@@ -35,6 +35,7 @@ class Level0DataTestCase(unittest.TestCase):
level0_id = '000001101', level0_id = '000001101',
obs_id = '0000011', obs_id = '0000011',
detector_no = "01", detector_no = "01",
filter = "u",
obs_type = "sci", obs_type = "sci",
obs_time = "2021-06-06 11:12:13", obs_time = "2021-06-06 11:12:13",
exp_time = 150, exp_time = 150,
......
...@@ -34,7 +34,7 @@ class HSTDMLevel1TestCase(unittest.TestCase): ...@@ -34,7 +34,7 @@ class HSTDMLevel1TestCase(unittest.TestCase):
prc_status = 3, prc_status = 3,
prc_time = '2021-10-22 11:12:13', prc_time = '2021-10-22 11:12:13',
filename = "MSC_MS_210525121500_100000001_09_raw", filename = "MSC_MS_210525121500_100000001_09_raw",
file_path = "/opt/temp/csst/MSC_MS_210525121500_100000001_09_raw.fits", file_path = "/opt/temp/csst/CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
pipeline_id = "P2", pipeline_id = "P2",
refs = {'dark': 1, 'bias': 2, 'flat': 3 }) refs = {'dark': 1, 'bias': 2, 'flat': 3 })
print('write:', rec) print('write:', rec)
\ No newline at end of file
...@@ -35,8 +35,8 @@ class IFSLevel1DataTestCase(unittest.TestCase): ...@@ -35,8 +35,8 @@ class IFSLevel1DataTestCase(unittest.TestCase):
prc_params = "/opt/dddasd.params", prc_params = "/opt/dddasd.params",
prc_status = 3, prc_status = 3,
prc_time = '2021-06-05 11:12:13', prc_time = '2021-06-05 11:12:13',
filename = "MSC_MS_210525121500_100000001_09_raw", filename = "CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
file_path = "/opt/temp/csst/MSC_MS_210525121500_100000001_09_raw.fits", file_path = "/opt/temp/csst/CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
pipeline_id = "P2", pipeline_id = "P2",
refs = {'dark': 1, 'bias': 2, 'flat': 3, 'sky': 33 }) refs = {'dark': 1, 'bias': 2, 'flat': 3, 'sky': 33 })
print('write:', rec) print('write:', rec)
\ No newline at end of file
...@@ -4,7 +4,7 @@ from astropy.io import fits ...@@ -4,7 +4,7 @@ from astropy.io import fits
from csst_dfs_api.mbi.level1 import Level1DataApi from csst_dfs_api.mbi.level1 import Level1DataApi
class MSCLevel1DataTestCase(unittest.TestCase): class MBILevel1DataTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.api = Level1DataApi() self.api = Level1DataApi()
...@@ -35,8 +35,8 @@ class MSCLevel1DataTestCase(unittest.TestCase): ...@@ -35,8 +35,8 @@ class MSCLevel1DataTestCase(unittest.TestCase):
prc_params = "/opt/dddasd.params", prc_params = "/opt/dddasd.params",
prc_status = 3, prc_status = 3,
prc_time = '2021-10-22 11:12:13', prc_time = '2021-10-22 11:12:13',
filename = "MSC_MS_210525121500_100000001_09_raw", filename = "CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
file_path = "/opt/temp/csst/msc/level1/MSC_210304093000_0000000_06_img.fits.fz", file_path = "/opt/temp/csst/CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
pipeline_id = "P1", pipeline_id = "P1",
refs = {'dark': 1, 'bias': 2, 'flat': 3 }) refs = {'dark': 1, 'bias': 2, 'flat': 3 })
print('write:', rec) print('write:', rec)
\ No newline at end of file
...@@ -4,7 +4,7 @@ from astropy.io import fits ...@@ -4,7 +4,7 @@ from astropy.io import fits
from csst_dfs_api.mbi.level1prc import Level1PrcApi from csst_dfs_api.mbi.level1prc import Level1PrcApi
class MSCLevel1PrcTestCase(unittest.TestCase): class MBILevel1PrcTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.api = Level1PrcApi() self.api = Level1PrcApi()
......
...@@ -4,29 +4,29 @@ from astropy.io import fits ...@@ -4,29 +4,29 @@ from astropy.io import fits
from csst_dfs_api.common.utils import to_table as to_fits_table from csst_dfs_api.common.utils import to_table as to_fits_table
from csst_dfs_api.mbi.level2 import Level2DataApi from csst_dfs_api.mbi.level2 import Level2DataApi
class MSCLevel2DataTestCase(unittest.TestCase): class MBILevel2DataTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.api = Level2DataApi() self.api = Level2DataApi()
# def test_find(self): def test_find(self):
# recs = self.api.find( recs = self.api.find(
# level1_id=1, level1_id=1,
# create_time = ("2022-06-15 11:12:13","2022-06-16 11:12:13")) create_time = ("2022-06-15 11:12:13","2022-06-16 11:12:13"))
# print('find:', recs) print('find:', recs)
# def test_catalog_query(self): def test_catalog_query(self):
# result = self.api.catalog_query( result = self.api.catalog_query(
# obs_id = '100000133', obs_id = '100000133',
# detector_no = '13', detector_no = '13',
# ra = 192, ra = 192,
# dec = 26, dec = 26,
# radius = 1, radius = 1,
# limit = 2) limit = 2)
# print(result) print(result)
# if result.success and result['totalCount'] > 0: if result.success and result['totalCount'] > 0:
# dt = to_fits_table(result) dt = to_fits_table(result)
# dt.pprint() dt.pprint()
def test_catalog_query_file(self): def test_catalog_query_file(self):
result = self.api.catalog_query_file( result = self.api.catalog_query_file(
...@@ -35,25 +35,25 @@ class MSCLevel2DataTestCase(unittest.TestCase): ...@@ -35,25 +35,25 @@ class MSCLevel2DataTestCase(unittest.TestCase):
radius = 1) radius = 1)
print(result) print(result)
# def test_get(self): def test_get(self):
# rec = self.api.get(id = 1) rec = self.api.get(id = 1)
# print('get:', rec) print('get:', rec)
# def test_update_proc_status(self): def test_update_proc_status(self):
# rec = self.api.update_proc_status(id = 1, status = 4) rec = self.api.update_proc_status(id = 1, status = 4)
# print('update_proc_status:', rec) print('update_proc_status:', rec)
# def test_update_qc2_status(self): def test_update_qc2_status(self):
# rec = self.api.update_qc2_status(id = 1, status = 7) rec = self.api.update_qc2_status(id = 1, status = 7)
# print('update_qc2_status:', rec) print('update_qc2_status:', rec)
# def test_write(self): def test_write(self):
# rec = self.api.write( rec = self.api.write(
# level1_id= 1, level1_id= 1,
# data_type = "sci", data_type = "sci",
# prc_status = 3, prc_status = 3,
# prc_time = '2021-10-22 11:12:13', prc_time = '2021-10-22 11:12:13',
# filename = "MSC_MS_210525120000_100000000_20_cat.fits", filename = "MSC_MS_210525120000_100000000_20_cat.fits",
# file_path = "/opt/temp/csst/msc_data/MSC_MS_210525120000_100000000_20_cat.fits" file_path = "/opt/temp/csst/msc_data/MSC_MS_210525120000_100000000_20_cat.fits"
# ) )
# print('write:', rec) print('write:', rec)
...@@ -4,7 +4,7 @@ from astropy.io import fits ...@@ -4,7 +4,7 @@ from astropy.io import fits
from csst_dfs_api.mbi.level2co import Level2CoApi from csst_dfs_api.mbi.level2co import Level2CoApi
class MSCLevel2CoDataTestCase(unittest.TestCase): class MBILevel2CoDataTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
self.api = Level2CoApi() self.api = Level2CoApi()
......
...@@ -35,8 +35,8 @@ class MCILevel1DataTestCase(unittest.TestCase): ...@@ -35,8 +35,8 @@ class MCILevel1DataTestCase(unittest.TestCase):
prc_params = "/opt/dddasd.params", prc_params = "/opt/dddasd.params",
prc_status = 3, prc_status = 3,
prc_time = '2021-06-05 11:12:13', prc_time = '2021-06-05 11:12:13',
filename = "MSC_MS_210525121500_100000001_09_raw", filename = "CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
file_path = "/opt/temp/csst/MSC_MS_210525121500_100000001_09_raw.fits", file_path = "/opt/temp/csst/CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
pipeline_id = "P2", pipeline_id = "P2",
refs = {'dark': 1, 'bias': 2, 'flat': 3, 'sky': 33 }) refs = {'dark': 1, 'bias': 2, 'flat': 3, 'sky': 33 })
print('write:', rec) print('write:', rec)
\ No newline at end of file
...@@ -37,8 +37,8 @@ class SLSResult1TestCase(unittest.TestCase): ...@@ -37,8 +37,8 @@ class SLSResult1TestCase(unittest.TestCase):
prc_params = "/opt/dddasd.params", prc_params = "/opt/dddasd.params",
prc_status = 3, prc_status = 3,
prc_time = '2021-10-22 11:12:13', prc_time = '2021-10-22 11:12:13',
filename = "MSC_MS_210525121500_100000001_09_raw", filename = "CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
file_path = "/opt/temp/csst/MSC_MS_210525121500_100000001_09_raw.fits", file_path = "/opt/temp/csst/CSST_MSC_MS_SCI_20270810142128_20270810142358_100000101_20_img_L1.fits",
pipeline_id = "P2", pipeline_id = "P2",
refs = {'dark': 1, 'bias': 2, 'flat': 3 }) refs = {'dark': 1, 'bias': 2, 'flat': 3 })
print('write:', rec) print('write:', rec)
\ No newline at end of file
...@@ -33,7 +33,7 @@ class SLSLevel2SpectraTestCase(unittest.TestCase): ...@@ -33,7 +33,7 @@ class SLSLevel2SpectraTestCase(unittest.TestCase):
region = "[12,13,24,24]", region = "[12,13,24,24]",
prc_status = 3, prc_status = 3,
prc_time = '2021-10-22 11:12:13', prc_time = '2021-10-22 11:12:13',
filename = "MSC_MS_210525121500_100000001_09_raw", filename = "MSC_MS_210525120000_100000000_20_cat.fits",
file_path = "/opt/temp/csst/MSC_MS_210525121500_100000001_09_raw.fits", file_path = "/opt/temp/csst/msc_data/MSC_MS_210525120000_100000000_20_cat.fits",
pipeline_id = "P2") pipeline_id = "P2")
print('write:', rec) print('write:', rec)
\ No newline at end of file
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