From 18c6f061e3f2b49daf3819b5f2511c00303518fd Mon Sep 17 00:00:00 2001 From: LukasK13 Date: Tue, 14 Apr 2020 19:55:09 +0200 Subject: [PATCH] Grey body factory and lambda checker added --- esbo_etc/lib/helpers.py | 42 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/esbo_etc/lib/helpers.py b/esbo_etc/lib/helpers.py index e17e97a..ed4cd80 100644 --- a/esbo_etc/lib/helpers.py +++ b/esbo_etc/lib/helpers.py @@ -1,6 +1,9 @@ import logging import sys import traceback +import astropy.units as u +from astropy.modeling.models import BlackBody +from typing import Union def error(msg: str, exit_: bool = True): @@ -22,3 +25,42 @@ def error(msg: str, exit_: bool = True): if exit_: traceback.print_stack() sys.exit(1) + + +@u.quantity_input(temp=[u.Kelvin, u.Celsius]) +def gb_factory(temp: u.Quantity, em: Union[int, float] = 1): + """ + Factory for a grey body lambda-function. + + Parameters + ---------- + temp : Quantity in Kelvin / Celsius + The temperature fo the grey body. + em : Union[int, float] + Emissivity of the the grey body + + Returns + ------- + bb : Callable + The lambda function for the grey body. + """ + bb = BlackBody(temperature=temp * u.K, scale=em * u.W / (u.m ** 2 * u.nm * u.sr)) + return lambda wl: bb(wl) + + +def isLambda(v: object): + """ + Check if a object is of type lambda + + Parameters + ---------- + v : object + The object to check. + + Returns + ------- + res : bool + Result of the check + """ + LAMBDA = lambda: 0 + return isinstance(v, type(LAMBDA)) and v.__name__ == LAMBDA.__name__