Skip to content
GitLab
Explore
Sign in
Register
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
a7d32718
Commit
a7d32718
authored
6 years ago
by
Auke Klazema
Browse files
Options
Downloads
Patches
Plain Diff
SW-598
: Add username, password, port options to load_hba_rotations.py
parent
1f4e5a8c
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MAC/Deployment/data/Coordinates/load_hba_rotations.py
+79
-37
79 additions, 37 deletions
MAC/Deployment/data/Coordinates/load_hba_rotations.py
with
79 additions
and
37 deletions
MAC/Deployment/data/Coordinates/load_hba_rotations.py
+
79
−
37
View file @
a7d32718
#!/usr/bin/env python
#coding: iso-8859-15
import
re
,
sys
,
pgdb
,
pg
from
math
import
*
from
database
import
*
# coding: iso-8859-15
import
sys
import
pgdb
import
pg
from
math
import
pi
from
optparse
import
OptionParser
import
getpass
# get info from database.py
dbName
=
getDBname
()
dbHost
=
getDBhost
()
db1
=
pgdb
.
connect
(
user
=
"
postgres
"
,
host
=
dbHost
,
database
=
dbName
)
cursor
=
db1
.
cursor
()
# calling stored procedures only works from the pg module for some reason.
db2
=
pg
.
connect
(
user
=
"
postgres
"
,
host
=
dbHost
,
dbname
=
dbName
)
#
# getRotationLines
#
def
get
R
otation
L
ines
(
filename
):
def
get
_r
otation
_l
ines
(
filename
):
"""
Returns a list containing all lines with rotations
"""
f
=
open
(
filename
,
'
r
'
)
f
=
open
(
filename
,
'
r
'
)
lines
=
f
.
readlines
()
f
.
close
()
return
[
line
.
strip
().
split
(
'
,
'
)
for
line
in
lines
[
1
:]]
return
[
line
.
strip
().
split
(
'
,
'
)
for
line
in
lines
[
1
:]]
##
def
get
R
otation
(
line
):
def
get
_r
otation
(
line
):
hba0
=
hba1
=
None
station
=
str
(
line
[
0
]).
upper
()
if
line
[
1
]
!=
''
:
hba0
=
(
int
(
line
[
1
])
/
360.
)
*
2.
*
pi
if
line
[
2
]
!=
''
:
hba1
=
(
int
(
line
[
2
])
/
360.
)
*
2.
*
pi
return
(
station
,
hba0
,
hba1
)
return
(
station
,
hba0
,
hba1
)
#
# MAIN
#
if
__name__
==
'
__main__
'
:
parser
=
OptionParser
(
"
Usage: %prog [options] datafile
"
)
parser
.
add_option
(
"
-D
"
,
"
--database
"
,
dest
=
"
dbName
"
,
type
=
"
string
"
,
default
=
"
StationCoordinates
"
,
help
=
"
Name of StationCoordinates database to use
"
)
parser
.
add_option
(
"
-H
"
,
"
--host
"
,
dest
=
"
dbHost
"
,
type
=
"
string
"
,
default
=
"
sasdb.control.lofar
"
,
help
=
"
Hostname of StationCoordinates database
"
)
parser
.
add_option
(
"
-P
"
,
"
--port
"
,
dest
=
"
dbPort
"
,
type
=
"
int
"
,
default
=
"
5432
"
,
help
=
"
Port of StationCoordinates database
"
)
parser
.
add_option
(
"
-U
"
,
"
--user
"
,
dest
=
"
dbUser
"
,
type
=
"
string
"
,
default
=
"
postgres
"
,
help
=
"
Username of StationCoordinates database
"
)
# parse arguments
(
options
,
args
)
=
parser
.
parse_args
()
# check syntax of invocation
# Expected syntax: load_measurement stationname objecttypes datafile
#
if
(
len
(
sys
.
argv
)
!=
2
):
print
"
Syntax: %s datafile
"
%
sys
.
argv
[
0
]
dbName
=
options
.
dbName
dbHost
=
options
.
dbHost
dbPort
=
options
.
dbPort
dbUser
=
options
.
dbUser
dbPassword
=
getpass
.
getpass
()
host
=
"
{}:{}
"
.
format
(
dbHost
,
dbPort
)
db1
=
pgdb
.
connect
(
user
=
dbUser
,
host
=
host
,
database
=
dbName
,
password
=
dbPassword
)
cursor
=
db1
.
cursor
()
# calling stored procedures only works from the pg module for some reason.
db2
=
pg
.
connect
(
user
=
dbUser
,
host
=
dbHost
,
dbname
=
dbName
,
port
=
dbPort
,
passwd
=
dbPassword
)
# print sys.argv
if
len
(
args
)
!=
1
:
parser
.
print_help
()
sys
.
exit
(
1
)
filename
=
str
(
sys
.
argv
[
1
])
lines
=
getRotationLines
(
filename
)
filename
=
str
(
args
[
0
])
lines
=
get_rotation_lines
(
filename
)
for
line
in
lines
:
(
stationname
,
rotation0
,
rotation1
)
=
get
R
otation
(
line
)
(
stationname
,
rotation0
,
rotation1
)
=
get
_r
otation
(
line
)
# check stationname
cursor
.
execute
(
"
select name from station
"
)
stations
=
cursor
.
fetchall
()
station
=
[]
station
.
append
(
stationname
)
if
station
not
in
stations
:
print
"
station %s is not a legal stationame
"
%
stationname
sys
.
exit
(
1
)
try
:
if
rotation1
==
None
:
db2
.
query
(
"
select * from add_field_rotation(
'
%s
'
,
'
HBA
'
,%s)
"
%
(
stationname
,
rotation0
))
print
'
station %s rotation=%f
'
%
(
stationname
,
rotation0
)
if
rotation0
!=
None
and
rotation1
!=
None
:
db2
.
query
(
"
select * from add_field_rotation(
'
%s
'
,
'
HBA0
'
,%s)
"
%
(
stationname
,
rotation0
))
db2
.
query
(
"
select * from add_field_rotation(
'
%s
'
,
'
HBA1
'
,%s)
"
%
(
stationname
,
rotation1
))
print
'
station %s rotation0=%f rotation1=%f
'
%
(
stationname
,
rotation0
,
rotation1
)
if
rotation1
is
None
:
db2
.
query
(
"
select * from add_field_rotation(
'
%s
'
,
'
HBA
'
,%s)
"
%
(
stationname
,
rotation0
))
print
'
station %s rotation=%f
'
%
(
stationname
,
rotation0
)
if
rotation0
is
not
None
and
rotation1
is
not
None
:
db2
.
query
(
"
select * from add_field_rotation(
'
%s
'
,
'
HBA0
'
,%s)
"
%
(
stationname
,
rotation0
))
db2
.
query
(
"
select * from add_field_rotation(
'
%s
'
,
'
HBA1
'
,%s)
"
%
(
stationname
,
rotation1
))
print
'
station %s rotation0=%f rotation1=%f
'
%
(
stationname
,
rotation0
,
rotation1
)
except
:
print
'
WARN, station %s has no HBA types defined yet
'
%
(
stationname
)
print
'
WARN, station %s has no HBA types defined yet
'
%
(
stationname
)
print
'
Done
'
db1
.
close
()
db2
.
close
()
...
...
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