From 1813419af2c4bb3bec46c74043ab5bb7d2b3ebc3 Mon Sep 17 00:00:00 2001 From: Nikhil Sarin Date: Fri, 24 Nov 2023 11:52:06 +1100 Subject: [PATCH 1/6] cleanup --- redback_surrogates/afterglowmodels.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/redback_surrogates/afterglowmodels.py b/redback_surrogates/afterglowmodels.py index b0edea7..74d9b3f 100644 --- a/redback_surrogates/afterglowmodels.py +++ b/redback_surrogates/afterglowmodels.py @@ -20,9 +20,9 @@ def _shape_data(thv, loge0, thc, logn0, p, logepse, logepsb, g0,frequency): if isinstance(frequency, (int, float)) == True: - test_data= np.array([np.log10(thv) , loge0 , np.log10(thc), logn0, p, logepse, logepsb, np.log10(g0), frequency]).reshape(1,-1) + test_data = np.array([np.log10(thv) , loge0 , np.log10(thc), logn0, p, logepse, logepsb, np.log10(g0), frequency]).reshape(1,-1) else: - test_data= [] + test_data = [] for f in frequency: test_data.append([np.log10(thv) , loge0 , np.log10(thc), logn0, p, logepse, logepsb, np.log10(g0), f]) return np.array(test_data) @@ -45,15 +45,15 @@ def tophat_emulator(new_time, thv, loge0, thc, logn0, p, logepse, logepsb, g0, f """ test_data = _shape_data(thv, loge0, thc, logn0, p, logepse, logepsb, g0,frequency) - logtime= np.logspace(2.94,7.41,100)/86400 + logtime = np.logspace(2.94,7.41,100)/86400 if thv<=thc: - xtests= scalerx_on.transform(test_data) - prediction= model_on.predict(xtests) + xtests = scalerx_on.transform(test_data) + prediction = model_on.predict(xtests) prediction = np.exp(scalery_on.inverse_transform(prediction)) elif thv>thc: - xtests= scalerx_off.transform(test_data) - prediction= model_off.predict(xtests) + xtests = scalerx_off.transform(test_data) + prediction = model_off.predict(xtests) prediction = np.exp(scalery_off.inverse_transform(prediction)) afterglow = interpolate.interp1d(logtime, prediction, kind='linear', fill_value='extrapolate') From 2543b65d5d73868a37aaf986a2ae9bfe0bc228ef Mon Sep 17 00:00:00 2001 From: Nikhil Sarin Date: Fri, 24 Nov 2023 11:59:28 +1100 Subject: [PATCH 2/6] why cant you build --- docs/conf.py | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/conf.py b/docs/conf.py index 22cdc9c..be270e6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,6 +24,7 @@ # The full version, including alpha/beta/rc tags release = 'alpha' autosummary_generate = True +autodoc_mock_imports = ["bilby"] source_suffix = ['.rst', '.md', '.txt', '.ipynb', '.py'] # -- General configuration --------------------------------------------------- From f9d788db1f2020fcf2724ea99147fab611cf181d Mon Sep 17 00:00:00 2001 From: Nikhil Sarin Date: Fri, 24 Nov 2023 12:07:26 +1100 Subject: [PATCH 3/6] some interface changes --- redback_surrogates/afterglowmodels.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/redback_surrogates/afterglowmodels.py b/redback_surrogates/afterglowmodels.py index 74d9b3f..0f40aa6 100644 --- a/redback_surrogates/afterglowmodels.py +++ b/redback_surrogates/afterglowmodels.py @@ -27,7 +27,7 @@ def _shape_data(thv, loge0, thc, logn0, p, logepse, logepsb, g0,frequency): test_data.append([np.log10(thv) , loge0 , np.log10(thc), logn0, p, logepse, logepsb, np.log10(g0), f]) return np.array(test_data) -def tophat_emulator(new_time, thv, loge0, thc, logn0, p, logepse, logepsb, g0, frequency): +def tophat_emulator(new_time, thv, loge0, thc, logn0, p, logepse, logepsb, g0, **kwargs): """ tophat afterglow model using trained mpl regressor @@ -40,13 +40,15 @@ def tophat_emulator(new_time, thv, loge0, thc, logn0, p, logepse, logepsb, g0, f :param logepse: log10 fraction of thermal energy in electrons :param logepsb: log10 fraction of thermal energy in magnetic field :param g0: initial lorentz factor + :param kwargs: extra arguments for the model :param frequency: frequency of the band to view in- single number or same length as time array :return: flux density at each time for given frequency """ - + + frequency = kwargs['frequency'] test_data = _shape_data(thv, loge0, thc, logn0, p, logepse, logepsb, g0,frequency) logtime = np.logspace(2.94,7.41,100)/86400 - + if thv<=thc: xtests = scalerx_on.transform(test_data) prediction = model_on.predict(xtests) From 95aaca16e47e4e6df8f37457de0b7cf921adb420 Mon Sep 17 00:00:00 2001 From: Nikhil Sarin Date: Fri, 24 Nov 2023 12:10:04 +1100 Subject: [PATCH 4/6] add to autodoc --- docs/conf.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/conf.py b/docs/conf.py index be270e6..56231e0 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -24,7 +24,7 @@ # The full version, including alpha/beta/rc tags release = 'alpha' autosummary_generate = True -autodoc_mock_imports = ["bilby"] +autodoc_mock_imports = ["pickle", "scipy", "kilonovanet"] source_suffix = ['.rst', '.md', '.txt', '.ipynb', '.py'] # -- General configuration --------------------------------------------------- From 359d5496363445495b55f2c4afd0c17f988e6553 Mon Sep 17 00:00:00 2001 From: Nikhil Sarin Date: Fri, 24 Nov 2023 12:15:12 +1100 Subject: [PATCH 5/6] add citation and misc --- redback_surrogates/afterglowmodels.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/redback_surrogates/afterglowmodels.py b/redback_surrogates/afterglowmodels.py index 0f40aa6..1a3ceef 100644 --- a/redback_surrogates/afterglowmodels.py +++ b/redback_surrogates/afterglowmodels.py @@ -2,6 +2,7 @@ from scipy import interpolate import numpy as np import os +from redback_surrogates.utils import citation_wrapper dirname = os.path.dirname(__file__) with open(f"{dirname}/surrogate_data/onax_redback.pkl", "rb") as f_on: @@ -26,7 +27,8 @@ def _shape_data(thv, loge0, thc, logn0, p, logepse, logepsb, g0,frequency): for f in frequency: test_data.append([np.log10(thv) , loge0 , np.log10(thc), logn0, p, logepse, logepsb, np.log10(g0), f]) return np.array(test_data) - + +@citation_wrapper("Wallace and Sarin in prep.") def tophat_emulator(new_time, thv, loge0, thc, logn0, p, logepse, logepsb, g0, **kwargs): """ tophat afterglow model using trained mpl regressor @@ -49,17 +51,17 @@ def tophat_emulator(new_time, thv, loge0, thc, logn0, p, logepse, logepsb, g0, * test_data = _shape_data(thv, loge0, thc, logn0, p, logepse, logepsb, g0,frequency) logtime = np.logspace(2.94,7.41,100)/86400 - if thv<=thc: + if thv <= thc: xtests = scalerx_on.transform(test_data) prediction = model_on.predict(xtests) prediction = np.exp(scalery_on.inverse_transform(prediction)) - elif thv>thc: + else: xtests = scalerx_off.transform(test_data) prediction = model_off.predict(xtests) prediction = np.exp(scalery_off.inverse_transform(prediction)) afterglow = interpolate.interp1d(logtime, prediction, kind='linear', fill_value='extrapolate') - fluxd= afterglow(new_time) + fluxd = afterglow(new_time) if test_data.shape == (1,9): return fluxd[0] From d76bdc4871e9bd445330d55f6bcb296e64b7c032 Mon Sep 17 00:00:00 2001 From: Nikhil Sarin Date: Fri, 24 Nov 2023 12:16:26 +1100 Subject: [PATCH 6/6] minor version bump --- CHANGELOG.md | 6 ++++++ setup.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b4ca21..84d5707 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # All notable changes will be documented in this file +## [0.2.1] 2023-11-24 +Version 0.2.1 release of `redback_surrogates` + +### Changed +- Minor changes to the documentation/interface for afterglow emulator. + ## [0.2] 2023-11-24 Version 0.2 release of `redback_surrogates` diff --git a/setup.py b/setup.py index 6e307a0..ce736b0 100644 --- a/setup.py +++ b/setup.py @@ -4,7 +4,7 @@ long_description = fh.read() setup(name='redback_surrogates', - version='0.2', + version='0.2.1', description='A surrogates package to work with redback, the bayesian inference package for electromagnetic transients', long_description=long_description, long_description_content_type="text/markdown",