Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
csst-dfs
csst-dfs-api
Commits
a5abca08
Commit
a5abca08
authored
Feb 12, 2023
by
Wei Shoulin
Browse files
add filter
parent
fd7a071c
Changes
18
Hide whitespace changes
Inline
Side-by-side
csst_dfs_api/common/delegate.py
View file @
a5abca08
...
...
@@ -2,7 +2,6 @@ import os
import
importlib
import
logging
from
csst_dfs_commons.models.errors
import
*
from
.constants
import
*
...
...
@@ -12,9 +11,9 @@ 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
):
if
self
.
mode
==
MODE_LOCAL
:
self
.
local_path
=
os
.
getenv
(
"CSST_LOCAL_FILE_ROOT"
)
...
...
csst_dfs_api/common/utils.py
View file @
a5abca08
...
...
@@ -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
=
{}
...
...
@@ -117,4 +117,8 @@ 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
\ No newline at end of file
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
csst_dfs_api/facility/level0.py
View file @
a5abca08
...
...
@@ -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],
...
...
csst_dfs_api/mbi/level2.py
View file @
a5abca08
...
...
@@ -93,7 +93,7 @@ class Level2DataApi(object):
def
write
(
self
,
**
kwargs
):
''' insert a level2 record into database
:param kwargs: Parameter dictionary, key items support:
level1_id: [int]
data_type : [str]
...
...
csst_dfs_api/sls/level2spectra.py
View file @
a5abca08
...
...
@@ -61,7 +61,7 @@ class Level2SpectraApi(object):
def
write
(
self
,
**
kwargs
):
''' insert a level1 record into database
:param kwargs: Parameter dictionary, key items support:
level0_id: [str]
level1_id: [int]
...
...
tests/common/test_common_utils.py
0 → 100644
View file @
a5abca08
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
tests/cpic/test_cpic_level1.py
View file @
a5abca08
...
...
@@ -9,7 +9,7 @@ class CPICLevel1TestCase(unittest.TestCase):
def
test_find
(
self
):
recs
=
self
.
api
.
find
(
level0_id
=
'0000223'
,
level0_id
=
'
4
0000
1
223'
,
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_10
0000001_
09_raw
"
,
file_path
=
"/opt/temp/csst/MSC_MS_
210525121500
_100000
0
01_
09_raw
.fits"
,
filename
=
"
CSST_
MSC_MS_
SCI_20270810142128_20270810142358_1
00000
1
01_
20_img_L1.fits
"
,
file_path
=
"/opt/temp/csst/
CSST_
MSC_MS_
SCI_20270810142128_20270810142358
_100000
1
01_
20_img_L1
.fits"
,
pipeline_id
=
"P2"
,
refs
=
{
'dark'
:
1
,
'bias'
:
2
,
'flat'
:
3
})
print
(
'write:'
,
rec
)
\ No newline at end of file
tests/facility/test_facility_brick.py
View file @
a5abca08
...
...
@@ -13,7 +13,7 @@ class FacilityBrickTestCase(unittest.TestCase):
print
(
'find:'
,
recs
)
def
test_get
(
self
):
rec
=
self
.
api
.
get
(
id
=
1
7
)
rec
=
self
.
api
.
get
(
id
=
1
)
print
(
'get:'
,
rec
)
def
test_write
(
self
):
...
...
@@ -26,4 +26,4 @@ class FacilityBrickTestCase(unittest.TestCase):
def
test_find_level1_data
(
self
):
rec
=
self
.
api
.
find_level1_data
(
brick_id
=
1
,
level1_id
=
1
,
module
=
'msc'
)
print
(
'find_level1_data:'
,
rec
)
print
(
'find_level1_data:'
,
rec
)
tests/facility/test_facility_level0.py
View file @
a5abca08
...
...
@@ -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
,
...
...
tests/hstdm/test_hstdm_level1.py
View file @
a5abca08
...
...
@@ -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
_100000
0
01_
09_raw
.fits"
,
file_path
=
"/opt/temp/csst/
CSST_
MSC_MS_
SCI_20270810142128_20270810142358
_100000
1
01_
20_img_L1
.fits"
,
pipeline_id
=
"P2"
,
refs
=
{
'dark'
:
1
,
'bias'
:
2
,
'flat'
:
3
})
print
(
'write:'
,
rec
)
\ No newline at end of file
tests/ifs/test_ifs_level1.py
View file @
a5abca08
...
...
@@ -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_10
0000001_
09_raw
"
,
file_path
=
"/opt/temp/csst/MSC_MS_
210525121500
_100000
0
01_
09_raw
.fits"
,
filename
=
"
CSST_
MSC_MS_
SCI_20270810142128_20270810142358_1
00000
1
01_
20_img_L1.fits
"
,
file_path
=
"/opt/temp/csst/
CSST_
MSC_MS_
SCI_20270810142128_20270810142358
_100000
1
01_
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
tests/mbi/test_mbi_level1.py
View file @
a5abca08
...
...
@@ -4,7 +4,7 @@ from astropy.io import fits
from
csst_dfs_api.mbi.level1
import
Level1DataApi
class
M
SC
Level1DataTestCase
(
unittest
.
TestCase
):
class
M
BI
Level1DataTestCase
(
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_10
0000001_
09_raw
"
,
file_path
=
"/opt/temp/csst/
msc/level1/MSC_210304093000_0000000_06
_img.fits
.fz
"
,
filename
=
"
CSST_
MSC_MS_
SCI_20270810142128_20270810142358_1
00000
1
01_
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
tests/mbi/test_mbi_level1_prc.py
View file @
a5abca08
...
...
@@ -4,7 +4,7 @@ from astropy.io import fits
from
csst_dfs_api.mbi.level1prc
import
Level1PrcApi
class
M
SC
Level1PrcTestCase
(
unittest
.
TestCase
):
class
M
BI
Level1PrcTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
api
=
Level1PrcApi
()
...
...
tests/mbi/test_mbi_level2.py
View file @
a5abca08
...
...
@@ -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
M
SC
Level2DataTestCase
(
unittest
.
TestCase
):
class
M
BI
Level2DataTestCase
(
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
)
tests/mbi/test_mbi_level2co.py
View file @
a5abca08
...
...
@@ -4,7 +4,7 @@ from astropy.io import fits
from
csst_dfs_api.mbi.level2co
import
Level2CoApi
class
M
SC
Level2CoDataTestCase
(
unittest
.
TestCase
):
class
M
BI
Level2CoDataTestCase
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
api
=
Level2CoApi
()
...
...
tests/mci/test_mci_level1.py
View file @
a5abca08
...
...
@@ -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_10
0000001_
09_raw
"
,
file_path
=
"/opt/temp/csst/MSC_MS_
210525121500
_100000
0
01_
09_raw
.fits"
,
filename
=
"
CSST_
MSC_MS_
SCI_20270810142128_20270810142358_1
00000
1
01_
20_img_L1.fits
"
,
file_path
=
"/opt/temp/csst/
CSST_
MSC_MS_
SCI_20270810142128_20270810142358
_100000
1
01_
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
tests/sls/test_sls_level1.py
View file @
a5abca08
...
...
@@ -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_10
0000001_
09_raw
"
,
file_path
=
"/opt/temp/csst/MSC_MS_
210525121500
_100000
0
01_
09_raw
.fits"
,
filename
=
"
CSST_
MSC_MS_
SCI_20270810142128_20270810142358_1
00000
1
01_
20_img_L1.fits
"
,
file_path
=
"/opt/temp/csst/
CSST_
MSC_MS_
SCI_20270810142128_20270810142358
_100000
1
01_
20_img_L1
.fits"
,
pipeline_id
=
"P2"
,
refs
=
{
'dark'
:
1
,
'bias'
:
2
,
'flat'
:
3
})
print
(
'write:'
,
rec
)
\ No newline at end of file
tests/sls/test_sls_level2_spectra.py
View file @
a5abca08
...
...
@@ -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_21052512
15
00_10000000
1_09_raw
"
,
file_path
=
"/opt/temp/csst/MSC_MS_21052512
15
00_10000000
1_09_raw
.fits"
,
filename
=
"MSC_MS_21052512
00
00_10000000
0_20_cat.fits
"
,
file_path
=
"/opt/temp/csst/
msc_data/
MSC_MS_21052512
00
00_10000000
0_20_cat
.fits"
,
pipeline_id
=
"P2"
)
print
(
'write:'
,
rec
)
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment