Skip to content

Depreciated Loading SEG-Y

Warning

These methods have been depreciated in favour of the direct Xarray backend engine interface. Examples in this documentation have been updated to use the backend engine or consult the Backend Engine reference.

segy_loader(segyfile, cdp=None, iline=None, xline=None, cdp_x=None, cdp_y=None, offset=None, vert_domain='TWT', data_type='AMP', ix_crop=None, cdp_crop=None, xy_crop=None, z_crop=None, return_geometry=False, extra_byte_fields=None, head_df=None, **segyio_kwargs)

Load SEG-Y file into xarray.Dataset

The output dataset has the following structure Dimensions: cdp/iline - CDP or Inline axis xline - Xline axis twt/depth - The vertical axis offset - Offset/Angle Axis Coordinates: iline - The inline numbering xline - The xline numbering cdp_x - Eastings cdp_y - Northings cdp - Trace Number for 2d Variables data - The data volume Attributes: ns - number of samples vertical sample_rate - sample rate in ms/m test - text header measurement_system : m/ft source_file : segy source srd : seismic reference datum percentiles : data amplitude percentiles coord_scalar : from trace headers

Parameters:

Name Type Description Default
segyfile str

Input segy file path

required
cdp int

The CDP byte location, usually 21.

None
iline int

Inline byte location, usually 189

None
xline int

Cross-line byte location, usually 193

None
cdp_x int

UTMX byte location, usually 181

None
cdp_y int

UTMY byte location, usually 185

None
offset int

Offset/angle byte location

None
vert_domain str

Vertical sampling domain. One of ['TWT', 'DEPTH']. Defaults to 'TWT'.

'TWT'
data_type str

Data type ['AMP', 'VEL']. Defaults to 'AMP'.

'AMP'
ix_crop list

List of minimum and maximum inline and crossline to output. Has the form '[min_il, max_il, min_xl, max_xl]'. Ignored for 2D data.

None
cdp_crop list

List of minimum and maximum cmp values to output. Has the form '[min_cmp, max_cmp]'. Ignored for 3D data.

None
xy_crop list

List of minimum and maximum cdp_x and cdp_y to output. Has the form '[min_x, max_x, min_y, max_y]'. Ignored for 2D data.

None
z_crop list

List of minimum and maximum vertical samples to output. Has the form '[min, max]'.

None
return_geometry bool

If true returns an xarray.dataset which doesn't contain data but mirrors the input volume header information.

False
extra_byte_fields list / mapping

A list of int or mapping of byte fields that should be returned as variables in the dataset.

None
head_df DataFrame

The DataFrame output from segy_header_scrape. This DataFrame can be filtered by the user to load select trace sets. Trace loading is based upon the DataFrame index.

None
**segyio_kwargs

Extra keyword arguments for segyio.open

{}

Returns:

Type Description

xarray.Dataset: If ncfile keyword is specified returns open handle to disk netcdf4, otherwise the data in memory. If return_geometry is True does not load trace data and returns headers in geometry.

