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-commons
Commits
71125392
Commit
71125392
authored
Apr 17, 2024
by
Wei Shoulin
Browse files
C9
parent
a64fbab9
Changes
1
Show whitespace changes
Inline
Side-by-side
csst_dfs_commons/utils/fits.py
View file @
71125392
...
@@ -48,24 +48,39 @@ def get_raw_header(filepath, **keys):
...
@@ -48,24 +48,39 @@ def get_raw_header(filepath, **keys):
return
union
return
union
def
heapix_sql_condition
(
ra
,
dec
,
radius
,
ra_col
=
'ra'
,
dec_col
=
'dec'
,
nside
=
DEFAULT_NSIDE
):
def
heapix_sql_condition
(
ra
,
dec
,
radius
,
ra_col
=
'ra'
,
dec_col
=
'dec'
,
nside
=
DEFAULT_NSIDE
):
"""
生成用于筛选特定天区范围内数据的SQL条件语句(大圆公式)。
Args:
ra (float): 天区中心的赤经值,单位为度。
dec (float): 天区中心的赤纬值,单位为度。
radius (float): 天区的半径,单位为度。
ra_col (str, optional): 数据表中赤经值的列名,默认为'ra'。
dec_col (str, optional): 数据表中赤纬值的列名,默认为'dec'。
nside (int, optional): Healpix像素化的nside参数,默认为DEFAULT_NSIDE。
Returns:
str: 用于筛选特定天区范围内数据的SQL条件语句。
"""
arcDec
=
(
PI
/
180
)
*
dec
arcDec
=
(
PI
/
180
)
*
dec
whereSql
=
f
"abs((180./
{
PI
}
) * ACOS(SIN(
{
PI
}
*
{
dec_col
}
/180) * SIN(
{
arcDec
}
) + COS(
{
PI
}
*
{
dec_col
}
/180) * COS(
{
arcDec
}
) * COS(
(
{
PI
}
/180)
* (
{
ra_col
}
-
{
ra
}
)))) <
{
radius
}
"
whereSql
=
f
"abs((180./
pi()
) * ACOS(SIN(
pi()
*
{
dec_col
}
/180) * SIN(
{
arcDec
}
) + COS(
pi()
*
{
dec_col
}
/180) * COS(
{
arcDec
}
) * COS(
pi()
* (
{
ra_col
}
-
{
ra
}
)
/180
))) <
{
radius
}
"
heapix_ids
=
get_healpix_ids
(
ra
,
dec
,
radius
,
nside
)
heapix_ids
=
get_healpix_ids
(
ra
,
dec
,
radius
,
nside
)
nside_column
=
"NS%dHIdx"
%
(
nside
,)
nside_column
=
"NS%dHIdx"
%
(
nside
,)
whereZoneSql
=
"%s in (%s)"
%
\
whereZoneSql
=
"%s in (%s)"
%
\
(
nside_column
,
','
.
join
([
str
(
i
)
for
i
in
heapix_ids
]))
(
nside_column
,
','
.
join
([
str
(
i
)
for
i
in
heapix_ids
]))
return
where
ZoneSql
,
whereSql
return
f
"
{
where
Sql
}
and
{
where
Zone
Sql
}
"
def
catalog_heapix_sql_condition
(
ra
,
dec
,
radius
,
ra_col
=
'ra'
,
dec_col
=
'dec'
,
nside
=
DEFAULT_NSIDE
):
def
catalog_heapix_sql_condition
(
ra
,
dec
,
radius
,
ra_col
=
'ra'
,
dec_col
=
'dec'
,
nside
=
DEFAULT_NSIDE
):
x2
=
f
"cos(
{
dec_col
}
)*cos(
{
ra_col
}
)"
x2
=
f
"cos(
pi()*
{
dec_col
}
/180.0
)*cos(
pi()*
{
ra_col
}
/180.0
)"
y2
=
f
"cos(
{
dec_col
}
)*sin(
{
ra_col
}
)"
y2
=
f
"cos(
pi()*
{
dec_col
}
/180.0
)*sin(
pi()*
{
ra_col
}
/180.0
)"
z2
=
f
"sin(
{
dec_col
}
)"
z2
=
f
"sin(
pi()*
{
dec_col
}
/180.0
)"
x1
=
f
"cos(
{
dec
}
)*cos(
{
ra
}
)"
x1
=
f
"cos(
pi()*
{
dec
}
/180.0)*cos(pi()*
{
ra
}
/180.0
)"
y1
=
f
"cos(
{
dec
}
)*sin(
{
ra
}
)"
y1
=
f
"cos(
pi()*
{
dec
}
/180.0)*sin(pi()*
{
ra
}
/180.0
)"
z1
=
f
"sin(
{
dec
}
)"
z1
=
f
"sin(
pi()*
{
dec
}
/180.0
)"
distance
=
f
"pow((
{
x2
}
-
{
x1
}
),2)+pow((
{
y2
}
-
{
y1
}
),2)+pow((
{
z2
}
-
{
z1
}
),2)"
distance
=
f
"pow((
{
x2
}
-
{
x1
}
),2)+pow((
{
y2
}
-
{
y1
}
),2)+pow((
{
z2
}
-
{
z1
}
),2)"
...
@@ -73,18 +88,18 @@ def catalog_heapix_sql_condition(ra, dec, radius, ra_col = 'ra', dec_col = 'dec'
...
@@ -73,18 +88,18 @@ def catalog_heapix_sql_condition(ra, dec, radius, ra_col = 'ra', dec_col = 'dec'
nside_column
=
"NS%dHIdx"
%
(
nside
,)
nside_column
=
"NS%dHIdx"
%
(
nside
,)
whereZoneSql
=
"%s in (%s)"
%
\
whereZoneSql
=
"%s in (%s)"
%
\
(
nside_column
,
','
.
join
([
str
(
i
)
for
i
in
heapix_ids
]))
(
nside_column
,
','
.
join
([
str
(
i
)
for
i
in
heapix_ids
]))
whereSql
=
f
"
{
distance
}
<= 4*pow(
{
radius
}
/2, 2) and
{
whereZoneSql
}
"
whereSql
=
f
"
{
distance
}
<= 4*pow(
pi()*
{
radius
}
/
180.0/
2, 2) and
{
whereZoneSql
}
"
return
whereSql
return
whereSql
def
level2_heapix_sql_condition
(
ra
,
dec
,
radius
,
ra_col
=
'ra'
,
dec_col
=
'dec'
,
nside
=
DEFAULT_NSIDE
):
def
level2_heapix_sql_condition
(
ra
,
dec
,
radius
,
ra_col
=
'ra'
,
dec_col
=
'dec'
,
nside
=
DEFAULT_NSIDE
):
x2
=
f
"cos(
{
dec_col
}
)*cos(
{
ra_col
}
)"
x2
=
f
"cos(
pi()*
{
dec_col
}
/180.0
)*cos(
pi()*
{
ra_col
}
/180.0
)"
y2
=
f
"cos(
{
dec_col
}
)*sin(
{
ra_col
}
)"
y2
=
f
"cos(
pi()*
{
dec_col
}
/180.0
)*sin(
pi()*
{
ra_col
}
/180.0
)"
z2
=
f
"sin(
{
dec_col
}
)"
z2
=
f
"sin(
pi()*
{
dec_col
}
/180.0
)"
x1
=
f
"cos(
{
dec
}
)*cos(
{
ra
}
)"
x1
=
f
"cos(
pi()*
{
dec
}
/180.0)*cos(pi()*
{
ra
}
/180.0
)"
y1
=
f
"cos(
{
dec
}
)*sin(
{
ra
}
)"
y1
=
f
"cos(
pi()*
{
dec
}
/180.0)*sin(pi()*
{
ra
}
/180.0
)"
z1
=
f
"sin(
{
dec
}
)"
z1
=
f
"sin(
pi()*
{
dec
}
/180.0
)"
distance
=
f
"pow((
{
x2
}
-
{
x1
}
),2)+pow((
{
y2
}
-
{
y1
}
),2)+pow((
{
z2
}
-
{
z1
}
),2)"
distance
=
f
"pow((
{
x2
}
-
{
x1
}
),2)+pow((
{
y2
}
-
{
y1
}
),2)+pow((
{
z2
}
-
{
z1
}
),2)"
...
@@ -93,6 +108,6 @@ def level2_heapix_sql_condition(ra, dec, radius, ra_col = 'ra', dec_col = 'dec',
...
@@ -93,6 +108,6 @@ def level2_heapix_sql_condition(ra, dec, radius, ra_col = 'ra', dec_col = 'dec',
whereZoneSql
=
"%s in (%s)"
%
\
whereZoneSql
=
"%s in (%s)"
%
\
(
nside_column
,
','
.
join
([
str
(
i
)
for
i
in
heapix_ids
]))
(
nside_column
,
','
.
join
([
str
(
i
)
for
i
in
heapix_ids
]))
whereSql
=
f
"
{
distance
}
<= 4*pow(
{
radius
}
/2, 2) and
{
whereZoneSql
}
"
whereSql
=
f
"
{
distance
}
<= 4*pow(
pi()*
{
radius
}
/
180.0/
2, 2) and
{
whereZoneSql
}
"
return
whereSql
return
whereSql
\ 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