Skip to content

Commit

Permalink
Try this
Browse files Browse the repository at this point in the history
  • Loading branch information
Sosnowsky committed Feb 23, 2024
1 parent 24fb435 commit 9169b15
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 110 deletions.
224 changes: 115 additions & 109 deletions blobmodel/blob_shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,121 @@ def get_blob_shape_perp(self, theta: np.ndarray, **kwargs) -> np.ndarray:
raise NotImplementedError


def _get_exponential_shape(theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the exponential pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the exponential pulse shape.
"""
return np.exp(theta) * np.heaviside(-1.0 * theta, 1)


def _get_lorentz_shape(theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the Lorentzian pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the Lorentzian pulse shape.
"""
return 1 / (np.pi * (1 + theta**2))


def _get_double_exponential_shape(theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the double-exponential pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
lam : float
Asymmetry parameter controlling the shape.
Returns
-------
np.ndarray
Array representing the double-exponential pulse shape.
"""
lam = kwargs["lam"]
assert (lam > 0.0) & (lam < 1.0)
kern = np.zeros(shape=np.shape(theta))
kern[theta < 0] = np.exp(theta[theta < 0] / lam)
kern[theta >= 0] = np.exp(-theta[theta >= 0] / (1 - lam))
return kern


def _get_gaussian_shape(theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the Gaussian pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the Gaussian pulse shape.
"""
return 1 / np.sqrt(2 * np.pi) * np.exp(-(theta**2) / 2)


def _get_secant_shape(theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the secant pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the secant pulse shape.
"""
return 2 / np.pi / (np.exp(theta) + np.exp(-theta))


def _get_dipole_shape(theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the diople pulse shape as a derivative of a gaussian pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the dipole pulse shape.
"""
return -2 * theta / np.sqrt(2 * np.pi) * np.exp(-(theta**2) / 2)


class BlobShapeImpl(AbstractBlobShape):
"""Implementation of the AbstractPulseShape class."""

Expand Down Expand Up @@ -77,115 +192,6 @@ def get_blob_shape_perp(self, theta: np.ndarray, **kwargs) -> np.ndarray:
"""
raise NotImplementedError

def _get_exponential_shape(self, theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the exponential pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the exponential pulse shape.
"""
return np.exp(theta) * np.heaviside(-1.0 * theta, 1)

def _get_lorentz_shape(self, theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the Lorentzian pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the Lorentzian pulse shape.
"""
return 1 / (np.pi * (1 + theta**2))

def _get_double_exponential_shape(self, theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the double-exponential pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
lam : float
Asymmetry parameter controlling the shape.
Returns
-------
np.ndarray
Array representing the double-exponential pulse shape.
"""
lam = kwargs["lam"]
assert (lam > 0.0) & (lam < 1.0)
kern = np.zeros(shape=np.shape(theta))
kern[theta < 0] = np.exp(theta[theta < 0] / lam)
kern[theta >= 0] = np.exp(-theta[theta >= 0] / (1 - lam))
return kern

def _get_gaussian_shape(self, theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the Gaussian pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the Gaussian pulse shape.
"""
return 1 / np.sqrt(2 * np.pi) * np.exp(-(theta**2) / 2)

def _get_secant_shape(self, theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the secant pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the secant pulse shape.
"""
return 2 / np.pi / (np.exp(theta) + np.exp(-theta))

def _get_dipole_shape(self, theta: np.ndarray, **kwargs) -> np.ndarray:
"""Compute the diople pulse shape as a derivative of a gaussian pulse shape.
Parameters
----------
theta : np.ndarray
Array of theta values.
kwargs
Additional keyword arguments.
Returns
-------
np.ndarray
Array representing the dipole pulse shape.
"""
return -2 * theta / np.sqrt(2 * np.pi) * np.exp(-(theta**2) / 2)

__GENERATORS = {
"exp": _get_exponential_shape,
"gauss": _get_gaussian_shape,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pulse_shape.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import pytest
from blobmodel import BlobShapeImpl, AbstractBlobShape, BlobShapeImpl
from blobmodel import AbstractBlobShape, BlobShapeImpl
import numpy as np


Expand Down

0 comments on commit 9169b15

Please sign in to comment.