# Path: python/pipeline/exceptions.py
# class PipelineException(Exception):
#     """Base pipeline exception. Prints the message plus any specific info."""
#     def __init__(self, message, info=None):
#         info_message = '\nError info: ' + repr(info) if info else ''
#         super().__init__(message + info_message)
#         self.info = info


import numpy as np
    import pyfftw
from scipy import interpolate  as interp
from scipy import signal
from scipy import ndimage
from ..exceptions import PipelineException
from ..utils.signal import mirrconv
    from imreg_dft import utils
    from sklearn.linear_model import TheilSenRegressor
    X = np.arange(len(shifts)).reshape(-1, 1)
    y = shifts
    model = TheilSenRegressor() # robust regression
    model.fit(X, y)
    line = model.predict(X)

    return line


def correct_raster(scan, raster_phase, temporal_fill_fraction, in_place=True):
    """ Raster correction for resonant scans.

    Corrects multi-photon images in n-dimensional scans. Positive raster phase shifts
    even lines to the left and odd lines to the right. Negative raster phase shifts even
    lines to the right and odd lines to the left.

    :param np.array scan: Volume with images to be corrected in the first two dimensions.
        Works for 2-dimensions and up, usually (image_height, image_width, num_frames).
    :param float raster_phase: Angle difference between expected and recorded scan angle.
    :param float temporal_fill_fraction: Ratio between active acquisition and total
        length of the scan line.
    :param bool in_place: If True (default), the original array is modified in place.

    :return: Raster-corrected scan.
    :rtype: Same as scan if scan.dtype is subtype of np.float, else np.float32.

    :raises: PipelineException
    """
    # Basic checks
    if not isinstance(scan, np.ndarray):

# Path: python/pipeline/exceptions.py
# class PipelineException(Exception):
#     """Base pipeline exception. Prints the message plus any specific info."""
#     def __init__(self, message, info=None):
#         info_message = '\nError info: ' + repr(info) if info else ''
#         super().__init__(message + info_message)
#         self.info = info


# Path: python/pipeline/utils/galvo_corrections.py
import numpy as np
    import pyfftw
from scipy import interpolate  as interp
from scipy import signal
from scipy import ndimage
from ..exceptions import PipelineException
from ..utils.signal import mirrconv
    from imreg_dft import utils
    from sklearn.linear_model import TheilSenRegressor

    X = np.arange(len(shifts)).reshape(-1, 1)
    y = shifts
    model = TheilSenRegressor() # robust regression
    model.fit(X, y)
    line = model.predict(X)

    return line


def correct_raster(scan, raster_phase, temporal_fill_fraction, in_place=True):
    """ Raster correction for resonant scans.

    Corrects multi-photon images in n-dimensional scans. Positive raster phase shifts
    even lines to the left and odd lines to the right. Negative raster phase shifts even
    lines to the right and odd lines to the left.

    :param np.array scan: Volume with images to be corrected in the first two dimensions.
        Works for 2-dimensions and up, usually (image_height, image_width, num_frames).
    :param float raster_phase: Angle difference between expected and recorded scan angle.
    :param float temporal_fill_fraction: Ratio between active acquisition and total
        length of the scan line.
    :param bool in_place: If True (default), the original array is modified in place.

    :return: Raster-corrected scan.
    :rtype: Same as scan if scan.dtype is subtype of np.float, else np.float32.

    :raises: PipelineException
    """
    # Basic checks
    if not isinstance(scan, np.ndarray):

        raise PipelineException('Scan needs to be a numpy array.')