Skip to content

Commit

Permalink
ENH: Add general loading routine for corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
jwboth committed Jul 24, 2024
1 parent 19eeaf0 commit 6644b3c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/darsia/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
from darsia.corrections.color.colorcorrection import *
from darsia.corrections.color.relativecolorcorrection import *
from darsia.corrections.color.experimentalcolorcorrection import *
from darsia.corrections.readcorrection import *
from darsia.image.coordinatetransformation import * # Requires affine correction
from darsia.signals.models.basemodel import *
from darsia.signals.models.combinedmodel import *
Expand Down
41 changes: 41 additions & 0 deletions src/darsia/corrections/readcorrection.py
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

0 comments on commit 6644b3c

Please sign in to comment.