<commit_before>import numpy as np
import scipy.ndimage.interpolation as ndinterp
import matplotlib as mpl
import matplotlib.cm as cm

def findCorners(img):
    data = img.get_data()

    # Individual axis min/max
    xmin, xmax = np.where(np.any(data, axis=(1, 2)))[0][[0, -1]]
    ymin, ymax = np.where(np.any(data, axis=(0, 2)))[0][[0, -1]]
    zmin, zmax = np.where(np.any(data, axis=(0, 1)))[0][[0, -1]]

    # Now convert to physical space
    corners = np.array([[xmin, ymin, zmin, 1.],
                        [xmax, ymax, zmax, 1.]])
    corners = np.dot(img.get_affine(), corners.T)
    corner1 = np.min(corners[0:3,:], axis=1)
    corner2 = np.max(corners[0:3,:], axis=1)
    # Now do min/max again to standardise corners

    return corner1, corner2

def setupSlice(c1, c2, axis, f, samples):
    if (axis == 'z'):
        ll = np.array([c1[0], c1[1], c1[2]*(1-f)+c2[2]*f])
        up = np.array([0, c2[1]-c1[1], 0])
        rt = np.array([c2[0]-c1[0], 0, 0])
        extent = (c1[0], c2[0], c1[1], c2[1])
    elif (axis == 'y'):
        ll = np.array([c1[0], c1[1]*(1-f)+c2[1]*f, c1[2]])
        up = np.array([0, 0, c2[2]-c1[2]])
        rt = np.array([c2[0]-c1[0], 0, 0])
        extent = (c1[0], c2[0], c1[2], c2[2])
    elif (axis == 'x'):
        ll = np.array([c1[0]*(1-f)+c2[0]*f, c1[1], c1[2]])
        up = np.array([0, c2[1]-c1[1], 0])
        rt = np.array([0, 0, c2[2]-c1[2]])
        extent = (c1[2], c2[2], c1[1], c2[1])

    slice = ll[:, None, None] + (rt[:, None, None] * np.linspace(0, 1, samples)[None, :, None] +
                  up[:, None, None] * np.linspace(0, 1, samples)[None, None, :])
    <commit_msg>ENH: Added absolute slice positioning<commit_after>import numpy as np
import scipy.ndimage.interpolation as ndinterp
import matplotlib as mpl
import matplotlib.cm as cm

def findCorners(img):
    data = img.get_data()

    # Individual axis min/max
    xmin, xmax = np.where(np.any(data, axis=(1, 2)))[0][[0, -1]]
    ymin, ymax = np.where(np.any(data, axis=(0, 2)))[0][[0, -1]]
    zmin, zmax = np.where(np.any(data, axis=(0, 1)))[0][[0, -1]]

    # Now convert to physical space
    corners = np.array([[xmin, ymin, zmin, 1.],
                        [xmax, ymax, zmax, 1.]])
    corners = np.dot(img.get_affine(), corners.T)
    corner1 = np.min(corners[0:3,:], axis=1)
    corner2 = np.max(corners[0:3,:], axis=1)
    # Now do min/max again to standardise corners

    return corner1, corner2

def setupSlice(c1, c2, axis, pos, samples, absolute=False):
    ll = np.copy(c1)
    if (axis == 'z'):
        if absolute:
            ll[2] = pos
        else:
            ll[2] = c1[2]*(1-pos)+c2[2]*pos
        up = np.array([0, c2[1]-c1[1], 0])
        rt = np.array([c2[0]-c1[0], 0, 0])
        extent = (c1[0], c2[0], c1[1], c2[1])
    elif (axis == 'y'):
        if absolute:
            ll[1] = pos
        else:
            ll[1] = c1[1]*(1-pos)+c2[1]*pos
        up = np.array([0, 0, c2[2]-c1[2]])
        rt = np.array([c2[0]-c1[0], 0, 0])
        extent = (c1[0], c2[0], c1[2], c2[2])
    elif (axis == 'x'):
        if absolute:
            ll[0] = pos
        else:
            ll[0] = c1[0]*(1-pos)+c2[0]*pos
        up = np.array([0, c2[1]-c1[1], 0])
        rt = np.array([0, 0, c2[2]-c1[2]])
        extent = (c1[2], c2[2], c1[1], c2[1])
    slice = ll[:, None, None] + (rt[:, None, None] * np.linspace(0, 1, samples)[None, :, None] +
                  up[:, None, None] * np.linspace(0, 1, samples)[None, None, :])
    
{'fraction_non_alphanumeric': 0.22167912593444508, 'fraction_numerical': 0.06756756756756757, 'mean_word_length': 2.4445544554455445, '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': '1133895', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1504, 'n_words': 332}