From 443dddeae81b9d0944e234fce52bd913494d9ea7 Mon Sep 17 00:00:00 2001 From: Karl Gordon Date: Wed, 14 Aug 2024 15:26:30 -0400 Subject: [PATCH] adding developer docs --- docs/dust_extinction/extinguish.rst | 2 + docs/dust_extinction/fit_extinction.rst | 1 + docs/index.rst | 8 +++ dust_extinction/baseclasses.py | 58 ++++++++++++++++++++-- dust_extinction/grain_models.py | 66 ++++--------------------- 5 files changed, 74 insertions(+), 61 deletions(-) diff --git a/docs/dust_extinction/extinguish.rst b/docs/dust_extinction/extinguish.rst index b0a9699..a5bcf4c 100644 --- a/docs/dust_extinction/extinguish.rst +++ b/docs/dust_extinction/extinguish.rst @@ -1,3 +1,5 @@ +.. _extinguish_example: + ############################### Extinguish or Unextinguish Data ############################### diff --git a/docs/dust_extinction/fit_extinction.rst b/docs/dust_extinction/fit_extinction.rst index 69096aa..0dcb1b0 100644 --- a/docs/dust_extinction/fit_extinction.rst +++ b/docs/dust_extinction/fit_extinction.rst @@ -1,3 +1,4 @@ +.. _fit_curves: ##################### Fit Extinction Curves ##################### diff --git a/docs/index.rst b/docs/index.rst index 428fa93..bd70b54 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -39,6 +39,14 @@ User Documentation Fitting extinction curves References +User Documentation +================== + +.. toctree:: + :maxdepth: 2 + + Model Base Classes (how to add a model) + Installation ============ diff --git a/dust_extinction/baseclasses.py b/dust_extinction/baseclasses.py index de98ade..3157b5d 100644 --- a/dust_extinction/baseclasses.py +++ b/dust_extinction/baseclasses.py @@ -2,12 +2,14 @@ from astropy.modeling import Model, Parameter, InputParameterError -__all__ = ["BaseExtModel", "BaseExtRvModel", "BaseExtRvAfAModel"] +from .helpers import _get_x_in_wavenumbers, _test_valid_x_range + +__all__ = ["BaseExtModel", "BaseExtRvModel", "BaseExtRvAfAModel", "BaseExtGrainModel"] class BaseExtModel(Model): """ - Base Extinction Model. Do not use. + Base Extinction Model. Do not use directly. """ n_inputs = 1 @@ -55,7 +57,7 @@ def extinguish(self, x, Av=None, Ebv=None): class BaseExtRvModel(BaseExtModel): """ - Base Extinction R(V)-dependent Model. Do not use. + Base Extinction R(V)-dependent Model. Do not use directly. """ Rv = Parameter( @@ -89,7 +91,7 @@ def Rv(self, value): class BaseExtRvAfAModel(BaseExtModel): """ - Base Extinction R(V)_A, f_A -dependent Model. Do not use. + Base Extinction R(V)_A, f_A -dependent Model. Do not use directly. """ RvA = Parameter( @@ -152,3 +154,51 @@ def fA(self, value): + " and " + str(self.fA_range[1]) ) + + +class GMBase(BaseExtModel): + r""" + Base for Grain Models + + Parameters + ---------- + None + + Raises + ------ + None + """ + + def evaluate(self, in_x): + """ + Generic dust grain model function + + Parameters + ---------- + in_x: float + expects either x in units of wavelengths or frequency + or assumes wavelengths in wavenumbers [1/micron] + + internally wavenumbers are used + + Returns + ------- + axav: np array (float) + A(x)/A(V) extinction curve [mag] + + Raises + ------ + ValueError + Input x values outside of defined range + """ + x = _get_x_in_wavenumbers(in_x) + + # check that the wavenumbers are within the defined range + _test_valid_x_range(x, self.x_range, self.__class__.__name__) + + # define the function allowing for spline interpolation + # fill value needed to handle numerical issues at the edges + # the x values has already been checked to be in range + f = interp1d(self.data_x, self.data_axav, fill_value="extrapolate") + + return f(x) diff --git a/dust_extinction/grain_models.py b/dust_extinction/grain_models.py index b6be5da..db6c29c 100644 --- a/dust_extinction/grain_models.py +++ b/dust_extinction/grain_models.py @@ -7,61 +7,13 @@ from astropy.modeling import InputParameterError from astropy.io.fits import getdata -from .helpers import _get_x_in_wavenumbers, _test_valid_x_range -from .baseclasses import BaseExtModel +from dust_extinction.baseclasses import BaseExtGrainModel -__all__ = ["DBP90", "WD01", "D03", "ZDA04", "C11", "J13", "HD23"] - - -class GMBase(BaseExtModel): - r""" - Base for Grain Models - Parameters - ---------- - None - - Raises - ------ - None - """ - - def evaluate(self, in_x): - """ - WD01 function - - Parameters - ---------- - in_x: float - expects either x in units of wavelengths or frequency - or assumes wavelengths in wavenumbers [1/micron] - - internally wavenumbers are used - - Returns - ------- - axav: np array (float) - A(x)/A(V) extinction curve [mag] - - Raises - ------ - ValueError - Input x values outside of defined range - """ - x = _get_x_in_wavenumbers(in_x) - - # check that the wavenumbers are within the defined range - _test_valid_x_range(x, self.x_range, self.__class__.__name__) - - # define the function allowing for spline interpolation - # fill value needed to handle numerical issues at the edges - # the x values has already been checked to be in range - f = interp1d(self.data_x, self.data_axav, fill_value="extrapolate") - - return f(x) +__all__ = ["DBP90", "WD01", "D03", "ZDA04", "C11", "J13", "HD23"] -class DBP90(GMBase): +class DBP90(BaseExtGrainModel): r""" Desert et al (1990) Grain Models @@ -144,7 +96,7 @@ def __init__(self, modelname="MWRV31", **kwargs): super().__init__(**kwargs) -class WD01(GMBase): +class WD01(BaseExtGrainModel): r""" Weingartner & Draine (2001) Grain Models @@ -238,7 +190,7 @@ def __init__(self, modelname="MWRV31", **kwargs): super().__init__(**kwargs) -class D03(GMBase): +class D03(BaseExtGrainModel): r""" Draine (2003) Grain Models @@ -330,7 +282,7 @@ def __init__(self, modelname="MWRV31", **kwargs): super().__init__(**kwargs) -class ZDA04(GMBase): +class ZDA04(BaseExtGrainModel): r""" Zubko, Dwek, & Arendt (2004) Grain Models @@ -413,7 +365,7 @@ def __init__(self, modelname="BARE-GR-S", **kwargs): super().__init__(**kwargs) -class C11(GMBase): +class C11(BaseExtGrainModel): r""" Compiegne et al (2011) Grain Models @@ -496,7 +448,7 @@ def __init__(self, modelname="MWRV31", **kwargs): super().__init__(**kwargs) -class J13(GMBase): +class J13(BaseExtGrainModel): r""" Jones et al (2013) Grain Models @@ -579,7 +531,7 @@ def __init__(self, modelname="MWRV31", **kwargs): super().__init__(**kwargs) -class HD23(GMBase): +class HD23(BaseExtGrainModel): r""" Hensley & Draine (2023) Grain Model