-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
2d shape #54
Merged
2d shape #54
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
ff57a76
Refactor pulse shape
Sosnowsky 5825d42
Perp width distribution should be indepdendent
Sosnowsky 85a9d07
Flex blob shape
Sosnowsky 73c376b
Remove unnecessary underscores
Sosnowsky 8e9ccaf
Fix speedup
Sosnowsky f5acce1
Fix docs
Sosnowsky e00589a
Update version from yml
Sosnowsky 93b6b76
Try this
Sosnowsky aa5d558
Try this
Sosnowsky f681ab2
Try this
Sosnowsky da863a2
Fix mypy
Sosnowsky 2fdb990
This is better
Sosnowsky e85ae6b
Fix mypy
Sosnowsky 3a68e3b
Remove unused method
Sosnowsky 670bf79
MR
Sosnowsky fe1da46
ops
Sosnowsky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
|
@@ -30,7 +30,7 @@ jobs: | |
|
||
pytest: | ||
|
||
runs-on: ubuntu-latest | ||
runs-on: ubuntu-20.04 | ||
if: always() | ||
strategy: | ||
matrix: | ||
|
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
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
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,74 @@ | ||
from abc import ABC, abstractmethod | ||
import numpy as np | ||
from nptyping import NDArray | ||
|
||
|
||
class AbstractBlobShape(ABC): | ||
"""Abstract class containing the blob pulse shapes. Two-dimensional blob | ||
pulse shapes are written in the form. | ||
|
||
phi(theta_x, theta_y) = phi_x(theta_x) * phi_y(theta_y). | ||
""" | ||
|
||
@abstractmethod | ||
def get_pulse_shape_prop(self, theta_prop: NDArray, kwargs): | ||
raise NotImplementedError | ||
|
||
@abstractmethod | ||
def get_pulse_shape_perp(self, theta_perp: NDArray, kwargs): | ||
raise NotImplementedError | ||
|
||
|
||
class BlobShapeImpl(AbstractBlobShape): | ||
"""Implementation of the AbstractPulseShape class.""" | ||
|
||
__SHAPE_NAMES__ = {"exp", "gauss", "2-exp", "lorentz", "secant"} | ||
|
||
def __init__(self, pulse_shape_prop="gauss", pulse_shape_perp="gauss"): | ||
self.__GENERATORS__ = { | ||
gregordecristoforo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"exp": BlobShapeImpl._get_exponential_shape, | ||
"gauss": BlobShapeImpl._get_gaussian_shape, | ||
"2-exp": BlobShapeImpl._get_double_exponential_shape, | ||
"lorentz": BlobShapeImpl._get_lorentz_shape, | ||
"secant": BlobShapeImpl._get_secant_shape, | ||
} | ||
self.pulse_shape_prop = pulse_shape_prop | ||
self.pulse_shape_perp = pulse_shape_perp | ||
if ( | ||
pulse_shape_prop not in BlobShapeImpl.__SHAPE_NAMES__ | ||
or pulse_shape_perp not in BlobShapeImpl.__SHAPE_NAMES__ | ||
): | ||
raise NotImplementedError( | ||
f"{self.__class__.__name__}.blob_shape not implemented" | ||
) | ||
|
||
def get_pulse_shape_prop(self, theta: np.ndarray, kwargs) -> np.ndarray: | ||
return self.__GENERATORS__.get(self.pulse_shape_prop)(theta, kwargs) | ||
|
||
def get_pulse_shape_perp(self, theta: np.ndarray, kwargs) -> np.ndarray: | ||
return self.__GENERATORS__.get(self.pulse_shape_perp)(theta, kwargs) | ||
|
||
@staticmethod | ||
def _get_exponential_shape(theta: np.ndarray, kwargs) -> np.ndarray: | ||
return np.exp(theta) * np.heaviside(-1.0 * theta, 1) | ||
|
||
@staticmethod | ||
def _get_lorentz_shape(theta: np.ndarray, kwargs) -> np.ndarray: | ||
return 1 / (np.pi * (1 + theta**2)) | ||
|
||
@staticmethod | ||
def _get_double_exponential_shape(theta: np.ndarray, kwargs) -> np.ndarray: | ||
lam = kwargs["lam"] | ||
gregordecristoforo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assert (lam > 0.0) & (lam < 1.0) | ||
kern = np.zeros(len(theta)) | ||
kern[theta < 0] = np.exp(theta[theta < 0] / lam) | ||
kern[theta >= 0] = np.exp(-theta[theta >= 0] / (1 - lam)) | ||
return kern | ||
|
||
@staticmethod | ||
def _get_gaussian_shape(theta: np.ndarray, kwargs) -> np.ndarray: | ||
return 1 / np.sqrt(np.pi) * np.exp(-(theta**2)) | ||
|
||
@staticmethod | ||
def _get_secant_shape(theta: np.ndarray, kwargs) -> np.ndarray: | ||
return 2 / np.pi / (np.exp(theta) + np.exp(-theta)) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... serves as a placeholder for
kwargs
right?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep