-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
153 additions
and
207 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,31 +1,18 @@ | ||
from typing import Tuple, TypeVar | ||
from .utils.typing import Frame, Frames | ||
|
||
from numpy import dtype, ndarray | ||
|
||
FrameDType = TypeVar("FrameDType", bound=dtype) | ||
NumFrames = TypeVar("NumFrames", bound=int) | ||
FrameWidth = TypeVar("FrameWidth", bound=int) | ||
FrameHeight = TypeVar("FrameHeight", bound=int) | ||
|
||
|
||
def subtract_background( | ||
foreground_frames: ndarray[Tuple[NumFrames, FrameWidth, FrameHeight], FrameDType], | ||
background_frame: ndarray[Tuple[FrameWidth, FrameHeight], FrameDType], | ||
) -> ndarray[Tuple[NumFrames, FrameWidth, FrameHeight], FrameDType]: | ||
def subtract_background(foreground_frames: Frames, background_frame: Frame) -> Frames: | ||
"""Subtract a background frame from a sequence of foreground frames. | ||
Subtract a background frame from a sequence of foreground frames, as detailed in | ||
section 3.4.6 of 'Everything SAXS: small-angle scattering pattern collection and | ||
correction' [https://doi.org/10.1088/0953-8984/25/38/383201]. | ||
Args: | ||
foreground_frames (ndarray[Tuple[NumFrames, FrameWidth, FrameHeight], | ||
FrameDType]): A sequence of foreground frames to be corrected. | ||
background_frame (ndarray[Tuple[FrameWidth, FrameHeight], FrameDType]): The | ||
background which is to be corrected for. | ||
foreground_frames: A sequence of foreground frames to be corrected. | ||
background_frame: The background which is to be corrected for. | ||
Returns: | ||
ndarray[Tuple[NumFrames, FrameWidth, FrameHeight], FrameDType]: A sequence of | ||
corrected frames. | ||
A sequence of corrected frames. | ||
""" | ||
return foreground_frames - background_frame |
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 |
---|---|---|
@@ -1,30 +1,24 @@ | ||
from typing import Tuple, TypeVar, cast | ||
from typing import cast | ||
|
||
from numpy import dtype, ndarray | ||
from .utils.typing import Frames | ||
|
||
FrameDType = TypeVar("FrameDType", bound=dtype) | ||
FramesShape = TypeVar("FramesShape", bound=Tuple[int, int, int]) | ||
|
||
|
||
def correct_displaced_volume( | ||
frames: ndarray[FramesShape, FrameDType], | ||
displaced_fraction: float, | ||
) -> ndarray[FramesShape, FrameDType]: | ||
def correct_displaced_volume(frames: Frames, displaced_fraction: float) -> Frames: | ||
"""Correct for displaced volume of solvent by multiplying signal by retained fraction. | ||
Correct for displaced volume of solvent by multiplying signal by the retained | ||
fraction, as detailed in section 3.xviii and appendix B of `The modular small-angle | ||
fraction, as detailed in section 3.xviii and appendix B of 'The modular small-angle | ||
X-ray scattering data correction sequence' | ||
[https://doi.org/10.1107/S1600576717015096]. | ||
Args: | ||
frames (ndarray[FramesShape, FrameDType]): A stack of frames to be corrected. | ||
displaced_fraction (float): The fraction of solvent displaced by the analyte. | ||
frames: A stack of frames to be corrected. | ||
displaced_fraction: The fraction of solvent displaced by the analyte. | ||
Returns: | ||
ndarray[FramesShape, FrameDType]: The corrected stack of frames. | ||
The corrected stack of frames. | ||
""" | ||
if displaced_fraction < 0.0 or displaced_fraction > 1.0: | ||
raise ValueError("Displaced Fraction must be in interval [0, 1].") | ||
|
||
return cast(ndarray[FramesShape, FrameDType], frames * (1.0 - displaced_fraction)) | ||
return cast(Frames, frames * (1.0 - displaced_fraction)) |
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,31 +1,22 @@ | ||
from typing import Tuple, TypeVar | ||
|
||
from numpy import dtype, floating, ndarray | ||
|
||
FrameDType = TypeVar("FrameDType", bound=dtype) | ||
NumFrames = TypeVar("NumFrames", bound=int) | ||
FrameWidth = TypeVar("FrameWidth", bound=int) | ||
FrameHeight = TypeVar("FrameHeight", bound=int) | ||
from .utils.typing import Frames, FrameShape | ||
|
||
|
||
def correct_flatfield( | ||
frames: ndarray[Tuple[NumFrames, FrameHeight, FrameWidth], FrameDType], | ||
flatfield: ndarray[Tuple[FrameHeight, FrameWidth], dtype[floating]], | ||
) -> ndarray[Tuple[NumFrames, FrameHeight, FrameWidth], FrameDType]: | ||
frames: Frames, flatfield: ndarray[FrameShape, dtype[floating]] | ||
) -> Frames: | ||
"""Apply multiplicative flatfield correction, to correct for inter-pixel sensitivity. | ||
Apply multiplicative flatfield correction, to correct for inter-pixel sensitivity, | ||
as described in section 3.xii of 'The modular small-angle X-ray scattering data | ||
correction sequence' [https://doi.org/10.1107/S1600576717015096]. | ||
Args: | ||
frames (ndarray[Tuple[NumFrames, FrameHeight, FrameWidth], FrameDType]): A | ||
stack of frames to be corrected. | ||
flatfield (ndarray[Tuple[FrameHeight, FrameWidth], dtype[floating]]): The | ||
multiplicative flatfield correction to be applied. | ||
frames: A stack of frames to be corrected. | ||
flatfield: The multiplicative flatfield correction to be applied. | ||
Returns: | ||
ndarray[Tuple[NumFrames, FrameHeight, FrameWidth], FrameDType]: The corrected | ||
stack of frames. | ||
The corrected stack of frames. | ||
""" | ||
return frames * flatfield |
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,26 +1,21 @@ | ||
from typing import Any, TypeVar | ||
from numpy import expand_dims, sum | ||
|
||
from numpy import dtype, expand_dims, ndarray, sum | ||
from .utils.typing import Frames | ||
|
||
FrameDType = TypeVar("FrameDType", bound=dtype) | ||
FramesShape = TypeVar("FramesShape", bound=Any) | ||
|
||
|
||
def normalize_transmitted_flux( | ||
frames: ndarray[FramesShape, FrameDType] | ||
) -> ndarray[FramesShape, FrameDType]: | ||
def normalize_transmitted_flux(frames: Frames) -> Frames: | ||
"""Normalize for incident flux and transmissibility by scaling photon counts. | ||
Normalize for incident flux and transmissibility by scaling photon counts with | ||
respect to the total observed flux, as detailed in section 4 of `The modular small- | ||
respect to the total observed flux, as detailed in section 4 of 'The modular small- | ||
angle X-ray scattering data correction sequence' | ||
[https://doi.org/10.1107/S1600576717015096]. | ||
Args: | ||
frames (ndarray[FramesShape, FrameDType]): A stack of frames to be normalized. | ||
frames: A stack of frames to be normalized. | ||
Returns: | ||
ndarray[FramesShape, FrameDType]: The normalized stack of frames. | ||
The normalized stack of frames. | ||
""" | ||
frame_flux = expand_dims(sum(frames, axis=(-1, -2)), (-1, -2)) | ||
return frames / frame_flux |
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
Oops, something went wrong.