Skip to content

Commit

Permalink
Merge pull request #219 from vijayvarma392/rename_set_failures_kw
Browse files Browse the repository at this point in the history
rename kw for handling small ecc failure
  • Loading branch information
vijayvarma392 authored Jun 26, 2024
2 parents 4e08849 + 4e0fdf9 commit 76b8941
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 18 deletions.
20 changes: 10 additions & 10 deletions gw_eccentricity/eccDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,15 @@ def __init__(self, dataDict, num_orbits_to_exclude_before_merger=2,
eccDefinitionUsingFrequencyFits.get_default_kwargs_for_fits_methods
for allowed keys.
set_failures_to_zero : bool, default=False
return_zero_if_small_ecc_failure : bool, default=False
The code normally raises an exception if sufficient number of
extrema are not found. This can happen for various reasons
including when the eccentricity is too small for some methods
(like the Amplitude method) to measure. See e.g. Fig.4 of
arxiv.2302.11257. If no extrema are found, we check whether the
following two conditions are satisfied.
1. `set_failures_to_zero` is set to `True`.
1. `return_zero_if_small_ecc_failure` is set to `True`.
2. The waveform is at least
(5 + `num_obrits_to_exclude_before_merger`) orbits long. By
default, `num_obrits_to_exclude_before_merger` is set to 2,
Expand Down Expand Up @@ -314,7 +314,7 @@ def __init__(self, dataDict, num_orbits_to_exclude_before_merger=2,
= self.get_available_omega_gw_averaging_methods()
self.debug_level = self.extra_kwargs["debug_level"]
self.debug_plots = self.extra_kwargs["debug_plots"]
self.set_failures_to_zero = self.extra_kwargs["set_failures_to_zero"]
self.return_zero_if_small_ecc_failure = self.extra_kwargs["return_zero_if_small_ecc_failure"]
# check if there are unrecognized keys in the dataDict
self.recognized_dataDict_keys = self.get_recognized_dataDict_keys()
for kw in dataDict.keys():
Expand Down Expand Up @@ -831,7 +831,7 @@ def get_default_extra_kwargs(self):
"treat_mid_points_between_pericenters_as_apocenters": False,
"refine_extrema": False,
"kwargs_for_fits_methods": {}, # Gets overriden in fits methods
"set_failures_to_zero": False,
"return_zero_if_small_ecc_failure": False,
}
return default_extra_kwargs

Expand Down Expand Up @@ -1194,7 +1194,7 @@ def check_num_extrema(self, extrema, extrema_type="extrema"):
If it is sufficiently long, but the chosen method fails to detect any
extrema, it is possible that the eccentricity is too small. If
`set_failures_to_zero` is set to True, then we set
`return_zero_if_small_ecc_failure` is set to True, then we set
`insufficient_extrema_but_long_waveform` to True and return it.
Parameters
Expand Down Expand Up @@ -1235,13 +1235,13 @@ def check_num_extrema(self, extrema, extrema_type="extrema"):
else:
insufficient_extrema_but_long_waveform = False
if insufficient_extrema_but_long_waveform \
and self.set_failures_to_zero:
and self.return_zero_if_small_ecc_failure:
debug_message(
"The waveform has approximately "
f"{approximate_num_orbits:.2f}"
f" orbits but number of {extrema_type} found is "
f"{num_extrema}. Since `set_failures_to_zero` is set to "
f"{self.set_failures_to_zero}, no exception is raised. "
f"{num_extrema}. Since `return_zero_if_small_ecc_failure` is set to "
f"{self.return_zero_if_small_ecc_failure}, no exception is raised. "
"Instead the eccentricity and mean anomaly will be set to "
"zero.",
important=True,
Expand Down Expand Up @@ -1472,14 +1472,14 @@ def measure_ecc(self, tref_in=None, fref_in=None):
= self.check_num_extrema(apocenters, "apocenters")

# If the eccentricity is too small for a method to find the extrema,
# and `set_failures_to_zero` is true, then we set the eccentricity and
# and `return_zero_if_small_ecc_failure` is true, then we set the eccentricity and
# mean anomaly to zero and return them. In this case, the rest of the
# code in this function is not executed, and therefore, many variables
# that are needed for making diagnostic plots are not computed. Thus,
# in such cases, the diagnostic plots may not work.
if any([insufficient_pericenters_but_long_waveform,
insufficient_apocenters_but_long_waveform]) \
and self.set_failures_to_zero:
and self.return_zero_if_small_ecc_failure:
# Store this information that we are setting ecc and mean anomaly
# to zero to use it in other places
self.setting_ecc_to_zero = True
Expand Down
4 changes: 2 additions & 2 deletions gw_eccentricity/gw_eccentricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -390,15 +390,15 @@ def measure_eccentricity(tref_in=None,
eccDefinitionUsingFrequencyFits.get_default_kwargs_for_fits_methods
for allowed keys.
set_failures_to_zero : bool, default=False
return_zero_if_small_ecc_failure : bool, default=False
The code normally raises an exception if sufficient number of
extrema are not found. This can happen for various reasons
including when the eccentricity is too small for some methods (like
the Amplitude method) to measure. See e.g. Fig.4 of
arxiv.2302.11257. If no extrema are found, we check whether the
following two conditions are satisfied.
1. `set_failures_to_zero` is set to `True`.
1. `return_zero_if_small_ecc_failure` is set to `True`.
2. The waveform is at least (5 +
`num_obrits_to_exclude_before_merger`) orbits long. By default,
`num_obrits_to_exclude_before_merger` is set to 2, meaning that 2
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@
import numpy as np


def test_set_failures_to_zero():
"""Test that the interface works with set_failures_to_zero for waveforms
with small or zero ecc.
def test_return_zero_if_small_ecc_failure():
"""Test that the interface works with return_zero_if_small_ecc_failure for
waveforms with small or zero ecc.
In certain situations, the waveform may have zero eccentricity or a very
small eccentricity, making it difficult for the given method to identify
any extrema. In cases where such a situation occurs, and if the user has
set 'set_failures_to_zero' to `True` in the 'extra_kwargs' parameter, both
the eccentricity and mean anomaly will be set to zero.
set 'return_zero_if_small_ecc_failure' to `True` in the 'extra_kwargs'
parameter, both the eccentricity and mean anomaly will be set to zero.
"""
# The Amplitude and Frequency methods usually fail to detect any extrema
# for eccentricities less than about 1e-3. Therefore, to test whether we
Expand All @@ -39,7 +39,7 @@ def test_set_failures_to_zero():
available_methods = gw_eccentricity.get_available_methods()
# The following will set ecc and mean ano to zero
# if no extrema are found.
extra_kwargs = {"set_failures_to_zero": True}
extra_kwargs = {"return_zero_if_small_ecc_failure": True}

# We want to test it with both a single reference point
# as well as an array of reference points
Expand Down

0 comments on commit 76b8941

Please sign in to comment.