Пример #1
0
def run(src, deletekey, key, newkey, uid_insert, uid_year, value):
    if src is None:
        click.secho("No source specified...", fg="red")
        click.echo("run 'python append.py --help to see options'")
        return

    if deletekey is not None:
        if click.confirm("Are you sure you want to delete key '%s'" % deletekey):
            subdirs = get_files_to_process(src)
            with Pool(processes=cpu_count()) as pool:
                pool.starmap(delete_key, [(dir, deletekey) for dir in subdirs])
        return

    if key is not None and newkey is not None:
        if click.confirm(
            "Are you sure you want to replace the key '%s' with '%s'" % (key, newkey)
        ):
            pass
        else:
            return

    if (key is not None and value is not None) or (
        key is not None and newkey is not None
    ):
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(
                append_or_change_filenames,
                [(dir, key, newkey, value) for dir in subdirs],
            )
        return
    if uid_insert is not None:
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(do_uid_insert, [(dir, uid_insert) for dir in subdirs])
        return
    if uid_year is not None:
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(replace_uid_year, [(dir, uid_year) for dir in subdirs])
        return
    else:
        click.secho("I'm afraid I don't quite know what to do.", fg="red")
        click.echo("run 'python append.py --help to see options'")
Пример #2
0
def run(old, src):
    if src:
        click.secho("Measuring scalebars...", fg="white")
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(measure_scalebar, [(dir, old) for dir in subdirs])
        click.secho("Done!", fg="green")

    else:
        click.secho("no source", fg="red")
Пример #3
0
def run(src):
    subdirs = get_files_to_process(src)
    # print(subdirs)
    for dir in subdirs:
        for file in dir["files"]:
            image = read_file(file)
            backdrop = detect_backdrop(image)
            crop = crop_left_of_blue_line_hsv(image,
                                              backdrop=backdrop,
                                              visualize=True)
            filename = file.split("/")[-1]
            write_file(crop, "/Users/creimers/Downloads", filename)
Пример #4
0
def run(dest, destdir, destsub, keep, no_black_tape, old, smoothen, src, visualize):
    if not src:
        click.secho("No source specified. Use --src", fg="red")
        return

    if dest and not os.path.exists(dest):
        pathlib.Path(dest).mkdir(parents=True)

    subdirs = get_files_to_process(src)

    if visualize is True:
        name = None
        clear = True
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(
                mask_overlay_parallel,
                [(dir, smoothen, old, clear, name, no_black_tape) for dir in subdirs],
            )
        return

    clear = True
    name = None
    with Pool(processes=cpu_count()) as pool:
        pool.starmap(
            binary_mask_parallel,
            [(dir, smoothen, old, clear, name, no_black_tape) for dir in subdirs],
        )

    # move result to final destination
    if dest:
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(
                copy_results,
                [
                    (
                        os.path.join(dir["path"], BINARY_MASKS_DIR),
                        dest,
                        destdir,
                        destsub,
                    )
                    for dir in subdirs
                ],
            )

    if dest and not keep:
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(
                shutil.rmtree,
                [(os.path.join(dir["path"], BINARY_MASKS_DIR),) for dir in subdirs],
            )
Пример #5
0
def run(aspect, length, old, smoothen, src):
    if not aspect:
        click.secho("No aspect specified. Use --aspect", fg="red")
        return
    if not src:
        click.secho("No source specified. Use --src", fg="red")
        return

    clear = True

    mask_dest = BINARY_MASKS_DIR
    straight_dest = STRAIGHTENED_MASKS_DIR

    if aspect == "blue-line":
        name = None
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(draw_blue_line, [(dir, old) for dir in subdirs])
        return

    if aspect == "black-box":
        name = None
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(draw_black_box, [(dir, old) for dir in subdirs])
        return

    if aspect == "midline":
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(draw_midline, [(dir["path"], ) for dir in subdirs])
        return

    if aspect == "shouldering":
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(visualize_shouldering,
                         [(dir["path"], ) for dir in subdirs])
        return

    # TODO: is this working??
    if aspect == "graph":
        subdirs = get_files_to_process(src)
        with Pool(processes=cpu_count()) as pool:

            # make masks
            pool.starmap(
                binary_mask_parallel,
                [(dir, smoothen, old, clear, None) for dir in subdirs],
            )

            # draw graphs
            pool.starmap(draw_graph, [(os.path.join(dir["path"], mask_dest), )
                                      for dir in subdirs])
        return

    if aspect == "tip-angle":
        subdirs = get_files_to_process(src)
        no_tip_dest = "tip-angle"
        with Pool(processes=cpu_count()) as pool:
            # make masks
            pool.starmap(
                binary_mask_parallel,
                [(dir, smoothen, old, clear, None) for dir in subdirs],
            )

            # straighten mask (own folder)
            pool.starmap(
                straighten_binary_masks,
                [(os.path.join(dir["path"], mask_dest), ) for dir in subdirs],
            )

        # moving straight masks
        with Pool(processes=cpu_count()) as pool:
            pool.starmap(
                copy_results,
                [(
                    os.path.join(dir["path"], mask_dest),
                    os.path.join(dir["path"], straight_dest),
                    "",
                    None,
                    True,
                ) for dir in subdirs],
            )

            # # tip mask
            dry = False
            pool.starmap(
                tip_mask,
                [(os.path.join(dir["path"], straight_dest), dry)
                 for dir in subdirs],
            )

            # draw dip lines
            pool.starmap(
                draw_tip_lines,
                [(os.path.join(dir["path"], DETIPPED_MASKS_DIR), )
                 for dir in subdirs],
            )

            # remove intermediate
            pool.starmap(
                shutil.rmtree,
                [(os.path.join(dir["path"], mask_dest), ) for dir in subdirs],
            )
            pool.starmap(
                shutil.rmtree,
                [(os.path.join(dir["path"], straight_dest), )
                 for dir in subdirs],
            )