Source code in segysak/segy/_segy_loader.py
Python
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
def segy_loader(
    segyfile,
    cdp=None,
    iline=None,
    xline=None,
    cdp_x=None,
    cdp_y=None,
    offset=None,
    vert_domain="TWT",
    data_type="AMP",
    ix_crop=None,
    cdp_crop=None,
    xy_crop=None,
    z_crop=None,
    return_geometry=False,
    extra_byte_fields=None,
    head_df=None,
    **segyio_kwargs,
):
    """Load SEG-Y file into xarray.Dataset

    The output dataset has the following structure
        Dimensions:
            cdp/iline - CDP or Inline axis
            xline - Xline axis
            twt/depth - The vertical axis
            offset - Offset/Angle Axis
        Coordinates:
            iline - The inline numbering
            xline - The xline numbering
            cdp_x - Eastings
            cdp_y - Northings
            cdp - Trace Number for 2d
        Variables
            data - The data volume
        Attributes:
            ns - number of samples vertical
            sample_rate - sample rate in ms/m
            test - text header
            measurement_system : m/ft
            source_file : segy source
            srd : seismic reference datum
            percentiles : data amplitude percentiles
            coord_scalar : from trace headers

    Args:
        segyfile (str): Input segy file path
        cdp (int, optional): The CDP byte location, usually 21.
        iline (int, optional): Inline byte location, usually 189
        xline (int, optional): Cross-line byte location, usually 193
        cdp_x (int, optional): UTMX byte location, usually 181
        cdp_y (int, optional): UTMY byte location, usually 185
        offset (int, optional): Offset/angle byte location
        vert_domain (str, optional): Vertical sampling domain. One of ['TWT', 'DEPTH']. Defaults to 'TWT'.
        data_type (str, optional): Data type ['AMP', 'VEL']. Defaults to 'AMP'.
        ix_crop (list, optional): List of minimum and maximum inline and crossline to output.
            Has the form '[min_il, max_il, min_xl, max_xl]'. Ignored for 2D data.
        cdp_crop (list, optional): List of minimum and maximum cmp values to output.
            Has the form '[min_cmp, max_cmp]'. Ignored for 3D data.
        xy_crop (list, optional): List of minimum and maximum cdp_x and cdp_y to output.
            Has the form '[min_x, max_x, min_y, max_y]'. Ignored for 2D data.
        z_crop (list, optional): List of minimum and maximum vertical samples to output.
            Has the form '[min, max]'.
        return_geometry (bool, optional): If true returns an xarray.dataset which doesn't contain data but mirrors
            the input volume header information.
        extra_byte_fields (list/mapping): A list of int or mapping of byte fields that should be returned as variables in the dataset.
        head_df (pandas.DataFrame): The DataFrame output from `segy_header_scrape`. This DataFrame can be filtered by the user
            to load select trace sets. Trace loading is based upon the DataFrame index.
        **segyio_kwargs: Extra keyword arguments for segyio.open

    Returns:
        xarray.Dataset: If ncfile keyword is specified returns open handle to disk netcdf4,
            otherwise the data in memory. If return_geometry is True does not load trace data and
            returns headers in geometry.
    """
    warn(
        "segy_loader will be removed in v0.6, please use the Xarray engine ds = xr.open_dataset(segy_file) method instead.",
        DeprecationWarning,
        stacklevel=2,
    )

    extra_byte_fields = _loader_converter_checks(cdp, iline, xline, extra_byte_fields)

    head_df, head_bin, head_loc = _loader_converter_header_handling(
        segyfile,
        cdp=cdp,
        iline=iline,
        xline=xline,
        cdp_x=cdp_x,
        cdp_y=cdp_y,
        offset=offset,
        vert_domain=vert_domain,
        data_type=data_type,
        ix_crop=ix_crop,
        cdp_crop=cdp_crop,
        xy_crop=xy_crop,
        z_crop=z_crop,
        return_geometry=return_geometry,
        silent=Progress.silent(),
        extra_byte_fields=extra_byte_fields,
        head_df=head_df,
        **segyio_kwargs,
    )

    byte_loc = [
        bytel
        for bytel in [cdp, iline, xline, cdp_x, cdp_y, offset]
        if bytel is not None
    ]
    check_tracefield(byte_loc)

    common_args = (segyfile, head_df, head_bin, head_loc)

    common_kwargs = dict(
        zcrop=z_crop,
        vert_domain=vert_domain,
        data_type=data_type,
        return_geometry=return_geometry,
        silent=Progress.silent(),
    )

    # 3d data needs iline and xline
    if all(v is not None for v in (head_loc.iline, head_loc.xline)):
        print("Loading as 3D")
        ds = _3dsegy_loader(
            *common_args,
            **common_kwargs,
            **segyio_kwargs,
        )
        indexer = ["il_index", "xl_index"]
        dims = (
            DimensionKeyField.threed_head
            if offset is None
            else DimensionKeyField.threed_ps_head
        )
        is3d2d = True

    # 2d data
    elif head_loc.cdp is not None:
        print("Loading as 2D")
        ds = _2dsegy_loader(*common_args, **common_kwargs, **segyio_kwargs)
        indexer = ["cdp_index"]
        dims = (
            DimensionKeyField.twod_head
            if offset is None
            else DimensionKeyField.twod_ps_head
        )
        is3d2d = True

    # fallbak to just a 2d array of traces
    else:
        ds = _2dsegy_loader(*common_args, **common_kwargs, **segyio_kwargs)
        indexer = []
        dims = DimensionKeyField.cdp_2d
        is3d2d = False

    indexer = indexer + ["off_index"] if offset is not None else indexer

    ds = _loader_converter_write_headers(
        ds, head_df, indexer, dims, extra_byte_fields, is3d2d=is3d2d
    )

    # ds.seis.get_corner_points()
    return ds

