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
e81bfd8d
Commit
e81bfd8d
authored
Nov 05, 2022
by
Wei Shoulin
Browse files
add pipeline_id
parent
650b8f74
Changes
5
Hide whitespace changes
Inline
Side-by-side
csst_dfs_api/common/catalog.py
View file @
e81bfd8d
...
...
@@ -2,7 +2,7 @@ from astropy.table import Table
from
.delegate
import
Delegate
from
csst_dfs_commons.models
import
Result
from
csst_dfs_api.common.utils
import
to_table
as
to_fits_table
class
CatalogApi
(
object
):
def
__init__
(
self
):
...
...
@@ -29,32 +29,8 @@ class CatalogApi(object):
else
:
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
):
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
return
to_fits_table
(
query_result
)
def
gaia3_query
(
self
,
ra
:
float
,
dec
:
float
,
radius
:
float
,
min_mag
:
float
,
max_mag
:
float
,
obstime
:
int
,
limit
:
int
):
"""retrieval GAIA EDR 3
...
...
csst_dfs_api/common/utils.py
View file @
e81bfd8d
from
datetime
import
datetime
from
astropy.table
import
Table
import
time
def
format_datetime
(
dt
):
...
...
@@ -60,4 +61,33 @@ def revoke(cmd, desc=''):
def
__call__
(
self
,
*
args
,
**
kw
):
return
self
.
func
(
*
args
,
**
kw
)
return
Wrapper
(
cmd
,
desc
,
func
)
return
decorator
\ No newline at end of file
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
csst_dfs_api/msc/level2.py
View file @
e81bfd8d
...
...
@@ -41,35 +41,6 @@ class Level2DataApi(object):
'''
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
):
''' fetch a record from database
...
...
@@ -93,7 +64,7 @@ class Level2DataApi(object):
return
self
.
stub
.
update_proc_status
(
**
kwargs
)
def
update_qc2_status
(
self
,
**
kwargs
):
''' update the status of QC
0
''' update the status of QC
2
:param kwargs: Parameter dictionary, key items support:
id = [int],
...
...
@@ -113,6 +84,7 @@ class Level2DataApi(object):
file_path : [str]
prc_status : [int]
prc_time : [str]
pipeline_id : [str]
:returns: csst_dfs_common.models.Result
'''
...
...
csst_dfs_api/msc/level2co.py
0 → 100644
View file @
e81bfd8d
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
)
tests/common/test_common_catalog.py
View file @
e81bfd8d
...
...
@@ -13,8 +13,8 @@ class CommonCatalogTestCase(unittest.TestCase):
def
test_catalog_query
(
self
):
t
=
time
.
time
()
result
=
self
.
api
.
catalog_query
(
ra
=
1
28
,
# 15415
dec
=
-
40
,
ra
=
1
93.2990269
,
# 15415
dec
=
0.038331050065405756
,
radius
=
2
,
catalog_name
=
'gaia3'
,
min_mag
=-
1
,
...
...
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