equinor / segyio

Fast Python library for SEGY files.
Other
476 stars 214 forks source link

RuntimeError: unable to find sorting #433

Closed nitishkannan23 closed 4 years ago

nitishkannan23 commented 4 years ago

I created a Segy file after some process and wrote the file using following code:

spec = segyio.spec()
file = 'segy_file1.segy'
spec.sorting = 2
spec.format = 1
spec.xline = 193
spec.iline = 189
spec.offsets = [0]
spec.samples = np.unique(final_values[:,2])
spec.ilines = np.unique(final_values[:,0])
spec.xlines = np.unique(final_values[:,1])
with segyio.create(file, spec) as f:
    ix = len_ilines*len_xlines
    f.trace[:ix] = final_clusters[:ix]
    hdx = 0
    for ilno in spec.ilines:
        for xlno in spec.xlines:
            f.header[hdx] = {segyio.TraceField.INLINE_3D: int(ilno),
                             segyio.TraceField.CROSSLINE_3D: int(xlno),
                             segyio.TraceField.offset: int(xlno)}
            hdx = hdx+1

When I read the file:

c = segyio.open(file, 'r+')

RuntimeError                              Traceback (most recent call last)
<ipython-input-7-1b7e0bebc5a4> in <module>
----> 1 c = segyio.open(file, 'r+')

D:\Anaconda3\envs\keras-gpu\lib\site-packages\segyio\open.py in open(filename, mode, iline, xline, strict, ignore_geometry, endian)
    185         return f
    186 
--> 187     return infer_geometry(f, metrics, iline, xline, strict)

D:\Anaconda3\envs\keras-gpu\lib\site-packages\segyio\open.py in infer_geometry(f, metrics, iline, xline, strict)
      5 def infer_geometry(f, metrics, iline, xline, strict):
      6     try:
----> 7         cube_metrics = f.xfd.cube_metrics(iline, xline)
      8         f._sorting   = cube_metrics['sorting']
      9         iline_count  = cube_metrics['iline_count']

RuntimeError: unable to find sorting.

or When i use this:

c = segyio.open(file, 'r+', iline=189, xline=193)

RuntimeError                              Traceback (most recent call last)
<ipython-input-8-3def40615fed> in <module>
----> 1 c = segyio.open(file, 'r+', iline=189, xline=193)

D:\Anaconda3\envs\keras-gpu\lib\site-packages\segyio\open.py in open(filename, mode, iline, xline, strict, ignore_geometry, endian)
    185         return f
    186 
--> 187     return infer_geometry(f, metrics, iline, xline, strict)

D:\Anaconda3\envs\keras-gpu\lib\site-packages\segyio\open.py in infer_geometry(f, metrics, iline, xline, strict)
      5 def infer_geometry(f, metrics, iline, xline, strict):
      6     try:
----> 7         cube_metrics = f.xfd.cube_metrics(iline, xline)
      8         f._sorting   = cube_metrics['sorting']
      9         iline_count  = cube_metrics['iline_count']

RuntimeError: unable to find sorting.

But when I use ignore_geometry=True, it is working:

c = segyio.open(file, 'r+', ignore_geometry=True)

But c.ilines, c.xlines does not display anything. c.iline, c.xline displays

ValueError: File opened in unstructured mode.

c.samples has resetted the values from 0 to 400. However c.header[i][189,193] and c.trace[i][:] are working fine.

Please note the ilines, xlines and samples of the file:

spec.ilines

array([ 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.,  1199.,  1200.,  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.])

spec.xlines

array([ 1020.,  1021.,  1022.,  1023.,  1024.,  1025.,  1026.,  1027.,
        1028.,  1029.,  1030.,  1031.,  1032.,  1033.,  1034.,  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.,  1199.,  1200.,  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.])

spec.samples

array([ 500.,  504.,  508.,  512.,  516.,  520.,  524.,  528.,  532.,
        536.,  540.,  544.,  548.,  552.,  556.,  560.,  564.,  568.,
        572.,  576.,  580.,  584.,  588.,  592.,  596.,  600.,  604.,
        608.,  612.,  616.,  620.,  624.,  628.,  632.,  636.,  640.,
        644.,  648.,  652.,  656.,  660.,  664.,  668.,  672.,  676.,
        680.,  684.,  688.,  692.,  696.,  700.,  704.,  708.,  712.,
        716.,  720.,  724.,  728.,  732.,  736.,  740.,  744.,  748.,
        752.,  756.,  760.,  764.,  768.,  772.,  776.,  780.,  784.,
        788.,  792.,  796.,  800.,  804.,  808.,  812.,  816.,  820.,
        824.,  828.,  832.,  836.,  840.,  844.,  848.,  852.,  856.,
        860.,  864.,  868.,  872.,  876.,  880.,  884.,  888.,  892.,
        896.,  900.])
