Skip to content

Commit c2fd591

Browse files
authored
Merge pull request #5 from MaxMelching/formatting
Black Formatting
2 parents ecdeba3 + fbb47ee commit c2fd591

File tree

4 files changed

+98
-81
lines changed

4 files changed

+98
-81
lines changed

docs/conf.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
project = 'pycbc_wferrors_plugin'
1010

1111
import datetime
12+
1213
year = datetime.datetime.now().year
1314
copyright = f'{year}, The PyCBC Team'
1415
# copyright = '2025, Sumit Kumar and Max Melching and Frank Ohme'
@@ -29,15 +30,14 @@
2930
'm2r2', # including markdown files
3031
# 'sphinx_mdinclude', # including markdown files -> then comment m2r2 -> seems to work much better -> but not compatible with nbsphinx...
3132
'nbsphinx',
32-
'nbsphinx_link'
33+
'nbsphinx_link',
3334
]
3435

3536

3637
templates_path = ['_templates']
3738
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
3839

3940

40-
4141
# -- Options for HTML output -------------------------------------------------
4242
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
4343

@@ -51,6 +51,5 @@
5151
'collapse_navigation': False, # Makes navigation expandable
5252
'sticky_navigation': True,
5353
'navigation_depth': 4,
54-
'titles_only': False
54+
'titles_only': False,
5555
}
56-

