From 4330119d127c8939ae71253a00ee8c12540a851e Mon Sep 17 00:00:00 2001 From: Sahil Jhawar Date: Sun, 23 Jun 2024 15:09:21 +0200 Subject: [PATCH 1/5] add support for citations --- nmma/em/model.py | 78 ++++++++++++++++--- test.ipynb | 191 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 258 insertions(+), 11 deletions(-) create mode 100644 test.ipynb diff --git a/nmma/em/model.py b/nmma/em/model.py index 5ff2306e..04f0e79b 100644 --- a/nmma/em/model.py +++ b/nmma/em/model.py @@ -99,12 +99,52 @@ ], } - -class GenericCombineLightCurveModel(object): +class Mixin: + + + @property + def citation(self): + + citation_dict = { + **dict.fromkeys(["LANLTP1", "LANLTP2", "LANLTS1", "LANLTS2"], ["https://arxiv.org/abs/2105.11543"]), + "Ka2017": ["https://arxiv.org/abs/1710.05463"], + **dict.fromkeys(["Bu2019lm", "Bu2019lm_sparse"], ["https://arxiv.org/abs/2002.11355", "https://arxiv.org/abs/1906.04205"]), + **dict.fromkeys( + [ + "AnBa2022_sparse", + "AnBa2022_log", + "AnBa2022_linear", + ], + ["https://arxiv.org/abs/2302.09226", "https://arxiv.org/abs/2205.10421"], + ), + "Bu2019nsbh": ["https://arxiv.org/abs/2009.07210", "https://arxiv.org/abs/1906.04205"], + **dict.fromkeys( + ["Bu2022Ye", "Bu2023Ye", "Bu2022mv"], ["https://arxiv.org/abs/2307.11080", "https://arxiv.org/abs/1906.04205"] + ), + "TrPi2018": ["https://arxiv.org/abs/1909.11691"], + "Piro2021": ["https://arxiv.org/abs/2007.08543"], + "Me2017": ["https://arxiv.org/abs/1910.01617"], + "Sr2023": None, # TODO: add citation, + "nugent-hyper": ["https://sncosmo.readthedocs.io/en/stable/source-list.html"], + **dict.fromkeys(["PL_BB_fixedT", "blackbody_fixedT", "synchrotron_powerlaw"], "Analytical models"), + } + return {self.model: citation_dict[self.model]} + + +class GenericCombineLightCurveModel(Mixin): def __init__(self, models, sample_times): self.models = models self.sample_times = sample_times + @property + def citation(self): + citations = [] + for model in self.models: + + citations.append(model.citation) + + return citations + def generate_lightcurve(self, sample_times, parameters, return_all=False): total_lbol = np.zeros(len(sample_times)) @@ -149,7 +189,7 @@ def generate_lightcurve(self, sample_times, parameters, return_all=False): return total_lbol, total_mag -class SVDLightCurveModel(object): +class SVDLightCurveModel(Mixin): """A light curve model object An object to evaluate the light curve across filters @@ -412,7 +452,7 @@ def generate_spectra(self, sample_times, wavelengths, parameters): return spec -class GRBLightCurveModel(object): +class GRBLightCurveModel(Mixin): def __init__( self, sample_times, @@ -508,7 +548,7 @@ def generate_lightcurve(self, sample_times, parameters): return lbol, mag -class KilonovaGRBLightCurveModel(object): +class KilonovaGRBLightCurveModel(Mixin): def __init__( self, sample_times, @@ -537,6 +577,12 @@ def __repr__(self): self.kilonova_lightcurve_model ) return self.__class__.__name__ + details + + @property + def citation(self): + citations = [self.grb_lightcurve_model.citation] + citations.append(self.kilonova_lightcurve_model.citation) + return citations def observation_angle_conversion(self, parameters): @@ -600,7 +646,7 @@ def generate_lightcurve(self, sample_times, parameters): return total_lbol, total_mag -class HostGalaxyLightCurveModel(object): +class HostGalaxyLightCurveModel(Mixin): def __init__( self, sample_times, @@ -657,7 +703,7 @@ def generate_lightcurve(self, sample_times, parameters): return lbol, mag -class SupernovaLightCurveModel(object): +class SupernovaLightCurveModel(Mixin): def __init__( self, sample_times, @@ -719,7 +765,7 @@ def generate_lightcurve(self, sample_times, parameters): return lbol, mag -class SupernovaGRBLightCurveModel(object): +class SupernovaGRBLightCurveModel(Mixin): def __init__( self, sample_times, @@ -744,6 +790,11 @@ def __init__( def __repr__(self): details = "(grb model using afterglowpy with supernova model nugent-hyper)" return self.__class__.__name__ + details + + @property + def citation(self): + citations = [self.grb_lightcurve_model.citation, self.supernova_lightcurve_model.citation] + return citations def generate_lightcurve(self, sample_times, parameters): @@ -786,7 +837,7 @@ def generate_lightcurve(self, sample_times, parameters): return total_lbol, total_mag -class ShockCoolingLightCurveModel(object): +class ShockCoolingLightCurveModel(Mixin): def __init__( self, sample_times, parameter_conversion=None, model="Piro2021", filters=None ): @@ -839,7 +890,7 @@ def generate_lightcurve(self, sample_times, parameters): return lbol, mag -class SupernovaShockCoolingLightCurveModel(object): +class SupernovaShockCoolingLightCurveModel(Mixin): def __init__(self, sample_times, parameter_conversion=None, filters=None): self.sample_times = sample_times @@ -857,6 +908,11 @@ def __repr__(self): "(shock cooling model using Piro2021 with supernova model nugent-hyper)" ) return self.__class__.__name__ + details + + @property + def citation(self): + citations = [self.sc_lightcurve_model.citation, self.supernova_lightcurve_model.citation] + return citations def generate_lightcurve(self, sample_times, parameters): @@ -903,7 +959,7 @@ def generate_lightcurve(self, sample_times, parameters): return total_lbol, total_mag -class SimpleKilonovaLightCurveModel(object): +class SimpleKilonovaLightCurveModel(Mixin): def __init__( self, sample_times, parameter_conversion=None, model="Me2017", filters=None ): diff --git a/test.ipynb b/test.ipynb new file mode 100644 index 00000000..29a10b50 --- /dev/null +++ b/test.ipynb @@ -0,0 +1,191 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 121, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "The autoreload extension is already loaded. To reload it, use:\n", + " %reload_ext autoreload\n" + ] + } + ], + "source": [ + "%load_ext autoreload\n", + "%autoreload 2\n", + "\n", + "from nmma.em.model import *" + ] + }, + { + "cell_type": "code", + "execution_count": 122, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loaded filter 2massh\n" + ] + } + ], + "source": [ + "kn = SVDLightCurveModel(model=\"Bu2019lm\",sample_times=[0,0.5],svd_path=\"/home/enlil/jhawar/svdmodels_new\",local_only=True,filters=[\"2massh\"])" + ] + }, + { + "cell_type": "code", + "execution_count": 124, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "{'TrPi2018': ['https://arxiv.org/abs/1909.11691']}" + ] + }, + "execution_count": 124, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "grb.citation" + ] + }, + { + "cell_type": "code", + "execution_count": 129, + "metadata": {}, + "outputs": [], + "source": [ + "b = GenericCombineLightCurveModel(models=[kn,grb],sample_times=[0,0.5])" + ] + }, + { + "cell_type": "code", + "execution_count": 130, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'Bu2019lm': ['https://arxiv.org/abs/2002.11355',\n", + " 'https://arxiv.org/abs/1906.04205']},\n", + " {'TrPi2018': ['https://arxiv.org/abs/1909.11691']}]" + ] + }, + "execution_count": 130, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "b.citation" + ] + }, + { + "cell_type": "code", + "execution_count": 137, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Loaded filter 2massh\n" + ] + } + ], + "source": [ + "kngrb = KilonovaGRBLightCurveModel(sample_times=[0,5],kilonova_kwargs=dict(model=\"Bu2019lm\",sample_times=[0,0.5],svd_path=\"/home/enlil/jhawar/svdmodels_new\",local_only=True,filters=[\"2massh\"],parameter_conversion=None))" + ] + }, + { + "cell_type": "code", + "execution_count": 139, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "[{'TrPi2018': ['https://arxiv.org/abs/1909.11691']},\n", + " {'Bu2019lm': ['https://arxiv.org/abs/2002.11355',\n", + " 'https://arxiv.org/abs/1906.04205']}]" + ] + }, + "execution_count": 139, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "kngrb.citation" + ] + }, + { + "cell_type": "code", + "execution_count": 143, + "metadata": {}, + "outputs": [], + "source": [ + "snsc =SupernovaShockCoolingLightCurveModel(sample_times=[0,5])" + ] + }, + { + "cell_type": "code", + "execution_count": 145, + "metadata": {}, + "outputs": [ + { + "ename": "AttributeError", + "evalue": "'SupernovaShockCoolingLightCurveModel' object has no attribute 'model'", + "output_type": "error", + "traceback": [ + "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", + "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", + "Cell \u001b[0;32mIn[145], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43msnsc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcitation\u001b[49m\n", + "File \u001b[0;32m~/testnmma/nmma/nmma/em/model.py:131\u001b[0m, in \u001b[0;36mMixin.citation\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[38;5;129m@property\u001b[39m\n\u001b[1;32m 106\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcitation\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 108\u001b[0m citation_dict \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 109\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mdict\u001b[39m\u001b[38;5;241m.\u001b[39mfromkeys([\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLANLTP1\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLANLTP2\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLANLTS1\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLANLTS2\u001b[39m\u001b[38;5;124m\"\u001b[39m], [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://arxiv.org/abs/2105.11543\u001b[39m\u001b[38;5;124m\"\u001b[39m]),\n\u001b[1;32m 110\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mKa2017\u001b[39m\u001b[38;5;124m\"\u001b[39m: [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://arxiv.org/abs/1710.05463\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mdict\u001b[39m\u001b[38;5;241m.\u001b[39mfromkeys([\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPL_BB_fixedT\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mblackbody_fixedT\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msynchrotron_powerlaw\u001b[39m\u001b[38;5;124m\"\u001b[39m], \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAnalytical models\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m 130\u001b[0m }\n\u001b[0;32m--> 131\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m {\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel\u001b[49m: citation_dict[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel]}\n", + "\u001b[0;31mAttributeError\u001b[0m: 'SupernovaShockCoolingLightCurveModel' object has no attribute 'model'" + ] + } + ], + "source": [ + "snsc.citation" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + } + ], + "metadata": { + "kernelspec": { + "display_name": "nmma_env311", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.11.5" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +} From 4e25cb79aa8db9c2e3adb76293db48e2cccca035 Mon Sep 17 00:00:00 2001 From: Sahil Jhawar Date: Sun, 23 Jun 2024 15:19:41 +0200 Subject: [PATCH 2/5] delete notebook --- test.ipynb | 191 ----------------------------------------------------- 1 file changed, 191 deletions(-) delete mode 100644 test.ipynb diff --git a/test.ipynb b/test.ipynb deleted file mode 100644 index 29a10b50..00000000 --- a/test.ipynb +++ /dev/null @@ -1,191 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": 121, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "The autoreload extension is already loaded. To reload it, use:\n", - " %reload_ext autoreload\n" - ] - } - ], - "source": [ - "%load_ext autoreload\n", - "%autoreload 2\n", - "\n", - "from nmma.em.model import *" - ] - }, - { - "cell_type": "code", - "execution_count": 122, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Loaded filter 2massh\n" - ] - } - ], - "source": [ - "kn = SVDLightCurveModel(model=\"Bu2019lm\",sample_times=[0,0.5],svd_path=\"/home/enlil/jhawar/svdmodels_new\",local_only=True,filters=[\"2massh\"])" - ] - }, - { - "cell_type": "code", - "execution_count": 124, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "{'TrPi2018': ['https://arxiv.org/abs/1909.11691']}" - ] - }, - "execution_count": 124, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "grb.citation" - ] - }, - { - "cell_type": "code", - "execution_count": 129, - "metadata": {}, - "outputs": [], - "source": [ - "b = GenericCombineLightCurveModel(models=[kn,grb],sample_times=[0,0.5])" - ] - }, - { - "cell_type": "code", - "execution_count": 130, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'Bu2019lm': ['https://arxiv.org/abs/2002.11355',\n", - " 'https://arxiv.org/abs/1906.04205']},\n", - " {'TrPi2018': ['https://arxiv.org/abs/1909.11691']}]" - ] - }, - "execution_count": 130, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "b.citation" - ] - }, - { - "cell_type": "code", - "execution_count": 137, - "metadata": {}, - "outputs": [ - { - "name": "stdout", - "output_type": "stream", - "text": [ - "Loaded filter 2massh\n" - ] - } - ], - "source": [ - "kngrb = KilonovaGRBLightCurveModel(sample_times=[0,5],kilonova_kwargs=dict(model=\"Bu2019lm\",sample_times=[0,0.5],svd_path=\"/home/enlil/jhawar/svdmodels_new\",local_only=True,filters=[\"2massh\"],parameter_conversion=None))" - ] - }, - { - "cell_type": "code", - "execution_count": 139, - "metadata": {}, - "outputs": [ - { - "data": { - "text/plain": [ - "[{'TrPi2018': ['https://arxiv.org/abs/1909.11691']},\n", - " {'Bu2019lm': ['https://arxiv.org/abs/2002.11355',\n", - " 'https://arxiv.org/abs/1906.04205']}]" - ] - }, - "execution_count": 139, - "metadata": {}, - "output_type": "execute_result" - } - ], - "source": [ - "kngrb.citation" - ] - }, - { - "cell_type": "code", - "execution_count": 143, - "metadata": {}, - "outputs": [], - "source": [ - "snsc =SupernovaShockCoolingLightCurveModel(sample_times=[0,5])" - ] - }, - { - "cell_type": "code", - "execution_count": 145, - "metadata": {}, - "outputs": [ - { - "ename": "AttributeError", - "evalue": "'SupernovaShockCoolingLightCurveModel' object has no attribute 'model'", - "output_type": "error", - "traceback": [ - "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m", - "\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)", - "Cell \u001b[0;32mIn[145], line 1\u001b[0m\n\u001b[0;32m----> 1\u001b[0m \u001b[43msnsc\u001b[49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mcitation\u001b[49m\n", - "File \u001b[0;32m~/testnmma/nmma/nmma/em/model.py:131\u001b[0m, in \u001b[0;36mMixin.citation\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m 105\u001b[0m \u001b[38;5;129m@property\u001b[39m\n\u001b[1;32m 106\u001b[0m \u001b[38;5;28;01mdef\u001b[39;00m \u001b[38;5;21mcitation\u001b[39m(\u001b[38;5;28mself\u001b[39m):\n\u001b[1;32m 108\u001b[0m citation_dict \u001b[38;5;241m=\u001b[39m {\n\u001b[1;32m 109\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mdict\u001b[39m\u001b[38;5;241m.\u001b[39mfromkeys([\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLANLTP1\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLANLTP2\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLANLTS1\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mLANLTS2\u001b[39m\u001b[38;5;124m\"\u001b[39m], [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://arxiv.org/abs/2105.11543\u001b[39m\u001b[38;5;124m\"\u001b[39m]),\n\u001b[1;32m 110\u001b[0m \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mKa2017\u001b[39m\u001b[38;5;124m\"\u001b[39m: [\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mhttps://arxiv.org/abs/1710.05463\u001b[39m\u001b[38;5;124m\"\u001b[39m],\n\u001b[0;32m (...)\u001b[0m\n\u001b[1;32m 129\u001b[0m \u001b[38;5;241m*\u001b[39m\u001b[38;5;241m*\u001b[39m\u001b[38;5;28mdict\u001b[39m\u001b[38;5;241m.\u001b[39mfromkeys([\u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mPL_BB_fixedT\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mblackbody_fixedT\u001b[39m\u001b[38;5;124m\"\u001b[39m, \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124msynchrotron_powerlaw\u001b[39m\u001b[38;5;124m\"\u001b[39m], \u001b[38;5;124m\"\u001b[39m\u001b[38;5;124mAnalytical models\u001b[39m\u001b[38;5;124m\"\u001b[39m),\n\u001b[1;32m 130\u001b[0m }\n\u001b[0;32m--> 131\u001b[0m \u001b[38;5;28;01mreturn\u001b[39;00m {\u001b[38;5;28;43mself\u001b[39;49m\u001b[38;5;241;43m.\u001b[39;49m\u001b[43mmodel\u001b[49m: citation_dict[\u001b[38;5;28mself\u001b[39m\u001b[38;5;241m.\u001b[39mmodel]}\n", - "\u001b[0;31mAttributeError\u001b[0m: 'SupernovaShockCoolingLightCurveModel' object has no attribute 'model'" - ] - } - ], - "source": [ - "snsc.citation" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "metadata": {}, - "outputs": [], - "source": [] - } - ], - "metadata": { - "kernelspec": { - "display_name": "nmma_env311", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.5" - } - }, - "nbformat": 4, - "nbformat_minor": 2 -} From b88a83e309d775de1d398f602ef80e5ae927cee4 Mon Sep 17 00:00:00 2001 From: Sahil Jhawar Date: Sun, 23 Jun 2024 15:22:16 +0200 Subject: [PATCH 3/5] reformat --- nmma/em/model.py | 132 ++++++++++++++--------------------------------- 1 file changed, 40 insertions(+), 92 deletions(-) diff --git a/nmma/em/model.py b/nmma/em/model.py index 04f0e79b..4a4a76cf 100644 --- a/nmma/em/model.py +++ b/nmma/em/model.py @@ -99,8 +99,8 @@ ], } + class Mixin: - @property def citation(self): @@ -108,7 +108,9 @@ def citation(self): citation_dict = { **dict.fromkeys(["LANLTP1", "LANLTP2", "LANLTS1", "LANLTS2"], ["https://arxiv.org/abs/2105.11543"]), "Ka2017": ["https://arxiv.org/abs/1710.05463"], - **dict.fromkeys(["Bu2019lm", "Bu2019lm_sparse"], ["https://arxiv.org/abs/2002.11355", "https://arxiv.org/abs/1906.04205"]), + **dict.fromkeys( + ["Bu2019lm", "Bu2019lm_sparse"], ["https://arxiv.org/abs/2002.11355", "https://arxiv.org/abs/1906.04205"] + ), **dict.fromkeys( [ "AnBa2022_sparse", @@ -128,6 +130,7 @@ def citation(self): "nugent-hyper": ["https://sncosmo.readthedocs.io/en/stable/source-list.html"], **dict.fromkeys(["PL_BB_fixedT", "blackbody_fixedT", "synchrotron_powerlaw"], "Analytical models"), } + return {self.model: citation_dict[self.model]} @@ -140,11 +143,10 @@ def __init__(self, models, sample_times): def citation(self): citations = [] for model in self.models: - citations.append(model.citation) return citations - + def generate_lightcurve(self, sample_times, parameters, return_all=False): total_lbol = np.zeros(len(sample_times)) @@ -236,9 +238,7 @@ def __init__( ): if model_parameters is None: - assert model in model_parameters_dict.keys(), ( - "Unknown model," "please update model_parameters_dict at em/model.py" - ) + assert model in model_parameters_dict.keys(), "Unknown model," "please update model_parameters_dict at em/model.py" self.model_parameters = model_parameters_dict[model] else: self.model_parameters = model_parameters @@ -265,9 +265,7 @@ def __init__( if self.interpolation_type == "sklearn_gp": if not local_only: - _, model_filters = get_model( - self.svd_path, f"{self.model}", filters=filters - ) + _, model_filters = get_model(self.svd_path, f"{self.model}", filters=filters) if filters is None and model_filters is not None: self.filters = model_filters @@ -303,9 +301,7 @@ def __init__( self.svd_mag_model = joblib.load(modelfile) for filt in self.filters: for ii in range(len(self.svd_mag_model[filt]["gps"])): - self.svd_mag_model[filt]["gps"][ii] = load_api_gp_model( - self.svd_mag_model[filt]["gps"][ii] - ) + self.svd_mag_model[filt]["gps"][ii] = load_api_gp_model(self.svd_mag_model[filt]["gps"][ii]) self.svd_lbol_model = None elif self.interpolation_type == "tensorflow": import tensorflow as tf @@ -314,9 +310,7 @@ def __init__( from tensorflow.keras.models import load_model if not local_only: - _, model_filters = get_model( - self.svd_path, f"{self.model}_tf", filters=filters - ) + _, model_filters = get_model(self.svd_path, f"{self.model}_tf", filters=filters) if filters is None: self.filters = model_filters @@ -349,15 +343,11 @@ def __init__( return ValueError("--interpolation-type must be sklearn_gp or tensorflow") def __repr__(self): - return self.__class__.__name__ + "(model={0}, svd_path={1})".format( - self.model, self.svd_path - ) + return self.__class__.__name__ + "(model={0}, svd_path={1})".format(self.model, self.svd_path) def observation_angle_conversion(self, parameters): if "KNtheta" not in parameters: - parameters["KNtheta"] = ( - parameters.get("inclination_EM", 0.0) * 180.0 / np.pi - ) + parameters["KNtheta"] = parameters.get("inclination_EM", 0.0) * 180.0 / np.pi return parameters def generate_lightcurve(self, sample_times, parameters): @@ -375,13 +365,9 @@ def generate_lightcurve(self, sample_times, parameters): parameters_list.append(new_parameters[parameter_name]) except KeyError: if "log10" in parameter_name: - parameters_list.append( - np.log10(new_parameters[parameter_name.replace("log10_", "")]) - ) + parameters_list.append(np.log10(new_parameters[parameter_name.replace("log10_", "")])) else: - parameters_list.append( - 10 ** new_parameters[f"log10_{parameter_name}"] - ) + parameters_list.append(10 ** new_parameters[f"log10_{parameter_name}"]) z = utils.getRedShift(new_parameters) @@ -479,9 +465,7 @@ def __init__( give a set of parameters """ - assert model in model_parameters_dict.keys(), ( - "Unknown model," "please update model_parameters_dict at em/model.py" - ) + assert model in model_parameters_dict.keys(), "Unknown model," "please update model_parameters_dict at em/model.py" self.model = model self.model_parameters = model_parameters_dict[model] self.sample_times = sample_times @@ -526,10 +510,7 @@ def generate_lightcurve(self, sample_times, parameters): if "thetaWing" in new_parameters: grb_param_dict["thetaWing"] = new_parameters["thetaWing"] - if ( - new_parameters["thetaWing"] / new_parameters["thetaCore"] - > self.resolution - ): + if new_parameters["thetaWing"] / new_parameters["thetaCore"] > self.resolution: return np.zeros(len(sample_times)), {} if grb_param_dict["epsilon_e"] + grb_param_dict["epsilon_B"] > 1.0: @@ -542,9 +523,7 @@ def generate_lightcurve(self, sample_times, parameters): Ebv = new_parameters.get("Ebv", 0.0) - _, lbol, mag = utils.grb_lc( - sample_times, Ebv, grb_param_dict, filters=self.filters - ) + _, lbol, mag = utils.grb_lc(sample_times, Ebv, grb_param_dict, filters=self.filters) return lbol, mag @@ -573,15 +552,14 @@ def __init__( ) def __repr__(self): - details = "(grb model using afterglowpy with kilonova model {0})".format( - self.kilonova_lightcurve_model - ) + details = "(grb model using afterglowpy with kilonova model {0})".format(self.kilonova_lightcurve_model) return self.__class__.__name__ + details - + @property def citation(self): citations = [self.grb_lightcurve_model.citation] citations.append(self.kilonova_lightcurve_model.citation) + return citations def observation_angle_conversion(self, parameters): @@ -602,9 +580,7 @@ def generate_lightcurve(self, sample_times, parameters): new_parameters = self.observation_angle_conversion(new_parameters) - grb_lbol, grb_mag = self.grb_lightcurve_model.generate_lightcurve( - sample_times, new_parameters - ) + grb_lbol, grb_mag = self.grb_lightcurve_model.generate_lightcurve(sample_times, new_parameters) if np.sum(grb_lbol) == 0.0 or len(np.isfinite(grb_lbol)) == 0: return total_lbol, total_mag @@ -612,9 +588,7 @@ def generate_lightcurve(self, sample_times, parameters): ( kilonova_lbol, kilonova_mag, - ) = self.kilonova_lightcurve_model.generate_lightcurve( - sample_times, new_parameters - ) + ) = self.kilonova_lightcurve_model.generate_lightcurve(sample_times, new_parameters) for filt in grb_mag.keys(): grb_mAB = grb_mag[filt] @@ -783,17 +757,16 @@ def __init__( resolution=GRB_resolution, jetType=jetType, ) - self.supernova_lightcurve_model = SupernovaLightCurveModel( - sample_times, parameter_conversion, model=SNmodel - ) + self.supernova_lightcurve_model = SupernovaLightCurveModel(sample_times, parameter_conversion, model=SNmodel) def __repr__(self): details = "(grb model using afterglowpy with supernova model nugent-hyper)" return self.__class__.__name__ + details - + @property def citation(self): citations = [self.grb_lightcurve_model.citation, self.supernova_lightcurve_model.citation] + return citations def generate_lightcurve(self, sample_times, parameters): @@ -801,9 +774,7 @@ def generate_lightcurve(self, sample_times, parameters): total_lbol = np.zeros(len(sample_times)) total_mag = {} - grb_lbol, grb_mag = self.grb_lightcurve_model.generate_lightcurve( - sample_times, parameters - ) + grb_lbol, grb_mag = self.grb_lightcurve_model.generate_lightcurve(sample_times, parameters) if np.sum(grb_lbol) == 0.0 or len(np.isfinite(grb_lbol)) == 0: return total_lbol, total_mag @@ -811,9 +782,7 @@ def generate_lightcurve(self, sample_times, parameters): ( supernova_lbol, supernova_mag, - ) = self.supernova_lightcurve_model.generate_lightcurve( - sample_times, parameters - ) + ) = self.supernova_lightcurve_model.generate_lightcurve(sample_times, parameters) if np.sum(supernova_lbol) == 0.0 or len(np.isfinite(supernova_lbol)) == 0: return total_lbol, total_mag @@ -838,9 +807,7 @@ def generate_lightcurve(self, sample_times, parameters): class ShockCoolingLightCurveModel(Mixin): - def __init__( - self, sample_times, parameter_conversion=None, model="Piro2021", filters=None - ): + def __init__(self, sample_times, parameter_conversion=None, model="Piro2021", filters=None): """A light curve model object An object to evaluted the shock cooling light curve across filters @@ -857,9 +824,7 @@ def __init__( give a set of parameters """ - assert model in model_parameters_dict.keys(), ( - "Unknown model," "please update model_parameters_dict at em/model.py" - ) + assert model in model_parameters_dict.keys(), "Unknown model," "please update model_parameters_dict at em/model.py" self.model = model self.model_parameters = model_parameters_dict[model] self.sample_times = sample_times @@ -895,23 +860,18 @@ def __init__(self, sample_times, parameter_conversion=None, filters=None): self.sample_times = sample_times - self.sc_lightcurve_model = ShockCoolingLightCurveModel( - sample_times, parameter_conversion - ) - self.supernova_lightcurve_model = SupernovaLightCurveModel( - sample_times, parameter_conversion - ) + self.sc_lightcurve_model = ShockCoolingLightCurveModel(sample_times, parameter_conversion) + self.supernova_lightcurve_model = SupernovaLightCurveModel(sample_times, parameter_conversion) self.filters = filters def __repr__(self): - details = ( - "(shock cooling model using Piro2021 with supernova model nugent-hyper)" - ) + details = "(shock cooling model using Piro2021 with supernova model nugent-hyper)" return self.__class__.__name__ + details - + @property def citation(self): citations = [self.sc_lightcurve_model.citation, self.supernova_lightcurve_model.citation] + return citations def generate_lightcurve(self, sample_times, parameters): @@ -960,9 +920,7 @@ def generate_lightcurve(self, sample_times, parameters): class SimpleKilonovaLightCurveModel(Mixin): - def __init__( - self, sample_times, parameter_conversion=None, model="Me2017", filters=None - ): + def __init__(self, sample_times, parameter_conversion=None, model="Me2017", filters=None): """A light curve model object An object to evaluted the kilonova (with Me2017) light curve across filters @@ -979,9 +937,7 @@ def __init__( give a set of parameters """ - assert model in model_parameters_dict.keys(), ( - "Unknown model," "please update model_parameters_dict at em/model.py" - ) + assert model in model_parameters_dict.keys(), "Unknown model," "please update model_parameters_dict at em/model.py" self.model = model self.model_parameters = model_parameters_dict[model] self.sample_times = sample_times @@ -1009,21 +965,13 @@ def generate_lightcurve(self, sample_times, parameters): param_dict["Ebv"] = Ebv if self.model == "Me2017": - _, lbol, mag = utils.metzger_lc( - sample_times, param_dict, filters=self.filters - ) + _, lbol, mag = utils.metzger_lc(sample_times, param_dict, filters=self.filters) elif self.model == "PL_BB_fixedT": - _, lbol, mag = utils.powerlaw_blackbody_constant_temperature_lc( - sample_times, param_dict, filters=self.filters - ) + _, lbol, mag = utils.powerlaw_blackbody_constant_temperature_lc(sample_times, param_dict, filters=self.filters) elif self.model == "blackbody_fixedT": - _, lbol, mag = utils.blackbody_constant_temperature( - sample_times, param_dict, filters=self.filters - ) + _, lbol, mag = utils.blackbody_constant_temperature(sample_times, param_dict, filters=self.filters) elif self.model == "synchrotron_powerlaw": - _, lbol, mag = utils.synchrotron_powerlaw( - sample_times, param_dict, filters=self.filters - ) + _, lbol, mag = utils.synchrotron_powerlaw(sample_times, param_dict, filters=self.filters) # remove the distance modulus for the synchrotron powerlaw # as the reference flux is defined at the observer dist_mod = 5.0 * np.log10(new_parameters["luminosity_distance"] * 1e6 / 10) From ca057178f26c094d47008bbcdee867b06e3aa969 Mon Sep 17 00:00:00 2001 From: Sahil Jhawar Date: Sun, 23 Jun 2024 15:36:01 +0200 Subject: [PATCH 4/5] convert to list --- nmma/em/model.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nmma/em/model.py b/nmma/em/model.py index 4a4a76cf..18e9cee4 100644 --- a/nmma/em/model.py +++ b/nmma/em/model.py @@ -126,9 +126,9 @@ def citation(self): "TrPi2018": ["https://arxiv.org/abs/1909.11691"], "Piro2021": ["https://arxiv.org/abs/2007.08543"], "Me2017": ["https://arxiv.org/abs/1910.01617"], - "Sr2023": None, # TODO: add citation, + "Sr2023": [None], # TODO: add citation, "nugent-hyper": ["https://sncosmo.readthedocs.io/en/stable/source-list.html"], - **dict.fromkeys(["PL_BB_fixedT", "blackbody_fixedT", "synchrotron_powerlaw"], "Analytical models"), + **dict.fromkeys(["PL_BB_fixedT", "blackbody_fixedT", "synchrotron_powerlaw"], ["Analytical models"]), } return {self.model: citation_dict[self.model]} From e3890801d06c775d3198abe294f2477e664f122e Mon Sep 17 00:00:00 2001 From: Sahil Jhawar Date: Sun, 23 Jun 2024 15:51:18 +0200 Subject: [PATCH 5/5] Mixin -> LightCurveMixin --- nmma/em/model.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/nmma/em/model.py b/nmma/em/model.py index 18e9cee4..592448ff 100644 --- a/nmma/em/model.py +++ b/nmma/em/model.py @@ -100,7 +100,7 @@ } -class Mixin: +class LightCurveMixin: @property def citation(self): @@ -134,7 +134,7 @@ def citation(self): return {self.model: citation_dict[self.model]} -class GenericCombineLightCurveModel(Mixin): +class GenericCombineLightCurveModel(LightCurveMixin): def __init__(self, models, sample_times): self.models = models self.sample_times = sample_times @@ -191,7 +191,7 @@ def generate_lightcurve(self, sample_times, parameters, return_all=False): return total_lbol, total_mag -class SVDLightCurveModel(Mixin): +class SVDLightCurveModel(LightCurveMixin): """A light curve model object An object to evaluate the light curve across filters @@ -438,7 +438,7 @@ def generate_spectra(self, sample_times, wavelengths, parameters): return spec -class GRBLightCurveModel(Mixin): +class GRBLightCurveModel(LightCurveMixin): def __init__( self, sample_times, @@ -527,7 +527,7 @@ def generate_lightcurve(self, sample_times, parameters): return lbol, mag -class KilonovaGRBLightCurveModel(Mixin): +class KilonovaGRBLightCurveModel(LightCurveMixin): def __init__( self, sample_times, @@ -620,7 +620,7 @@ def generate_lightcurve(self, sample_times, parameters): return total_lbol, total_mag -class HostGalaxyLightCurveModel(Mixin): +class HostGalaxyLightCurveModel(LightCurveMixin): def __init__( self, sample_times, @@ -677,7 +677,7 @@ def generate_lightcurve(self, sample_times, parameters): return lbol, mag -class SupernovaLightCurveModel(Mixin): +class SupernovaLightCurveModel(LightCurveMixin): def __init__( self, sample_times, @@ -739,7 +739,7 @@ def generate_lightcurve(self, sample_times, parameters): return lbol, mag -class SupernovaGRBLightCurveModel(Mixin): +class SupernovaGRBLightCurveModel(LightCurveMixin): def __init__( self, sample_times, @@ -806,7 +806,7 @@ def generate_lightcurve(self, sample_times, parameters): return total_lbol, total_mag -class ShockCoolingLightCurveModel(Mixin): +class ShockCoolingLightCurveModel(LightCurveMixin): def __init__(self, sample_times, parameter_conversion=None, model="Piro2021", filters=None): """A light curve model object @@ -855,7 +855,7 @@ def generate_lightcurve(self, sample_times, parameters): return lbol, mag -class SupernovaShockCoolingLightCurveModel(Mixin): +class SupernovaShockCoolingLightCurveModel(LightCurveMixin): def __init__(self, sample_times, parameter_conversion=None, filters=None): self.sample_times = sample_times @@ -919,7 +919,7 @@ def generate_lightcurve(self, sample_times, parameters): return total_lbol, total_mag -class SimpleKilonovaLightCurveModel(Mixin): +class SimpleKilonovaLightCurveModel(LightCurveMixin): def __init__(self, sample_times, parameter_conversion=None, model="Me2017", filters=None): """A light curve model object