-
Notifications
You must be signed in to change notification settings - Fork 14
feat: Dask get_fccd_images #94
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
Open
maffettone
wants to merge
6
commits into
master
Choose a base branch
from
enh-dask-operations
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 5 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f182f7b
feat: Dask get_fccd_images
ee1df16
fix: default false, use bool val for clockwise
2795117
maint: add pyproject toml for black
d935601
fix: remove ragged array in tests
98772cb
fix: drop pyproject, breaks build system
ec916d1
Apply suggestions from code review. Fix logic and clean docs
maffettone 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 hidden or 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 hidden or 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,53 @@ | ||
| from typing import Tuple | ||
|
|
||
| import numpy as np | ||
| from dask.array import Array as DaskArray | ||
| from numpy.typing import ArrayLike | ||
|
|
||
| GAIN_8 = 0x0000 | ||
| GAIN_2 = 0x8000 | ||
| GAIN_1 = 0xC000 | ||
| BAD_PIXEL = 0x2000 | ||
| PIXEL_MASK = 0x1FFF | ||
|
|
||
|
|
||
| def correct_images(images: DaskArray, dark: ArrayLike, flat: ArrayLike, gain: Tuple[float, float, float]): | ||
| """_summary_ | ||
|
|
||
| Parameters | ||
| ---------- | ||
| images : DaskArray | ||
| Input array of images to correct of shape (N, y, x) where N is the | ||
|
maffettone marked this conversation as resolved.
Outdated
|
||
| number of images and x and y are the image size. | ||
| dark : ArrayLike | ||
| Input array of dark images. This should be of shape (3, y, x). | ||
| dark[0] is the gain 8 (most sensitive setting) dark image with | ||
|
maffettone marked this conversation as resolved.
Outdated
|
||
| dark[2] being the gain 1 (least sensitive) dark image. | ||
|
maffettone marked this conversation as resolved.
Outdated
|
||
| flat : ArrayLike | ||
| Input array for the flatfield correction. This should be of shape | ||
| (y, x) | ||
| gain : Tuple[float, float, float] | ||
| These are the gain multiplication factors for the three different | ||
| gain settings | ||
|
|
||
| // Note GAIN_1 is the least sensitive setting which means we need to multiply the | ||
| // measured values by 8. Conversly GAIN_8 is the most sensitive and therefore only | ||
|
maffettone marked this conversation as resolved.
Outdated
|
||
| // does not need a multiplier | ||
| """ | ||
|
|
||
| # Shape checking: | ||
| if dark.ndim != 3: | ||
| raise ValueError(f"Expected 3D array, got {dark.ndim}D array for darks") | ||
| if dark.shape[0] != 3: | ||
| raise ValueError(f"Expected 3 dark images, got {dark.shape[0]}") | ||
| if dark.shape[-2:] != images.shape[-2]: | ||
| raise ValueError(f"Dark images shape {dark.shape[-2:]} does not match images shape {images.shape[-2]}") | ||
| if flat.shape != images.shape[-2:]: | ||
| raise ValueError(f"Flatfield shape {flat.shape} does not match images shape {images.shape[-2]}") | ||
|
|
||
| corrected = np.where(images & BAD_PIXEL, np.NaN, images) | ||
| corrected = np.where(images & GAIN_1, flat * gain[-1] * (corrected - dark[-1, ...]), corrected) | ||
| corrected = np.where(images & GAIN_2, flat * gain[-2] * (corrected - dark[-2, ...]), corrected) | ||
| corrected = np.where(images & GAIN_8, flat * gain[-3] * (corrected - dark[-3, ...]), corrected) | ||
|
|
||
| return corrected | ||
This file contains hidden or 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 hidden or 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 @@ | ||
| import dask.array as da | ||
| from dask.array import Array as DaskArray | ||
|
|
||
|
|
||
| def rotate90(images: DaskArray, sense: bool) -> DaskArray: | ||
| """ | ||
| Rotate images by 90 degrees using Dask. | ||
| This whole function is a moot wrapper around `da.rot90` from Dask, but written | ||
| explicitly to match the old C code. | ||
|
|
||
| Parameters | ||
| ---------- | ||
| images : da.Array | ||
| Input Dask array of images to rotate of shape (N, y, x), | ||
| where N is the number of images and y, x are the image dimensions. | ||
| sense : bool | ||
| False to rotate clockwise, True to rotate anticlockwise. | ||
|
|
||
| Returns | ||
| ------- | ||
| da.Array | ||
| The rotated images as a Dask array. | ||
| """ | ||
| # Rotate images. The axes (1, 2) specify the plane of rotation (y-x plane for each image). | ||
| # k controls the direction and repetitions of the rotation. | ||
| if sense: | ||
| k = 1 | ||
| elif sense: | ||
| k = -1 | ||
|
maffettone marked this conversation as resolved.
Outdated
|
||
| rotated_images = da.rot90(images, k=k, axes=(-2, -1)) | ||
| return rotated_images | ||
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.