From 4cf8f8ce472f1cdd644c35cc61717d7386ceaadc Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 12 Oct 2023 11:25:12 -0400 Subject: [PATCH 1/5] add option to pass sc settings --- legwork/source.py | 4 ++-- legwork/visualisation.py | 10 ++++++---- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/legwork/source.py b/legwork/source.py index 000f2c7..9268e98 100644 --- a/legwork/source.py +++ b/legwork/source.py @@ -1192,7 +1192,7 @@ def plot_source_variables(self, xstr, ystr=None, which_sources=None, return vis.plot_1D_dist(x=x[which_sources], weights=weights, **kwargs) def plot_sources_on_sc(self, snr_cutoff=0, fig=None, ax=None, show=True, - label="Stationary sources", **kwargs): # pragma: no cover + label="Stationary sources", sc_vis_settings={}, **kwargs): # pragma: no cover """Plot all sources in the class on the sensitivity curve Parameters @@ -1250,7 +1250,7 @@ def plot_sources_on_sc(self, snr_cutoff=0, fig=None, ax=None, show=True, weights = self.weights[stat] if self.weights is not None else None fig, ax = vis.plot_sources_on_sc(f_dom=f_dom, snr=self.snr[stat], weights=weights, snr_cutoff=snr_cutoff, show=show, fig=fig, ax=ax, - label=label, **self._sc_params, **kwargs) + label=label, sc_vis_settings=sc_vis_settings, **self._sc_params, **kwargs) # show warnings for evolving sources circ_evol = self.get_source_mask(circular=True, stationary=False) diff --git a/legwork/visualisation.py b/legwork/visualisation.py index 0bd367c..08dfe40 100644 --- a/legwork/visualisation.py +++ b/legwork/visualisation.py @@ -374,7 +374,7 @@ def plot_sensitivity_curve(frequency_range=None, y_quantity="ASD", fig=None, ax= def plot_sources_on_sc(f_dom, snr, weights=None, snr_cutoff=0, t_obs="auto", instrument="LISA", custom_psd=None, L="auto", approximate_R=False, - confusion_noise="auto", fig=None, ax=None, show=True, **kwargs): + confusion_noise="auto", fig=None, ax=None, show=True, sc_vis_settings={}, **kwargs): """Overlay *stationary* sources on the LISA sensitivity curve. Each source is plotted at its max snr harmonic frequency such that that its height above the curve is @@ -446,7 +446,7 @@ def plot_sources_on_sc(f_dom, snr, weights=None, snr_cutoff=0, t_obs="auto", if fig is None or ax is None: fig, ax = plot_sensitivity_curve(show=False, t_obs=t_obs, instrument=instrument, L=L, custom_psd=custom_psd, approximate_R=approximate_R, - confusion_noise=confusion_noise) + confusion_noise=confusion_noise, **sc_vis_settings) # work out which binaries are above the cutoff detectable = snr > snr_cutoff @@ -455,12 +455,14 @@ def plot_sources_on_sc(f_dom, snr, weights=None, snr_cutoff=0, t_obs="auto", return fig, ax # calculate asd that makes it so height above curve is snr - asd = snr[detectable] * np.sqrt(psd.power_spectral_density(f_dom[detectable])) + asd = (snr[detectable] * np.sqrt(psd.power_spectral_density(f_dom[detectable]))).to(u.Hz**(-1/2)) + h_c = asd * np.sqrt(f_dom[detectable]) + use_h_c = ("y_quantity" in sc_vis_settings and sc_vis_settings["y_quantity"] == "h_c") # plot either a scatter or density plot of the detectable binaries ylims = ax.get_ylim() weights = weights[detectable] if weights is not None else None - fig, ax = plot_2D_dist(x=f_dom[detectable], y=asd.to(u.Hz**(-1/2)), weights=weights, + fig, ax = plot_2D_dist(x=f_dom[detectable], y=h_c if use_h_c else asd, weights=weights, fig=fig, ax=ax, show=False, **kwargs) ax.set_ylim(ylims) From 14f18008fb6231e39a87eda88dec5a1827bd66af Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 12 Oct 2023 11:27:03 -0400 Subject: [PATCH 2/5] add docstrings --- legwork/source.py | 4 ++++ legwork/visualisation.py | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/legwork/source.py b/legwork/source.py index 9268e98..1f70beb 100644 --- a/legwork/source.py +++ b/legwork/source.py @@ -1214,6 +1214,10 @@ def plot_sources_on_sc(self, snr_cutoff=0, fig=None, ax=None, show=True, label : `str` Label to use for the plotted points + sc_vis_settings : `dict` + Dictionary of parameters to pass to :meth:`~legwork.visualisation.plot_sensitivity_curve`, + e.g. {"y_quantity": "h_c"} will plot characteristic strain instead of ASD + **kwargs : `various` Keyword arguments to be passed to plotting functions diff --git a/legwork/visualisation.py b/legwork/visualisation.py index 08dfe40..4a72ba6 100644 --- a/legwork/visualisation.py +++ b/legwork/visualisation.py @@ -429,6 +429,10 @@ def plot_sources_on_sc(f_dom, snr, weights=None, snr_cutoff=0, t_obs="auto", show : `boolean` Whether to immediately show the plot or only return the Figure and Axis + sc_vis_settings : `dict` + Dictionary of parameters to pass to :meth:`~legwork.visualisation.plot_sensitivity_curve`, + e.g. {"y_quantity": "h_c"} will plot characteristic strain instead of ASD + **kwargs : `various` This function is a wrapper on :func:`legwork.visualisation.plot_2D_dist` and each kwarg is passed directly to this function. For example, you can write `disttype="kde"` for a kde density plot From bbc65ffbcfac4fb0d32858d38b0d8de9adb1ae89 Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 12 Oct 2023 11:27:16 -0400 Subject: [PATCH 3/5] stop numba from complaining --- legwork/evol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legwork/evol.py b/legwork/evol.py index ae64836..10092cf 100644 --- a/legwork/evol.py +++ b/legwork/evol.py @@ -15,7 +15,7 @@ 'determine_stationarity'] -@jit +@jit(nopython=True) def de_dt(e, times, beta, c_0): # pragma: no cover """Compute eccentricity time derivative From ae88444b85cc826e7056773503160bbccf8e2b68 Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 12 Oct 2023 11:34:43 -0400 Subject: [PATCH 4/5] update changelog and version --- changelog.md | 8 ++++++-- legwork/_version.py | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/changelog.md b/changelog.md index f6cf0df..94da070 100644 --- a/changelog.md +++ b/changelog.md @@ -166,6 +166,10 @@ having two when we could just set `f_dom=2 f_orb` - Ensure `theta` is a co-latitude in `amplitude_modulation` ## 0.4.6 -*TW 13/04/22* +*TW 13/04/23* - [Issue [#109](https://github.com/TeamLEGWORK/LEGWORK/issues/109)] Upgrade `numpy` version - - Upgrade required to avoid error in `np.nan_to_num` usage - thanks to Jakob Stegmann for raising this \ No newline at end of file + - Upgrade required to avoid error in `np.nan_to_num` usage - thanks to Jakob Stegmann for raising this + +## 0.4.7 +*TW 12/10/23* +- [Issue [#111](https://github.com/TeamLEGWORK/LEGWORK/issues/111)] Allow `plot_sources_on_sc` to change the underlying sensitivity curve directly with `sc_vis_settings` diff --git a/legwork/_version.py b/legwork/_version.py index 3dd3d2d..a34b2f6 100644 --- a/legwork/_version.py +++ b/legwork/_version.py @@ -1 +1 @@ -__version__ = "0.4.6" +__version__ = "0.4.7" From 4af9d325c76368dbd78f1d94e91fc56f25efd531 Mon Sep 17 00:00:00 2001 From: Tom Wagg Date: Thu, 12 Oct 2023 11:48:48 -0400 Subject: [PATCH 5/5] less stringent test to avoid rounding confusion --- legwork/tests/test_evol.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/legwork/tests/test_evol.py b/legwork/tests/test_evol.py index d3d0674..4159919 100644 --- a/legwork/tests/test_evol.py +++ b/legwork/tests/test_evol.py @@ -137,7 +137,7 @@ def test_t_merge_special_cases(self): single_time = evol.get_t_merge_ecc(beta=beta[0], a_i=a_i[0], ecc_i=ecc_i[0], large_e_tol=0.9).to(u.yr) - self.assertTrue(array_time[0] == single_time) + self.assertTrue(np.isclose(array_time[0], single_time)) def test_mandel_fit(self): """checks that the Mandel fit to the Peters timescale is the same