-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added factory pattern method to the integ configs
- Loading branch information
Showing
6 changed files
with
99 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,56 +1,52 @@ | ||
from typing import Callable | ||
from typing import Callable, Tuple, Dict | ||
|
||
import numpy as np | ||
|
||
ZERO = np.finfo(float).eps | ||
RADIAL_CUTOFF = 6 | ||
|
||
_ZERO = np.finfo(float).eps | ||
|
||
|
||
class IntegrationConfig: | ||
"""Config object for the LOS/shell integration in the simulation. | ||
Attributes | ||
---------- | ||
R_max | ||
Maximum distance from the observer for which to evaluate the | ||
dust density. | ||
n | ||
Number of shells for which to evaluate the dust density. | ||
integator | ||
Function which performs the integration. | ||
""" | ||
"""Configuration for the integration strategies in the simulations.""" | ||
|
||
def __init__( | ||
self, | ||
R_max: float, | ||
n:int, | ||
integrator: Callable[[float, float, int], np.ndarray] = np.trapz | ||
): | ||
self.R = np.expand_dims(np.linspace(ZERO, R_max, n), axis=1) | ||
self.R = np.expand_dims(np.linspace(_ZERO, R_max, n), axis=1) | ||
self.dR = np.diff(self.R) | ||
self.integrator = integrator | ||
|
||
|
||
DEFAULT = { | ||
'cloud': IntegrationConfig(RADIAL_CUTOFF, 250), | ||
'band1': IntegrationConfig(RADIAL_CUTOFF, 50), | ||
'band2': IntegrationConfig(RADIAL_CUTOFF, 50), | ||
'band3': IntegrationConfig(RADIAL_CUTOFF, 50), | ||
'ring': IntegrationConfig(2.25, 50), | ||
'feature': IntegrationConfig(1, 50), | ||
} | ||
|
||
HIGH = { | ||
'cloud': IntegrationConfig(RADIAL_CUTOFF, 500), | ||
'band1': IntegrationConfig(RADIAL_CUTOFF, 500), | ||
'band2': IntegrationConfig(RADIAL_CUTOFF, 500), | ||
'band3': IntegrationConfig(RADIAL_CUTOFF, 500), | ||
'ring': IntegrationConfig(2.25, 200), | ||
'feature': IntegrationConfig(1, 200), | ||
} | ||
|
||
|
||
INTEGRATION_CONFIGS = { | ||
'default' : DEFAULT, | ||
'high' : HIGH, | ||
} | ||
class IntegrationConfigFactory: | ||
"""Factory responsible for registring and book-keeping integration configs.""" | ||
|
||
def __init__(self) -> None: | ||
self._configs = {} | ||
|
||
def register_config( | ||
self, | ||
name: str, | ||
components: Dict[str, Tuple[float,int]] | ||
) -> None: | ||
"""Initializes and stores an integration config.""" | ||
|
||
config = {} | ||
for key, value in components.items(): | ||
config[key] = IntegrationConfig(*value) | ||
|
||
self._configs[name] = config | ||
|
||
def get_config(self, name: str) -> IntegrationConfig: | ||
"""Returns a registered config.""" | ||
|
||
config = self._configs.get(name) | ||
if config is None: | ||
raise ValueError( | ||
f'Config {name} is not registered. Available configs are ' | ||
f'{list(self._configs.keys())}' | ||
) | ||
|
||
return config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,35 @@ | ||
from zodipy._emissivity import Emissivity | ||
|
||
_PLANCK_FREQUENCIES = (100.0, 143.0, 217.0, 353.0, 545.0, 857.0) | ||
|
||
|
||
PLANCK_2013 = Emissivity( | ||
frequencies=_PLANCK_FREQUENCIES, | ||
components=dict( | ||
PLANCK_2013 = { | ||
'frequencies' : _PLANCK_FREQUENCIES, | ||
'components' : dict( | ||
cloud=(0.003, -0.014, 0.031, 0.168, 0.223, 0.301), | ||
band1=(1.129, 1.463, 2.024, 2.035, 2.235, 1.777), | ||
band2=(0.674, 0.530, 0.338, 0.436, 0.718, 0.716), | ||
band3=(1.106, 1.794, 2.507, 2.400, 3.193, 2.870), | ||
ring=(0.163, -0.252, -0.185, -0.211, 0.591, 0.578), | ||
feature=(0.252, -0.002, 0.243, 0.676, -0.182, 0.423) | ||
) | ||
) | ||
|
||
|
||
PLANCK_2015 = Emissivity( | ||
frequencies=_PLANCK_FREQUENCIES, | ||
components=dict( | ||
} | ||
PLANCK_2015 = { | ||
'frequencies' : _PLANCK_FREQUENCIES, | ||
'components' : dict( | ||
cloud=(0.012, 0.022, 0.051, 0.106, 0.167, 0.256), | ||
band1=(1.02, 1.23, 1.30, 1.58, 1.74, 2.06), | ||
band2=(0.08, 0.15, 0.15, 0.39, 0.54, 0.85), | ||
band3=(0.72, 1.16, 1.27, 1.88, 2.54, 3.37), | ||
ring=None, | ||
feature=None, | ||
) | ||
) | ||
|
||
|
||
PLANCK_2018 = Emissivity( | ||
frequencies=_PLANCK_FREQUENCIES, | ||
components=dict( | ||
} | ||
PLANCK_2018 = { | ||
'frequencies' : _PLANCK_FREQUENCIES, | ||
'components' : dict( | ||
cloud=(0.018, 0.020, 0.042, 0.082, 0.179, 0.304), | ||
band1=(0.54, 1.00, 1.11, 1.52, 1.47, 1.58), | ||
band2=(0.07, 0.17, 0.21, 0.35, 0.49, 0.70), | ||
band3=(0.19, 0.84, 1.12, 1.77, 1.84, 2.11), | ||
ring=None, | ||
feature=None, | ||
) | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from zodipy._integration import IntegrationConfigFactory | ||
|
||
|
||
_RADIAL_CUTOFF = 6 | ||
|
||
integration_configs = IntegrationConfigFactory() | ||
|
||
integration_configs.register_config( | ||
name='default', | ||
components={ | ||
'cloud': (_RADIAL_CUTOFF, 250), | ||
'band1': (_RADIAL_CUTOFF, 50), | ||
'band2': (_RADIAL_CUTOFF, 50), | ||
'band3': (_RADIAL_CUTOFF, 50), | ||
'ring': (2.25, 50), | ||
'feature': (1, 50), | ||
} | ||
) | ||
integration_configs.register_config( | ||
name='high', | ||
components={ | ||
'cloud': (_RADIAL_CUTOFF, 500), | ||
'band1': (_RADIAL_CUTOFF, 500), | ||
'band2': (_RADIAL_CUTOFF, 500), | ||
'band3': (_RADIAL_CUTOFF, 500), | ||
'ring': (2.25, 200), | ||
'feature': (1, 200), | ||
} | ||
) | ||
integration_configs.register_config( | ||
name='fast', | ||
components={ | ||
'cloud': (_RADIAL_CUTOFF, 25), | ||
'band1': (_RADIAL_CUTOFF, 25), | ||
'band2': (_RADIAL_CUTOFF, 25), | ||
'band3': (_RADIAL_CUTOFF, 25), | ||
'ring': (2.25, 25), | ||
'feature': (1, 25), | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters