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
cc619975
Commit
cc619975
authored
May 05, 2022
by
Wei Shoulin
Browse files
to astropy table
parent
85b8e44f
Changes
2
Hide whitespace changes
Inline
Side-by-side
csst_dfs_api/common/catalog.py
View file @
cc619975
from
astropy.table
import
QTable
,
Table
,
Column
from
.delegate
import
Delegate
from
.delegate
import
Delegate
from
csst_dfs_commons.models
import
Result
from
csst_dfs_commons.models
import
Result
class
CatalogApi
(
object
):
class
CatalogApi
(
object
):
def
__init__
(
self
):
def
__init__
(
self
):
self
.
module
=
Delegate
().
load
(
sub_module
=
"common"
)
self
.
module
=
Delegate
().
load
(
sub_module
=
"common"
)
...
@@ -24,6 +28,27 @@ class CatalogApi(object):
...
@@ -24,6 +28,27 @@ class CatalogApi(object):
return
self
.
gaia3_query
(
ra
,
dec
,
radius
,
min_mag
,
max_mag
,
obstime
,
limit
)
return
self
.
gaia3_query
(
ra
,
dec
,
radius
,
min_mag
,
max_mag
,
obstime
,
limit
)
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'
)
if
f
.
type
==
float
:
dtypes
.
append
(
'f8'
)
if
f
.
type
==
str
:
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
)
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
...
...
tests/common/test_common_catalog.py
View file @
cc619975
...
@@ -22,5 +22,8 @@ class CommonCatalogTestCase(unittest.TestCase):
...
@@ -22,5 +22,8 @@ class CommonCatalogTestCase(unittest.TestCase):
obstime
=
-
1
,
obstime
=
-
1
,
limit
=
2
limit
=
2
)
)
dt
=
self
.
api
.
to_table
(
result
)
df
=
dt
.
to_pandas
()
print
(
df
.
head
())
print
(
'used:'
,
time
.
time
()
-
t
)
print
(
'used:'
,
time
.
time
()
-
t
)
print
(
'return:'
,
result
)
print
(
'return:'
,
result
)
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