Skip to content

Commit

Permalink
Stylistic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kkacanja committed Nov 12, 2024
1 parent 0128224 commit 9e43a4b
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions pycbc/waveform/generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -1198,27 +1198,38 @@ def generate(self, **kwargs):
# =============================================================================
#


# Updated code to make the logic clearer and simplify decision-making based on the domain

def get_td_generator(approximant, modes=False):
"""Returns the time-domain generator for the given approximant."""
if approximant in waveform.td_approximants():
return TDomainCBCModesGenerator if modes else TDomainCBCGenerator
if modes:
return TDomainCBCModesGenerator
return TDomainCBCGenerator

if approximant in ringdown.ringdown_td_approximants:
return TDomainMassSpinRingdownGenerator if approximant == 'TdQNMfromFinalMassSpin' else TDomainFreqTauRingdownGenerator
if approximant == 'TdQNMfromFinalMassSpin':
return TDomainMassSpinRingdownGenerator
return TDomainFreqTauRingdownGenerator

if approximant in supernovae.supernovae_td_approximants:
return TDomainSupernovaeGenerator
raise ValueError(f"No time-domain generator found for approximant: {approximant}")

raise ValueError(f"No time-domain generator found for "
"approximant: {approximant}")

def get_fd_generator(approximant, modes=False):
"""Returns the frequency-domain generator for the given approximant."""
if approximant in waveform.fd_approximants():
return FDomainCBCModesGenerator if modes else FDomainCBCGenerator
if modes:
return FDomainCBCModesGenerator
return FDomainCBCGenerator

if approximant in ringdown.ringdown_fd_approximants:
return FDomainMassSpinRingdownGenerator if approximant == 'FdQNMfromFinalMassSpin' else FDomainFreqTauRingdownGenerator
raise ValueError(f"No frequency-domain generator found for approximant: {approximant}")
if approximant == 'FdQNMfromFinalMassSpin':
return FDomainMassSpinRingdownGenerator
return FDomainFreqTauRingdownGenerator

raise ValueError(f"No frequency-domain generator found for "
"approximant: {approximant}")

def select_waveform_generator(approximant, domain=None):
"""Returns the single-IFO generator for the approximant.
Expand Down Expand Up @@ -1252,7 +1263,8 @@ def select_waveform_generator(approximant, domain=None):
"""

if domain not in {None, 'td', 'fd'}:
raise ValueError(f"Invalid domain '{domain}'. Must be one of: None, 'td', or 'fd'.")
raise ValueError(f"Invalid domain '{domain}'. "
"Must be one of: None, 'td', or 'fd'.")

if domain == 'td':
return get_td_generator(approximant)
Expand Down Expand Up @@ -1283,7 +1295,8 @@ def select_waveform_modes_generator(approximant, domain=None):
"""

if domain not in {None, 'td', 'fd'}:
raise ValueError(f"Invalid domain '{domain}'. Must be one of: None, 'td', or 'fd'.")
raise ValueError(f"Invalid domain '{domain}'. "
"Must be one of: None, 'td', or 'fd'.")

if domain == 'td':
return get_td_generator(approximant, modes=True)
Expand Down

0 comments on commit 9e43a4b

Please sign in to comment.