Skip to content

Commit aa4bc95

Browse files
committed
Add unit test to ensure formatting with black
1 parent 047a999 commit aa4bc95

12 files changed

Lines changed: 368 additions & 197 deletions

File tree

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
- name: Install dependencies
2121
run: |
22-
pip install lalsuite pycbc pytest
22+
pip install lalsuite pycbc pytest black
2323
pip install -e .
2424
2525
- name: Run tests

esigmapy/blend.py

Lines changed: 13 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Copyright (C) 2023 Kartikey Sharma, Prayush Kumar
22
#
3-
"""Master function to hybridise any complex timeseries using the 'frequency' as a user input,
3+
"""Master function to hybridise any complex timeseries using the 'frequency' as a user input,
44
specifically to be used for gravitational waveform hybridisation, fine-tuned for a single mode.
55
"""
66

@@ -100,17 +100,13 @@ def align_in_phase(
100100
align_merger_to_inspiral=True,
101101
):
102102
if len(inspiral) == 0:
103-
raise IOError(
104-
f"""You passed an inspiral waveform of zero length, to align
105-
with merger-ringdown!"""
106-
)
103+
raise IOError(f"""You passed an inspiral waveform of zero length, to align
104+
with merger-ringdown!""")
107105
if (t2_index_insp + 1 - t1_index_insp) < 1:
108-
raise IOError(
109-
f"""You have passed a very narrow window for the inspiral
106+
raise IOError(f"""You have passed a very narrow window for the inspiral
110107
waveform's hybridization. As per your input, the inspiral
111108
waveform from index {t1_index_insp} to {t2_index_insp + 1}
112-
should be used to attach merger-ringdown"""
113-
)
109+
should be used to attach merger-ringdown""")
114110

115111
# Function alignes the two waveforms using the phase, optimised over the attachment region
116112
# m from l,m mode
@@ -237,10 +233,8 @@ def blend_modes(
237233
Set this to True to enable logging output.
238234
"""
239235
if frq_width <= 0:
240-
raise IOError(
241-
f"""You are trying to blend over a frequency window of
242-
negative length (= {frq_width}Hz). Fix this."""
243-
)
236+
raise IOError(f"""You are trying to blend over a frequency window of
237+
negative length (= {frq_width}Hz). Fix this.""")
244238
if blend_using_avg_orbital_frequency:
245239
if len(inspiral_orbital_frequency) != len(inspiral_modes[mode_to_align_by]):
246240
raise IOError(
@@ -327,14 +321,12 @@ def blend_modes(
327321
inspiral_orbital_frequency, (frq_attach + frq_width / 2) / em
328322
)
329323
if verbose > 1:
330-
print(
331-
f"""Hybridizing using orbital frequency. Frequency
324+
print(f"""Hybridizing using orbital frequency. Frequency
332325
{frq_attach + frq_width / 2}Hz found at {t2_index_insp}.
333326
The same frequency would have been found at index
334327
{find_last_value_location_in_series(frq_insp[(el, em)],
335328
frq_attach + frq_width / 2)} of mode frequency evolution.
336-
"""
337-
)
329+
""")
338330
else:
339331
t2_index_insp = find_last_value_location_in_series(
340332
frq_insp[(el, em)], frq_attach + frq_width / 2
@@ -344,17 +336,13 @@ def blend_modes(
344336
t1_index_insp = t2_index_insp - (t2_index_mr - t1_index_mr)
345337

346338
if verbose > 4:
347-
print(
348-
f"""In the merger-ringdown waveform, the hybridization frequency window
339+
print(f"""In the merger-ringdown waveform, the hybridization frequency window
349340
[{frq_attach - frq_width / 2}, {frq_attach + frq_width / 2}]
350341
was found at indices [{t1_index_mr}, {t2_index_mr}]
351-
"""
352-
)
353-
print(
354-
f"""In the inspiral waveform, the same window is to be found at
342+
""")
343+
print(f"""In the inspiral waveform, the same window is to be found at
355344
indices [{t1_index_insp}, {t2_index_insp}.]
356-
"""
357-
)
345+
""")
358346
"""
359347
Theoretically, we NEED a timeshift to align the waveforms in frequency.
360348
Instead of shifting one of the two waveforms for alignment, we are defining

esigmapy/generator.py

Lines changed: 24 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ def get_inspiral_esigma_modes(
269269

270270
if f_ref < f_lower:
271271
ref_idx = np.searchsorted(
272-
(retval[1].data.data ** 1.5) / ((mass1 + mass2) * lal.MTSUN_SI * np.pi),
272+
(retval[1].data.data**1.5) / ((mass1 + mass2) * lal.MTSUN_SI * np.pi),
273273
f_lower,
274274
)
275275
new_len = len(retval[0].data.data) - ref_idx
@@ -535,10 +535,8 @@ def _get_transition_frequency_window(
535535
# frequency, towards the end of waveform
536536

537537
if verbose > 4:
538-
print(
539-
f"""Transition frequency found at index {transition_idx}
540-
in the orbital frequency array of length {len(orbital_freq)}"""
541-
)
538+
print(f"""Transition frequency found at index {transition_idx}
539+
in the orbital frequency array of length {len(orbital_freq)}""")
542540

543541
if blend_using_avg_orbital_frequency:
544542
# We integrate `orbital_freq` to obtain `orbital_phase`
@@ -640,11 +638,9 @@ def _get_transition_frequency_window(
640638
)
641639

642640
if verbose > 4:
643-
print(
644-
f"""The transition is to happen in a window from
641+
print(f"""The transition is to happen in a window from
645642
frequencies: [{orbital_freq[window_start_idx]}, {orbital_freq[transition_idx]}]Hz,
646-
between indices: [{window_start_idx}, {transition_idx}]"""
647-
)
643+
between indices: [{window_start_idx}, {transition_idx}]""")
648644
else:
649645
raise RuntimeError(
650646
"""We should never reach here. Did you set a non-bool value for the
@@ -772,22 +768,16 @@ def get_imr_esigma_modes(
772768
"""
773769
check_available_mr_approximants(merger_ringdown_approximant)
774770
if (mean_anomaly is None) and (coa_phase is None):
775-
raise IOError(
776-
f"""Please specify one of the phase angles, either of
777-
`mean_anomaly` or `coa_phase`."""
778-
)
771+
raise IOError(f"""Please specify one of the phase angles, either of
772+
`mean_anomaly` or `coa_phase`.""")
779773
if blend_aligning_merger_to_inspiral and (mean_anomaly is None):
780-
raise IOError(
781-
f"""If you want to attach ESIGMA inspiral to merger, by
774+
raise IOError(f"""If you want to attach ESIGMA inspiral to merger, by
782775
phase shifting merger to inspiral, please specify the
783-
phase angle `mean_anomaly`"""
784-
)
776+
phase angle `mean_anomaly`""")
785777
if (not blend_aligning_merger_to_inspiral) and (coa_phase is None):
786-
raise IOError(
787-
f"""If you want to attach ESIGMA inspiral to merger, by
778+
raise IOError(f"""If you want to attach ESIGMA inspiral to merger, by
788779
phase shifting inspiral to merger, please specify the
789-
phase angle `coa_phase`"""
790-
)
780+
phase angle `coa_phase`""")
791781
if mean_anomaly is None:
792782
mean_anomaly = 0
793783
if coa_phase is None:
@@ -807,13 +797,11 @@ def get_imr_esigma_modes(
807797
set(available_inspiral_orbital_params)
808798
)
809799
if return_orbital_params_user != set(return_orbital_params):
810-
print(
811-
f"""Warning: You requested the following list of orbital
800+
print(f"""Warning: You requested the following list of orbital
812801
parameters to be returned: {return_orbital_params}, but we reduce it to
813802
{return_orbital_params_user} as we only have the evolution of the following
814803
parameters available with us: {available_inspiral_orbital_params}.
815-
"""
816-
)
804+
""")
817805
elif not return_orbital_params:
818806
return_orbital_params = []
819807
return_orbital_params_user = False
@@ -871,26 +859,21 @@ def get_imr_esigma_modes(
871859
raise RuntimeError(
872860
f"""The inspiral modes do not contain the primary
873861
desired {mode_to_align_by} multipole. It currently holds only the following:
874-
{modes_inspiral_numpy.keys()}"""
875-
)
862+
{modes_inspiral_numpy.keys()}""")
876863

877864
orbital_eccentricity = retval[-2]["e"]
878865
# Throw error if eccentricity at the end of inspiral is definitely unsafe
879866
if orbital_eccentricity[-1] > ECCENTRICITY_LEVEL_ISCO_ERROR:
880-
raise IOError(
881-
f"""ERROR: You entered a very large initial eccentricity
867+
raise IOError(f"""ERROR: You entered a very large initial eccentricity
882868
{eccentricity}. The orbital eccentricity at the end of inspiral was
883869
{orbital_eccentricity[-1]}. The merger-ringdown attachment with a
884-
quasicircular will be questionable."""
885-
)
870+
quasicircular will be questionable.""")
886871
# Warn user if eccentricity at the end of inspiral is potentially unsafe
887872
if orbital_eccentricity[-1] > ECCENTRICITY_LEVEL_ISCO_WARNING and verbose:
888-
print(
889-
f"""WARNING: You entered a very large initial eccentricity
873+
print(f"""WARNING: You entered a very large initial eccentricity
890874
{eccentricity}. The orbital eccentricity at the end of inspiral was
891875
{orbital_eccentricity[-1]}. The merger-ringdown attachment with a quasicircular
892-
model might be affected."""
893-
)
876+
model might be affected.""")
894877

895878
if (f_window_mr_transition is None) or failsafe or (verbose > 1):
896879
if blend_using_avg_orbital_frequency:
@@ -914,14 +897,12 @@ def get_imr_esigma_modes(
914897
modes_inspiral_numpy[mode_to_align_by]
915898
)
916899
mode_frequency = esigmapy.blend.compute_frequency(mode_phase, delta_t)
917-
print(
918-
f"""DEBUG: Orbital freq at end of inspiral is {orbital_frequency[-1]}Hz,
900+
print(f"""DEBUG: Orbital freq at end of inspiral is {orbital_frequency[-1]}Hz,
919901
mode-{mode_to_align_by} freq at the end of inspiral is {mode_frequency[-1]}Hz, max and min
920902
mode-{mode_to_align_by} frequencies are {np.max(mode_frequency)}Hz and
921903
{np.min(mode_frequency)}Hz, and the transition frequency (of {mode_to_align_by}-mode)
922904
requested is {f_mr_transition}Hz, which should be less than the maximum freq of
923-
{mode_to_align_by}-mode: {mode_frequency.max()}Hz."""
924-
)
905+
{mode_to_align_by}-mode: {mode_frequency.max()}Hz.""")
925906
return (
926907
modes_inspiral_numpy,
927908
mode_phase,
@@ -940,12 +921,10 @@ def get_imr_esigma_modes(
940921
mode_frequency = esigmapy.blend.compute_frequency(mode_phase, delta_t)
941922
if mode_frequency.max() < f_mr_transition:
942923
if verbose:
943-
print(
944-
f"""FAILSAFE: Maximum orbital freq during inspiral is
924+
print(f"""FAILSAFE: Maximum orbital freq during inspiral is
945925
{orbital_frequency.max()}Hz, and max frequency of {mode_to_align_by}-mode is
946926
{mode_frequency.max()}Hz, so we are resetting transition frequency from
947-
{f_mr_transition}Hz to {mode_frequency.max()}Hz."""
948-
)
927+
{f_mr_transition}Hz to {mode_frequency.max()}Hz.""")
949928
f_mr_transition = mode_frequency.max()
950929

951930
# If the user does not provide the width of hybridization window (
@@ -1026,12 +1005,10 @@ def get_imr_esigma_modes(
10261005
verbose=verbose,
10271006
)
10281007
except Exception as exc:
1029-
print(
1030-
f"""Inspiral + MergerRingdown attachment failed. Its very likely
1008+
print(f"""Inspiral + MergerRingdown attachment failed. Its very likely
10311009
that you entered a very large initial eccentricity {eccentricity}. The orbital
10321010
eccentricity at the end of inspiral was {orbital_eccentricity[-1]}
1033-
"""
1034-
)
1011+
""")
10351012
raise exc
10361013
modes_imr_numpy = retval[0]
10371014

esigmapy/legacy.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# Copyright (C) 2023 Prayush Kumar
22
#
3-
"""Legacy code to calibrate transition/attachment of inspiral and merger-ringdown
4-
"""
3+
"""Legacy code to calibrate transition/attachment of inspiral and merger-ringdown"""
54

65

76
class FitMOmegaIMRAttachmentNonSpinning:

esigmapy/surrogate/generator.py

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -422,13 +422,11 @@ def get_imr_esigmasur_mode(
422422
set(available_inspiral_orbital_params)
423423
)
424424
if return_orbital_params_user != set(return_orbital_params):
425-
print(
426-
f"""Warning: You requested the following list of orbital
425+
print(f"""Warning: You requested the following list of orbital
427426
parameters to be returned: {return_orbital_params}, but we reduce it to
428427
{return_orbital_params_user} as we only have the evolution of the following
429428
parameters available with us: {available_inspiral_orbital_params}.
430-
"""
431-
)
429+
""")
432430
elif not return_orbital_params:
433431
return_orbital_params = []
434432
return_orbital_params_user = False
@@ -475,29 +473,23 @@ def get_imr_esigmasur_mode(
475473
modes_inspiral_numpy = retval[-1]
476474

477475
if mode_to_align_by not in modes_inspiral_numpy:
478-
raise RuntimeError(
479-
f"""The inspiral modes do not contain the primary
476+
raise RuntimeError(f"""The inspiral modes do not contain the primary
480477
desired {mode_to_align_by} multipole. It currently holds only the following:
481-
{modes_inspiral_numpy.keys()}"""
482-
)
478+
{modes_inspiral_numpy.keys()}""")
483479

484480
orbital_eccentricity = retval[-2]["e"]
485481
# Throw error if eccentricity at the end of inspiral is definitely unsafe
486482
if orbital_eccentricity[-1] > ECCENTRICITY_LEVEL_ISCO_ERROR:
487-
raise IOError(
488-
f"""ERROR: You entered a very large reference eccentricity
483+
raise IOError(f"""ERROR: You entered a very large reference eccentricity
489484
{reference_eccentricity}. The orbital eccentricity at the end of inspiral was
490485
{orbital_eccentricity[-1]}. The merger-ringdown attachment with a
491-
quasicircular will be questionable."""
492-
)
486+
quasicircular will be questionable.""")
493487
# Warn user if eccentricity at the end of inspiral is potentially unsafe
494488
if orbital_eccentricity[-1] > ECCENTRICITY_LEVEL_ISCO_WARNING and verbose:
495-
print(
496-
f"""WARNING: You entered a very large reference eccentricity
489+
print(f"""WARNING: You entered a very large reference eccentricity
497490
{reference_eccentricity}. The orbital eccentricity at the end of inspiral was
498491
{orbital_eccentricity[-1]}. The merger-ringdown attachment with a quasicircular
499-
model might be affected."""
500-
)
492+
model might be affected.""")
501493

502494
if (f_window_mr_transition is None) or failsafe or (verbose > 1):
503495
if blend_using_avg_orbital_frequency:
@@ -521,14 +513,12 @@ def get_imr_esigmasur_mode(
521513
modes_inspiral_numpy[mode_to_align_by]
522514
)
523515
mode_frequency = esigmapy.blend.compute_frequency(mode_phase, delta_t)
524-
print(
525-
f"""DEBUG: Orbital freq at end of inspiral is {orbital_frequency[-1]}Hz,
516+
print(f"""DEBUG: Orbital freq at end of inspiral is {orbital_frequency[-1]}Hz,
526517
mode-{mode_to_align_by} freq at the end of inspiral is {mode_frequency[-1]}Hz, max and min
527518
mode-{mode_to_align_by} frequencies are {np.max(mode_frequency)}Hz and
528519
{np.min(mode_frequency)}Hz, and the transition frequency (of {mode_to_align_by}-mode)
529520
requested is {f_mr_transition}Hz, which should be less than the maximum freq of
530-
{mode_to_align_by}-mode: {mode_frequency.max()}Hz."""
531-
)
521+
{mode_to_align_by}-mode: {mode_frequency.max()}Hz.""")
532522
return (
533523
modes_inspiral_numpy,
534524
mode_phase,
@@ -547,12 +537,10 @@ def get_imr_esigmasur_mode(
547537
mode_frequency = esigmapy.blend.compute_frequency(mode_phase, delta_t)
548538
if mode_frequency.max() < f_mr_transition:
549539
if verbose:
550-
print(
551-
f"""FAILSAFE: Maximum orbital freq during inspiral is
540+
print(f"""FAILSAFE: Maximum orbital freq during inspiral is
552541
{orbital_frequency.max()}Hz, and max frequency of {mode_to_align_by}-mode is
553542
{mode_frequency.max()}Hz, so we are resetting transition frequency from
554-
{f_mr_transition}Hz to {mode_frequency.max()}Hz."""
555-
)
543+
{f_mr_transition}Hz to {mode_frequency.max()}Hz.""")
556544
f_mr_transition = mode_frequency.max()
557545

558546
# If the user does not provide the width of hybridization window (
@@ -633,12 +621,10 @@ def get_imr_esigmasur_mode(
633621
verbose=verbose,
634622
)
635623
except Exception as exc:
636-
print(
637-
f"""Inspiral + MergerRingdown attachment failed. Its very likely
624+
print(f"""Inspiral + MergerRingdown attachment failed. Its very likely
638625
that you entered a very large reference eccentricity {reference_eccentricity}. The orbital
639626
eccentricity at the end of inspiral was {orbital_eccentricity[-1]}
640-
"""
641-
)
627+
""")
642628
raise exc
643629
modes_imr_numpy = retval[0]
644630

esigmapy/surrogate/surrogate.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@ def __call__(
170170
return_amp_phase_only=False,
171171
return_orbital_variables=False,
172172
):
173-
174173
if delta_t is None and times is None:
175174
raise ValueError("Either delta_t or times must be provided.")
176175

@@ -290,9 +289,12 @@ def check_param_range(self, q, e_ref, l_ref, override=False):
290289
)
291290

292291
def load_sur_metadata(self):
293-
self.sur_total_mass, self.t_ref, self.t_grid_sur, self.l_grid_sur = (
294-
self.get_metadata(["M", "t_ref", "t_grid_sur", "l_grid_sur"])
295-
)
292+
(
293+
self.sur_total_mass,
294+
self.t_ref,
295+
self.t_grid_sur,
296+
self.l_grid_sur,
297+
) = self.get_metadata(["M", "t_ref", "t_grid_sur", "l_grid_sur"])
296298

297299
def load_ei_indices(self):
298300
filename_ei_indices = os.path.join(self.sur_dir, f"ei_indices.npz")
@@ -364,7 +366,6 @@ def __call__(
364366
remove_start_phase=True,
365367
return_orbital_variables=False,
366368
):
367-
368369
if delta_t is None and times is None:
369370
raise ValueError("Either delta_t or times must be provided.")
370371

0 commit comments

Comments
 (0)