segy_freeloader(segyfile, vert_domain='TWT', data_type='AMP', return_geometry=False, extra_byte_fields=None, head_df=None, segyio_kwargs=None, **dim_kwargs)

Freeform loader for SEG-Y data. This loader allows you to load SEG-Y into an xarray.Dataset using an arbitrary number of header locations to create othogonal dimensions. This is an eager loader and will transfer the entire SEG-Y and requested header information to memory.

From the dimension header locations specified the freeloader will try to create a Dataset where each trace is assigned to a dimension.

Parameters:

Name Type Description Default
segyfile string

The SEG-Y file/path.

required
vert_domain str

One of ('TWT', 'DEPTH'). Defaults to 'TWT'.

'TWT'
data_type str

Defaults to "AMP".

'AMP'
return_geometry bool

If true, just returned the empty dataset based upon the calcuated header geometry. Defaults to False.

False
extra_byte_fields dict

Additional header information to load into the Dataset. Defaults to None.

None
head_df DataFrame

The DataFrame output from segy_header_scrape. This DataFrame can be filtered by the user to load select trace sets. Trace loading is based upon the DataFrame index.

None
segyio_kwargs dict

Extra keyword arguments for segyio.open

None
**dim_kwargs

Dimension names and byte location pairs.

{}
Source code in segysak/segy/_segy_loader.py
Python
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
def segy_freeloader(
    segyfile,
    vert_domain="TWT",
    data_type="AMP",
    return_geometry=False,
    extra_byte_fields=None,
    head_df=None,
    segyio_kwargs=None,
    **dim_kwargs,
):
    """Freeform loader for SEG-Y data. This loader allows you to load SEG-Y into
    an xarray.Dataset using an arbitrary number of header locations to create
    othogonal dimensions. This is an eager loader and will transfer the entire
    SEG-Y and requested header information to memory.

    From the dimension header locations specified the freeloader will try to
    create a Dataset where each trace is assigned to a dimension.

    Args:
        segyfile (string): The SEG-Y file/path.
        vert_domain (str, optional): One of ('TWT', 'DEPTH'). Defaults to 'TWT'.
        data_type (str, optional): Defaults to "AMP".
        return_geometry (bool, optional): If true, just returned the empty
            dataset based upon the calcuated header geometry. Defaults to False.
        extra_byte_fields (dict, optional): Additional header information to
            load into the Dataset. Defaults to None.
        head_df (pandas.DataFrame): The DataFrame output from `segy_header_scrape`.
            This DataFrame can be filtered by the user
            to load select trace sets. Trace loading is based upon the DataFrame index.
        segyio_kwargs (dict, optional): Extra keyword arguments for segyio.open
        **dim_kwargs: Dimension names and byte location pairs.
    """
    warn(
        "segy_loader will be removed in v0.6, please use the Xarray engine ds = xr.open_dataset(segy_file) method instead.",
        DeprecationWarning,
        stacklevel=2,
    )
    if segyio_kwargs is None:
        segyio_kwargs = dict()

    if head_df is None:
        # Start by scraping the headers.
        head_df = segy_header_scrape(segyfile, **segyio_kwargs)

    head_bin = segy_bin_scrape(segyfile, **segyio_kwargs)

    # get vertical sample ranges
    n0 = 0
    nsamp = head_bin["Samples"]
    ns0 = head_df.DelayRecordingTime.min()

    # binary header translation
    nsamp = head_bin["Samples"]
    sample_rate = head_bin["Interval"] / 1000.0
    msys = _SEGY_MEASUREMENT_SYSTEM[head_bin["MeasurementSystem"]]
    vert_samples = np.arange(ns0, ns0 + sample_rate * nsamp, sample_rate, dtype=int)

    # creating dimensions and new dataset
    dims = dict()
    dim_index_names = list()
    dim_fields = list()
    for dim in dim_kwargs:
        trace_field = str(segyio.TraceField(dim_kwargs[dim]))
        if trace_field == "Unknown Enum":
            raise ValueError(f"{dim}:{dim_kwargs[dim]} was not a valid byte header")
        dim_fields.append(trace_field)
        as_unique = head_df[trace_field].unique()
        dims[dim] = np.sort(as_unique)
        d_map = {dval: i for i, dval in enumerate(as_unique)}
        index_name = f"{dim}_index"
        dim_index_names.append(index_name)
        head_df.loc[:, index_name] = head_df[trace_field].map(d_map)

    if (
        head_df[dim_index_names].shape
        != head_df[dim_index_names].drop_duplicates().shape
    ):
        raise ValueError(
            "The selected dimensions results in multiple traces per "
            "dimension location, add additional dimensions or use "
            "trace numbering to load as 2D."
        )

    builder, domain = _dataset_coordinate_helper(vert_samples, vert_domain, **dims)
    ds = create_seismic_dataset(**builder)

    # getting attributes
    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

    # map extra byte fields into ds
    if extra_byte_fields is not None:
        to_add = list()
        for name, byte in extra_byte_fields.items():
            trace_field = str(segyio.TraceField(byte))
            if trace_field == "Unknown Enum":
                raise ValueError(f"{name}:{byte} was not a valid byte header")
            to_add.append(trace_field)
        to_add = to_add + dim_fields
        extras = head_df[to_add].set_index(dim_fields).to_xarray()
        extras = extras.rename_dims(
            {b: a for a, b in zip(dim_kwargs, dim_fields) if a != b}
        )
        for name, xtr in zip(extra_byte_fields, to_add):
            ds[name] = extras[xtr]

    if return_geometry:
        # return geometry -> e.g. don't process segy traces
        return ds

    segyio_kwargs.update(dict(ignore_geometry=True))

    with segyio.open(segyfile, "r", **segyio_kwargs) as segyf:

        segyf.mmap()
        shape = [ds.sizes[d] for d in dim_kwargs] + [vert_samples.size]
        volume = np.zeros(shape, dtype=np.float32)

        # this can probably be done as a block - leaving for now just incase sorting becomes an issue
        indexes = tuple([head_df[idx].values for idx in dim_index_names])
        volume[indexes] = segyf.trace.raw[:][head_df.index.values]

    percentiles = np.percentile(volume, PERCENTILES)
    ds[VariableKeyField.data] = (
        list(dim_kwargs) + [VerticalKeyDim[domain]],
        volume,
    )
    ds.attrs[AttrKeyField.percentiles] = list(percentiles)

    return ds

