Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

move debug_level out of extra_kwargs #227 #228

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 19 additions & 19 deletions gw_eccentricity/eccDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import numpy as np
import matplotlib.pyplot as plt
import warnings
from .load_data import get_coprecessing_data_dict
from .utils import peak_time_via_quadratic_fit, check_kwargs_and_set_defaults
from .utils import amplitude_using_all_modes
Expand All @@ -25,8 +24,7 @@ class eccDefinition:
"""Base class to define eccentricity for given waveform data dictionary."""

def __init__(self, dataDict, num_orbits_to_exclude_before_merger=2,
precessing=False,
frame="inertial",
precessing=False, frame="inertial", debug_level=0,
extra_kwargs=None):
"""Init eccDefinition class.

Expand Down Expand Up @@ -196,6 +194,14 @@ def __init__(self, dataDict, num_orbits_to_exclude_before_merger=2,

Default value is "inertial".

debug_level: int
Debug settings for warnings/errors:
-1: All warnings are suppressed. NOTE: Use at your own risk!
0: Only important warnings are issued.
1: All warnings are issued. Use when investigating.
2: All warnings become exceptions.
Default: 0.

extra_kwargs: dict
A dictionary of any extra kwargs to be passed. Allowed kwargs
are:
Expand Down Expand Up @@ -227,14 +233,6 @@ def __init__(self, dataDict, num_orbits_to_exclude_before_merger=2,
eccDefinition.get_width_for_peak_finder_from_phase_gw for more
details.

debug_level: int
Debug settings for warnings/errors:
-1: All warnings are suppressed. NOTE: Use at your own risk!
0: Only important warnings are issued.
1: All warnings are issued. Use when investigating.
2: All warnings become exceptions.
Default: 0.

debug_plots: bool
If True, diagnostic plots are generated. This can be
computationally expensive and should only be used when
Expand Down Expand Up @@ -308,6 +306,7 @@ def __init__(self, dataDict, num_orbits_to_exclude_before_merger=2,
"""
self.precessing = precessing
self.frame = frame
self.debug_level = debug_level
# check if frame makes sense.
available_frames = ["inertial", "coprecessing"]
if self.frame not in available_frames:
Expand Down Expand Up @@ -352,7 +351,6 @@ def __init__(self, dataDict, num_orbits_to_exclude_before_merger=2,
"utils.get_default_spline_kwargs()")
self.available_averaging_methods \
= self.get_available_omega_gw_averaging_methods()
self.debug_level = self.extra_kwargs["debug_level"]
self.debug_plots = self.extra_kwargs["debug_plots"]
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
Expand Down Expand Up @@ -623,11 +621,12 @@ def process_data_dict(self,
# frame, rotate the modes and obtain the corresponding modes in the
# coprecessing frame
if self.precessing is True and self.frame == "inertial":
warnings.warn(
debug_message(
f"The system is precessing but the modes are provided in "
f"the {self.frame} frame. Transforming the modes from"
f" the {self.frame} frame to the coprecessing frame and "
"updating `self.frame` to `coprecessing`.")
"updating `self.frame` to `coprecessing`.",
debug_level=self.debug_level, important=False)
dataDict = self.transform_inertial_to_coprecessing(dataDict)
# transform the zeroecc modes as well if provided in dataDict
if "hlm_zeroecc" in dataDict or "amplm_zeroecc" in dataDict:
Expand Down Expand Up @@ -755,20 +754,22 @@ def transform_inertial_to_coprecessing(self, data_dict, tag=""):
hlm_dict = self.get_hlm_from_amplm_phaselm(amplm_dict, phaselm_dict)
data_dict.update(hlm_dict)
data_dict = get_coprecessing_data_dict(data_dict, tag=tag)
warnings.warn(
debug_message(
f"Removing the input inertial frame {'amplm' + tag}, "
f"{'phaselm' + tag} from `dataDict`. The corresponding "
"coprecessing frame quantities are computed "
f"later from the coprecessing {'hlm' + tag} in "
f"`get_amp_phase_omega_data`.")
f"`get_amp_phase_omega_data`.", debug_level=self.debug_level,
important=False)
data_dict.pop("amplm" + tag, None)
data_dict.pop("phaselm" + tag, None)
if "omegalm" + tag in data_dict:
warnings.warn(
debug_message(
f"Removing the input inertial frame {'omegalm' + tag} "
f"from `dataDict`. The coprecessing {'omegalm' + tag} is "
f"computed later from the coprecessing {'hlm' + tag} in "
f"`get_amp_phase_omega_data`.")
f"`get_amp_phase_omega_data`.", debug_level=self.debug_level,
important=False)
data_dict.pop("omegalm" + tag, None)
return data_dict

Expand Down Expand Up @@ -987,7 +988,6 @@ def get_default_extra_kwargs(self):
"spline_kwargs": {},
"extrema_finding_kwargs": {}, # Gets overridden in methods like
# eccDefinitionUsingAmplitude
"debug_level": 0,
"debug_plots": False,
"omega_gw_averaging_method": "orbit_averaged_omega_gw",
"treat_mid_points_between_pericenters_as_apocenters": False,
Expand Down
19 changes: 10 additions & 9 deletions gw_eccentricity/gw_eccentricity.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ def measure_eccentricity(tref_in=None,
num_orbits_to_exclude_before_merger=2,
precessing=False,
frame="inertial",
debug_level=0,
extra_kwargs=None):
"""Measure eccentricity and mean anomaly from a gravitational waveform.

Expand Down Expand Up @@ -337,6 +338,14 @@ def measure_eccentricity(tref_in=None,

Default value is "inertial".

debug_level: int
Debug settings for warnings/errors:
-1: All warnings are suppressed. NOTE: Use at your own risk!
0: Only important warnings are issued.
1: All warnings are issued. Use when investigating.
2: All warnings become exceptions.
Default: 0.

extra_kwargs: A dict of any extra kwargs to be passed. Allowed kwargs are:
spline_kwargs:
Dictionary of arguments to be passed to the spline interpolation
Expand Down Expand Up @@ -365,14 +374,6 @@ def measure_eccentricity(tref_in=None,
eccDefinition.get_width_for_peak_finder_from_phase_gw for more
details.

debug_level: int
Debug settings for warnings/errors:
-1: All warnings are suppressed. NOTE: Use at your own risk!
0: Only important warnings are issued.
1: All warnings are issued. Use when investigating.
2: All warnings become exceptions.
Default: 0.

debug_plots: bool
If True, diagnostic plots are generated. This can be
computationally expensive and should only be used when
Expand Down Expand Up @@ -500,7 +501,7 @@ def measure_eccentricity(tref_in=None,
if method in available_methods:
gwecc_object = available_methods[method](
dataDict, num_orbits_to_exclude_before_merger,
precessing, frame, extra_kwargs)
precessing, frame, debug_level, extra_kwargs)
return_dict = gwecc_object.measure_ecc(
tref_in=tref_in, fref_in=fref_in)
return_dict.update({"gwecc_object": gwecc_object})
Expand Down
Loading