Skip to content

Commit

Permalink
get appropriate ylabel
Browse files Browse the repository at this point in the history
  • Loading branch information
md-arif-shaikh committed Jun 25, 2024
1 parent 2e43222 commit 3a8b0e8
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 21 deletions.
20 changes: 10 additions & 10 deletions examples/gw_eccentricity_demo.ipynb

Large diffs are not rendered by default.

33 changes: 28 additions & 5 deletions gw_eccentricity/eccDefinition.py
Original file line number Diff line number Diff line change
Expand Up @@ -2954,7 +2954,7 @@ def plot_omega_gw(
va="top",
transform=ax.transAxes)
ax.set_xlabel(r"$t$")
ax.set_ylabel(labelsDict["omega_gw"])
ax.set_ylabel(self.get_label_for_plots("omega"))
ax.legend(frameon=True,
handlelength=1, labelspacing=0.2, columnspacing=1)
if fig is None or ax is None:
Expand Down Expand Up @@ -3028,7 +3028,7 @@ def plot_omega_gw_average(
c='k',
alpha=0.4,
lw=0.5,
label=labelsDict["omega_gw"])
label=self.get_label_for_plots("omega"))
if (self.extra_kwargs["omega_gw_averaging_method"] == "orbit_averaged_omega_gw" and
plot_orbit_averaged_omega_gw_between_extrema):
ax.plot(self.t_average_apocenters,
Expand Down Expand Up @@ -3125,7 +3125,7 @@ def plot_amp_gw(
ymax = max(self.amp_gw)
ax.set_ylim(ymin, ymax)
ax.set_xlabel(labelsDict["t"])
ax.set_ylabel(labelsDict["amp_gw"])
ax.set_ylabel(self.get_label_for_plots("amp"))
ax.legend(handlelength=1, labelspacing=0.2, columnspacing=1)
if fig is None or ax is None:
return figNew, ax
Expand Down Expand Up @@ -3288,7 +3288,7 @@ def plot_residual_omega_gw(
pad = 0.05 * ylim # 5 % buffer for better visibility
ax.set_ylim(-ylim - pad, ylim + pad)
ax.set_xlabel(labelsDict["t"])
ax.set_ylabel(labelsDict["res_omega_gw"])
ax.set_ylabel(self.get_label_for_plots("res_omega"))
ax.legend(frameon=True, loc="center left",
handlelength=1, labelspacing=0.2, columnspacing=1)
if fig is None or ax is None:
Expand Down Expand Up @@ -3358,7 +3358,7 @@ def plot_residual_amp_gw(
pad = 0.05 * ylim # 5 % buffer for better visibility
ax.set_ylim(-ylim - pad, ylim + pad)
ax.set_xlabel(labelsDict["t"])
ax.set_ylabel(labelsDict["res_amp_gw"])
ax.set_ylabel(self.get_label_for_plots("res_amp"))
ax.legend(frameon=True, loc="center left", handlelength=1,
labelspacing=0.2,
columnspacing=1)
Expand Down Expand Up @@ -3470,6 +3470,29 @@ def plot_data_used_for_finding_extrema(
else:
return ax

def get_label_for_plots(self, data_str):
"""Get appropriate label for plots.
Depending on whether system is precessing or not, generate appropriate
labels to use in plots.
Parameters:
-----------
data_str: str
A string representing the data for which label will be generated.
It must be one of [`amp`, `omega`, `res_amp`, `res_omega`].
Returns:
--------
Appropriate label for the input `data_str`.
"""
allowd_data_str_list = ["amp", "omega", "res_amp", "res_omega"]
if data_str not in allowd_data_str_list:
raise KeyError(f"`data_str` must be one of {allowd_data_str_list}")
return (labelsDict[data_str + "_gw"]
+ " = "
+ labelsDict[data_str + "22" + ("_copr_symm" if self.precessing else "")])

def save_debug_fig(self, fig, fname, fig_name=None, format="pdf"):
"""Save debug plots in fig using fname.
Expand Down
2 changes: 1 addition & 1 deletion gw_eccentricity/eccDefinitionUsingAmplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def __init__(self, *args, **kwargs):
"""
super().__init__(*args, **kwargs)
self.data_for_finding_extrema = self.get_data_for_finding_extrema()
self.label_for_data_for_finding_extrema = labelsDict["amp_gw"]
self.label_for_data_for_finding_extrema = self.get_label_for_plots("amp")
self.method = "Amplitude"

def get_data_for_finding_extrema(self):
Expand Down
2 changes: 1 addition & 1 deletion gw_eccentricity/eccDefinitionUsingAmplitudeFits.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, *args, **kwargs):
"""
super().__init__(*args, **kwargs)
self.data_str = "amp_gw"
self.label_for_data_for_finding_extrema = labelsDict[self.data_str]
self.label_for_data_for_finding_extrema = self.get_label_for_plots("amp")
self.label_for_fit_to_data_for_finding_extrema \
= labelsDict[f"{self.data_str}_fit"]
self.method = "AmplitudeFits"
Expand Down
2 changes: 1 addition & 1 deletion gw_eccentricity/eccDefinitionUsingFrequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def __init__(self, *args, **kwargs):
dataDict: Dictionary containing the waveform data.
"""
super().__init__(*args, **kwargs)
self.label_for_data_for_finding_extrema = labelsDict["omega_gw"]
self.label_for_data_for_finding_extrema = self.get_label_for_plots("omega")
self.method = "Frequency"

def get_data_for_finding_extrema(self):
Expand Down
2 changes: 1 addition & 1 deletion gw_eccentricity/eccDefinitionUsingFrequencyFits.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self, *args, **kwargs):
"""
super().__init__(*args, **kwargs)
self.data_str = "omega_gw"
self.label_for_data_for_finding_extrema = labelsDict[self.data_str]
self.label_for_data_for_finding_extrema = self.get_label_for_plots("omega")
self.label_for_fit_to_data_for_finding_extrema \
= labelsDict[f"{self.data_str}_fit"]
# Make a copy of omega_gw and use it to set data_for_finding_extrema.
Expand Down
2 changes: 1 addition & 1 deletion gw_eccentricity/eccDefinitionUsingResidualAmplitude.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, *args, **kwargs):
"""
super().__init__(*args, **kwargs)
self.method = "ResidualAmplitude"
self.label_for_data_for_finding_extrema = labelsDict["res_amp_gw"]
self.label_for_data_for_finding_extrema = self.get_label_for_plots("res_amp")

def check_and_raise_zeroecc_data_not_found(self, method):
"""Raise exception if zeroecc data not found for Residual method.
Expand Down
2 changes: 1 addition & 1 deletion gw_eccentricity/eccDefinitionUsingResidualFrequency.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def __init__(self, *args, **kwargs):
"""
super().__init__(*args, **kwargs)
self.method = "ResidualFrequency"
self.label_for_data_for_finding_extrema = labelsDict["res_omega_gw"]
self.label_for_data_for_finding_extrema = self.get_label_for_plots("res_omega")

def get_data_for_finding_extrema(self):
"""Get the data for extrema finding."""
Expand Down
2 changes: 2 additions & 0 deletions gw_eccentricity/plot_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,4 +204,6 @@ def use_fancy_plotsettings(usetex=True, style="Notebook"):
"res_omega_gw": r"$\Delta\omega_{\mathrm{gw}}$",
"res_omega_gw_dimless": r"$\Delta\omega_{\mathrm{gw}}$ [rad/$M$]",
"res_amp_gw": r"$\Delta A_{\mathrm{gw}}$",
"omega22_copr_symm": r"\omega_{22}^{\mathrm{copr, sym}}",
"amp22_copr_symm": r"A_{22}^{\mathrm{copr, sym}}"
}

0 comments on commit 3a8b0e8

Please sign in to comment.