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
3f82a5fe
Commit
3f82a5fe
authored
13 years ago
by
Wouter Klijn
Browse files
Options
Downloads
Patches
Plain Diff
Task #3139: Helperclass WritableParmDB.py added with implementation
parent
ab0a060c
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
CEP/Pipeline/recipes/sip/helpers/WritableParmDB.py
+58
-0
58 additions, 0 deletions
CEP/Pipeline/recipes/sip/helpers/WritableParmDB.py
with
58 additions
and
0 deletions
CEP/Pipeline/recipes/sip/helpers/WritableParmDB.py
+
58
−
0
View file @
3f82a5fe
from
__future__
import
with_statement
from
lofar.parmdb
import
parmdb
from
argparse
import
ArgumentTypeError
def
list_stations
(
parmdb
,
pattern
=
''
):
"""
Get a sorted list of all the station names, without prepending polarisation
Information,
Can be called with a path or an instantiated parmdb
"""
# validate input
if
isinstance
(
parmdb
,
basestring
):
# create a WritableParmDB
parmdb
=
WritableParmDB
(
parmdb
)
elif
not
isinstance
(
parmdb
,
WritableParmDB
):
raise
ArgumentTypeError
(
"
list_stations can only be called with a string or an
"
"
instantiated WritableParmDB
"
)
raw_name_list
=
parmdb
.
getNames
(
parmnamepattern
=
pattern
)
# The names are 'complex' split at the :
# and get the last index of the split. use set so they are unique.
# return the sorted list
return
sorted
(
set
(
name
.
split
(
"
:
"
)[
-
1
]
for
name
in
raw_name_list
))
class
WritableParmDB
(
parmdb
):
def
__init__
(
self
,
name
):
super
(
WritableParmDB
,
self
).
__init__
(
name
)
self
.
name
=
name
def
setValues
(
self
,
name
,
values
,
start_freq
,
freqstep
,
start_time
,
timestep
):
"""
Write values to the ParmDB.
Note that values should be a two dimenstional array with the first
index corresponding to time and the second to time (this is the same
as returned by ParmDB.getValues()).
Arguments:
name -- Parameter name to write.
values -- NumPy array of values to write.
start_freq -- Frequency at centre of first bin (Hz).
freqstep -- Bin-to-bin frequency increment (Hz).
start_time -- Time at centre of first bin (MJD in seconds).
timestep -- Bin-to-bin time increment (s).
Version 1.0: usage of direct parmdb calls instead of subprocess and
an executable
"""
# Get the number of steps, both in time and freq
time_steps
,
freq_steps
=
values
.
shape
# remove the old entry
self
.
deleteValues
(
name
)
self
.
addValues
(
name
,
values
,
start_freq
,
start_freq
+
freqstep
*
freq_steps
,
start_time
,
start_time
+
timestep
*
time_steps
,
False
)
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