<commit_before>import sys

import fiona
from shapely.geometry import shape, mapping
import click

import surficial

@click.command(options_metavar='<options>')
@click.argument('stream_f', nargs=1, type=click.Path(exists=True), metavar='<stream_file>')
@click.argument('output_f', nargs=1, type=click.Path(), metavar='<output_file>')
@click.argument('distance', nargs=1, type=click.FLOAT, metavar='<float>')
@click.option('-s', '--source', nargs=1, type=click.INT, metavar='<int>', help="Source node ID")
@click.option('-o', '--outlet', nargs=1, type=click.INT, metavar='<int>', help="Outlet node ID")
def cli(stream_f, output_f, distance, source, outlet):
    """
    Buffers a network graph or path within a network graph

    \b
    Example:
    buffer stream_ln.shp buf.shp 100.0 -s 5
    """

    with fiona.open(stream_f) as stream_src:
        lines = [shape(line['geometry']) for line in stream_src]
        source_driver = stream_src.driver
        source_crs = stream_src.crs

    # make the graph
    graph = surficial.construct(lines)

    if not outlet:
        outlet = surficial.get_outlet(graph)
    if not source:
        path = graph.edges()
    else:
        path = list(surficial.get_path_edges(graph, source, outlet))
    buf = surficial.get_edge_buffer(graph, distance, edges=path)

    sink_schema = {
        'geometry': 'Polygon',
        'properties': {'id': 'int'},
    }

    with fiona.open(
        output_f,
        'w',
        driver=source_driver,
        crs=source_crs,
        schema=sink_schema) as sink:
        sink.write({
           	'geometry': mapping(buf),
           	'properties': {'id': 0},
        })

    click.echo('Output written to: {}'.format(output_f))<commit_msg>update buffer script to use the Alignment class<commit_after>import sys

import fiona
from shapely.geometry import shape, mapping
import click

import surficial

@click.command(options_metavar='<options>')
@click.argument('alignment_f', nargs=1, type=click.Path(exists=True), metavar='<alignment_file>')
@click.argument('output_f', nargs=1, type=click.Path(), metavar='<output_file>')
@click.argument('distance', nargs=1, type=click.FLOAT, metavar='<float>')
@click.option('-s', '--source', nargs=1, type=click.INT, metavar='<int>', help="Source node ID")
@click.option('-o', '--outlet', nargs=1, type=click.INT, metavar='<int>', help="Outlet node ID")
def cli(alignment_f, output_f, distance, source, outlet):
    """
    Buffers a network graph or path within a network graph

    \b
    Example:
    buffer stream_ln.shp buf.shp 100.0 -s 5
    """

    with fiona.open(alignment_f) as alignment_src:
        lines = [shape(line['geometry']) for line in alignment_src]
        source_driver = alignment_src.driver
        source_crs = alignment_src.crs

    # make the graph
    alignment = surficial.Alignment(lines)

    if not outlet:
        outlet = alignment.outlet()
    if not source:
        path = alignment.edges()
    else:
        path = list(alignment.path_edges(source, outlet))
    buf = alignment.edge_buffer(distance, edges=path)

    sink_schema = {
        'geometry': 'Polygon',
        'properties': {'id': 'int'},
    }

    with fiona.open(
        output_f,
        'w',
        driver=source_driver,
        crs=source_crs,
        schema=sink_schema) as sink:
        sink.write({
           	'geometry': mapping(buf),
           	'properties': {'id': 0},
        })

    click.echo('Output written to: {}'.format(output_f))
{'fraction_non_alphanumeric': 0.146355517142034, 'fraction_numerical': 0.006338231057332181, 'mean_word_length': 3.3076923076923075, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, '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': '1744877', 'n_tokens_mistral': 1168, 'n_tokens_neox': 1140, 'n_words': 262}