<commit_before>#!/usr/bin/env python
# coding=utf-8

"""Splats a xypt OME-TIFF stack into p substacks.
Reduces bit depth from 12 bits to 8 bits."""

from __future__ import print_function
import os.path
import tifffile as tf
import numpy as np
from distutils.dir_util import mkpath

def extrude(filename, outpath, n_positions, handler=print):
    tiff = tf.TiffFile(filename)
    assert len(tiff) % n_positions == 0
    # n_timepoints = len(tiff) / n_positions
    mkpath(outpath)
    for p in xrange(n_positions):
        handler(p)
        outfn = os.path.join(outpath, "{}.tif".format(p))
        with tf.TiffWriter(outfn) as tw:
            array = tf.stack_pages(tiff[p::n_positions])
            array >>= 4
            array = array.astype(np.uint8)
            tw.save(array)

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("input_stack")
    parser.add_argument("output_path")
    parser.add_argument("n_positions", type=int)
    args = parser.parse_args()
    extrude(args.input_stack, args.output_path, args.n_positions)<commit_msg>extrude: tiffs encode number of locations already<commit_after>#!/usr/bin/env python
# coding=utf-8

"""Splats a xypt OME-TIFF stack into p substacks.
Reduces bit depth from 12 bits to 8 bits."""

from __future__ import print_function
import os
import tifffile as tf
import numpy as np

def extrude(filename, outpath, handler=print):
    tiff = tf.TiffFile(filename, multifile=True, multifile_close=False)
    serieses = tiff.series
    os.makedirs(outpath)
    for p, series in enumerate(serieses):
        handler(p)
        outfn = os.path.join(outpath, "{}.tif".format(p))
        with tf.TiffWriter(outfn) as tw:
            array = tf.stack_pages(series['pages'])
            array >>= 4
            array = array.astype(np.uint8)
            tw.save(array)

if __name__ == "__main__":
    import argparse
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("input_stack")
    parser.add_argument("output_path")
    args = parser.parse_args()
    extrude(args.input_stack, args.output_path)
{'fraction_non_alphanumeric': 0.11023255813953488, 'fraction_numerical': 0.0060465116279069765, 'mean_word_length': 3.4077868852459017, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 7, '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': '1238407', 'n_tokens_mistral': 728, 'n_tokens_neox': 708, 'n_words': 171}