Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LOFAR
Manage
Activity
Members
Labels
Plan
Issues
Wiki
Jira issues
Open Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
RadioObservatory
LOFAR
Commits
7ca276f9
Commit
7ca276f9
authored
14 years ago
by
Ger van Diepen
Browse files
Options
Downloads
Patches
Plain Diff
bug 1634: Added improvements
parent
c9af7931
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CEP/pyparmdb/src/gsm.py
+26
-22
26 additions, 22 deletions
CEP/pyparmdb/src/gsm.py
with
26 additions
and
22 deletions
CEP/pyparmdb/src/gsm.py
+
26
−
22
View file @
7ca276f9
#!/usr/bin/env python
#!/usr/bin/env python
import
sys
# Select a subset from the GSM and write into a makesourcdb input file.
# ra and dec both in degrees
# ra and dec both in degrees
# integrated flux [in Jy] above which the sources will be selected
# integrated flux [in Jy] above which the sources will be selected
# You should know that:
# You should know that:
# cat_id = 3 => NVSS
# cat_id = 3 => NVSS
# cat_id = 4 => VLSS
# cat_id = 4 => VLSS
# cat_id = 5 => WENSS
# cat_id = 5 => WENSS
def
gsmSelect
(
outfile
,
ra_st
,
ra_end
,
dec_
min
,
dec_
max
,
fluxi_min
,
cat_ids
):
def
gsmSelect
(
outfile
,
ra_st
,
ra_end
,
dec_
st
,
dec_
end
,
fluxi_min
,
cat_ids
):
import
os
,
errno
import
os
import
monetdb.sql
as
db
import
monetdb.sql
as
db
from
monetdb.sql
import
Error
as
Error
from
monetdb.sql
import
Error
as
Error
import
logging
db_type
=
"
MonetDB
"
db_type
=
"
MonetDB
"
db_host
=
"
ldb001
"
db_host
=
"
ldb001
"
...
@@ -23,10 +21,14 @@ def gsmSelect (outfile, ra_st, ra_end, dec_min, dec_max, fluxi_min, cat_ids):
...
@@ -23,10 +21,14 @@ def gsmSelect (outfile, ra_st, ra_end, dec_min, dec_max, fluxi_min, cat_ids):
db_passwd
=
"
msss
"
db_passwd
=
"
msss
"
#db_lang = "sql"
#db_lang = "sql"
# If RA crosses 360 degrees, split in two parts.
if
(
ra_st
<=
ra_end
):
if
(
ra_st
<=
ra_end
):
ra_where
=
'
c1.ra BETWEEN %f AND %f
'
%
(
ra_st
,
ra_end
)
ra_where
=
'
c1.ra BETWEEN %f AND %f
'
%
(
ra_st
,
ra_end
)
else
:
else
:
ra_where
=
'
(c1.ra BETWEEN %f AND 360 OR c1.ra BETWEEN 0 AND %f)
'
%
(
ra_st
,
ra_end
)
ra_where
=
'
(c1.ra BETWEEN %f AND 360 OR c1.ra BETWEEN 0 AND %f)
'
%
(
ra_st
,
ra_end
)
# IN clause needs (), not [].
cat_where
=
str
(
cat_ids
)[
1
:
-
1
]
where
=
'
WHERE c1.cat_id IN (%s) AND %s AND c1.decl BETWEEN %f AND %f AND c1.i_int_avg >= %f
'
%
(
cat_where
,
ra_where
,
dec_st
,
dec_end
,
fluxi_min
)
conn
=
db
.
connect
(
hostname
=
db_host
\
conn
=
db
.
connect
(
hostname
=
db_host
\
,
port
=
db_port
\
,
port
=
db_port
\
...
@@ -113,26 +115,25 @@ def gsmSelect (outfile, ra_st, ra_end, dec_min, dec_max, fluxi_min, cat_ids):
...
@@ -113,26 +115,25 @@ def gsmSelect (outfile, ra_st, ra_end, dec_min, dec_max, fluxi_min, cat_ids):
"
END AS SpectralIndex_1
"
+
\
"
END AS SpectralIndex_1
"
+
\
"
FROM catalogedsources c1
"
+
\
"
FROM catalogedsources c1
"
+
\
"
LEFT OUTER JOIN spectralindices si ON c1.catsrcid = si.catsrc_id
"
+
\
"
LEFT OUTER JOIN spectralindices si ON c1.catsrcid = si.catsrc_id
"
+
\
"
WHERE c1.cat_id IN %s
"
+
\
where
+
"
AND %s
"
+
\
"
AND c1.decl BETWEEN %f AND %f
"
+
\
"
AND c1.i_int_avg > %f
"
+
\
"
) t0
"
+
\
"
) t0
"
+
\
"
) t
"
,
(
str
(
cat_ids
),
ra_where
,
decl_min
,
decl_max
,
fluxi_min
))
"
) t
"
,
())
y
=
cursor
.
fetchall
()
y
=
cursor
.
fetchall
()
cursor
.
close
()
cursor
.
close
()
#print "y:", y
#print "y:", y
except
db
.
Error
,
e
:
except
db
.
Error
,
e
:
import
logging
logging
.
warn
(
"
writeBBSFile %s failed
"
%
(
outfile
))
logging
.
warn
(
"
writeBBSFile %s failed
"
%
(
outfile
))
logging
.
warn
(
"
Failed on query in writeBBSFile() for reason: %s
"
%
(
e
))
logging
.
warn
(
"
Failed on query in writeBBSFile() for reason: %s
"
%
(
e
))
logging
.
debug
(
"
Failed writeBBSFile() select query: %s
"
%
(
e
))
logging
.
debug
(
"
Failed writeBBSFile() select query: %s
"
%
(
e
))
return
False
file
=
open
(
outfile
,
'
w
'
)
file
=
open
(
outfile
,
'
w
'
)
for
i
in
range
(
len
(
y
)):
for
i
in
range
(
len
(
y
)):
file
.
write
(
y
[
i
][
0
]
+
'
\n
'
)
file
.
write
(
y
[
i
][
0
]
+
'
\n
'
)
file
.
close
()
file
.
close
()
print
"
BBS File written in:
"
,
outfil
e
return
Tru
e
def
gsmMain
(
name
,
argv
):
def
gsmMain
(
name
,
argv
):
...
@@ -155,7 +156,7 @@ def gsmMain (name, argv):
...
@@ -155,7 +156,7 @@ def gsmMain (name, argv):
print
'
(NVSS, VLSS, and/or WENSS)
'
print
'
(NVSS, VLSS, and/or WENSS)
'
print
'
If multiple, separate by commas
'
print
'
If multiple, separate by commas
'
print
'
Default is WENSS
'
print
'
Default is WENSS
'
return
0
return
False
outfile
=
argv
[
0
]
outfile
=
argv
[
0
]
stRA
=
float
(
argv
[
1
])
stRA
=
float
(
argv
[
1
])
endRA
=
float
(
argv
[
2
])
endRA
=
float
(
argv
[
2
])
...
@@ -164,14 +165,14 @@ def gsmMain (name, argv):
...
@@ -164,14 +165,14 @@ def gsmMain (name, argv):
for
ra
in
[
stRA
,
endRA
]:
for
ra
in
[
stRA
,
endRA
]:
if
ra
<
0
or
ra
>
360
:
if
ra
<
0
or
ra
>
360
:
print
'
RA
'
,
ra
,
'
is invalid: <0 or >360 degrees
'
print
'
RA
'
,
ra
,
'
is invalid: <0 or >360 degrees
'
return
1
return
False
for
dec
in
[
stDEC
,
endDEC
]:
for
dec
in
[
stDEC
,
endDEC
]:
if
dec
<
-
90
or
dec
>
90
:
if
dec
<
-
90
or
dec
>
90
:
print
'
DEC
'
,
dec
,
'
is invalid: <-90 or >90 degrees
'
print
'
DEC
'
,
dec
,
'
is invalid: <-90 or >90 degrees
'
return
1
return
False
if
stDEC
>
endDEC
:
if
stDEC
>
endDEC
:
print
'
invalid DEC: start
'
,
stDEC
,
'
> end
'
,
endDEC
print
'
invalid DEC: start
'
,
stDEC
,
'
> end
'
,
endDEC
return
1
return
False
minFlux
=
0.5
minFlux
=
0.5
if
len
(
argv
)
>
5
:
if
len
(
argv
)
>
5
:
minFlux
=
float
(
argv
[
5
])
minFlux
=
float
(
argv
[
5
])
...
@@ -192,12 +193,15 @@ def gsmMain (name, argv):
...
@@ -192,12 +193,15 @@ def gsmMain (name, argv):
cat_ids
.
append
(
5
)
cat_ids
.
append
(
5
)
else
:
else
:
print
cat
,
'
is an invalid catalog name
'
print
cat
,
'
is an invalid catalog name
'
return
1
return
False
# Do the selection and create the makesourcedb file.
# Do the selection and create the makesourcedb file.
gsmSelect
(
outfile
,
stRA
,
endRA
,
stDEC
,
endDEC
,
minFlux
,
cat_ids
)
gsmSelect
(
outfile
,
stRA
,
endRA
,
stDEC
,
endDEC
,
minFlux
,
cat_ids
)
return
0
return
True
# This is the main entry.
# This is the main entry.
if
__name__
==
"
__main__
"
:
if
__name__
==
"
__main__
"
:
sys
.
exit
(
gsmMain
(
sys
.
argv
[
0
],
sys
.
argv
[
1
:]))
import
sys
if
gsmMain
(
sys
.
argv
[
0
],
sys
.
argv
[
1
:]):
sys
.
exit
(
0
)
sys
.
exit
(
1
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
register
or
sign in
to comment