Example #1
0
def convert(output_file, input_file, iline, xline, crop, output_type,
            dimension):
    input_file = pathlib.Path(input_file)
    if output_type is None and output_file is not None:
        output_type = guess_file_type(output_file)
    elif output_type is None and output_file is None:
        """Because currently only one conversion exists we can guess the output from the input"""
        input_type = guess_file_type(input_file)
        if input_type:
            output_type = "SEGY" if input_type == "NETCDF" else "NETCDF"

    if output_type is None:
        click.echo(
            "Output type not recognised! Please provide the desired output file type explicitly using the --output-type option"
        )
        raise SystemExit

    click.echo(f"Converting file {input_file.name} to {output_type}")

    if len(crop) == 0:
        crop = None

    if output_type == "NETCDF":
        if output_file is None:
            output_file = input_file.stem + ".SEISNC"
        segy_converter(input_file,
                       ncfile=output_file,
                       iline=iline,
                       xline=xline,
                       ix_crop=crop)
        click.echo(f"Converted file saved as {output_file}")
        LOGGER.info(f"NetCDF output written to {output_file}")
    elif output_type == "SEGY":
        if output_file is None:
            output_file = input_file.stem + ".segy"
        ncdf2segy(input_file,
                  output_file,
                  iline=iline,
                  xline=xline,
                  dimension=dimension)
        click.echo(f"Converted file saved as {output_file}")
        LOGGER.info(f"SEGY output written to {output_file}")
    else:
        click.echo(
            f"Conversion to output-type {output_type} is not implemented yet")
        raise SystemExit
Example #2
0
def main():

    # how to track down warnings
    #import warnings
    #warnings.filterwarnings('error', category=UnicodeWarning)
    #warnings.filterwarnings('error', category=DeprecationWarning, module='numpy')

    #parse args
    sys_parser = segysakArgsParser()
    args = sys_parser.parse_args()

    # gaffe
    print(f'SEGY-SAK - v{version}')

    # initialise logging
    LOGGER.info(f'segysak v{version}')

    # check inputs
    checked_files = check_file(args.files)

    # Generate or Load Configuration File

    for input_file in checked_files:
        print(input_file.name)
        # Print EBCIDC header
        if args.ebcidc:
            try:
                print(get_segy_texthead(input_file))
            except IOError:
                LOGGER.error(
                    "Input SEGY file was not found - check name and path")

        if args.scan > 0:
            hscan, nscan = segy_header_scan(input_file,
                                            max_traces_scan=args.scan)
            width = 10
            print(f'Traces scanned: {nscan}')
            print("{:>40s} {:>8s} {:>10s} {:>10s}".format(
                'Item', 'Byte Loc', 'Min', 'Max'))
            for key, item in hscan.items():
                print("{:>40s} {:>8d} {:>10.0f} {:>10.0f}".format(
                    key, item[0], item[1], item[2]))

        iline = args.iline
        xline = args.xline

        if args.netCDF is None or args.netCDF is not False:
            if args.netCDF is None:
                outfile = input_file.stem + '.SEISNC'
            else:
                outfile = args.netCDF
            _ = segy_loader(input_file,
                            ncfile=outfile,
                            iline=iline,
                            xline=xline,
                            ix_crop=args.crop)
            LOGGER.info(f"NetCDF output written to {outfile}")

        if args.SEGY is None or args.SEGY is not False:
            if args.SEGY is None:
                outfile = input_file.stem + '.segy'
            else:
                outfile = args.SEGY
            ncdf2segy(input_file, outfile, iline=iline,
                      xline=xline)  #, crop=args.crop)
            LOGGER.info(f"SEGY output written to {outfile}")