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

add filter

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