@@ -0,0 +1,2914 @@
+import sys%0Aimport logging%0Aimport time%0A%0Aimport json%0Aimport click%0Aimport pandas as pnd%0Aimport matplotlib.pyplot as plt%0A%0Aimport orangery as o%0A%0A@click.command(options_metavar='%3Coptions%3E')%0A@click.argument('areas_f', nargs=1, type=click.Path(exists=True), metavar='%3Careas_file%3E')%0A@click.argument('materials_f', nargs=1, type=click.Path(exists=True), metavar='%3Cmaterials_file%3E')%0Adef segment(areas_f, materials_f):%0A    %22%22%22Prompt the user to assign materials to polygon areas listed in a csv file.%0A%0A    The segment subcommand takes two arguments: A path to a csv file listing cut-and-fill polygon areas and a path to a JSON file listing possible materials.%0A%0A    The csv file listing the cut-and-fill polygon areas is created with the --save option of the cutfill subcommand.%0A%0A    %5Cb%0A    Example:%0A    orangery segment XS-3-20130514-20170609.csv materials.json%0A%0A    %22%22%22%0A    def __assign_material(p, low, high):%0A        prompt = 'Enter a material no. for area %7B0%7D: '.format(p)%0A        err = 'Input must be an integer number between %7B0%7D and %7B1%7D.'.format(low, high)%0A        while True:%0A            try:%0A                if sys.hexversion %3E= 0x03000000:%0A                    m = int(input(prompt))%0A                else:%0A                    m = int(raw_input(prompt))%0A                if low %3C= m %3C= high:%0A                    return m%0A                else:%0A                    print(err)%0A            except ValueError:%0A                print(err)%0A%0A    areas = pnd.read_csv(areas_f, index_col=0)%0A    # materials list and array to track assignment of material to polygon%0A    materials = json.load(open(materials_f, 'r'))%0A    materials = materials%5B'materials'%5D%0A    assignments = %5B%5D%0A%0A    print('%5Cn')%0A    print('Areas')%0A    print('--------------------')%0A    print(areas)%0A    print('-------------------')%0A%0A    print('%5Cn')%0A    print(%22No.   Material%22)%0A    print('-------------------')%0A    for i, material in enumerate(materials):%0A        print(i, %22   %22, material%5B'name'%5D)%0A%0A    print('%5Cn')%0A    print(%22Assign a material, by number, to each area%22)%0A    print('-------------------')%0A    for i, area in areas.iterrows():%0A        m = __assign_material(i, 0, len(materials)-1)%0A        assignments.append(%5Bi, m, materials%5Bm%5D%5B'name'%5D, materials%5Bm%5D%5B'density'%5D, materials%5Bm%5D%5B'fines'%5D%5D)%0A    assignments_df = pnd.DataFrame(assignments, columns=%5B'polygon', 'material', 'name', 'density', 'fines'%5D)%0A    result = assignments_df.join(areas)%0A    result%5B'mass_fines'%5D = result%5B'density'%5D*result%5B'fines'%5D/100*result%5B'area'%5D%0A%0A    print('%5Cn')%0A    print('Results ')%0A    print('-------------------')%0A    print(result)%0A    print('-------------------')%0A    print('Net change in mass of fines: ', result%5B'mass_fines'%5D.sum())%0A    %0A    print('%5Cn')%0A%0A    if sys.hexversion %3E= 0x03000000:%0A        input(%22Press Enter to exit%22)%0A    else:%0A        raw_input(%22Press Enter to exit%22)%0A%0A    outfile = areas_f.split('.')%5B0%5D + '-sgmt.' + areas_f.split('.')%5B1%5D%0A    result.to_csv(outfile)

add segment subcommand