segy_converter(segyfile, ncfile, cdp=None, iline=None, xline=None, cdp_x=None, cdp_y=None, offset=None, vert_domain='TWT', data_type='AMP', ix_crop=None, cdp_crop=None, xy_crop=None, z_crop=None, return_geometry=False, extra_byte_fields=None, **segyio_kwargs)

Convert SEG-Y data to NetCDF4 File

The output ncfile has the following structure Dimensions: cdp/iline - CDP or Inline axis xline - Xline axis twt/depth - The vertical axis offset - Offset/Angle Axis Coordinates: iline - The inline numbering xline - The xline numbering cdp_x - Eastings cdp_y - Northings cdp - Trace Number for 2d Variables data - The data volume Attributes: ns - number of samples vertical sample_rate - sample rate in ms/m test - text header measurement_system : m/ft source_file : segy source srd : seismic reference datum percentiles : data amplitude percentiles coord_scalar : from trace headers

Parameters:

Name Type Description Default
segyfile str

Input segy file path

required
ncfile str

Output SEISNC file path. If none the loaded data will be returned in memory as an xarray.Dataset.

required
cdp int

The CDP byte location, usually 21.

None
iline int

Inline byte location, usually 189

None
xline int

Cross-line byte location, usually 193

None
cdp_x int

UTMX byte location, usually 181

None
cdp_y int

UTMY byte location, usually 185

None
offset int

Offset/angle byte location

None
vert_domain str

