def test_illegal_domain_raise_errors(self, t): assume(t not in list(VerticalKeyField.values())) with pytest.raises(ValueError): _dataset_coordinate_helper(None, t)
def _2dsegy_loader( segyfile, head_df, head_bin, head_loc, ncfile=None, vert_domain="TWT", data_type="AMP", crop=None, zcrop=None, silent=False, return_geometry=False, **segyio_kwargs, ): """Convert SEGY data to Xarray or Netcdf4 This is a helper function for segy_loader. Users should use that function directly to load all segy data. """ # get names of columns where stuff we want is if head_loc.cdp is None: cdp = 21 head_loc.cdp = _get_tf(cdp) head_df[head_loc.cdp] = head_df.index.values # get vertical sample ranges n0 = 0 nsamp = head_bin["Samples"] ns0 = head_df.DelayRecordingTime.min() # short way to get cdps cdps = head_df[head_loc.cdp].unique() cdps = np.sort(cdps) head_df["cdp_index"] = _header_to_index_mapping(head_df[head_loc.cdp]) # binary header translation nsamp = head_bin["Samples"] sample_rate = head_bin["Interval"] / 1000.0 msys = _SEGY_MEASUREMENT_SYSTEM[head_bin["MeasurementSystem"]] # for offset if head_loc.offset is not None: offsets = head_df[head_loc.offset].unique() offsets = np.sort(offsets) head_df["off_index"] = _header_to_index_mapping( head_df[head_loc.offset]) else: offsets = None if zcrop is not None: zcrop = check_zcrop(zcrop, [0, nsamp]) n0, nsamp = zcrop ns0 = sample_rate * n0 nsamp = nsamp - n0 + 1 vert_samples = np.arange(ns0, ns0 + sample_rate * nsamp, sample_rate, dtype=int) builder, domain = _dataset_coordinate_helper(vert_samples, vert_domain, cdp=cdps, offset=offsets) ds = create_seismic_dataset(**builder) # create_seismic_dataset(d1=ni, d2=nx, d3=nsamp) text = get_segy_texthead(segyfile, **segyio_kwargs) ds.attrs[AttrKeyField.text] = text ds.attrs[AttrKeyField.source_file] = pathlib.Path(segyfile).name ds.attrs[AttrKeyField.measurement_system] = msys ds.attrs[AttrKeyField.sample_rate] = sample_rate if ncfile is not None and return_geometry == True: ds.seisio.to_netcdf(ncfile) return ds elif return_geometry: return ds segyio_kwargs.update(dict(ignore_geometry=True)) # stacked data if head_loc.offset is None: ds = _segy2d_xr( segyfile, ds, segyio_kwargs, n0, nsamp, head_df, head_loc, vert_domain=vert_domain, silent=silent, ) # # prestack data if head_loc.offset is not None: ds = _segy2d_ps_xr( segyfile, ds, segyio_kwargs, n0, nsamp, head_df, head_loc, vert_domain=vert_domain, silent=silent, ) if ncfile is not None: ds.seisio.to_netcdf(ncfile) del ds ds = ncfile return ds
def test_domains_pass_checking(self, p): _, domain = _dataset_coordinate_helper(None, p) assert p == domain
def _3dsegy_loader( segyfile, head_df, head_bin, head_loc, ncfile=None, vert_domain="TWT", data_type="AMP", crop=None, zcrop=None, silent=False, return_geometry=False, **segyio_kwargs, ): """Convert SEGY data to Xarray or Netcdf4 This is a helper function for segy_loader. Users should use that function directly to load all segy data. """ # get vertical sample ranges n0 = 0 nsamp = head_bin["Samples"] ns0 = head_df.DelayRecordingTime.min() # short way to get inlines/xlines ilines = head_df[head_loc.iline].unique() xlines = head_df[head_loc.xline].unique() inlines = np.sort(ilines) xlines = np.sort(xlines) iline_index_map = {il: i for i, il in enumerate(ilines)} xline_index_map = {xl: i for i, xl in enumerate(xlines)} head_df.loc[:, "il_index"] = head_df[head_loc.iline].replace(iline_index_map) head_df.loc[:, "xl_index"] = head_df[head_loc.xline].replace(xline_index_map) # binary header translation ns = head_bin["Samples"] sample_rate = head_bin["Interval"] / 1000.0 msys = _SEGY_MEASUREMENT_SYSTEM[head_bin["MeasurementSystem"]] # for offset if head_loc.offset is not None: offsets = head_df[head_loc.offset].unique() offsets = np.sort(offsets) offset_index_map = {off: i for i, off in enumerate(offsets)} head_df["off_index"] = head_df[head_loc.offset].replace( offset_index_map) else: offsets = None if zcrop is not None: zcrop = check_zcrop(zcrop, [0, ns]) n0, ns = zcrop ns0 = sample_rate * n0 nsamp = ns - n0 + 1 vert_samples = np.arange(ns0, ns0 + sample_rate * nsamp, sample_rate, dtype=int) builder, domain = _dataset_coordinate_helper(vert_samples, vert_domain, iline=ilines, xline=xlines, offset=offsets) ds = create_seismic_dataset(**builder) # create_seismic_dataset(d1=ni, d2=nx, d3=nsamp) text = get_segy_texthead(segyfile, **segyio_kwargs) ds.attrs[AttrKeyField.text] = text ds.attrs[AttrKeyField.source_file] = pathlib.Path(segyfile).name ds.attrs[AttrKeyField.measurement_system] = msys ds.attrs[AttrKeyField.sample_rate] = sample_rate if ncfile is not None and return_geometry == False: ds.seisio.to_netcdf(ncfile) elif return_geometry: # return geometry -> e.g. don't process segy traces return ds else: ncfile = ds segyio_kwargs.update( dict(ignore_geometry=True, iline=head_loc.iline, xline=head_loc.xline)) # not prestack data if head_loc.offset is None and not isinstance(ncfile, xr.Dataset): ds = _segy3d_ncdf( segyfile, ncfile, segyio_kwargs, n0, ns, head_df, head_loc, vert_domain=vert_domain, silent=silent, ) # not prestack data load into memory if head_loc.offset is None and isinstance(ncfile, xr.Dataset): ds = _segy3d_xr( segyfile, ncfile, segyio_kwargs, n0, ns, head_df, head_loc, vert_domain=vert_domain, silent=silent, ) # prestack data if head_loc.offset is not None and not isinstance(ncfile, xr.Dataset): ds = _segy3dps_ncdf( segyfile, ncfile, segyio_kwargs, n0, ns, head_df, head_loc, vert_domain=vert_domain, silent=silent, ) # prestack data load into memory if head_loc.offset is not None and isinstance(ncfile, xr.Dataset): ds = _segy3dps_xr( segyfile, ncfile, segyio_kwargs, n0, ns, head_df, head_loc, vert_domain=vert_domain, silent=silent, ) return ds