<commit_before>import os
import argparse

import numpy as np
import scipy.ndimage as nd

from jicbioimage.core.image import Image

from utils import get_microscopy_collection

HERE = os.path.dirname(__file__)
UNPACK = os.path.join(HERE, '..', 'data', 'unpack')
OUTPUT = os.path.join(HERE, '..', 'output')


def generate_surface_from_stack(stack, sd=(2, 2, 2), surface_blur_sd=5):
    """Return a 2D image encoding a height map, generated from the input stack.
    The image is generated by first blurring the stack, then taking the z index
    of the brightest point for each X, Y location. The resultant surface is
    then smoothed with a gaussian filter.

    sd: standard deviation in each direction
    surface_blur_sd: standard deviation of smoothing applied to 2D surface."""


    smoothed_stack = nd.gaussian_filter(stack, sd)
    raw_surface = np.argmax(smoothed_stack, 2)
    smoothed_surface = nd.gaussian_filter(raw_surface, surface_blur_sd)

    return smoothed_surface

def projection_from_stack_and_surface(stack, surface, z_below=1, z_above=1):
    """Return a 2D projection of a 3D stack. The projection is obtained by
    using the elements of the 2D array surface as the Z index for each
    point in the plane."""

    projection = np.zeros(surface.shape, dtype=np.uint8)

    xdim, ydim, zdim = stack.shape
    for x in range(xdim):
        for y in range(ydim):
            z_index = surface[x, y]
            z_min = max(0, z_index-z_below)
            z_max = min(zdim-1, z_index+z_above)
            value = np.mean(stack[x, y, z_min:z_max])
            projection[x, y] = value

    return projection.view(Image)

def save_image(filename, image):
    """Save the given image to a file."""

    with open(filename, 'wb') as f:
        f.write(image.png())

def generate_projections_from_microscope_image(input_file,
                                               cell_wall_file,<commit_msg>Made z_below and z_above reference slize 0 as top of data.<commit_after>import os
import argparse

import numpy as np
import scipy.ndimage as nd

from jicbioimage.core.image import Image

from utils import get_microscopy_collection

HERE = os.path.dirname(__file__)
UNPACK = os.path.join(HERE, '..', 'data', 'unpack')
OUTPUT = os.path.join(HERE, '..', 'output')


def generate_surface_from_stack(stack, sd=(2, 2, 2), surface_blur_sd=5):
    """Return a 2D image encoding a height map, generated from the input stack.
    The image is generated by first blurring the stack, then taking the z index
    of the brightest point for each X, Y location. The resultant surface is
    then smoothed with a gaussian filter.

    sd: standard deviation in each direction
    surface_blur_sd: standard deviation of smoothing applied to 2D surface."""


    smoothed_stack = nd.gaussian_filter(stack, sd)
    raw_surface = np.argmax(smoothed_stack, 2)
    smoothed_surface = nd.gaussian_filter(raw_surface, surface_blur_sd)

    return smoothed_surface

def projection_from_stack_and_surface(stack, surface, z_above=1, z_below=1):
    """Return a 2D projection of a 3D stack. The projection is obtained by
    using the elements of the 2D array surface as the Z index for each
    point in the plane."""

    projection = np.zeros(surface.shape, dtype=np.uint8)

    xdim, ydim, zdim = stack.shape
    for x in range(xdim):
        for y in range(ydim):
            z_index = surface[x, y]
            z_min = max(0, z_index-z_above)
            z_max = min(zdim-1, z_index+z_below)
            value = np.mean(stack[x, y, z_min:z_max])
            projection[x, y] = value

    return projection.view(Image)

def save_image(filename, image):
    """Save the given image to a file."""

    with open(filename, 'wb') as f:
        f.write(image.png())

def generate_projections_from_microscope_image(input_file,
                                               cell_wall_file,
{'fraction_non_alphanumeric': 0.08898632963631674, 'fraction_numerical': 0.007995873097755997, 'mean_word_length': 3.1788793103448274, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1030356', 'n_tokens_mistral': 1260, 'n_tokens_neox': 1195, 'n_words': 399}