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
74748c4e
Commit
74748c4e
authored
5 years ago
by
Mattia Mancini
Browse files
Options
Downloads
Patches
Plain Diff
SSB-47
: implemented storing in hdf5 file
parent
f32eb766
No related branches found
No related tags found
1 merge request
!44
Merge back holography to master
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
CAL/CalibrationCommon/lib/datacontainers/calibration_table.py
+10
-1
10 additions, 1 deletion
...CalibrationCommon/lib/datacontainers/calibration_table.py
CAL/CalibrationCommon/test/t_calibration_table.py
+20
-1
20 additions, 1 deletion
CAL/CalibrationCommon/test/t_calibration_table.py
with
30 additions
and
2 deletions
CAL/CalibrationCommon/lib/datacontainers/calibration_table.py
+
10
−
1
View file @
74748c4e
...
@@ -4,7 +4,7 @@ from re import fullmatch
...
@@ -4,7 +4,7 @@ from re import fullmatch
from
struct
import
iter_unpack
,
pack
from
struct
import
iter_unpack
,
pack
from
typing
import
BinaryIO
from
typing
import
BinaryIO
from
typing
import
List
from
typing
import
List
from
h5py
import
File
from
dataclasses
import
dataclass
,
asdict
from
dataclasses
import
dataclass
,
asdict
from
numpy
import
empty
as
empty_ndarray
,
ndarray
,
fromiter
as
array_from_iter
,
float64
from
numpy
import
empty
as
empty_ndarray
,
ndarray
,
fromiter
as
array_from_iter
,
float64
...
@@ -126,6 +126,15 @@ class CalibrationTable:
...
@@ -126,6 +126,15 @@ class CalibrationTable:
data_packed
=
pack
(
'
%sd
'
%
len
(
data_flattened
),
*
data_flattened
)
data_packed
=
pack
(
'
%sd
'
%
len
(
data_flattened
),
*
data_flattened
)
f_stream
.
write
(
data_packed
)
f_stream
.
write
(
data_packed
)
def
store_to_hdf
(
self
,
file_descriptor
:
File
,
uri
:
str
):
if
uri
not
in
file_descriptor
:
file_descriptor
[
uri
]
=
self
.
data
for
key
,
value
in
asdict
(
self
).
items
():
if
key
is
'
data
'
:
continue
file_descriptor
[
uri
].
attrs
[
key
]
=
value
file_descriptor
.
flush
()
def
store_to_file
(
self
,
file_path
):
def
store_to_file
(
self
,
file_path
):
with
open
(
file_path
,
'
wb
'
)
as
file_stream
:
with
open
(
file_path
,
'
wb
'
)
as
file_stream
:
self
.
__serialize_header
(
file_stream
)
self
.
__serialize_header
(
file_stream
)
...
...
This diff is collapsed.
Click to expand it.
CAL/CalibrationCommon/test/t_calibration_table.py
+
20
−
1
View file @
74748c4e
import
unittest
import
unittest
from
lofar.calibration.common.datacontainers.calibration_table
import
CalibrationTable
,
UnvalidFileException
from
lofar.calibration.common.datacontainers.calibration_table
import
CalibrationTable
,
UnvalidFileException
from
h5py
import
File
as
H5File
import
logging
import
logging
from
tempfile
import
NamedTemporaryFile
from
tempfile
import
NamedTemporaryFile
from
numpy.testing
import
assert_array_equal
from
numpy
import
array
CALIBRATION_TABLE_FILENAME
=
'
t_calibration_table.in_CalTable-401-HBA-110_190.dat
'
CALIBRATION_TABLE_FILENAME
=
'
t_calibration_table.in_CalTable-401-HBA-110_190.dat
'
...
@@ -29,6 +32,22 @@ class TestCalibrationTable(unittest.TestCase):
...
@@ -29,6 +32,22 @@ class TestCalibrationTable(unittest.TestCase):
stored_calibration_table
=
CalibrationTable
.
load_from_file
(
temp_file
.
name
)
stored_calibration_table
=
CalibrationTable
.
load_from_file
(
temp_file
.
name
)
self
.
assertEqual
(
test_calibration_table
.
observation_station
,
self
.
assertEqual
(
test_calibration_table
.
observation_station
,
stored_calibration_table
.
observation_station
)
stored_calibration_table
.
observation_station
)
assert_array_equal
(
test_calibration_table
.
data
,
stored_calibration_table
.
data
)
def
test_storing_to_hdf
(
self
):
with
NamedTemporaryFile
(
'
w+b
'
)
as
temp_file
:
h5_file
=
H5File
(
temp_file
.
name
,
'
w
'
)
test_calibration_table
=
CalibrationTable
.
load_from_file
(
CALIBRATION_TABLE_FILENAME
)
test_calibration_table
.
store_to_hdf
(
h5_file
,
'
/calibration_table
'
)
h5_file
.
close
()
h5_file
=
H5File
(
temp_file
.
name
,
'
r
'
)
self
.
assertEqual
(
h5_file
[
'
/calibration_table
'
].
attrs
[
'
observation_station
'
],
'
CS401
'
)
assert_array_equal
(
array
(
h5_file
[
'
/calibration_table
'
]),
test_calibration_table
.
data
)
if
__name__
==
'
__main__
'
:
if
__name__
==
'
__main__
'
:
...
...
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