Skip to content

Commit

Permalink
adding developer docs
Browse files Browse the repository at this point in the history
  • Loading branch information
karllark committed Aug 14, 2024
1 parent 010ca10 commit 443ddde
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 61 deletions.
2 changes: 2 additions & 0 deletions docs/dust_extinction/extinguish.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.. _extinguish_example:

###############################
Extinguish or Unextinguish Data
###############################
Expand Down
1 change: 1 addition & 0 deletions docs/dust_extinction/fit_extinction.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.. _fit_curves:
#####################
Fit Extinction Curves
#####################
Expand Down
8 changes: 8 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@ User Documentation
Fitting extinction curves <dust_extinction/fit_extinction.rst>
References <dust_extinction/references.rst>

User Documentation
==================

.. toctree::
:maxdepth: 2

Model Base Classes (how to add a model) <dust_extinction/dev_model.rst>

Installation
============

Expand Down
58 changes: 54 additions & 4 deletions dust_extinction/baseclasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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)
66 changes: 9 additions & 57 deletions dust_extinction/grain_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -238,7 +190,7 @@ def __init__(self, modelname="MWRV31", **kwargs):
super().__init__(**kwargs)


class D03(GMBase):
class D03(BaseExtGrainModel):
r"""
Draine (2003) Grain Models
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 443ddde

Please sign in to comment.