-
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.
Implemented manual step-wise trapezoidal integration.
Drastically improved memory usage for high nsides by moving away from using np.trapz. Also renamed some files.
- Loading branch information
Showing
7 changed files
with
160 additions
and
135 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Callable | ||
|
||
import numpy as np | ||
|
||
|
||
EmissionCallable = Callable[ | ||
[float, np.ndarray, np.ndarray, np.ndarray, float], np.ndarray | ||
] | ||
|
||
|
||
def trapezoidal( | ||
emission_func: EmissionCallable, | ||
freq: float, | ||
x_obs: np.ndarray, | ||
x_earth: np.ndarray, | ||
x_unit: np.ndarray, | ||
R: np.ndarray, | ||
npix: int, | ||
pixels: np.ndarray, | ||
) -> np.ndarray: | ||
"""Integrates the emission for a component using trapezoidal.""" | ||
|
||
comp_emission = np.zeros(npix)[pixels] | ||
emission_prev = emission_func(freq, x_obs, x_earth, x_unit, R[0]) | ||
for i in range(1, len(R)): | ||
dR = R[i] - R[i - 1] | ||
emission_cur = emission_func(freq, x_obs, x_earth, x_unit, R[i]) | ||
comp_emission += (emission_prev + emission_cur) * dR / 2 | ||
emission_prev = emission_cur | ||
|
||
return comp_emission |
This file was deleted.
Oops, something went wrong.
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,50 @@ | ||
from typing import Tuple, Dict | ||
|
||
import numpy as np | ||
|
||
|
||
class LOSFactory: | ||
"""Factory responsible for registring and book-keeping a line-of-sight (LOS).""" | ||
|
||
def __init__(self) -> None: | ||
self._configs = {} | ||
|
||
def register_config( | ||
self, name: str, components: Dict[str, Tuple[float, int]] | ||
) -> None: | ||
"""Initializes and stores a LOS.""" | ||
|
||
config = {} | ||
for key, value in components.items(): | ||
if isinstance(value, np.ndarray): | ||
config[key] = value | ||
elif isinstance(value, (tuple, list)): | ||
try: | ||
start, stop, n, geom = value | ||
except ValueError: | ||
raise ValueError( | ||
"Line-of-sight config must either be an array, or " | ||
"a tuple with the format (start, stop, n, geom)" | ||
"where geom is either 'linear' or 'log'" | ||
) | ||
if geom.lower() == "linear": | ||
geom = np.linspace | ||
elif geom.lower() == "log": | ||
geom = np.geomspace | ||
else: | ||
raise ValueError("geom must be either 'linear' or 'log'") | ||
config[key] = geom(start, stop, n) | ||
|
||
self._configs[name] = config | ||
|
||
def get_config(self, name: str) -> np.ndarray: | ||
"""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 was deleted.
Oops, something went wrong.
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,43 @@ | ||
from zodipy._los_config import LOSFactory | ||
|
||
import numpy as np | ||
|
||
|
||
EPS = np.finfo(float).eps | ||
RADIAL_CUTOFF = 6 | ||
|
||
LOS_configs = LOSFactory() | ||
|
||
LOS_configs.register_config( | ||
name="default", | ||
components={ | ||
"cloud": (EPS, RADIAL_CUTOFF, 250, "linear"), | ||
"band1": (EPS, RADIAL_CUTOFF, 50, "linear"), | ||
"band2": (EPS, RADIAL_CUTOFF, 50, "linear"), | ||
"band3": (EPS, RADIAL_CUTOFF, 50, "linear"), | ||
"ring": (EPS, 2.25, 50, "linear"), | ||
"feature": (EPS, 1, 50, "linear"), | ||
}, | ||
) | ||
LOS_configs.register_config( | ||
name="high", | ||
components={ | ||
"cloud": (EPS, RADIAL_CUTOFF, 500, "linear"), | ||
"band1": (EPS, RADIAL_CUTOFF, 500, "linear"), | ||
"band2": (EPS, RADIAL_CUTOFF, 500, "linear"), | ||
"band3": (EPS, RADIAL_CUTOFF, 500, "linear"), | ||
"ring": (EPS, 2.25, 200, "linear"), | ||
"feature": (EPS, 1, 200, "linear"), | ||
}, | ||
) | ||
LOS_configs.register_config( | ||
name="fast", | ||
components={ | ||
"cloud": (EPS, RADIAL_CUTOFF, 25, "linear"), | ||
"band1": (EPS, RADIAL_CUTOFF, 25, "linear"), | ||
"band2": (EPS, RADIAL_CUTOFF, 25, "linear"), | ||
"band3": (EPS, RADIAL_CUTOFF, 25, "linear"), | ||
"ring": (EPS, 2.25, 25, "linear"), | ||
"feature": (EPS, 1, 25, "linear"), | ||
}, | ||
) |
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