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-local
Commits
66ee8623
Commit
66ee8623
authored
Apr 15, 2021
by
Wei Shoulin
Browse files
ephem
parent
36ba9fbc
Changes
8
Show whitespace changes
Inline
Side-by-side
README.md
View file @
66ee8623
...
...
@@ -9,6 +9,9 @@ This package provides APIs to access csst's files and databases in your localize
This library can be installed with the following command:
```
bash
git clone https://github.com/astronomical-data-processing/csst-dfs-api-local.git
cd
csst-dfs-api-local
pip
install
-r
requirements.txt
python setup.py
install
```
...
...
csst_dfs_api_local/common/__init__.py
View file @
66ee8623
from
.catalog
import
CatalogApi
\ No newline at end of file
csst_dfs_api_local/common/catalog.py
View file @
66ee8623
from
urllib
import
request
import
urllib
import
json
from
csst_dfs_commons.models
import
Result
class
CatalogApi
(
object
):
def
__init__
(
self
):
self
.
data
=
[]
self
.
url
=
'http://
172.31.248.218
:30180/search/v2'
self
.
url
=
r
'http://
csst.astrolab.cn
:30180/search/v2'
def
gaia3_query
(
self
,
ra
:
float
,
dec
:
float
,
radius
:
float
,
min_mag
:
float
,
max_mag
:
float
,
obstime
:
int
,
limit
:
int
):
req
=
request
.
Request
(
url
=
self
.
url
,
method
=
"post"
)
req
.
add_header
(
'Content-Type'
,
'application/json'
)
data
=
{
"ra"
:
ra
,
"dec"
:
dec
,
"radius"
:
radius
,
"min_mag"
:
min_mag
,
"max_mag"
:
max_mag
,
"obstime"
:
obstime
,
"limit"
:
limit
}
data
=
json
.
dumps
(
data
)
data
=
data
.
encode
()
res
=
request
.
urlopen
(
req
,
data
=
data
)
content
=
res
.
read
()
print
(
content
)
return
content
\ No newline at end of file
data
=
{
"ra"
:
ra
,
"dec"
:
dec
,
"radius"
:
radius
,
"catalog_name"
:
"gaia3"
,
"min_mag"
:
min_mag
,
"max_mag"
:
max_mag
,
"obstime"
:
obstime
,
"limit"
:
limit
}
return
self
.
rest_request
(
data
)
def
rest_request
(
self
,
data
):
try
:
Headers
=
{
"Content-type"
:
"application/x-www-form-urlencoded"
}
data
=
urllib
.
parse
.
urlencode
(
data
).
encode
(
"utf-8"
)
req
=
urllib
.
request
.
Request
(
self
.
url
,
data
,
Headers
)
response
=
urllib
.
request
.
urlopen
(
req
,
timeout
=
30
)
html
=
response
.
read
().
decode
(
"utf-8"
)
resp
=
json
.
loads
(
html
)
if
resp
[
"code"
]
==
0
:
return
Result
.
ok_data
(
data
=
resp
[
"data"
]).
append
(
"totalCount"
,
resp
[
"object"
][
"totalCount"
])
else
:
return
Result
.
error
(
message
=
resp
.
message
)
except
Exception
as
e
:
return
Result
.
error
(
message
=
repr
(
e
))
\ No newline at end of file
csst_dfs_api_local/ifs/fits.py
View file @
66ee8623
...
...
@@ -12,6 +12,7 @@ from astropy.io import fits
from
..common.db
import
DBClient
from
..common.utils
import
*
from
csst_dfs_commons.models
import
Result
log
=
logging
.
getLogger
(
'csst'
)
class
FitsApi
(
object
):
...
...
@@ -36,9 +37,10 @@ class FitsApi(object):
exp_time = (start, end),
ccd_num = [int],
qc0_status = [int],
prc_status = [int]
prc_status = [int],
limit: limits returns the number of records
return
list of raw records
return
: csst_dfs_common.models.Result
'''
paths
=
[]
...
...
@@ -48,6 +50,10 @@ class FitsApi(object):
ccd_num
=
get_parameter
(
kwargs
,
"ccd_num"
)
qc0_status
=
get_parameter
(
kwargs
,
"qc0_status"
)
prc_status
=
get_parameter
(
kwargs
,
"prc_status"
)
limit
=
get_parameter
(
kwargs
,
"limit"
,
0
)
limit
=
to_int
(
limit
,
0
)
try
:
sql
=
[]
...
...
@@ -56,20 +62,28 @@ class FitsApi(object):
if
exp_time
[
0
]
is
not
None
:
sql
.
append
(
" and exp_time>='"
+
exp_time
[
0
]
+
"'"
)
if
obs_time
is
not
None
:
sql
.
append
(
" and obs_time="
+
obs_time
)
sql
.
append
(
" and obs_time="
+
repr
(
obs_time
)
)
if
ccd_num
is
not
None
:
sql
.
append
(
" and ccd_num="
+
ccd_num
)
sql
.
append
(
" and ccd_num="
+
repr
(
ccd_num
)
)
if
qc0_status
is
not
None
:
sql
.
append
(
" and qc0_status="
+
qc0_status
)
sql
.
append
(
" and qc0_status="
+
repr
(
qc0_status
)
)
if
prc_status
is
not
None
:
sql
.
append
(
" and prc_status="
+
prc_status
)
sql
.
append
(
" and prc_status="
+
repr
(
prc_status
))
if
limit
>
0
:
sql
.
append
(
f
" limit
{
limit
}
"
)
if
file_name
:
sql
=
[
"select * from ifs_rawfits where filename='"
+
file_name
+
"'"
]
totalCount
=
self
.
db
.
select_one
(
""
.
join
(
sql
).
replace
(
"select * from"
,
"select count(*) as v from"
))
_
,
recs
=
self
.
db
.
select_many
(
""
.
join
(
sql
))
for
r
in
recs
:
r
[
'file_path'
]
=
os
.
path
.
join
(
self
.
root_dir
,
r
[
'file_path'
])
return
recs
return
Result
.
ok_data
(
data
=
recs
).
append
(
"totalCount"
,
totalCount
[
'v'
])
except
Exception
as
e
:
return
Result
.
error
(
message
=
e
.
message
)
def
get
(
self
,
**
kwargs
):
'''
...
...
@@ -78,12 +92,15 @@ class FitsApi(object):
return dict or None
'''
try
:
fits_id
=
get_parameter
(
kwargs
,
"fits_id"
,
-
1
)
r
=
self
.
db
.
select_one
(
"select * from ifs_rawfits where id=?"
,
(
fits_id
,))
if
r
:
r
[
'file_path'
]
=
os
.
path
.
join
(
self
.
root_dir
,
r
[
'file_path'
])
return
r
return
Result
.
ok_data
(
data
=
r
)
except
Exception
as
e
:
return
Result
.
error
(
message
=
e
.
message
)
def
read
(
self
,
**
kwargs
):
'''
...
...
csst_dfs_api_local/ifs/reffits.py
View file @
66ee8623
...
...
@@ -56,13 +56,13 @@ class RefFitsApi(object):
if
exp_time
[
0
]
is
not
None
:
sql
.
append
(
" and exp_time>='"
+
exp_time
[
0
]
+
"'"
)
if
obs_time
is
not
None
:
sql
.
append
(
" and obs_time="
+
obs_time
)
sql
.
append
(
" and obs_time="
+
repr
(
obs_time
)
)
if
ccd_num
is
not
None
:
sql
.
append
(
" and ccd_num="
+
ccd_num
)
sql
.
append
(
" and ccd_num="
+
repr
(
ccd_num
)
)
if
ref_type
is
not
None
:
sql
.
append
(
" and ref_type='"
+
ref_type
+
"'"
)
if
status
is
not
None
:
sql
.
append
(
" and status="
+
status
)
sql
.
append
(
" and status="
+
repr
(
status
)
)
if
file_name
:
sql
=
[
"select * from ifs_ref_fits where filename='"
+
file_name
+
"'"
]
...
...
requirements.txt
View file @
66ee8623
DBUtils
==1.3
astropy
>=4.0
git+https://github.com/astronomical-data-processing/csst-dfs-commons.git
\ No newline at end of file
setup.cfg
View file @
66ee8623
tests/test_common_catalog.py
View file @
66ee8623
...
...
@@ -10,5 +10,5 @@ class CommonEphemTestCase(unittest.TestCase):
self
.
api
=
CatalogApi
()
def
test_gaia3_query
(
self
):
recs
=
self
.
api
.
gaia3_query
(
ra
=
260
,
dec
=-
27
,
radius
=
0.01
,
min_mag
=-
1
,
max_mag
=-
1
,
obstime
=-
1
,
limit
=
2
)
print
(
'find:'
,
recs
)
\ No newline at end of file
result
=
self
.
api
.
gaia3_query
(
ra
=
56.234
,
dec
=
14.4665
,
radius
=
1
,
min_mag
=-
1
,
max_mag
=-
1
,
obstime
=-
1
,
limit
=
2
)
print
(
'return:'
,
result
)
\ 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