Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
LISA Instrument
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LISA Simulation
LISA Instrument
Commits
e0211d4a
Commit
e0211d4a
authored
1 month ago
by
Wolfgang Kastaun
Browse files
Options
Downloads
Patches
Plain Diff
added unit test comparing new shift inversion directly to legacy algorithm
parent
50ee7bc7
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
tests/test_shift_inversion_numpy.py
+77
-0
77 additions, 0 deletions
tests/test_shift_inversion_numpy.py
with
77 additions
and
0 deletions
tests/test_shift_inversion_numpy.py
+
77
−
0
View file @
e0211d4a
...
...
@@ -3,6 +3,7 @@
import
numpy
as
np
import
pytest
from
lisainstrument
import
dsp
from
lisainstrument.shift_inversion_numpy
import
make_shift_inverse_lagrange_numpy
...
...
@@ -38,3 +39,79 @@ def test_shift_inversion_numpy():
valid_range
=
slice
(
op_np
.
margin_left
,
-
op_np
.
margin_right
)
assert
ai_np
[
valid_range
]
==
pytest
.
approx
(
ai_ex
[
valid_range
],
abs
=
tol
,
rel
=
0
)
def
legacy_invert_scet_wrt_tps
(
scet_wrt_tps
:
np
.
ndarray
,
clockinv_tolerance
:
float
,
physics_fs
:
float
,
interpolation_order
:
int
,
clockinv_maxiter
:
int
=
5
,
):
"""
Legacy shift inversion algorithm taken out of Instrument class for comparison
Slight adaptions to make it work without Instrument instance, and logging removed.
Args:
scet_wrt_tps: array of SCETs with respect to TPS
clockinv_tolerance: tolerance for result
physics_fs: sample rate
interpolation_order: Lagrange interpolation order
"""
# Drop samples at the edges to compute error
edge
=
min
(
100
,
len
(
scet_wrt_tps
)
//
2
-
1
)
error
=
0
niter
=
0
next_inverse
=
scet_wrt_tps
while
not
niter
or
error
>
clockinv_tolerance
:
if
niter
>=
clockinv_maxiter
:
msg
=
"
Legacy fixed point iter did not converge
"
raise
RuntimeError
(
msg
)
inverse
=
next_inverse
next_inverse
=
dsp
.
timeshift
(
scet_wrt_tps
,
-
inverse
*
physics_fs
,
interpolation_order
)
# originally,
# next_inverse = self.interpolate(scet_wrt_tps, -inverse)
error
=
np
.
max
(
np
.
abs
((
inverse
-
next_inverse
)[
edge
:
-
edge
]))
niter
+=
1
return
inverse
def
test_shift_inversion_legacy
():
"""
Compare shift_inversion_numpy to original algorithm
"""
order
=
31
nsamp
=
3000
fsample
=
16.0
dt
=
1
/
fsample
f_mod
=
0.005
a_mod
=
1e-2
/
(
2
*
np
.
pi
*
f_mod
)
max_it
=
5
tol
=
1e-10
def
dx_from_x
(
x
):
return
np
.
sin
(
2
*
np
.
pi
*
f_mod
*
x
)
*
a_mod
xi
=
np
.
arange
(
nsamp
)
*
dt
dxi
=
dx_from_x
(
xi
)
op_np
=
make_shift_inverse_lagrange_numpy
(
order
=
order
,
fsample
=
fsample
,
max_abs_shift
=
a_mod
*
1.01
,
max_iter
=
max_it
,
tolerance
=
tol
,
)
ai_np
=
op_np
(
dxi
)
ai_leg
=
legacy_invert_scet_wrt_tps
(
dxi
,
tol
,
fsample
,
order
,
max_it
)
valid_range
=
slice
(
op_np
.
margin_left
,
-
op_np
.
margin_right
)
assert
ai_np
[
valid_range
]
==
pytest
.
approx
(
ai_leg
[
valid_range
],
abs
=
tol
,
rel
=
0
)
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