def tonative(trace, format, endian): if endian == 'little': trace.byteswap(inplace=True) return native(trace, format=format, copy=False)
def extract(self, trace): # segyio.tools.native assumes MSB (big endian) and will always byteswap # on LSB hosts. This effectively means a double byteswap for LSB data # on LSB hosts. if self.endian == 'little': trace.byteswap(inplace=True) return native(trace['samples'], format=self.format, copy=False)
def upload(manifest, fragment_shape, src, filesys): """Upload volume to oneseismic Parameters ---------- manifest : dict The parsed output of the scan program fragment_shape : tuple of int src : io.BaseIO blob : azure.storage.blob.BlobServiceClient """ word1 = manifest['key-words'][0] word2 = manifest['key-words'][1] key1s = manifest['dimensions'][0] key2s = manifest['dimensions'][1] key3s = manifest['dimensions'][2] guid = manifest['guid'] # Seek past the textual headers and the binary header src.seek(int(manifest['byteoffset-first-trace']), io.SEEK_CUR) # Make a custom dtype that corresponds to a header and a trace. This # assumes all traces are of same length and sampled similarly, which is # a safe assumption in practice. This won't be checked though, the check # belongs in the scan program. # # The dtype is quite useful because it means the input can be read into the # numpy array as a buffer, and then passed on directly as numpy arrays to # put() dtype = np.dtype([ ('header', 'b', 240), ('samples', 'f4', len(key3s)), ]) trace = np.array(1, dtype=dtype) fmt = manifest['format'] files = fileset(key1s, key2s, key3s, fragment_shape) files.setlimits(manifest['key1-last-trace']) shapeident = '-'.join(map(str, fragment_shape)) prefix = f'src/{shapeident}' filesys.mkdir(guid) filesys.cd(guid) while True: n = src.readinto(trace) if n == 0: break header = segyio.field.Field(buf=trace['header'], kind='trace') data = native(data=trace['samples'], format=fmt) key1 = header[word1] key2 = header[word2] files.put(key1, key2, data) for ident, fragment in files.commit(key1): ident = '-'.join(map(str, ident)) name = f'{prefix}/{ident}.f32' print('uploading', name) with filesys.open(name, mode='wb') as f: f.write(fragment) with filesys.open('manifest.json', mode='wb') as f: f.write(json.dumps(manifest).encode())