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
499274de
Commit
499274de
authored
5 years ago
by
Mattia Mancini
Browse files
Options
Downloads
Patches
Plain Diff
SSB-47
: Move collection comparison outside class
parent
e07d33e5
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/holography_dataset.py
+28
-30
28 additions, 30 deletions
...alibrationCommon/lib/datacontainers/holography_dataset.py
with
28 additions
and
30 deletions
CAL/CalibrationCommon/lib/datacontainers/holography_dataset.py
+
28
−
30
View file @
499274de
...
...
@@ -11,6 +11,32 @@ from numpy import isnan
logger
=
logging
.
getLogger
(
__file__
)
def
compare_nested_collections
(
dict1
,
dict2
):
"""
This function compares the contents of nested collections that can be accessed through the __item__ method.
It recursively iterates over all keys and embedded dicts.
@return: False if a key in dict1 is not a key in dict2 or if values for
a key differ in the dicts, True if the contents of both dicts match.
@param dict1: A dict
@param dict2: Another dict
"""
result
=
True
for
key
in
dict1
.
keys
():
if
key
in
dict2
.
keys
():
if
isinstance
(
dict1
[
key
],
dict
)
and
isinstance
(
dict2
[
key
],
dict
):
result
=
result
and
compare_nested_collections
(
dict1
[
key
],
dict2
[
key
])
else
:
if
isinstance
(
dict1
[
key
],
numpy
.
ndarray
)
and
isinstance
(
dict2
[
key
],
numpy
.
ndarray
):
# Compares element by element the two arrays
return
numpy
.
array_equal
(
dict1
[
key
],
dict2
[
key
])
else
:
return
dict1
[
key
]
==
dict2
[
key
]
else
:
return
False
return
result
def
bytestring_list_to_string
(
list
):
return
[
item
.
decode
(
'
utf-8
'
)
for
item
in
list
]
...
...
@@ -105,33 +131,6 @@ class HolographyDataset():
# numpy.array()
self
.
derived_data
=
None
@staticmethod
def
compare_dicts
(
dict1
,
dict2
):
'''
This function compares the contents of two dicts. It recursively
iterates over all keys and embedded dicts.
@return: False if a key in dict1 is not a key in dict2 or if values for
a key differ in the dicts, True if the contents of both dicts match.
@param dict1: A dict
@param dict2: Another dict
'''
result
=
True
for
key
in
dict1
.
keys
():
if
key
in
dict2
.
keys
():
if
isinstance
(
dict1
[
key
],
dict
)
and
isinstance
(
dict2
[
key
],
dict
):
result
=
result
and
HolographyDataset
.
compare_dicts
(
dict1
[
key
],
dict2
[
key
])
else
:
if
isinstance
(
dict1
[
key
],
numpy
.
ndarray
)
and
isinstance
(
dict2
[
key
],
numpy
.
ndarray
):
# Compares element by element the two arrays
return
numpy
.
array_equal
(
dict1
[
key
],
dict2
[
key
])
else
:
return
dict1
[
key
]
==
dict2
[
key
]
else
:
return
False
return
result
def
__eq__
(
self
,
hds
=
None
):
'''
This comparison operator compares the values of the relevant members of
...
...
@@ -155,8 +154,7 @@ class HolographyDataset():
this_equality
=
numpy
.
array_equal
(
attribute_value
,
other_value
)
elif
isinstance
(
attribute_value
,
dict
)
is
True
and
isinstance
(
other_value
,
dict
)
is
True
:
this_equality
=
HolographyDataset
.
compare_dicts
(
attribute_value
,
other_value
)
this_equality
=
compare_nested_collections
(
attribute_value
,
other_value
)
elif
attribute_value
!=
other_value
:
this_equality
=
False
logger
.
error
(
"
values for field
\"
%s
\"
differs
"
,
attribute_name
)
...
...
@@ -175,7 +173,7 @@ class HolographyDataset():
return
False
return
equality
def
find_central_beamlets
(
self
,
source
,
ra_dec
,
frequencies
,
beamlets
):
def
find_central_beamlets
(
_
,
source
,
ra_dec
,
frequencies
,
beamlets
):
'''
This function finds the central beamlet of a target station for every
frequency.
...
...
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