Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
R
ringdown-systematics
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Yifan Wang
ringdown-systematics
Commits
3c29c440
Commit
3c29c440
authored
3 years ago
by
Yifan Wang
Browse files
Options
Downloads
Patches
Plain Diff
add comparison for duration, fix labeling issues
parent
9fba7cd6
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
1-compare-ringdown-pyring-snr.ipynb
+1181
-1127
1181 additions, 1127 deletions
1-compare-ringdown-pyring-snr.ipynb
utils/wheel.py
+73
-35
73 additions, 35 deletions
utils/wheel.py
with
1254 additions
and
1162 deletions
1-compare-ringdown-pyring-snr.ipynb
+
1181
−
1127
View file @
3c29c440
Source diff could not be displayed: it is too large. Options to address this:
view the blob
.
This diff is collapsed.
Click to expand it.
utils/wheel.py
+
73
−
35
View file @
3c29c440
...
...
@@ -73,7 +73,7 @@ def local_loglikelihood(model,
class
wheel
():
def
__init__
(
self
,
model
,
fit
=
None
):
def
__init__
(
self
,
model
,
fit
=
None
,
acf_from_psd
=
None
):
'''
A wheel to reproduce the PyRing loglikelihood and SNR computation
Parameter:
...
...
@@ -82,8 +82,6 @@ class wheel():
The KerrModel for pyring
'''
self
.
model
=
model
self
.
data
=
{}
self
.
cinv
=
{}
self
.
acf
=
{}
...
...
@@ -102,31 +100,63 @@ class wheel():
'
phi2220
'
:
-
0.9737754582321143
,
'
phi2221
'
:
1.652119726595113
}
_
=
model
.
log_likelihood
(
pyring_par
)
waveform_model
=
model
.
get_waveform
(
pyring_par
)
t_start
=
model
.
fixed_params
[
'
t
'
]
duration_n
=
model
.
duration_n
for
d
in
model
.
detectors
.
keys
():
dt
=
model
.
time_delay
[
'
{0}_
'
.
format
(
self
.
model
.
ref_det
)
+
d
]
tref
=
LIGOTimeGPS
(
t_start
+
dt
+
self
.
model
.
tevent
)
dt
=
model
.
time_delay
[
'
{0}_
'
.
format
(
model
.
ref_det
)
+
d
]
tref
=
LIGOTimeGPS
(
t_start
+
dt
+
model
.
tevent
)
# crop data
time_array_raw
=
self
.
model
.
detectors
[
d
].
time
-
(
self
.
model
.
tevent
+
dt
)
time_array_raw
=
model
.
detectors
[
d
].
time
-
(
model
.
tevent
+
dt
)
time_array
=
time_array_raw
[
time_array_raw
>=
t_start
][:
duration_n
]
self
.
data
[
d
]
=
self
.
model
.
detectors
[
d
].
time_series
[
time_array_raw
>=
t_start
][:
duration_n
]
self
.
cinv
[
d
]
=
self
.
model
.
detectors
[
d
].
inverse_covariance
self
.
data
[
d
]
=
model
.
detectors
[
d
].
time_series
[
time_array_raw
>=
t_start
][:
duration_n
]
self
.
cinv
[
d
]
=
model
.
detectors
[
d
].
inverse_covariance
# read in the acf
self
.
acf
[
d
]
=
np
.
loadtxt
(
'
./GW150914_PROD1_Kerr_221_0M/Noise/ACF_TD_cropped_
'
+
str
(
d
)
+
'
_1126257414_4096_4.0_2048_0.2.txt
'
)
psd
=
np
.
loadtxt
(
'
./GW150914_PROD1_Kerr_221_0M/Noise/PSD_
'
+
str
(
d
)
+
'
_1126257414_4096_4.0_2048.txt
'
)
if
acf_from_psd
:
self
.
acf
[
d
]
=
np
.
loadtxt
(
'
/work/yifan.wang/ringdown/GW150914/pyring/compare-pyring-ringdown-pycbc/GW150914_PROD1_Kerr_221_0M/Noise/ACF_TD_cropped_
'
+
str
(
d
)
+
'
_1126257414_4096_4.0_2048_0.2.txt
'
)
psd
=
np
.
loadtxt
(
'
/work/yifan.wang/ringdown/GW150914/pyring/compare-pyring-ringdown-pycbc/GW150914_PROD1_Kerr_221_0M/Noise/PSD_
'
+
str
(
d
)
+
'
_1126257414_4096_4.0_2048.txt
'
)
acf_psd
=
0.5
*
np
.
fft
.
irfft
(
psd
[:,
1
])
*
self
.
model
.
srate
c
=
toeplitz
(
acf_psd
[:
model
.
duration_n
])
self
.
cinv_acf_from_psd
[
d
]
=
inv
(
c
)
if
fit
is
not
None
:
acf
=
fit
.
acfs
[
d
].
values
[:
model
.
duration_n
]
c
=
toeplitz
(
acf
_psd
[:
model
.
duration_n
])
c
=
toeplitz
(
acf
[:
model
.
duration_n
])
self
.
cinv_acf_from_ringdown
[
d
]
=
inv
(
c
)
self
.
model
=
model
def
get_data
(
self
,
detector_time
,
detector_rawdata
):
'''
Get the date corredsponding to waveform after correcting the labeling issue
Parameters:
-----------
detector_time: dict
By default, 4s duration
detector_rawdata: dict
By default, 4s data
Return:
-----------
cropped_time: dict
cropped time duration corredspoinding to waveform
cropeed_data: dict
cropped data corresponding to waveform
'''
cropped_time
=
{}
cropped_data
=
{}
t_start
=
self
.
model
.
fixed_params
[
'
t
'
]
duration_n
=
self
.
model
.
duration_n
for
d
in
self
.
model
.
detectors
.
keys
():
dt
=
self
.
model
.
time_delay
[
'
{0}_
'
.
format
(
self
.
model
.
ref_det
)
+
d
]
tref
=
LIGOTimeGPS
(
t_start
+
dt
+
self
.
model
.
tevent
)
# crop data
lcrop
=
detector_time
[
d
]
>=
self
.
model
.
tevent
+
dt
+
t_start
cropped_time
[
d
]
=
detector_time
[
d
][
lcrop
][:
duration_n
]
cropped_data
[
d
]
=
detector_rawdata
[
d
][
lcrop
][:
duration_n
]
return
cropped_time
,
cropped_data
def
get_hstrain
(
self
,
pyring_par
,
detector_time
):
'''
Compute the waveform given parameters
...
...
@@ -140,6 +170,7 @@ class wheel():
'''
h
=
{}
waveform_time
=
{}
#To activate model.time_delay we need to run loglikelihood first
_
=
self
.
model
.
log_likelihood
(
pyring_par
)
waveform_model
=
self
.
model
.
get_waveform
(
pyring_par
)
...
...
@@ -153,13 +184,14 @@ class wheel():
for
d
in
self
.
model
.
detectors
.
keys
():
dt
=
self
.
model
.
time_delay
[
'
{0}_
'
.
format
(
self
.
model
.
ref_det
)
+
d
]
tref
=
LIGOTimeGPS
(
t_start
+
dt
+
self
.
model
.
tevent
)
# crop data
#time_array_raw = self.model.detectors[d].time - (self.model.tevent+dt)
time_array_raw
=
detector_time
[
d
]
-
(
self
.
model
.
tevent
+
dt
)
time_array
=
time_array_raw
[
time_array_raw
>=
t_start
][:
duration_n
]
wf_model
=
waveform_model
.
waveform
(
time_array
)
hs
,
hvx
,
hvy
,
hp
,
hc
=
wf_model
[
0
],
wf_model
[
1
],
wf_model
[
2
],
wf_model
[
3
],
wf_model
[
4
]
h
[
d
]
=
project
(
hs
,
hvx
,
hvy
,
hp
,
hc
,
self
.
model
.
detectors
[
d
].
lal_detector
,
ra
,
dec
,
psi
,
tref
)
waveform_time
[
d
]
=
time_array
+
self
.
model
.
tevent
+
dt
return
waveform_time
,
h
...
...
@@ -171,7 +203,7 @@ class wheel():
loglikelihood
+=
loglikelihood_core
(
residuals
,
self
.
cinv
[
d
],
self
.
model
.
detectors
[
d
].
log_normalisation
)
return
loglikelihood
def
optsnr
(
self
,
pyring_par
,
network
=
True
,
acf_from_psd
=
False
,
acf_from_ringdown
=
False
):
def
optsnr
(
self
,
pyring_par
,
rawtime
,
network
=
True
,
acf_from_psd
=
False
,
acf_from_ringdown
=
False
):
'''
Optimal SNR
...
...
@@ -182,13 +214,13 @@ class wheel():
If true, use the L from Ringdown, where C=LL^T (cholesky decomposition)
-----------
'''
h
=
self
.
get_hstrain
(
pyring_par
)
_
,
h
=
self
.
get_hstrain
(
pyring_par
,
rawtime
)
snr
=
{}
for
d
in
self
.
model
.
detectors
.
keys
():
if
acf_from_psd
==
True
:
cinv
=
self
.
cinv_acf_from_psd
[
d
]
elif
acf_from_ringdown
:
elif
acf_from_ringdown
==
True
:
cinv
=
self
.
cinv_acf_from_ringdown
[
d
]
else
:
cinv
=
self
.
cinv
[
d
]
...
...
@@ -204,24 +236,30 @@ class wheel():
snr
[
d
]
=
np
.
sqrt
(
snr
[
d
])
return
snr
def
mfsnr
(
self
,
pyring_par
,
network
=
True
,
acf_from_psd
=
False
,
acf_from_ringdown
=
False
):
'''
Matched-filter SNR
def
mfsnr
(
self
,
pyring_par
,
rawtime
,
rawdata
,
network
=
True
,
acf_from_psd
=
False
,
acf_from_ringdown
=
False
):
'''
Matched-filter SNR
Parameters:
-----------
pyring_par: dict
Source parameters
rawtime: dict
The time duration for one chunk of signal
rawdata: dict
The data for one chunk of signal
'''
h
=
self
.
get_hstrain
(
pyring_par
)
_
,
h
=
self
.
get_hstrain
(
pyring_par
,
rawtime
)
_
,
data
=
self
.
get_data
(
rawtime
,
rawdata
)
snr
=
{}
for
d
in
self
.
model
.
detectors
.
keys
():
if
acf_from_psd
==
True
:
if
acf_from_psd
:
cinv
=
self
.
cinv_acf_from_psd
[
d
]
elif
acf_from_ringdown
:
cinv
=
self
.
cinv_acf_from_ringdown
[
d
]
else
:
cinv
=
self
.
cinv
[
d
]
snr
[
d
]
=
np
.
dot
(
self
.
data
[
d
],
np
.
dot
(
cinv
,
h
[
d
]))
**
2
\
snr
[
d
]
=
np
.
dot
(
data
[
d
],
np
.
dot
(
cinv
,
h
[
d
]))
**
2
\
/
np
.
dot
(
h
[
d
],
np
.
dot
(
cinv
,
h
[
d
]))
if
network
:
...
...
@@ -289,7 +327,7 @@ class wheel():
/
np
.
dot
(
self
.
hstrain
[
d
],
solve_toeplitz
(
self
.
acf
[
d
],
self
.
hstrain
[
d
]))
return
np
.
sqrt
(
snr
)
def
compute_
pyring
_snr
(
model
,
M
,
chi
,
A
,
phi
,
def
compute_
multiple
_snr
(
model
,
pr_time
,
pr_data
,
M
,
chi
,
A
,
phi
,
fit
=
None
,
network
=
True
,
acf_from_psd
=
False
,
acf_from_ringdown
=
False
):
'''
Loop compute the optimal SNR and matched-filter SNR given a PyRing Model
...
...
@@ -321,12 +359,12 @@ def compute_pyring_snr(model,M,chi,A,phi,
'
phi2221
'
:
-
phi
[
1
][
i
].
values
}
if
network
:
optsnr
.
append
(
result
.
optsnr
(
pyring_par
,
network
,
acf_from_psd
,
acf_from_ringdown
))
mfsnr
.
append
(
result
.
mfsnr
(
pyring_par
,
network
,
acf_from_psd
,
acf_from_ringdown
))
optsnr
.
append
(
result
.
optsnr
(
pyring_par
,
pr_time
,
network
,
acf_from_psd
,
acf_from_ringdown
))
mfsnr
.
append
(
result
.
mfsnr
(
pyring_par
,
pr_time
,
pr_data
,
network
,
acf_from_psd
,
acf_from_ringdown
))
else
:
for
d
in
model
.
detectors
.
keys
():
optsnr
[
d
].
append
(
result
.
optsnr
(
pyring_par
,
network
,
acf_from_psd
,
acf_from_ringdown
)[
d
])
mfsnr
[
d
].
append
(
result
.
mfsnr
(
pyring_par
,
network
,
acf_from_psd
,
acf_from_ringdown
)[
d
])
optsnr
[
d
].
append
(
result
.
optsnr
(
pyring_par
,
pr_data
,
network
,
acf_from_psd
,
acf_from_ringdown
)[
d
])
mfsnr
[
d
].
append
(
result
.
mfsnr
(
pyring_par
,
pr_time
,
pr_data
,
network
,
acf_from_psd
,
acf_from_ringdown
)[
d
])
return
optsnr
,
mfsnr
...
...
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