<commit_before>#!/usr/bin/env python2
# Copyright 2013, <NAME> <<EMAIL>>

from matplotlib import image, pyplot
from numpy import append, array as _array, real, zeros as _zeros
from numpy.fft import fft2, ifft2, fftshift, ifftshift
try:
    from os import EX_NOINPUT as _EX_NOINPUT
    from os import EX_USAGE as _EX_USAGE
except ImportError:
    _EX_NOINPUT, _EX_USAGE = 1, 2
from os.path import basename, exists, splitext
from random import randint
from sys import argv as _argv, exit as _exit, stderr as _stderr

def _zeropad2(x, shape):
    m, n = x.shape
    p, q = shape
    assert p > m
    assert q > n
    tb = _zeros(((p - m) / 2, n))
    lr = _zeros((p, (q - n) / 2))
    x = append(tb, x, axis = 0)
    x = append(x, tb, axis = 0)
    x = append(lr, x, axis = 1)
    x = append(x, lr, axis = 1)
    return x

def resize(filename, factor = 1.5):
    img = image.imread(filename)
    fft = fft2(img)
    fft = fftshift(fft)
    reshape = lambda (x, y), a: (int(a * x), int(a * y))
    fft = _zeropad2(fft, reshape(img.shape, factor))
    ifft = ifftshift(fft)
    ifft = ifft2(ifft)
    ifft = real(ifft)
    return ifft

def _save(img, file):
    while True:
        newfile = splitext(file)[0] + '-'
        newfile = newfile + str(randint(0,1000)) + '.png'
        if not exists(newfile):
            break
    swap = lambda (x, y): (y, x)
    fig = pyplot.figure(figsize = swap(img.shape), dpi = 1)
    fig.figimage(img, cmap = pyplot.cm.gray)
    pyplot.savefig(newfile, dpi = 1)
    return newfile

def _fail(code):
    print>>_stderr, 'usage: fftresize.py <file> [alpha]'
    _exit(code)

if '__main__' in __name__:
    if len(_argv) == 2:
        file = _argv[1]
        if not exists(file):
            _exit(_EX_NOINPUT)
    elif len(_argv) == 3:
        file = _argv[1]
        if not exists(file):
            _exit(_EX_NOINPUT)
        try:
            factor = float(_argv[2])
        except ValueError:
            _fail(_EX_USAGE)
    else:
        _fail(_EX_USAGE)
    try:
        x = resize(file, factor)<commit_msg>Fix some whitespace style issues.<commit_after>#!/usr/bin/env python2
# Copyright 2013, <NAME> <<EMAIL>>


from matplotlib import image, pyplot
from numpy import append, array as _array, real, zeros as _zeros
from numpy.fft import fft2, ifft2, fftshift, ifftshift
try:
    from os import EX_NOINPUT as _EX_NOINPUT
    from os import EX_USAGE as _EX_USAGE
except ImportError:
    _EX_NOINPUT, _EX_USAGE = 1, 2
from os.path import basename, exists, splitext
from random import randint
from sys import argv as _argv, exit as _exit, stderr as _stderr


def _zeropad2(x, shape):
    m, n = x.shape
    p, q = shape
    assert p > m
    assert q > n
    tb = _zeros(((p - m) / 2, n))
    lr = _zeros((p, (q - n) / 2))
    x = append(tb, x, axis=0)
    x = append(x, tb, axis=0)
    x = append(lr, x, axis=1)
    x = append(x, lr, axis=1)
    return x


def resize(filename, factor=1.5):
    img = image.imread(filename)
    fft = fft2(img)
    fft = fftshift(fft)
    reshape = lambda (x, y), a: (int(a * x), int(a * y))
    fft = _zeropad2(fft, reshape(img.shape, factor))
    ifft = ifftshift(fft)
    ifft = ifft2(ifft)
    ifft = real(ifft)
    return ifft


def _save(img, file):
    while True:
        newfile = splitext(file)[0] + '-'
        newfile = newfile + str(randint(0, 1000)) + '.png'
        if not exists(newfile):
            break
    swap = lambda (x, y): (y, x)
    fig = pyplot.figure(figsize=swap(img.shape), dpi=1)
    fig.figimage(img, cmap=pyplot.cm.gray)
    pyplot.savefig(newfile, dpi=1)
    return newfile


def _fail(code):
    print>>_stderr, 'usage: fftresize.py <file> [alpha]'
    _exit(code)


if '__main__' in __name__:
    if len(_argv) == 2:
        file = _argv[1]
        if not exists(file):
            _exit(_EX_NOINPUT)
    elif len(_argv) == 3:
        file = _argv[1]
        if not exists(file):
            _exit(_EX_NOINPUT)
        try:
            factor = float(_argv[2])
        except ValueError:
            _fail(_EX_USAGE)
    else:
        _fail(_EX_USAGE)
    try:
        x = resize(file, factor)
{'fraction_non_alphanumeric': 0.1257017329753478, 'fraction_numerical': 0.016597510373443983, 'mean_word_length': 2.4995730145175066, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 19, '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': '447188', 'n_tokens_mistral': 1598, 'n_tokens_neox': 1542, 'n_words': 443}