Example #1
0
def test_upgrade_txt_richstr(segyio_all_test_files):
    file, segyio_kwargs = segyio_all_test_files
    text = get_segy_texthead(file, no_richstr=True, **segyio_kwargs)
    text = _upgrade_txt_richstr(text)
    assert isinstance(text, str)
    assert hasattr(text, "_repr_html_")
    assert hasattr(text, "_repr_pretty_")
Example #2
0
def scrape(filename, ebcidc=False, trace_headers=False):
    """Scrape the file meta information and output it to text file.

    If no options are specified both will be output. The output file will be
    <filename>.txt for the EBCIDC and <filename>.csv for
    trace headers.

    The trace headers can be read back into Python using
    pandas.read_csv(<filename>.csv, index_col=0)
    """
    for file in tqdm(filename, desc="File"):
        file = pathlib.Path(file)
        ebcidc_name = file.with_suffix(".txt")
        header_name = file.with_suffix(".csv")

        if ebcidc == False and trace_headers == False:
            ebcidc = True
            trace_headers = True

        if ebcidc:
            txt = get_segy_texthead(file)
            with open(ebcidc_name, "w") as txtfile:
                txtfile.writelines(txt)

        if trace_headers:
            head_df = segy_header_scrape(file)
            head_df.to_csv(header_name)
Example #3
0
def _action_ebcidc_out(arg, input_file):
    try:
        ebcidc = get_segy_texthead(input_file)
    except IOError:
        LOGGER.error("Input SEGY file was not found - check name and path")
        raise SystemExit

    if arg is None:
        print(ebcidc)
    else:
        ebcidc = fix_bad_chars(ebcidc)
        with open(arg, 'w') as f:
            f.write(ebcidc)
Example #4
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}")
Example #5
0
def test_get_segy_texthead(temp_dir, temp_segy):
    ebcidc = get_segy_texthead(temp_segy)
    assert isinstance(ebcidc, str)
    assert len(ebcidc) < 3200
    assert ebcidc[:3] == "C01"
Example #6
0
# %%
V3D_path = pathlib.Path("data/volve10r12-full-twt-sub3d.sgy")
print("3D", V3D_path, V3D_path.exists())

# %% [markdown]
# ## Scan SEGY headers
#

# %% [markdown]
# A basic operation would be to check the text header included in the SEG-Y file. The *get_segy_texthead*
# function accounts for commong encoding issues and returns the header as a text string.

# %%
from segysak.segy import get_segy_texthead

get_segy_texthead(V3D_path)

# %% [markdown]
# If you need to investigate the trace header data more deeply, then *segy_header_scan* can be used to report
# basic statistic of each byte position for a limited number of traces.
#
# *segy_header_scan* returns a `pandas.DataFrame`. To see the full DataFrame use the `pandas` option_context manager.

# %%
from segysak.segy import segy_header_scan

scan = segy_header_scan(V3D_path)
scan

# %% [markdown]
# The header report can also be reduced by filtering blank byte locations. Here we use the standard deviation `std`
Example #7
0
def ebcidc(filename):
    input_file = pathlib.Path(filename)
    click.echo(get_segy_texthead(input_file))