Ejemplo n.º 1
0
def convert_rp66v1_dir_or_file_to_las(
        path_in: str,
        path_out: str,
        recurse: bool,
        array_reduction: str,
        frame_slice: Slice.Slice,
        channels: typing.Set[str],
        field_width: int,
        float_format: str,
) -> typing.Dict[str, LASWriteResult]:
    """Convert a directory or file to a set of LAS files."""
    logging.info(f'index_dir_or_file(): "{path_in}" to "{path_out}" recurse: {recurse}')
    ret = {}
    try:
        if os.path.isdir(path_in):
            for file_in_out in dirWalk(path_in, path_out, theFnMatch='', recursive=recurse, bigFirst=False):
                ret[file_in_out.filePathIn] = single_rp66v1_file_to_las(
                    file_in_out.filePathIn, array_reduction, file_in_out.filePathOut, frame_slice, channels,
                    field_width, float_format
                )
        else:
            if os.path.isdir(path_out):
                path_out = os.path.join(path_out, os.path.basename(path_in))
            ret[path_in] = single_rp66v1_file_to_las(
                path_in, array_reduction, path_out, frame_slice, channels, field_width, float_format)
    except KeyboardInterrupt:  # pragma: no cover
        logger.critical('Keyboard interrupt, last file is probably incomplete or corrupt.')
    return ret
Ejemplo n.º 2
0
def main() -> int:
    description = """usage: %(prog)s [options] file
Scans a file for TIF markers or can copy a directory of files with TIF markers removed."""
    print('Cmd: %s' % ' '.join(sys.argv))
    parser = cmn_cmd_opts.path_in_out(description,
                                      prog='TotalDepth.DeTif.main',
                                      version=__version__,
                                      epilog=__rights__)
    cmn_cmd_opts.add_log_level(parser, level=20)
    # cmn_cmd_opts.add_multiprocessing(parser)
    parser.add_argument(
        '-n',
        '--nervous',
        action='store_true',
        help=
        'Nervous mode, don\'t do anything but report what would be done. [default: %(default)s]',
    )
    parser.add_argument('-o',
                        '--over-write',
                        help='Over write existing files, otherwise warns.',
                        action='store_true')
    args = parser.parse_args()
    # print('args:', args)
    # return 0
    cmn_cmd_opts.set_log_level(args)
    clk_start = time.perf_counter()
    # Your code here
    if args.path_out is None:
        tif_markers = tif_scan_path(args.path_in)
        print(f'Detected {len(tif_markers):,d} TIF Markers in {args.path_in}')
        if args.verbose:
            for t, tif_marker in enumerate(tif_markers):
                print(f'[{t:6,d}] {tif_marker}')
        else:
            print('Use -v option to see the actual TIF markers.')
    else:
        # Strip the TIF markers, respecting the nervous option.
        files_copied = tif_count = bytes_copied = 0
        if os.path.isfile(args.path_in):
            files_copied, tif_count, bytes_copied = de_tif_file(
                args.path_in, args.path_out, args.nervous, args.over_write)
        else:
            for file_in_out in dirWalk(args.path_in,
                                       args.path_out,
                                       theFnMatch='',
                                       recursive=args.recurse,
                                       bigFirst=False):
                _files_copied, _tif_count, _byte_count = de_tif_file(
                    file_in_out.filePathIn, file_in_out.filePathOut,
                    args.nervous, args.over_write)
                files_copied += _files_copied
                tif_count += _tif_count
                bytes_copied += _byte_count
        print(
            f'Files: {files_copied:,d} 12 byte TIF markers removed: {tif_count:,d} bytes: {bytes_copied:,d}'
        )
    clk_exec = time.perf_counter() - clk_start
    print('Execution time = %8.3f (S)' % clk_exec)
    print('Bye, bye!')
    return 0
Ejemplo n.º 3
0
def dump_frames_and_or_channels(path_in: str, recurse: bool, frame_slice: str, channels: str) -> None:
    """Dump available channels and frames."""
    assert frame_slice == '?' or channels == '?'
    if os.path.isdir(path_in):
        for file_in_out in dirWalk(path_in, '', theFnMatch='', recursive=recurse, bigFirst=False):
            dump_frames_and_or_channels_single_rp66v1_file(file_in_out.filePathIn, frame_slice == '?', channels == '?')
    else:
        dump_frames_and_or_channels_single_rp66v1_file(path_in, frame_slice == '?', channels == '?')
Ejemplo n.º 4
0
def read_index_dir_or_file(path_in: str, recurse: bool,
                           eflr_set_type: typing.List[str]) -> typing.Dict[str, IndexResult]:
    logging.info(f'index_dir_or_file(): "{path_in}" recurse: {recurse}')
    ret = {}
    if os.path.isdir(path_in):
        for file_in_out in dirWalk(path_in, theFnMatch='', recursive=recurse, bigFirst=False):
            # print(file_in_out)
            ret[file_in_out.filePathIn] = read_a_single_index(file_in_out.filePathIn, eflr_set_type)
    else:
        ret[path_in] = read_a_single_index(path_in, eflr_set_type)
    return ret
Ejemplo n.º 5
0
def index_dir_or_file(path_in: str, path_out: str, recurse: bool, read_back: bool) -> typing.Dict[str, IndexResult]:
    logging.info(f'index_dir_or_file(): "{path_in}" to "{path_out}" recurse: {recurse}')
    ret = {}
    if os.path.isdir(path_in):
        for file_in_out in dirWalk(path_in, path_out, theFnMatch='', recursive=recurse, bigFirst=False):
            bin_file_type = binary_file_type_from_path(file_in_out.filePathIn)
            if bin_file_type == 'RP66V1':
                ret[file_in_out.filePathIn] = index_a_single_file(file_in_out.filePathIn, file_in_out.filePathOut, read_back)
    else:
        bin_file_type = binary_file_type_from_path(path_in)
        if bin_file_type == 'RP66V1':
            ret[path_in] = index_a_single_file(path_in, path_out, read_back)
    return ret
Ejemplo n.º 6
0
def scan_dir_or_file(path_in: str,
                     path_out: str,
                     function: typing.Callable,
                     recurse: bool,
                     output_extension: str,
                     **kwargs) -> typing.Dict[str, IndexResult]:
    logging.info(f'scan_dir_or_file(): "{path_in}" to "{path_out}" with {function} recurse: {recurse}')
    ret = {}
    if os.path.isdir(path_in):
        for file_in_out in dirWalk(path_in, path_out, theFnMatch='', recursive=recurse, bigFirst=False):
            # print(file_in_out)
            ret[file_in_out.filePathIn] = scan_a_single_file(
                file_in_out.filePathIn, file_in_out.filePathOut, output_extension, function, **kwargs
            )
    else:
        ret[path_in] = scan_a_single_file(path_in, path_out, output_extension, function, **kwargs)
    return ret