<commit_before>import numpy as np
import bashes

import scipy.ndimage
import scipy.interpolate

def fourierMatrix(n):
    """
    Returns the fourier transform matrix for a square 2d matrix of size n.
    """
    i,j = np.meshgrid(np.arange(n), np.arange(n))
    A = np.multiply.outer(i.flatten(), i.flatten())
    B = np.multiply.outer(j.flatten(), j.flatten())
    omega = np.exp(-2*np.pi*1J/n)
    return np.power(omega, A+B)

def circularize(t):
    """
    Returns the azimuthally averaged 2d image about the center. 
    """
    # average over theta
    sx, sy = t.shape
    X, Y = np.ogrid[0:sx, 0:sy]
    r = np.hypot(X - sx/2 + 0.5, Y - sy/2 + 0.5)
    rbin = r.astype(np.int)
    tAvg = scipy.ndimage.mean(t, labels=rbin, index=np.arange(0, rbin.max()+1))
    # build 2d representation
    tAvgInterp = scipy.interpolate.InterpolatedUnivariateSpline(np.arange(len(tAvg)),tAvg)
    tAvg2d = tAvgInterp(r.flatten()).reshape(sx,sy)
    return tAvg2d

class FeatureCalculator(object):
    """
    Feature calculator abstract base class
    """
    def __init__(self, nfeatures):
        self.nfeatures = nfeatures
    def getFeatures(self, image, psf):
        pass

class FourierMoments(FeatureCalculator):
    """
    Calculates fourier domain moment features
    """
    def __init__(self, stampSize, pixelScale, sigma=None):
        self.stampSize = stampSize
        self.pixelScale = pixelScale
        self.sigma = sigma

        # k grid
        kx,ky = np.meshgrid(np.fft.fftfreq(stampSize),np.fft.fftfreq(stampSize))
        dk = kx[0,0]-kx[0,1]
        self.dksq = dk*dk

        # build part of weight function
        kxsq = kx*kx<commit_msg>Rename variables in circularize method for clarity<commit_after>import numpy as np
import bashes

import scipy.ndimage
import scipy.interpolate

def fourierMatrix(n):
    """
    Returns the fourier transform matrix for a square 2d matrix of size n.
    """
    i,j = np.meshgrid(np.arange(n), np.arange(n))
    A = np.multiply.outer(i.flatten(), i.flatten())
    B = np.multiply.outer(j.flatten(), j.flatten())
    omega = np.exp(-2*np.pi*1J/n)
    return np.power(omega, A+B)

def circularize(image):
    """
    Returns the azimuthally averaged 2d image about the center. 
    """
    # average over theta
    sx, sy = image.shape
    X, Y = np.ogrid[0:sx, 0:sy]
    r = np.hypot(X - sx/2 + 0.5, Y - sy/2 + 0.5)
    rbin = r.astype(np.int)
    avg = scipy.ndimage.mean(image, labels=rbin, index=np.arange(0, rbin.max()+1))
    # build 2d representation
    avgInterp = scipy.interpolate.InterpolatedUnivariateSpline(np.arange(len(avg)),avg)
    avg2d = avgInterp(r.flatten()).reshape(sx,sy)
    return avg2d

class FeatureCalculator(object):
    """
    Feature calculator abstract base class
    """
    def __init__(self, nfeatures):
        self.nfeatures = nfeatures
    def getFeatures(self, image, psf):
        pass

class FourierMoments(FeatureCalculator):
    """
    Calculates fourier domain moment features
    """
    def __init__(self, stampSize, pixelScale, sigma=None):
        self.stampSize = stampSize
        self.pixelScale = pixelScale
        self.sigma = sigma

        # k grid
        kx,ky = np.meshgrid(np.fft.fftfreq(stampSize),np.fft.fftfreq(stampSize))
        dk = kx[0,0]-kx[0,1]
        self.dksq = dk*dk

        # build part of weight function
        kxsq = kx*kx
{'fraction_non_alphanumeric': 0.1278240190249703, 'fraction_numerical': 0.01248513674197384, 'mean_word_length': 2.8457142857142856, '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': '6673672', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1220, 'n_words': 271}