-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ENH: Add general loading routine for corrections
- Loading branch information
Showing
2 changed files
with
42 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,41 @@ | ||
"""Module containing common reading functionality for corrections.""" | ||
|
||
from pathlib import Path | ||
|
||
import numpy as np | ||
|
||
from darsia import ( | ||
ColorCorrection, | ||
CurvatureCorrection, | ||
DriftCorrection, | ||
IlluminationCorrection, | ||
TypeCorrection, | ||
) | ||
|
||
AnyCorrection = ( | ||
TypeCorrection | ||
| DriftCorrection | ||
| CurvatureCorrection | ||
| IlluminationCorrection | ||
| ColorCorrection | ||
) | ||
|
||
|
||
def read_correction(path: Path) -> AnyCorrection: | ||
"""General function to read corrections from a file. | ||
Args: | ||
path (Path): path to npz file | ||
Returns: | ||
BaseCorrection: correction object | ||
""" | ||
|
||
# Read class name from npz file | ||
class_name = np.load(path, allow_pickle=True)["class_name"].item() | ||
|
||
# Load correction from file | ||
correction = eval(class_name)() | ||
correction.load(path) | ||
return correction |