def test_segyiotests_writer_from_seisnc(temp_dir, segyio3d_test_files): file, segyio_kwargs = segyio3d_test_files seisnc = temp_dir / file.with_suffix(".siesnc").name segy_converter(str(file), ncfile=seisnc, silent=True, **segyio_kwargs) outfile = temp_dir / file.name segy_writer(seisnc, outfile) ds = segy_loader(str(outfile), silent=True, **well_known_byte_locs("standard_3d")) assert isinstance(ds, xr.Dataset)
def test_segyiotests_writer_from_ds(temp_dir, segyio3d_test_files, il_chunks): file, segyio_kwargs = segyio3d_test_files ds = segy_loader(str(file), silent=True, **segyio_kwargs) outfile = temp_dir / file.name segy_writer(ds, outfile, il_chunks=il_chunks) del ds ds = segy_loader(str(outfile), silent=True, **well_known_byte_locs("standard_3d")) assert isinstance(ds, xr.Dataset)
def test_seisnc_return(temp_dir, empty): dims = list(empty.dims) shp = [empty.dims[d] for d in dims] domain = empty.d3_domain empty["data"] = (dims, np.zeros(shp)) if "offset" in empty: empty["offset"] = empty["offset"].astype(np.int32) segy_writer(empty, temp_dir / "temp_empty.segy") back = segy_loader(temp_dir / "temp_empty.segy", vert_domain=domain) assert empty == back
def convert(output_file, input_file, iline, xline, cdpx, cdpy, 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, cdpx=cdpx, cdpy=cdpy, ) 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" segy_writer(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
fixture_ref(empty3d_twt), ), ids=["2d", "2dgath", "3d", "3d_depth", "3d_gath", "3d_twt"], ) def test_seisnc_return(temp_dir, empty): dims = list(empty.dims) shp = [empty.dims[d] for d in dims] domain = empty.d3_domain empty["data"] = (dims, np.zeros(shp)) if "offset" in empty: empty["offset"] = empty["offset"].astype(np.int32) segy_writer(empty, temp_dir / "temp_empty.segy") back = segy_loader(temp_dir / "temp_empty.segy", vert_domain=domain) assert empty == back if __name__ == "__main__": iln, xln, n, off, dom = (10, 11, 12, 5, "TWT") seisnc = create3d_dataset( (iln, xln, n, off), sample_rate=1, first_iline=1, first_xline=1, vert_domain=dom, first_offset=2, offset_step=2, ) segy_writer(seisnc, "temp.segy")
fig, ax1 = plt.subplots(ncols=1, figsize=(15, 8)) iline_sel = 10093 V3D.data.transpose("twt", "iline", "xline", transpose_coords=True).sel( iline=iline_sel ).plot(yincrease=False, cmap="seismic_r") plt.grid("grey") plt.ylabel("TWT") plt.xlabel("XLINE") # %% [markdown] # ## Saving data to NetCDF4 # # SEGYSAK offers a convience utility to make saving to NetCDF4 simple. This is accesssed through the `seisio` accessor on the loaded # SEG-Y or SEISNC volume. The `to_netcdf` method accepts the same arguments as the `xarray` version. # %% V3D.seisio.to_netcdf("V3D.SEISNC") # %% [markdown] # ## Saving data to SEG-Y # # To return data to SEG-Y after modification use the `segy_writer` function. `segy_writer` takes as argument a SEISNC dataset which # requires certain attributes be set. You can also specify the byte locations to write header information. # %% from segysak.segy import segy_writer segy_writer( V3D, "V3D.segy", trace_header_map=dict(iline=5, xline=21) ) # Petrel Locations