<commit_before># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import numpy as np
from .math import fit_gaussian
import warnings
from scipy.ndimage import center_of_mass
from scipy.ndimage.interpolation import shift
from scipy.optimize import minimize

def find_center(IM, method='image_center', verbose=False, **kwargs):
    """
    Paramters
    ---------
    IM : 2D np.array
      image data

    method: str
      valid method:
        - image_center
        - com
        - gaussian

    Returns
    -------
    out: (float, float)
      coordinate of the center of the image in the (y,x) format (row, column)

    """
    return func_method[method](IM, verbose=verbose, **kwargs)


def center_image(IM, center='com', odd_size=True, verbose=False, **kwargs):
    """ Center image with the custom value or by several methods provided in `find_center` function

    Parameters
    ----------
    IM : 2D np.array
       The image data.

    center : tuple or str
        (float, float) coordinate of the center of the image in the (y,x) 
        format (row, column)

        str: method in which to determine the center of the image
        'image_center' - 
        'com' - center of mass using scipy.ndimage.center_of_mass
        'gaussian'
        'slice'

    Returns
    -------
    out : 2D np.array
       Centered image
    """

    rows, cols = IM.shape

    if odd_size and cols % 2 == 0:
        # drop rightside column
        IM = IM[:, :-1]
        rows, cols = IM.shape

    # center is in y,x (row column) format!
    if isinstance(center, str) or isinstance(center, unicode):
        center = find_center(IM, center, verbose=verbose, **kwargs)

    centered_data = set_center(IM, center, verbose=verbose)
    return centered_data


def set_center(data, center, crop='maintain_size', verbose=False):
    """ Move image center to mid-point of image
        
    Parameters
    ----------
    data : 2D np.array
        The image data
    
    center : tuple
        image pixel coordinate center (row, col)

    crop : str
        'maintain_size' : return image of the same size
        'valid_region'  : ?

    verbose: boolean
        True: print diagnostics
    """
    c0, c1 = center
    if isinstance(c0, (int, long)) and isinstance(c1, (int, long)):
        warnings.warn('Integer center detected, but not respected.'
                      'treating center as float and interpolating!')
        # need to include code here to treat integer centers
        # probably can use abel.tools.symmetry.center_image_asym(),
        # but this function lacks the ability to set the vertical center

    old_shape = data.shape
    old_center = data.shape[0]/2.0, data.shape[1]/2.0

    delta0 = old_center[0] - center[0]
    delta1 = old_center[1] - center[1]<commit_msg>int is the new long<commit_after># -*- coding: utf-8 -*-
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from __future__ import unicode_literals

import numpy as np
from .math import fit_gaussian
import warnings
from scipy.ndimage import center_of_mass
from scipy.ndimage.interpolation import shift
from scipy.optimize import minimize

def find_center(IM, method='image_center', verbose=False, **kwargs):
    """
    Paramters
    ---------
    IM : 2D np.array
      image data

    method: str
      valid method:
        - image_center
        - com
        - gaussian

    Returns
    -------
    out: (float, float)
      coordinate of the center of the image in the (y,x) format (row, column)

    """
    return func_method[method](IM, verbose=verbose, **kwargs)


def center_image(IM, center='com', odd_size=True, verbose=False, **kwargs):
    """ Center image with the custom value or by several methods provided in `find_center` function

    Parameters
    ----------
    IM : 2D np.array
       The image data.

    center : tuple or str
        (float, float) coordinate of the center of the image in the (y,x) 
        format (row, column)

        str: method in which to determine the center of the image
        'image_center' - 
        'com' - center of mass using scipy.ndimage.center_of_mass
        'gaussian'
        'slice'

    Returns
    -------
    out : 2D np.array
       Centered image
    """

    rows, cols = IM.shape

    if odd_size and cols % 2 == 0:
        # drop rightside column
        IM = IM[:, :-1]
        rows, cols = IM.shape

    # center is in y,x (row column) format!
    if isinstance(center, str) or isinstance(center, unicode):
        center = find_center(IM, center, verbose=verbose, **kwargs)

    centered_data = set_center(IM, center, verbose=verbose)
    return centered_data


def set_center(data, center, crop='maintain_size', verbose=False):
    """ Move image center to mid-point of image
        
    Parameters
    ----------
    data : 2D np.array
        The image data
    
    center : tuple
        image pixel coordinate center (row, col)

    crop : str
        'maintain_size' : return image of the same size
        'valid_region'  : ?

    verbose: boolean
        True: print diagnostics
    """
    c0, c1 = center
    if isinstance(c0, int) and isinstance(c1, int)):
        warnings.warn('Integer center detected, but not respected.'
                      'treating center as float and interpolating!')
        # need to include code here to treat integer centers
        # probably can use abel.tools.symmetry.center_image_asym(),
        # but this function lacks the ability to set the vertical center

    old_shape = data.shape
    old_center = data.shape[0]/2.0, data.shape[1]/2.0

    delta0 = old_center[0] - center[0]
    delta1 = old_center[1] - center[1]
{'fraction_non_alphanumeric': 0.0994674454561072, 'fraction_numerical': 0.008246005840920804, 'mean_word_length': 2.3987157034442497, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5962113', 'n_tokens_mistral': 1744, 'n_tokens_neox': 1669, 'n_words': 589}