Vertical sampling domain. One of ['TWT', 'DEPTH']. Defaults to 'TWT'.

'TWT'
data_type str

Data type ['AMP', 'VEL']. Defaults to 'AMP'.

'AMP'
ix_crop list

List of minimum and maximum inline and crossline to output. Has the form '[min_il, max_il, min_xl, max_xl]'. Ignored for 2D data.

None
cdp_crop list

List of minimum and maximum cmp values to output. Has the form '[min_cmp, max_cmp]'. Ignored for 3D data.

None
xy_crop list

List of minimum and maximum cdp_x and cdp_y to output. Has the form '[min_x, max_x, min_y, max_y]'. Ignored for 2D data.

None
z_crop list

List of minimum and maximum vertical samples to output. Has the form '[min, max]'.

None
return_geometry bool

If true returns an xarray.dataset which doesn't contain data but mirrors the input volume header information.

False
silent bool

Disable progress bar.

required
extra_byte_fields list / mapping

A list of int or mapping of byte fields that should be returned as variables in the dataset.a

None
**segyio_kwargs

Extra keyword arguments for segyio.open

{}
Source code in segysak/segy/_segy_loader.py
Python
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
def segy_converter(
    segyfile,
    ncfile,
    cdp=None,
    iline=None,
    xline=None,
    cdp_x=None,
    cdp_y=None,
    offset=None,
    vert_domain="TWT",
    data_type="AMP",
    ix_crop=None,
    cdp_crop=None,
    xy_crop=None,
    z_crop=None,
    return_geometry=False,
    extra_byte_fields=None,
    **segyio_kwargs,
):
    """Convert SEG-Y data to NetCDF4 File

    The output ncfile has the following structure
        Dimensions:
            cdp/iline - CDP or Inline axis
            xline - Xline axis
            twt/depth - The vertical axis
            offset - Offset/Angle Axis
        Coordinates:
            iline - The inline numbering
            xline - The xline numbering
            cdp_x - Eastings
            cdp_y - Northings
            cdp - Trace Number for 2d
        Variables
            data - The data volume
        Attributes:
            ns - number of samples vertical
            sample_rate - sample rate in ms/m
            test - text header
            measurement_system : m/ft
            source_file : segy source
            srd : seismic reference datum
            percentiles : data amplitude percentiles
            coord_scalar : from trace headers

    Args:
        segyfile (str): Input segy file path
        ncfile (str): Output SEISNC file path. If none the loaded data will be
            returned in memory as an xarray.Dataset.
        cdp (int, optional): The CDP byte location, usually 21.
        iline (int, optional): Inline byte location, usually 189
        xline (int, optional): Cross-line byte location, usually 193
        cdp_x (int, optional): UTMX byte location, usually 181
        cdp_y (int, optional): UTMY byte location, usually 185
        offset (int, optional): Offset/angle byte location
        vert_domain (str, optional): Vertical sampling domain. One of ['TWT', 'DEPTH']. Defaults to 'TWT'.
        data_type (str, optional): Data type ['AMP', 'VEL']. Defaults to 'AMP'.
        ix_crop (list, optional): List of minimum and maximum inline and crossline to output.
            Has the form '[min_il, max_il, min_xl, max_xl]'. Ignored for 2D data.
        cdp_crop (list, optional): List of minimum and maximum cmp values to output.
            Has the form '[min_cmp, max_cmp]'. Ignored for 3D data.
        xy_crop (list, optional): List of minimum and maximum cdp_x and cdp_y to output.
            Has the form '[min_x, max_x, min_y, max_y]'. Ignored for 2D data.
        z_crop (list, optional): List of minimum and maximum vertical samples to output.
            Has the form '[min, max]'.
        return_geometry (bool, optional): If true returns an xarray.dataset which doesn't contain data but mirrors
            the input volume header information.
        silent (bool): Disable progress bar.
        extra_byte_fields (list/mapping): A list of int or mapping of byte fields that should be returned as variables in the dataset.a
        **segyio_kwargs: Extra keyword arguments for segyio.open

    """
    warn(
        "segy_converter will be removed in v0.6, please use Xarray engine ds = xr.open_dataset(file) and then accessor ds.seisio.to_segy method instead.",
        DeprecationWarning,
        stacklevel=2,
    )
    # Input sanity checks
    extra_byte_fields = _loader_converter_checks(cdp, iline, xline, extra_byte_fields)
    byte_loc = [
        bytel
        for bytel in [cdp, iline, xline, cdp_x, cdp_y, offset]
        if bytel is not None
    ]
    check_tracefield(byte_loc)

    head_df, head_bin, head_loc = _loader_converter_header_handling(
        segyfile,
        cdp=cdp,
        iline=iline,
        xline=xline,
        cdp_x=cdp_x,
        cdp_y=cdp_y,
        offset=offset,
        vert_domain=vert_domain,
        data_type=data_type,
        ix_crop=ix_crop,
        cdp_crop=cdp_crop,
        xy_crop=xy_crop,
        z_crop=z_crop,
        return_geometry=return_geometry,
        silent=Progress.silent(),
        extra_byte_fields=extra_byte_fields,
        optimised_load=True,
        **segyio_kwargs,
    )
    print("header_loaded")
    common_args = (segyfile, head_df, head_bin, head_loc)

    common_kwargs = dict(
        zcrop=z_crop,
        ncfile=ncfile,
        vert_domain=vert_domain,
        data_type=data_type,
        return_geometry=return_geometry,
        silent=Progress.silent(),
    )

    # 3d data needs iline and xline
    if iline is not None and xline is not None:

        print("is_3d")
        ds = _3dsegy_loader(
            *common_args,
            **common_kwargs,
            **segyio_kwargs,
        )
        indexer = ["il_index", "xl_index"]
        dims = (
            DimensionKeyField.threed_head
            if offset is None
            else DimensionKeyField.threed_ps_head
        )
        is3d2d = True

    # 2d data
    elif cdp is not None:
        ds = _2dsegy_loader(*common_args, **common_kwargs, **segyio_kwargs)
        indexer = ["cdp_index"]
        dims = (
            DimensionKeyField.twod_head
            if offset is None
            else DimensionKeyField.twod_ps_head
        )
        is3d2d = True

    # fallbak to just a 2d array of traces
    else:
        ds = _2dsegy_loader(*common_args, **common_kwargs, **segyio_kwargs)
        indexer = []
        dims = DimensionKeyField.cdp_2d
        is3d2d = False

    indexer = indexer + ["off_index"] if offset is not None else indexer

    ds = _loader_converter_write_headers(
        ds, head_df, indexer, dims, extra_byte_fields, is3d2d=is3d2d
    )
    new_vars = {key: ds[key] for key in extra_byte_fields}
    ds.close()
    del ds

    with h5netcdf.File(ncfile, "a") as seisnc:
        for var, darray in new_vars.items():
            seisnc_var = seisnc.create_variable(
                var, dimensions=darray.dims, dtype=darray.dtype
            )
            seisnc_var[...] = darray[...]
            seisnc.flush()

    return None

well_known_byte_locs(name)

Return common bytes position kwargs_dict for segy_loader and segy_converter.

Returns a dict containing the byte locations for well known SEG-Y variants in the wild.

Parameters:

Name Type Description Default
name str

Takes one of keys from KNOWN_BYTES

required

Returns:

Name Type Description
dict

A dictionary of SEG-Y byte positions.

Example:

Use the output of this function to unpack arguments into segy_loader

seismic = segy_loader(filepath, **well_known_byte_locs('petrel_3d'))

Source code in segysak/segy/_segy_loader.py
Python
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
def well_known_byte_locs(name):
    """Return common bytes position kwargs_dict for segy_loader and segy_converter.

    Returns a dict containing the byte locations for well known SEG-Y variants in the wild.

    Args:
        name (str): Takes one of keys from KNOWN_BYTES

    Returns:
        dict: A dictionary of SEG-Y byte positions.

    Example:

    Use the output of this function to unpack arguments into ``segy_loader``

    >>> seismic = segy_loader(filepath, **well_known_byte_locs('petrel_3d'))

    """
    try:
        return KNOWN_BYTES[name]
    except KeyError:
        raise ValueError(
            f"No byte locatons for {name}, select from {list(KNOWN_BYTES.keys())}"
        )