Commit 737d9107 authored by Walsh, Michael's avatar Walsh, Michael
Browse files

remove tomopy and replace with pure numpy solution

parent 570d10c2
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -16,4 +16,4 @@ imars3d.backend.preparation.normalization module
   :members:
   :undoc-members:
   :show-inheritance:
   :exclude-members: arrays, cut_off, darks, flats, max_workers, name
   :exclude-members: arrays, darks, flats, max_workers, name
+6 −17
Original line number Diff line number Diff line
@@ -5,7 +5,6 @@ import logging
import param
from imars3d.backend.util.functions import clamp_max_workers
import numpy as np
import tomopy


logger = logging.getLogger(__name__)
@@ -23,8 +22,6 @@ class normalization(param.ParameterizedFunction):
        3D array of flat field images (aka flat field, open beam), axis=0 is the image number axis.
    darks:
        3D array of dark field images, axis=0 is the image number axis.
    cut_off:
        Permitted maximum value for the normalized data, originated from tomopy, negative values means no cutoff.
    max_workers:
        number of cores to use for parallel processing, default is 0, which means using all available cores.

@@ -38,10 +35,6 @@ class normalization(param.ParameterizedFunction):
        doc="3D array of flat field images (aka flat field, open beam), axis=0 is the image number axis.", default=None
    )
    darks = param.Array(doc="3D array of dark field images, axis=0 is the image number axis.", default=None)
    cut_off = param.Number(
        default=-1.0,
        doc="Permitted maximum value for the normalized data, originated from tomopy, negative values means no cutoff.",
    )
    max_workers = param.Integer(
        default=0,
        bounds=(0, None),
@@ -49,7 +42,7 @@ class normalization(param.ParameterizedFunction):
    )

    def __call__(self, **params):
        """Perform normalization via tomopy."""
        """Perform normalization via numpy."""
        logger.info("Executing Filter: Normalization")
        # type*bounds check via Parameter
        _ = self.instance(**params)
@@ -60,20 +53,16 @@ class normalization(param.ParameterizedFunction):
        self.max_workers = clamp_max_workers(params.max_workers)
        logger.debug(f"max_worker={self.max_workers}")

        # parse input (mostly for Tomopy)
        tomopy_cut_off = None if params.cut_off < 0 else float(params.cut_off)
        # use median filter to remove outliers from flats and darks
        # NOTE: this will remove the random noises coming from the environment.
        self.flats = np.median(params.flats, axis=0)
        self.darks = np.median(params.darks, axis=0)
        # apply normalization
        # NOTE:
        # For pixels where dark > flat, tomopy replace the value with 1e-6 on-the-fly
        # see https://github.com/tomopy/tomopy/blob/master/source/tomopy/prep/normalize.py#L135
        #
        arrays_normalized = tomopy.normalize(
            params.arrays, self.flats, self.darks, cutoff=tomopy_cut_off, ncore=self.max_workers
        )
        _bg = self.flats - self.darks
        _bg[_bg <= 0] = 1e-6
        params.arrays = params.arrays - self.darks
        arrays_normalized = np.true_divide(params.arrays, _bg, dtype=np.float32)

        # return
        logger.info("FINISHED Executing Filter: Normalization")

+1 −7
Original line number Diff line number Diff line
@@ -36,13 +36,7 @@ class Normalization(param.Parameterized):
            return

        # call the filter
        cutoff = -1.0 if self.auto_cutoff else self.cutoff
        self.parent.ct = normalization(
            arrays=self.parent.ct,
            flats=self.parent.ob,
            darks=self.parent.dc,
            cut_off=cutoff,
        )
        self.parent.ct = normalization(arrays=self.parent.ct, flats=self.parent.ob, darks=self.parent.dc)
        #
        self.status = True
        pn.state.notifications.success("normalization complete.", duration=3000)