jokva commented 4 years ago

Your offsets look inconsistent, why do you set them to int(xlno)? Try setting them to 0.

nitishkannan23 commented 4 years ago

It worked! Thanks a lot but the only problem that I face now is the sample values have been reset.

spec = segyio.spec()
file = 'segy_attribute_classifications_run2.segy'
spec.format = 1
spec.xline = 193
spec.iline = 189
spec.offsets = [0]
spec.samples = np.unique(final_values[:,2])
spec.ilines = np.unique(final_values[:,0])
spec.xlines = np.unique(final_values[:,1])
with segyio.create(file, spec) as f:
    ix = len_ilines*len_xlines
    f.trace[:ix] = final_clusters[:ix]
    hdx = 0
    for ilno in spec.ilines:
        for xlno in spec.xlines:
            f.header[hdx] = {segyio.TraceField.INLINE_3D: int(ilno),
                             segyio.TraceField.CROSSLINE_3D: int(xlno),
                             segyio.TraceField.offset:0}
            hdx = hdx+1

c = segyio.open(file, 'r+')

spec.samples

array([ 1800.,  1804.,  1808.,  1812.,  1816.,  1820.,  1824.,  1828.,
        1832.,  1836.,  1840.,  1844.,  1848.,  1852.,  1856.,  1860.,
        1864.,  1868.,  1872.,  1876.,  1880.,  1884.,  1888.,  1892.,
        1896.,  1900.,  1904.,  1908.,  1912.,  1916.,  1920.,  1924.,
        1928.,  1932.,  1936.,  1940.,  1944.,  1948.,  1952.,  1956.,
        1960.,  1964.,  1968.,  1972.,  1976.,  1980.,  1984.,  1988.,
        1992.,  1996.,  2000.,  2004.,  2008.,  2012.,  2016.,  2020.,
        2024.,  2028.,  2032.,  2036.,  2040.,  2044.,  2048.,  2052.,
        2056.,  2060.,  2064.,  2068.,  2072.,  2076.,  2080.,  2084.,
        2088.,  2092.,  2096.,  2100.,  2104.,  2108.,  2112.,  2116.,
        2120.,  2124.,  2128.,  2132.,  2136.,  2140.,  2144.,  2148.,
        2152.,  2156.,  2160.,  2164.,  2168.,  2172.,  2176.,  2180.,
        2184.,  2188.,  2192.,  2196.,  2200.])

c.samples

array([   0.,    4.,    8.,   12.,   16.,   20.,   24.,   28.,   32.,
         36.,   40.,   44.,   48.,   52.,   56.,   60.,   64.,   68.,
         72.,   76.,   80.,   84.,   88.,   92.,   96.,  100.,  104.,
        108.,  112.,  116.,  120.,  124.,  128.,  132.,  136.,  140.,
        144.,  148.,  152.,  156.,  160.,  164.,  168.,  172.,  176.,
        180.,  184.,  188.,  192.,  196.,  200.,  204.,  208.,  212.,
        216.,  220.,  224.,  228.,  232.,  236.,  240.,  244.,  248.,
        252.,  256.,  260.,  264.,  268.,  272.,  276.,  280.,  284.,
        288.,  292.,  296.,  300.,  304.,  308.,  312.,  316.,  320.,
        324.,  328.,  332.,  336.,  340.,  344.,  348.,  352.,  356.,
        360.,  364.,  368.,  372.,  376.,  380.,  384.,  388.,  392.,
        396.,  400.])

You know why is this happening?

jokva commented 4 years ago

Yes, create() apparently does not write to the delay-recording-time field (which is a bug). To work around it: f.bin[segyio.su.delrt] = spec.samples[0]

nitishkannan23 commented 4 years ago

Sorry, I'm not quite familiar with this package more importantly this function. Now I'm getting this error. It would be great if you'd help me with this.

f.bin[segyio.su.delrt] = int(spec.samples[0])

KeyError: 'No such field 109'
jokva commented 4 years ago

My apologies - delrt is a trace header word, which is why it's not written to the file in the first place.

Replace this:

            f.header[hdx] = {segyio.TraceField.INLINE_3D: int(ilno),
                             segyio.TraceField.CROSSLINE_3D: int(xlno),
                             segyio.TraceField.offset:0}

with

            f.header[hdx] = {segyio.TraceField.INLINE_3D: int(ilno),
                             segyio.TraceField.CROSSLINE_3D: int(xlno),
                             segyio.TraceField.offset:0,
                             segyio.TraceField.DelayRecordingTime: spec.samples[0]}