examples/notebooks/example_usage.ipynb

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
},
5858
{
5959
"cell_type": "code",
60-
"execution_count": 3,
60+
"execution_count": null,
6161
"metadata": {},
6262
"outputs": [],
6363
"source": [
@@ -66,8 +66,8 @@
6666
" 'mass2': 20,\n",
6767
" 'f_lower': 20,\n",
6868
" 'f_final': 1024,\n",
69-
" 'delta_f': 1/64,\n",
70-
" 'delta_t': 1/2048,\n",
69+
" 'delta_f': 1.0 / 64.0,\n",
70+
" 'delta_t': 1.0 / 2048.0,\n",
7171
" 'spin1z': 0,\n",
7272
" 'spin2z': 0,\n",
7373
" 'distance': 100,\n",
@@ -117,8 +117,8 @@
117117
"wf_no_mod_params = {\n",
118118
" 'modification_type': 'constant_shift',\n",
119119
" 'error_in_phase': 'relative',\n",
120-
" 'delta_amplitude': 0.,\n",
121-
" 'delta_phase': 0.,\n",
120+
" 'delta_amplitude': 0.0,\n",
121+
" 'delta_phase': 0.0,\n",
122122
"}\n",
123123
"\n",
124124
"hpf_no_mod, hcf_no_mod = get_fd_waveform(\n",
@@ -199,7 +199,7 @@
199199
" 'modification_type': 'constant_shift',\n",
200200
" 'error_in_phase': 'relative',\n",
201201
" 'delta_amplitude': 0.1,\n",
202-
" 'delta_phase': 0.,\n",
202+
" 'delta_phase': 0.0,\n",
203203
"}\n",
204204
"\n",
205205
"hpf_amp_mod, hcf_amp_mod = get_fd_waveform(\n",
@@ -246,7 +246,7 @@
246246
"wf_phase_mod_params = {\n",
247247
" 'modification_type': 'constant_shift',\n",
248248
" 'error_in_phase': 'relative',\n",
249-
" 'delta_amplitude': 0.,\n",
249+
" 'delta_amplitude': 0.0,\n",
250250
" 'delta_phase': 0.1,\n",
251251
"}\n",
252252
"\n",
@@ -350,7 +350,9 @@
350350
"f_high_calibration = wf_params['f_final']\n",
351351
"\n",
352352
"n_wf_nodal_points = 10\n",
353-
"wf_nodal_points = np.logspace(np.log10(f_low_calibration), np.log10(f_high_calibration), n_wf_nodal_points)\n",
353+
"wf_nodal_points = np.logspace(\n",
354+
" np.log10(f_low_calibration), np.log10(f_high_calibration), n_wf_nodal_points\n",
355+
")\n",
354356
"\n",
355357
"\n",
356358
"ampl_mean_err = 0.1\n",
@@ -360,8 +362,12 @@
360362
"phase_stddev_err = 0.05\n",
361363
"\n",
362364
"np.random.seed(42)\n",
363-
"delta_amplitude_arr = np.random.standard_normal(n_wf_nodal_points)*ampl_stddev_err + ampl_mean_err\n",
364-
"delta_phase_arr = np.random.standard_normal(n_wf_nodal_points)*phase_stddev_err + phase_mean_err\n",
365+
"delta_amplitude_arr = (\n",
366+
" np.random.standard_normal(n_wf_nodal_points) * ampl_stddev_err + ampl_mean_err\n",
367+
")\n",
368+
"delta_phase_arr = (\n",
369+
" np.random.standard_normal(n_wf_nodal_points) * phase_stddev_err + phase_mean_err\n",
370+
")\n",
365371
"\n",
366372
"\n",
367373
"wf_mod_spline_params = {\n",
@@ -519,8 +525,8 @@
519525
" # t_gps=float(t_ref),\n",
520526
")\n",
521527
"\n",
522-
"hf_ref = fp*hpf_ref + fc*hcf_ref\n",
523-
"hf_mod_spline = fp*hpf_mod_spline + fc*hcf_mod_spline\n",
528+
"hf_ref = fp * hpf_ref + fc * hcf_ref\n",
529+
"hf_mod_spline = fp * hpf_mod_spline + fc * hcf_mod_spline\n",
524530
"\n",
525531
"\n",
526532
"# from pycbc.waveform import apply_fseries_time_shift\n",

setup.py

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
"""
32
setup.py file for waveform-errors from pycbc waveform plugin package
43
"""
@@ -10,29 +9,33 @@
109
'version_file': '_pycbc_wferrors_version.py',
1110
'version_scheme': 'no-guess-dev',
1211
'local_scheme': 'dirty-tag',
13-
'fallback_version': '0.1.0'
12+
'fallback_version': '0.1.0',
1413
}
1514

1615

1716
setup(
18-
name = 'pycbc-wferrors',
19-
use_scm_version = version_config,
20-
description = 'An waveform plugin for systematic errors for PyCBC',
21-
long_description = open('descr.rst').read(),
22-
author = 'The PyCBC team',
23-
author_email = 'sumit.kumar@aei.mpg.de',
24-
url = 'http://www.pycbc.org/',
25-
keywords = ['pycbc', 'signal processing', 'gravitational waves'],
26-
setup_requires = [
17+
name='pycbc-wferrors',
18+
use_scm_version=version_config,
19+
description='An waveform plugin for systematic errors for PyCBC',
20+
long_description=open('descr.rst').read(),
21+
author='The PyCBC team',
22+
author_email='sumit.kumar@aei.mpg.de',
23+
url='http://www.pycbc.org/',
24+
keywords=['pycbc', 'signal processing', 'gravitational waves'],
25+
setup_requires=[
2726
'setuptools>=64',
2827
'setuptools_scm>=8',
2928
'wheel',
3029
],
31-
install_requires = ['pycbc'],
32-
py_modules = ['wferrors'],
33-
entry_points = {"pycbc.waveform.fd":["wferrors = wferrors:amplitude_phase_modification_fd",
34-
"wferrors_2p = wferrors:amplitude_phase_modification_both_polarization_fd"]},
35-
classifiers = [
30+
install_requires=['pycbc'],
31+
py_modules=['wferrors'],
32+
entry_points={
33+
"pycbc.waveform.fd": [
34+
"wferrors = wferrors:amplitude_phase_modification_fd",
35+
"wferrors_2p = wferrors:amplitude_phase_modification_both_polarization_fd",
36+
]
37+
},
38+
classifiers=[
3639
'Programming Language :: Python',
3740
'Programming Language :: Python :: 3.10',
3841
'Programming Language :: Python :: 3.11',
@@ -57,6 +60,5 @@
5760
'nbsphinx-link',
5861
'lxml_html_clean', # Needed by nbsphinx
5962
],
60-
61-
}
63+
},
6264
)

wferrors.py

Lines changed: 57 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,17 @@
77
def amplitude_phase_modification_fd(**kwds):
88
"""
99
This function applies the Amplitude-Phase modification, described in
10-
Kumar, Melching, Ohme (2025), to the base waveform approximant in
10+
Kumar, Melching, Ohme (2025), to the base waveform approximant in
1111
frequency domain.
1212
1313
Input in kwds:
1414
error_in_phase: 'relative' or 'absolute'
1515
This argument specify the type of errors to be
1616
applied.
17-
baseline_approximant: FD approximant of the reference waveform model to
17+
baseline_approximant: FD approximant of the reference waveform model to
1818
modified.
1919
modification_type: 'cubic_spline', 'cubic_spline_nodes', or 'constant_shift'
20-
'cubic_spline': If this option is passed, the dictionary should
20+
'cubic_spline': If this option is passed, the dictionary should
2121
includes array of delta_amplitude, delta_phase, and nodal_points
2222
'cubic_spline_nodes': When we specify this modification_type, the lower
2323
and upper limits of the frequency should be given along with number
@@ -97,9 +97,9 @@ def amplitude_phase_modification_fd(**kwds):
9797
+ delta_phase
9898
)
9999
elif dict_waveform_modification['modification_type'] == 'cubic_spline_nodes':
100-
f_lower = (dict_waveform_modification.get('f_lower_wferror',
101-
default=dict_waveform_modification['f_lower'])
102-
)
100+
f_lower = dict_waveform_modification.get(
101+
'f_lower_wferror', default=dict_waveform_modification['f_lower']
102+
)
103103
f_high_wferror = dict_waveform_modification['f_high_wferror']
104104
n_nodes_wferror = int(dict_waveform_modification['n_nodes_wferror'])
105105
wf_nodal_points = numpy.logspace(
@@ -158,6 +158,7 @@ def amplitude_phase_modification_fd(**kwds):
158158

159159
return hp, hc
160160

161+
161162
def amplitude_phase_modification_both_polarization_fd(**kwds):
162163
"""Modify amplitude and phase of waveform polarizations in frequency domain."""
163164

@@ -178,18 +179,14 @@ def amplitude_phase_modification_both_polarization_fd(**kwds):
178179
delta_amplitude_plus_interp = CubicSpline(
179180
wf_nodal_points, delta_amplitude_plus_arr
180181
)
181-
delta_phase_plus_interp = CubicSpline(
182-
wf_nodal_points, delta_phase_plus_arr
183-
)
182+
delta_phase_plus_interp = CubicSpline(wf_nodal_points, delta_phase_plus_arr)
184183

185184
delta_amplitude_cross_arr = dict_waveform_modification['delta_amplitude_cross']
186185
delta_phase_cross_arr = dict_waveform_modification['delta_phase_cross']
187186
delta_amplitude_cross_interp = CubicSpline(
188187
wf_nodal_points, delta_amplitude_cross_arr
189188
)
190-
delta_phase_cross_interp = CubicSpline(
191-
wf_nodal_points, delta_phase_cross_arr
192-
)
189+
delta_phase_cross_interp = CubicSpline(wf_nodal_points, delta_phase_cross_arr)
193190

194191
# Modify amplitude and phase for Plus and Cross polarization
195192
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (
@@ -222,8 +219,12 @@ def amplitude_phase_modification_both_polarization_fd(**kwds):
222219
delta_phase_cross = dict_waveform_modification['delta_phase_cross']
223220

224221
# Modify amplitude and phase for Plus and Cross polarization
225-
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (1 + delta_amplitude_plus)
226-
Am_cross = waveform.amplitude_from_frequencyseries(hc) * (1 + delta_amplitude_cross)
222+
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (
223+
1 + delta_amplitude_plus
224+
)
225+
Am_cross = waveform.amplitude_from_frequencyseries(hc) * (
226+
1 + delta_amplitude_cross
227+
)
227228

228229
if dict_waveform_modification['error_in_phase'] == 'relative':
229230
Ph_plus = waveform.phase_from_frequencyseries(
@@ -233,40 +234,50 @@ def amplitude_phase_modification_both_polarization_fd(**kwds):
233234
hc, remove_start_phase=False
234235
) * (1 + delta_phase_cross)
235236
elif dict_waveform_modification['error_in_phase'] == 'absolute':
236-
Ph_plus = waveform.phase_from_frequencyseries(
237-
hp, remove_start_phase=False
238-
) + delta_phase_plus
239-
Ph_cross = waveform.phase_from_frequencyseries(
240-
hc, remove_start_phase=False
241-
) + delta_phase_cross
237+
Ph_plus = (
238+
waveform.phase_from_frequencyseries(hp, remove_start_phase=False)
239+
+ delta_phase_plus
240+
)
241+
Ph_cross = (
242+
waveform.phase_from_frequencyseries(hc, remove_start_phase=False)
243+
+ delta_phase_cross
244+
)
242245

243246
elif modification_type == 'cubic_spline_nodes':
244-
f_lower = (dict_waveform_modification.get('f_lower_wferror',
245-
default=dict_waveform_modification['f_lower'])
246-
)
247+
f_lower = dict_waveform_modification.get(
248+
'f_lower_wferror', default=dict_waveform_modification['f_lower']
249+
)
247250
f_high_wferror = dict_waveform_modification['f_high_wferror']
248251
n_nodes_wferror = int(dict_waveform_modification['n_nodes_wferror'])
249252

250253
wf_nodal_points = numpy.logspace(
251254
numpy.log10(f_lower), numpy.log10(f_high_wferror), n_nodes_wferror
252255
)
253256

254-
delta_amplitude_plus_arr = numpy.hstack([
255-
dict_waveform_modification[f'wferror_amplitude_plus_{i}']
256-
for i in range(len(wf_nodal_points))
257-
])
258-
delta_phase_plus_arr = numpy.hstack([
259-
dict_waveform_modification[f'wferror_phase_plus_{i}']
260-
for i in range(len(wf_nodal_points))
261-
])
262-
delta_amplitude_cross_arr = numpy.hstack([
263-
dict_waveform_modification[f'wferror_amplitude_cross_{i}']
264-
for i in range(len(wf_nodal_points))
265-
])
266-
delta_phase_cross_arr = numpy.hstack([
267-
dict_waveform_modification[f'wferror_phase_cross_{i}']
268-
for i in range(len(wf_nodal_points))
269-
])
257+
delta_amplitude_plus_arr = numpy.hstack(
258+
[
259+
dict_waveform_modification[f'wferror_amplitude_plus_{i}']
260+
for i in range(len(wf_nodal_points))
261+
]
262+
)
263+
delta_phase_plus_arr = numpy.hstack(
264+
[
265+
dict_waveform_modification[f'wferror_phase_plus_{i}']
266+
for i in range(len(wf_nodal_points))
267+
]
268+
)
269+
delta_amplitude_cross_arr = numpy.hstack(
270+
[
271+
dict_waveform_modification[f'wferror_amplitude_cross_{i}']
272+
for i in range(len(wf_nodal_points))
273+
]
274+
)
275+
delta_phase_cross_arr = numpy.hstack(
276+
[
277+
dict_waveform_modification[f'wferror_phase_cross_{i}']
278+
for i in range(len(wf_nodal_points))
279+
]
280+
)
270281

271282
delta_amplitude_plus_interp = CubicSpline(
272283
wf_nodal_points, delta_amplitude_plus_arr
@@ -275,9 +286,7 @@ def amplitude_phase_modification_both_polarization_fd(**kwds):
275286
delta_amplitude_cross_interp = CubicSpline(
276287
wf_nodal_points, delta_amplitude_cross_arr
277288
)
278-
delta_phase_cross_interp = CubicSpline(
279-
wf_nodal_points, delta_phase_cross_arr
280-
)
289+
delta_phase_cross_interp = CubicSpline(wf_nodal_points, delta_phase_cross_arr)
281290

282291
# Modify amplitude and phase for Plus and Cross polarization
283292
Am_plus = waveform.amplitude_from_frequencyseries(hp) * (
@@ -306,10 +315,11 @@ def amplitude_phase_modification_both_polarization_fd(**kwds):
306315
raise TypeError("Currently, no other modification are supported")
307316

308317
# Apply the correction to the base model
309-
hp.data = numpy.vectorize(complex)(Am_plus * numpy.cos(Ph_plus),
310-
Am_plus * numpy.sin(Ph_plus))
311-
hc.data = numpy.vectorize(complex)(Am_cross * numpy.cos(Ph_cross),
312-
Am_cross * numpy.sin(Ph_cross))
318+
hp.data = numpy.vectorize(complex)(
319+
Am_plus * numpy.cos(Ph_plus), Am_plus * numpy.sin(Ph_plus)
320+
)
321+
hc.data = numpy.vectorize(complex)(
322+
Am_cross * numpy.cos(Ph_cross), Am_cross * numpy.sin(Ph_cross)
323+
)
313324

314325
return hp, hc
315-

0 commit comments

Comments
 (0)