<commit_before># Image windowing class

import numpy as np
import sidpy
from scipy import fftpack
from scipy.signal import hanning, blackman
from skimage.transform import rescale

class ImageWindowing:
    """
    This class will generate windows from sidpy dataset objects. At present only 2D windowing is allowed.
    """
    def __init__(self, parms_dict, verbose = False):
        '''Sliding Window Class.

        Parameters
        ----------
        - parms_dict : dictionary
            Dictionary with parameters of the windowing process, see below.

            Keys:
            - 'window_size_x' (integer) (required): size of the window across the x-axis
            - 'window_size_y' (integer) (required): size of the window across the y-axis
            - 'window_step_x' (integer) (required): step size of the window across the x-axis. Sometimes referred to as 'strides'
            - 'window_step_y' (integer) (required): step size of the window across the y-axis. Sometimes referred to as 'strides'
            - 'mode' (string) (Optional, default is 'image'): One of 'image' or 'fft' which defines the processing to be performed for each window.
                The choice of 'fft' will perform 2D fast Fourier transforms on each image whereas 'image' will not perform any operation on the window
            - 'fft_mode' (string) (Optional, default is 'abs'): If mode is 'fft', choose whether to look at amplitude or phase. Options are 'abs', 'phase'.
            - 'interpol_factor' (float) (Optional, default is 1.0): Interpolation factor for windows to increase or decrease size of the windows.
            - 'zoom_factor' (integer or list of ints) (Optional, default is 1): Zoom the window by this factor, typically done for 'fft' mode to observe higher frequencies clearly
                            If passing a list of ints, this will determine the degree of cropping per axis
            - 'filter' (string) (Optional, default is None): Filtering to use for the image window. Options are 'blackman', 'hanning'.
            The filter is applied to each window before 'mode'.
        - verbose : (Optional) Boolean
            Verbose flag. Default is False.

        Returns
        --------
        Instance of ImageWindowing object setup with parameters defined by the parms_dict above.
       '''

        self.window_step_x = parms_dict['window_step_x']
        self.window_step_y = parms_dict['window_step_y']
        self.window_size_x = parms_dict['window_size_x']
        self.window_size_y = parms_dict['window_size_y']
        self.fft_mode = 'abs'
        self.verbose = verbose

        if 'mode' in parms_dict.keys():
            if parms_dict['mode'] not in ['image', 'fft']:
                raise ValueError("Parameters dictionary field 'mode' must be one of 'image' or 'fft'."
                                 "Try again with one of these two options.")
            else:
                self.mode = parms_dict['mode']
        else:
            self.mode = 'image'
            parms_dict['mode'] = 'image'<commit_msg>adjust docstring<commit_after># Image windowing class

import numpy as np
import sidpy
from scipy import fftpack
from scipy.signal import hanning, blackman
from skimage.transform import rescale

class ImageWindowing:
    """
    This class will generate windows from sidpy dataset objects. At present only 2D windowing is allowed.
    """
    def __init__(self, parms_dict, verbose = False):
        '''Sliding Window Class.

        Parameters
        ----------
        - parms_dict : dictionary
            Dictionary with parameters of the windowing process, see below.

            Keys:
            - 'window_size_x' (integer) (required): size of the window across the x-axis
            - 'window_size_y' (integer) (required): size of the window across the y-axis
            - 'window_step_x' (integer) (required): step size of the window across the x-axis. Sometimes referred to as 'strides'
            - 'window_step_y' (integer) (required): step size of the window across the y-axis. Sometimes referred to as 'strides'
            - 'mode' (string) (Optional, default is 'image'): One of 'image' or 'fft' which defines the processing to be performed for each window.
                The choice of 'fft' will perform 2D fast Fourier transforms on each image whereas 'image' will not perform any operation on the window
            - 'fft_mode' (string) (Optional, default is 'abs'): If mode is 'fft', choose whether to look at amplitude or phase. Options are 'abs', 'phase' and 'complex'.
            - 'interpol_factor' (float) (Optional, default is 1.0): Interpolation factor for windows to increase or decrease size of the windows.
            - 'zoom_factor' (integer or list of ints) (Optional, default is 1): Zoom the window by this factor, typically done for 'fft' mode to observe higher frequencies clearly
                            If passing a list of ints, this will determine the degree of cropping per axis
            - 'filter' (string) (Optional, default is None): Filtering to use for the image window. Options are 'blackman', 'hanning'.
            The filter is applied to each window before 'mode'.
        - verbose : (Optional) Boolean
            Verbose flag. Default is False.

        Returns
        --------
        Instance of ImageWindowing object setup with parameters defined by the parms_dict above.
       '''

        self.window_step_x = parms_dict['window_step_x']
        self.window_step_y = parms_dict['window_step_y']
        self.window_size_x = parms_dict['window_size_x']
        self.window_size_y = parms_dict['window_size_y']
        self.fft_mode = 'abs'
        self.verbose = verbose

        if 'mode' in parms_dict.keys():
            if parms_dict['mode'] not in ['image', 'fft']:
                raise ValueError("Parameters dictionary field 'mode' must be one of 'image' or 'fft'."
                                 "Try again with one of these two options.")
            else:
                self.mode = parms_dict['mode']
        else:
            self.mode = 'image'
            parms_dict['mode'] = 'image'
{'fraction_non_alphanumeric': 0.08698485095292392, 'fraction_numerical': 0.0016289297931259162, 'mean_word_length': 2.414905450500556, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2114652', 'n_tokens_mistral': 1633, 'n_tokens_neox': 1598, 'n_words': 674}