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
f32eb766
Commit
f32eb766
authored
5 years ago
by
Mattia Mancini
Browse files
Options
Downloads
Patches
Plain Diff
SSB-47
: implemented storing function for calibration table
parent
1b1d363a
No related branches found
No related tags found
1 merge request
!44
Merge back holography to master
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
CAL/CalibrationCommon/lib/datacontainers/calibration_table.py
+16
-18
16 additions, 18 deletions
...CalibrationCommon/lib/datacontainers/calibration_table.py
with
16 additions
and
18 deletions
CAL/CalibrationCommon/lib/datacontainers/calibration_table.py
+
16
−
18
View file @
f32eb766
import
logging
from
datetime
import
datetime
from
re
import
fullmatch
from
struct
import
iter_unpack
from
struct
import
iter_unpack
,
pack
from
typing
import
BinaryIO
from
typing
import
List
...
...
@@ -12,7 +12,10 @@ logger = logging.getLogger(__name__)
__MAX_HEADER_LINES
=
100
__HEADER_LINE_PATTERN
=
'
(^[A-z]*\.[A-z]*\.[A-z]*\s=\s.*$)|(^[A-z]*\.[A-z]*\s=\s.*$)
'
__FREQUENCIES
=
512
__FLOATS_PER_FREQUENCY
=
2
__N_ANTENNAS_DUTCH
=
96
__N_ANTENNAS_INTERNATIONAL
=
192
_ATTRIBUTE_NAME_TO_SERIALIZED_NAME
=
{
'
observation_station
'
:
'
CalTableHeader.Observation.Station
'
,
'
observation_mode
'
:
'
CalTableHeader.Observation.Mode
'
,
...
...
@@ -50,19 +53,13 @@ def _extract_header(fstream: BinaryIO):
value
=
value
.
strip
()
header
[
key
]
=
value
else
:
logger
.
error
(
'
unrecognized line
%s
'
,
line
)
raise
UnvalidFileException
(
'
unrecognized line
%s
'
%
line
)
logger
.
error
(
'
unrecognized line
\"
%s
\"
'
,
line
)
raise
UnvalidFileException
(
'
unrecognized line
\"
%s
\"
'
%
line
)
if
len
(
header
)
==
0
:
raise
UnvalidFileException
(
'
empty header
'
)
return
header
__FREQUENCIES
=
512
__FLOATS_PER_FREQUENCY
=
2
__N_ANTENNAS_DUTCH
=
96
__N_ANTENNAS_INTERNATIONAL
=
192
def
parse_data
(
data_buffer
):
data
=
array_from_iter
(
map
(
lambda
x
:
x
[
0
],
iter_unpack
(
'
d
'
,
data_buffer
)),
dtype
=
float
)
n_antennas
=
data
.
shape
[
0
]
//
__FREQUENCIES
//
__FLOATS_PER_FREQUENCY
...
...
@@ -108,7 +105,7 @@ class CalibrationTable:
return
calibration_table
def
__serialize_header
(
self
,
f_stream
:
BinaryIO
):
f_stream
.
write
(
b
'
HeaderStart
'
)
f_stream
.
write
(
b
'
HeaderStart
\n
'
)
for
key
,
value
in
asdict
(
self
).
items
():
if
key
is
'
data
'
:
...
...
@@ -118,17 +115,18 @@ class CalibrationTable:
serialized_line
=
'
{} = {}
\n
'
.
format
(
serialized_name
,
value
).
encode
(
'
utf8
'
)
f_stream
.
write
(
serialized_line
)
f_stream
.
write
(
b
'
HeaderStop
'
)
f_stream
.
write
(
b
'
HeaderStop
\n
'
)
def
__serialize_data
(
self
,
f_stream
:
BinaryIO
):
dimensions
=
list
(
self
.
data
.
shape
)
+
[
2
]
data_
flatten
=
empty_ndarray
(
dimensions
,
dtype
=
float64
)
data_
flatten
[:,
:,
0
]
=
self
.
data
.
real
data_
flatten
[:,
:,
1
]
=
self
.
data
.
imag
data_flattened
=
data_
flatten
.
flatten
()
.
tolist
()
f_stream
.
write
(
)
data_
reshaped
=
empty_ndarray
(
dimensions
,
dtype
=
float64
)
data_
reshaped
[:,
:,
0
]
=
self
.
data
.
real
data_
reshaped
[:,
:,
1
]
=
self
.
data
.
imag
data_flattened
=
data_
reshaped
.
flatten
()
data_packed
=
pack
(
'
%sd
'
%
len
(
data_flattened
),
*
data_flattened
)
f_stream
.
write
(
data_packed
)
def
store_to_file
(
self
,
file_path
):
with
open
(
file_path
,
'
wb
'
)
as
file_stream
:
self
.
__serialize_header
(
file_stream
)
self
.
__serialize_data
(
file_stream
)
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