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
68d263e0
Commit
68d263e0
authored
6 years ago
by
Auke Klazema
Browse files
Options
Downloads
Patches
Plain Diff
SW-598
: Add username, password, port options to load_rotation_matrices.py
parent
540217d3
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
MAC/Deployment/data/Coordinates/load_rotation_matrices.py
+79
-39
79 additions, 39 deletions
MAC/Deployment/data/Coordinates/load_rotation_matrices.py
with
79 additions
and
39 deletions
MAC/Deployment/data/Coordinates/load_rotation_matrices.py
+
79
−
39
View file @
68d263e0
#!/usr/bin/env python
#!/usr/bin/env python
#coding: iso-8859-15
# coding: iso-8859-15
import
re
,
sys
,
pgdb
,
pg
import
sys
import
numpy
as
np
import
pgdb
from
math
import
*
import
pg
from
database
import
*
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
# getRotationLines
#
#
def
get
R
otation
L
ines
(
filename
):
def
get
_r
otation
_l
ines
(
filename
):
"""
"""
Returns a list containing all lines with rotations
Returns a list containing all lines with rotations
"""
"""
f
=
open
(
filename
,
'
r
'
)
f
=
open
(
filename
,
'
r
'
)
lines
=
f
.
readlines
()
lines
=
f
.
readlines
()
f
.
close
()
f
.
close
()
return
[
line
.
strip
().
split
(
'
,
'
)
for
line
in
lines
[
3
:]]
return
[
line
.
strip
().
split
(
'
,
'
)
for
line
in
lines
[
3
:]]
##
##
def
get
R
otation
M
atrix
(
line
):
def
get
_r
otation
_m
atrix
(
line
):
#print line
#
print line
station
=
str
(
line
[
0
]).
upper
().
strip
()
station
=
str
(
line
[
0
]).
upper
().
strip
()
anttype
=
str
(
line
[
1
]).
upper
().
strip
()
anttype
=
str
(
line
[
1
]).
upper
().
strip
()
# make db matrix [3][3]
# make db matrix [3][3]
matrix
=
"
ARRAY[[%f,%f,%f],[%f,%f,%f],[%f,%f,%f]]
"
%
\
matrix
=
"
ARRAY[[%f,%f,%f],[%f,%f,%f],[%f,%f,%f]]
"
%
\
(
float
(
line
[
2
]),
float
(
line
[
3
]),
float
(
line
[
4
]),
\
(
float
(
line
[
2
]),
float
(
line
[
3
]),
float
(
line
[
4
]),
float
(
line
[
5
]),
float
(
line
[
6
]),
float
(
line
[
7
]),
\
float
(
line
[
5
]),
float
(
line
[
6
]),
float
(
line
[
7
]),
float
(
line
[
8
]),
float
(
line
[
9
]),
float
(
line
[
10
]))
float
(
line
[
8
]),
float
(
line
[
9
]),
float
(
line
[
10
]))
return
(
station
,
anttype
,
matrix
)
return
(
station
,
anttype
,
matrix
)
#
#
# MAIN
# MAIN
#
#
if
__name__
==
'
__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
()
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
)
# check syntax of invocation
# check syntax of invocation
# Expected syntax: load_measurement stationname objecttypes datafile
# Expected syntax: load_measurement stationname objecttypes datafile
#
#
if
(
len
(
sys
.
argv
)
!=
2
):
filename
=
str
(
args
[
0
])
print
"
Syntax: %s datafile
"
%
sys
.
argv
[
0
]
sys
.
exit
(
1
)
# filename = 'rotation-matrices/rotation_matrices.dat'
filename
=
str
(
sys
.
argv
[
1
])
#filename = 'rotation-matrices/rotation_matrices.dat'
lines
=
get_rotation_lines
(
filename
)
lines
=
getRotationLines
(
filename
)
for
line
in
lines
:
for
line
in
lines
:
(
stationname
,
anttype
,
matrix
)
=
getRotationMatrix
(
line
)
(
stationname
,
anttype
,
matrix
)
=
get_rotation_matrix
(
line
)
if
stationname
==
'
CS001
'
:
print
stationname
,
'
'
,
anttype
,
'
'
,
matrix
[
0
]
if
stationname
==
'
CS001
'
:
print
stationname
,
'
'
,
anttype
,
'
'
,
matrix
[
0
]
# check stationname
# check stationname
cursor
.
execute
(
"
select name from station
"
)
cursor
.
execute
(
"
select name from station
"
)
stations
=
cursor
.
fetchall
()
stations
=
cursor
.
fetchall
()
station
=
[]
station
=
[]
station
.
append
(
stationname
)
station
.
append
(
stationname
)
if
station
not
in
stations
:
if
station
not
in
stations
:
print
"
station %s is not a legal stationame
"
%
stationname
print
"
station %s is not a legal stationame
"
%
stationname
sys
.
exit
(
1
)
sys
.
exit
(
1
)
try
:
try
:
db2
.
query
(
"
select * from add_rotation_matrix(
'
%s
'
,
'
%s
'
,%s)
"
%
(
stationname
,
anttype
,
matrix
))
db2
.
query
(
"
select * from add_rotation_matrix(
'
%s
'
,
'
%s
'
,%s)
"
%
(
stationname
,
anttype
,
matrix
))
print
stationname
,
'
'
,
anttype
,
'
'
,
matrix
print
stationname
,
'
'
,
anttype
,
'
'
,
matrix
except
:
except
:
print
'
ERR, station=%s has no types defined
'
%
(
stationname
)
print
'
ERR, station=%s has no types defined
'
%
(
stationname
)
print
'
Done
'
print
'
Done
'
db1
.
close
()
db1
.
close
()
db2
.
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