예제 #1
0
def main(args):

    sep = seppy.sep()

    keys = [
        'f3_shots', 'f3_srcx', 'f3_recx', 'f3_srcy', 'f3_recy', 'f3_nrec',
        'f3_strm'
    ]

    for key in keys:

        files = sorted([
            os.path.join(args.data_dir, ifile)
            for ifile in os.listdir(args.data_dir) if key in ifile
        ])

        output_file = os.path.join(args.data_dir, key + '_all_combined.H')
        for k, ifile in tqdm(enumerate(files),
                             desc='%s files' % (key),
                             total=len(files)):
            daxes, data = sep.read_file(ifile)
            data = data.reshape(daxes.n, order='F')
            if k == 0:
                sep.write_file(output_file, data, os=daxes.o, ds=daxes.d)
            else:
                sep.append_file(output_file, data)
예제 #2
0
def main(args):
    sep = seppy.sep()
    daxes, data = sep.read_file(args.input_data)
    data = data.reshape(daxes.n, order='F').T
    data = np.ascontiguousarray(data).astype('float32')
    ntr, nt = data.shape
    dt, _ = daxes.d

    if args.input_filter is not None:
        faxes, invflt = sep.read_file(args.input_filter)
        laxes, lags = sep.read_file(args.input_lags)
        lags = lags.astype('int32')
    else:
        lags, invflt = gapped_pef(
            data[args.trace_idx],
            na=args.na,
            gap=args.gap,
            niter=args.niter,
            verb=args.verb,
        )

    cop = conv1dm(nt, len(lags), lags, flt=invflt)

    deb = np.zeros(data.shape, dtype='float32')
    for itr in tqdm(range(ntr), desc="ntr", disable=(not args.verb)):
        cop.forward(False, data[itr], deb[itr])

    sep.write_file(args.output_data, deb.T, os=daxes.o, ds=daxes.d)
예제 #3
0
def main(args):
  segys = sorted([
      os.path.join(args.segy, isegy)
      for isegy in os.listdir(args.segy)
      if '.segy' in isegy
  ])
  if not os.path.isdir(args.output_info_dir):
    os.mkdir(args.output_info_dir)

  if args.qc:
    sep = seppy.sep()
    maxes, mig = sep.read_file(args.img)
    nt, nx, ny = maxes.n
    dt, dx, dy = maxes.d
    dx *= 1000
    dy *= 1000
    mig = mig.reshape(maxes.n, order='F')
    # Imaging origin
    ox = 469800.0
    oy = 6072350.0

  for segy in tqdm(segys, desc="nsegy"):
    datsgy = segyio.open(segy, ignore_geometry=True)

    # Get the coordinates
    srcx = np.asarray(datsgy.attributes(segyio.TraceField.SourceX),
                      dtype='int32')
    srcy = np.asarray(datsgy.attributes(segyio.TraceField.SourceY),
                      dtype='int32')
    srccoords = np.zeros([len(srcx), 2], dtype='int')
    srccoords[:, 0] = srcy
    srccoords[:, 1] = srcx

    ucoords, cts = np.unique(srccoords, axis=0, return_counts=True)
    nsht = ucoords.shape[0]

    if args.qc:
      # Plot the source coordinates
      fig = plt.figure(figsize=(10, 10))
      ax = fig.gca()
      ax.imshow(
          np.flipud(seppy.bytes2float(mig[args.slc_idx].T)),
          cmap='gray',
          extent=[ox, ox + nx * dx, oy, oy + ny * dy],
      )
      ax.scatter(ucoords[:, 1], ucoords[:, 0], marker='*', color='tab:red')
      ax.set_xlabel('X (km)', fontsize=15)
      ax.set_ylabel('Y (km)', fontsize=15)
      ax.tick_params(labelsize=15)
      plt.show()

    # Loop over unique coordinates and write to file
    bname = os.path.basename(segy)
    fname = os.path.splitext(bname)[0]
    ofile = os.path.join(args.output_info_dir, fname + '.txt')
    with open(ofile, 'w') as f:
      for icrd in range(nsht):
        f.write('%d %d %d\n' % (ucoords[icrd, 0], ucoords[icrd, 1], cts[icrd]))
예제 #4
0
def main(args):
    sep = seppy.sep()

    # Read in geometry
    sxaxes, srcx = sep.read_file(args.srcx_coords)
    syaxes, srcy = sep.read_file(args.srcy_coords)
    rxaxes, recx = sep.read_file(args.recx_coords)
    ryaxes, recy = sep.read_file(args.recy_coords)

    naxes, nrec = sep.read_file(args.nrec_per_shot)
    nrec = nrec.astype('int32')

    # Read in time slice for QC
    sep = seppy.sep()
    saxes, slc = sep.read_file(args.img)
    slc = slc.reshape(saxes.n, order='F')
    slcw = slc[args.slc_idx, 200:1200, 5:505]

    plot_acq(srcx, srcy, recx, recy, slcw, recs=False, show=True)
예제 #5
0
def main(args):
    sep = seppy.sep()

    output_suffix = args.suffix.split(".H")[0] + '-wind%d.H' % (args.nshots)

    # Window based on shots
    _, srcx = sep.read_file(
        os.path.join(args.data_dir, 'f3_srcx_all_' + args.suffix))
    srcxw = srcx[:args.nshots]
    sep.write_file(os.path.join(args.data_dir, 'f3_srcx_all_' + output_suffix),
                   srcxw)

    _, srcy = sep.read_file(
        os.path.join(args.data_dir, 'f3_srcy_all_' + args.suffix))
    srcyw = srcy[:args.nshots]
    sep.write_file(os.path.join(args.data_dir, 'f3_srcy_all_' + output_suffix),
                   srcyw)

    _, nrec = sep.read_file(
        os.path.join(args.data_dir, 'f3_nrec_all_' + args.suffix))
    nrecw = nrec[:args.nshots]
    sep.write_file(os.path.join(args.data_dir, 'f3_nrec_all_' + output_suffix),
                   nrecw)

    # Window based on traces
    ntrw = np.sum(nrec[:args.nshots].astype('int32'))

    daxes, data = sep.read_file(
        os.path.join(args.data_dir, 'f3_shots_all_' + args.suffix))
    data = data.reshape(daxes.n, order='F')
    dataw = data[:, :ntrw]
    sep.write_file(os.path.join(args.data_dir,
                                'f3_shots_all_' + output_suffix),
                   dataw,
                   os=daxes.o,
                   ds=daxes.d)

    _, recx = sep.read_file(
        os.path.join(args.data_dir, 'f3_recx_all_' + args.suffix))
    recxw = recx[:ntrw]
    sep.write_file(os.path.join(args.data_dir, 'f3_recx_all_' + output_suffix),
                   recxw)

    _, recy = sep.read_file(
        os.path.join(args.data_dir, 'f3_recy_all_' + args.suffix))
    recyw = recy[:ntrw]
    sep.write_file(os.path.join(args.data_dir, 'f3_recy_all_' + output_suffix),
                   recyw)

    _, strm = sep.read_file(
        os.path.join(args.data_dir, 'f3_strm_all_' + args.suffix))
    strmw = strm[:ntrw]
    sep.write_file(os.path.join(args.data_dir, 'f3_strm_all_' + output_suffix),
                   strmw)
예제 #6
0
def main(args):
    srcx_files = sorted([
        os.path.join(args.data_dir, ifile)
        for ifile in os.listdir(args.data_dir) if 'srcx' in ifile
    ])
    srcy_files = sorted([
        os.path.join(args.data_dir, ifile)
        for ifile in os.listdir(args.data_dir) if 'srcy' in ifile
    ])

    sep = seppy.sep()
    saxes, slc = sep.read_file(args.img)
    slc = slc.reshape(saxes.n, order='F')
    slcw = slc[args.slc_idx, 200:1200, 5:505]
    nx, ny = slcw.shape

    ox, oy = 469800, 6072350
    dx, dy = 25, 25
    oxv, oyv = 200, 5
    oxw = ox + oxv * dx
    oyw = oy + oyv * dy

    all_srcys, all_srcxs = [], []
    fig = plt.figure(figsize=(14, 7))
    for srcx_file, srcy_file in zip(srcx_files, srcy_files):
        saxes, srcx = sep.read_file(srcx_file)
        saxes, srcy = sep.read_file(srcy_file)
        all_srcxs.append(srcx)
        all_srcys.append(srcy)

        ax = fig.gca()
        ax.imshow(
            np.flipud(slcw.T),
            cmap='gray',
            extent=[oxw, oxw + nx * dx, oyw, oyw + ny * dy],
        )
        ax.scatter(srcx, srcy, marker='*', c='tab:red')
        ax.set_xlabel('X (km)', fontsize=15)
        ax.set_ylabel('Y (km)', fontsize=15)
        ax.tick_params(labelsize=15)
    plt.show()

    all_srcxs = np.concatenate(all_srcxs, axis=0)
    all_srcys = np.concatenate(all_srcys, axis=0)

    scoords = np.zeros([len(all_srcxs), 2], dtype='float32')
    scoords[:, 0] = all_srcxs
    scoords[:, 1] = all_srcys
    uscoords, counts = np.unique(scoords, axis=0, return_counts=True)

    print(scoords.shape)
    print(uscoords.shape)
예제 #7
0
def main(args):
  sep = seppy.sep()
  # Read the headers
  _, srcx = sep.read_file(args.srcx)
  _, srcy = sep.read_file(args.srcy)
  _, recx = sep.read_file(args.recx)
  _, recy = sep.read_file(args.recy)
  _, strm = sep.read_file(args.streamer_header)
  _, nrec = sep.read_file(args.nrec_per_shot)
  nrec = nrec.astype('int32')
  nsht = len(nrec)
  # Read the data
  daxes, data = sep.read_file(args.input_data)
  data = data.reshape(daxes.n, order='F').T
  data = np.ascontiguousarray(data).astype('float32')
  nt, ntr = daxes.n
  dt, _ = daxes.d

  # Output data
  smute = np.zeros(data.shape, dtype='float32')

  if args.qc:
    dmin, dmax = np.min(data), np.max(data)

  ntrw = 0
  for isht in tqdm(range(nsht), desc="nsht"):
    smute[ntrw:] = mute_f3shot(
        data[ntrw:],
        srcx[isht],
        srcy[isht],
        nrec[isht],
        strm[ntrw:],
        recx[ntrw:],
        recy[ntrw:],
    )
    if args.qc:
      plot_dat2d(data[ntrw:ntrw + nrec[isht], :1500],
                 show=False,
                 dt=dt,
                 dmin=dmin,
                 dmax=dmax,
                 pclip=0.01,
                 aspect=50)
      plot_dat2d(smute[ntrw:ntrw + nrec[isht], :1500],
                 dt=dt,
                 dmin=dmin,
                 dmax=dmax,
                 pclip=0.01,
                 aspect=50)
    ntrw += nrec[isht]

  sep.write_file(args.output_data, smute.T, os=daxes.o, ds=daxes.d)
예제 #8
0
def main(args):

  suffixes = sorted([
      ifile.split('f3_shots')[-1]
      for ifile in os.listdir(args.data_dir)
      if 'f3_shots' in ifile
  ])

  # Read in the image slice
  sep = seppy.sep()
  saxes, slc = sep.read_file(args.img)
  slc = slc.reshape(saxes.n, order='F')
  slcw = slc[args.slc_idx, 200:1200, 5:505]

  print("Press 'n' to move forward, 'm' to move back one shot")
  print("Press 'y' to move forward, 'u' to move back %d shots" % (args.sjump))

  for suffix in tqdm(suffixes[args.start_idx:args.end_idx], desc='file'):
    # Read in the geometry
    _, srcx = sep.read_file(os.path.join(args.data_dir, 'f3_srcx' + suffix))
    _, srcy = sep.read_file(os.path.join(args.data_dir, 'f3_srcy' + suffix))
    _, recx = sep.read_file(os.path.join(args.data_dir, 'f3_recx' + suffix))
    _, recy = sep.read_file(os.path.join(args.data_dir, 'f3_recy' + suffix))
    _, nrec = sep.read_file(os.path.join(args.data_dir, 'f3_nrec' + suffix))
    nrec = nrec.astype('int32')
    # Read in the data
    dname = 'f3_shots' + suffix
    daxes, data = sep.read_file(os.path.join(args.data_dir, dname))
    data = data.reshape(daxes.n, order='F').T
    dt, _ = daxes.d

    qc_f3data(
        data,
        srcx,
        recx,
        srcy,
        recy,
        nrec,
        slcw,
        pclip=args.pclip,
        sjump=args.sjump,
        dt=dt,
        ntw=args.ntw
    )
예제 #9
0
def main(args):
    sep = seppy.sep()
    daxes, data = sep.read_file(args.input_data)
    data = data.reshape(daxes.n, order='F').T
    data = np.ascontiguousarray(data).astype('float32')
    ntr, nt = data.shape
    dt, _ = daxes.d

    samples = int(args.time_shift / dt)
    data_pad = np.pad(data, ((0, 0), (0, samples)))

    data_shift = np.roll(data_pad, samples, axis=1)

    # Window to max time
    max_samples = int(args.max_time / dt)
    data_shift = data_shift[:, :max_samples]

    trace_energy = np.sum(data_shift * data_shift, axis=1)
    if args.energy_qc:
        fig = plt.figure()
        ax = fig.gca()
        ax.plot(trace_energy)
        ax.set_xlabel("Trace No")
        ax.set_ylabel("Energy")
        plt.show()

    # Compute energy over time axis
    if args.energy_level > 0:
        idx = trace_energy > args.energy_level
        if np.sum(idx) > 100:
            print(
                "WARNING: energy threshold is probably too low. Cleaning up %d traces"
                % (len(idx)))
        for itr in range(ntr):
            if idx[itr]:
                data_shift[itr] = data_shift[itr - 1]

    sep.write_file(args.output_data, data_shift.T, os=daxes.o, ds=daxes.d)
예제 #10
0
def main(args):
    comm = MPI.COMM_WORLD

    rank = comm.Get_rank()
    size = comm.Get_size()

    if rank == 0:
        segys = [
            os.path.join(args.segy, isegy) for isegy in os.listdir(args.segy)
            if '.segy' in isegy
        ]
        segy_chunks = chunks(segys, size)
    else:
        segy_chunks = None

    segy_chunk = comm.scatter(segy_chunks, root=0)

    srcoords = _get_src_rec_coords(rank, segy_chunk)

    all_srcoords = comm.gather(srcoords, root=0)

    if rank == 0:
        all_scoords, all_rcoords = [], []
        for srcoord in all_srcoords:
            all_scoords.append(srcoord['src'])
            all_rcoords.append(srcoord['rec'])

        all_scoords = np.concatenate(all_scoords, axis=0).astype('float32')
        all_rcoords = np.concatenate(all_rcoords, axis=0).astype('float32')

    if rank == 0:
        sep = seppy.sep()
        sep.write_file(args.src_coords, all_scoords)
        sep.write_file(args.rec_coords, all_rcoords)

        if args.unique_src_coords is not None:
            uscoords = np.unique(all_scoords, axis=0)
            sep.write_file(args.unique_src_coords, uscoords)
예제 #11
0
def main(args):
    sep = seppy.sep()
    # Read in the geometry
    _, srcx = sep.read_file(args.srcx)
    _, srcy = sep.read_file(args.srcy)
    _, recx = sep.read_file(args.recx)
    _, recy = sep.read_file(args.recy)
    _, nrec = sep.read_file(args.nrec_per_shot)
    nrec = nrec.astype('int32')
    # Read in the data
    daxes, data = sep.read_file(args.data)
    data = data.reshape(daxes.n, order='F').T
    dt, _ = daxes.d

    # Read in the image slice
    saxes, slc = sep.read_file(args.img)
    slc = slc.reshape(saxes.n, order='F')
    slcw = slc[args.slc_idx, 200:1200, 5:505]

    print("Press 'n' to move forward, 'm' to move back one shot")
    print("Press 'y' to move forward, 'u' to move back %d shots" %
          (args.sjump))
    ntw = 750 if dt == 0.004 else 1500
    qc_f3data(
        data,
        srcx,
        recx,
        srcy,
        recy,
        nrec,
        slcw,
        dt=dt,
        ntw=ntw,
        pclip=args.pclip,
        sjump=args.sjump,
    )
예제 #12
0
def _process_inline(
    sychunk,
    sxs,
    fcrds,
    hmap,
    fnames,
    rank,
    dt=0.002,
    logdir='./log',
):

    # Create a logger
    logging.basicConfig(
        filename='%s/rank-%d.log' % (logdir, rank),
        level=logging.INFO,
        format='%(asctime)s - %(filename)s:%(lineno)d - %(message)s',
    )

    # Write SEP files
    sep = seppy.sep()

    dmap = {}
    srcs = set()
    rsxs, rsys = [], []
    nsy, nsx = len(sychunk), len(sxs)
    ymin, ymax = np.min(sychunk), np.max(sychunk)
    logging.info('Ymin: %d Ymax: %d' % (ymin, ymax))
    with tqdm(total=nsy * nsx,
              desc='rank %d nshots' % (rank),
              position=rank + 1,
              nrows=40) as pbar:
        # Loop over chunks
        for isy in range(nsy):
            gsy = sychunk[isy]
            for isx in range(nsx):
                pbar.update(1)
                gsx = sxs[isx]
                # Compute the distance between this point and
                # all of the source coordinates
                dists = np.sqrt((gsy - fcrds[:, 0])**2 +
                                (gsx - fcrds[:, 1])**2)
                # Find this coordinate
                idx = np.argmin(dists)
                rsy, rsx = fcrds[idx]
                # If we have seen these source before, keep going
                if ((rsy, rsx) in srcs):
                    logging.info("Saw %d %d before, not writing" % (rsy, rsx))
                    continue
                else:
                    srcs.add((rsy, rsx))
                rsys.append(rsy)
                rsxs.append(rsx)
                # Get the key that tells us which files contain the data
                key = str(int(rsy)) + ' ' + str(int(rsx))
                recxinfo, recyinfo = [], []
                strminfo, tidcinfo = [], []
                srcdat = []
                for ifile in hmap[key]:
                    if (ifile not in dmap):
                        dmap[ifile] = segyio.open(ifile, ignore_geometry=True)
                    # Get the source coordinates
                    srcxf = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.SourceX),
                        dtype='int32',
                    )
                    srcyf = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.SourceY),
                        dtype='int32',
                    )
                    # Get the receiver coordinates
                    recxf = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.GroupX),
                        dtype='int32',
                    )
                    recyf = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.GroupY),
                        dtype='int32',
                    )
                    # Get the streamer header
                    strmr = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.CDP_TRACE),
                        dtype='int32',
                    )
                    # Get the trace identification code
                    tidcd = np.asarray(
                        dmap[ifile].attributes(
                            segyio.TraceField.TraceIdentificationCode),
                        dtype='int32',
                    )
                    # Find the traces with that source coordinate
                    scoordsf = np.zeros([len(srcxf), 2], dtype='int32')
                    scoordsf[:, 0] = srcyf
                    scoordsf[:, 1] = srcxf
                    idx1 = scoordsf == fcrds[idx]
                    s = np.sum(idx1, axis=1)
                    nidx1 = s == 2
                    # Get receiver coordinates for this shot
                    recxinfo.append(recxf[nidx1])
                    recyinfo.append(recyf[nidx1])
                    # Get the streamer header for this shot
                    strminfo.append(strmr[nidx1])
                    # Get the trace identification codes for this shot
                    tidcinfo.append(tidcd[nidx1])
                    # Get the data for this shot
                    data = dmap[ifile].trace.raw[:]
                    srcdat.append(data[nidx1, :])
                # Concatenate data from different files
                recxinfo = np.concatenate(recxinfo, axis=0)
                recyinfo = np.concatenate(recyinfo, axis=0)
                strminfo = np.concatenate(strminfo, axis=0)
                tidcinfo = np.concatenate(tidcinfo, axis=0)
                srcdat = np.concatenate(srcdat, axis=0)
                ntr, nt = srcdat.shape
                nrec = len(recxinfo)
                # Skip writing if dead traces
                if (np.all(tidcinfo == 2)):
                    logging.info("Bad shot, not writing shot %d %d" %
                                 (rsy, rsx))
                    continue
                # Add the tuple to the set and make sure we have not used it
                if (nrec != len(recyinfo)):
                    logging.warning("Warning nrecx != nrecy for shot %f %f" %
                                    (rsy, rsx))
                if (isy == 0 and isx == 0):
                    sep.write_file(fnames['srcx'] % (ymin, ymax),
                                   np.asarray([rsx]))
                    sep.write_file(fnames['srcy'] % (ymin, ymax),
                                   np.asarray([rsy]))
                    sep.write_file(
                        fnames['recx'] % (ymin, ymax),
                        recxinfo.astype('float32'),
                    )
                    sep.write_file(
                        fnames['recy'] % (ymin, ymax),
                        recyinfo.astype('float32'),
                    )
                    sep.write_file(
                        fnames['nrec'] % (ymin, ymax),
                        np.asarray([nrec], dtype='float32'),
                    )
                    sep.write_file(
                        fnames['streamer'] % (ymin, ymax),
                        strminfo.astype('float32'),
                    )
                    sep.write_file(
                        fnames['shots'] % (ymin, ymax),
                        srcdat.T,
                        ds=[dt, 1.0],
                    )
                else:
                    sep.append_file(fnames['srcx'] % (ymin, ymax),
                                    np.asarray([rsx]))
                    sep.append_file(fnames['srcy'] % (ymin, ymax),
                                    np.asarray([rsy]))
                    sep.append_file(
                        fnames['recx'] % (ymin, ymax),
                        recxinfo.astype('float32'),
                    )
                    sep.append_file(
                        fnames['recy'] % (ymin, ymax),
                        recyinfo.astype('float32'),
                    )
                    sep.append_file(
                        fnames['nrec'] % (ymin, ymax),
                        np.asarray([nrec], dtype='float32'),
                    )
                    sep.append_file(
                        fnames['streamer'] % (ymin, ymax),
                        strminfo.astype('float32'),
                    )
                    sep.append_file(fnames['shots'] % (ymin, ymax), srcdat.T)

    # Close all of the opened files
    for kvp in dmap.items():
        kvp[1].close()
예제 #13
0
def main(args):
    files = os.listdir(args.chunk_dir)
    files = list(filter(lambda f: '.H' in f, files))

    keys = [
        'f3_shots', 'f3_srcx', 'f3_recx', 'f3_srcy', 'f3_recy', 'f3_nrec',
        'f3_strm', 'f3_mute', 'f3_debubble', 'f3_processed'
    ]

    ddict = {
        key: os.path.join(args.chunk_dir, ifile)
        for key in keys for ifile in files if key in ifile
    }

    # Read in the geometry
    sep = seppy.sep()
    _, srcx = sep.read_file(ddict['f3_srcx'])
    _, srcy = sep.read_file(ddict['f3_srcy'])
    _, recx = sep.read_file(ddict['f3_recx'])
    _, recy = sep.read_file(ddict['f3_recy'])
    _, nrec = sep.read_file(ddict['f3_nrec'])
    nrec = nrec.astype('int32')
    # Read in the different stages of processing
    daxes, raw = sep.read_file(ddict['f3_shots'])
    raw = raw.reshape(daxes.n, order='F').T
    daxes, mute = sep.read_file(ddict['f3_mute'])
    mute = mute.reshape(daxes.n, order='F').T
    daxes, deb = sep.read_file(ddict['f3_debubble'])
    deb = deb.reshape(daxes.n, order='F').T
    paxes, prc = sep.read_file(ddict['f3_processed'])
    prc = prc.reshape(paxes.n, order='F').T
    dt, _ = daxes.d

    # Read in the image slice
    saxes, slc = sep.read_file(args.img)
    slc = slc.reshape(saxes.n, order='F')
    slcw = slc[args.slc_idx, 200:1200, 5:505]

    print("Press 'n' to move forward, 'm' to move back one shot")
    print("Press 'y' to move forward, 'u' to move back %d shots" %
          (args.sjump))
    qc_f3data(
        raw,
        srcx,
        recx,
        srcy,
        recy,
        nrec,
        slcw,
        dt=dt,
        ntw=args.ntw,
        pclip=args.pclip / 2,
        sjump=args.sjump,
        show=False,
    )

    qc_f3data(
        mute,
        srcx,
        recx,
        srcy,
        recy,
        nrec,
        slcw,
        dt=dt,
        ntw=args.ntw,
        pclip=args.pclip,
        sjump=args.sjump,
        show=False,
    )

    qc_f3data(deb,
              srcx,
              recx,
              srcy,
              recy,
              nrec,
              slcw,
              dt=dt,
              ntw=args.ntw,
              pclip=args.pclip,
              sjump=args.sjump,
              show=False)

    qc_f3data(
        prc,
        srcx,
        recx,
        srcy,
        recy,
        nrec,
        slcw,
        dt=dt,
        ntw=args.ntw,
        pclip=args.pclip,
        sjump=args.sjump,
        show=True,
    )
예제 #14
0
def main(args):
    # Get the file names for this chunk
    files = os.listdir(args.chunk_dir)
    files = list(filter(lambda f: '.H' in f, files))
    files = list(
        filter(
            lambda f: 'mute' not in f and 'debubble' not in f and 'processed'
            not in f and 'gnc' not in f, files))

    keys = [
        'f3_shots', 'f3_srcx', 'f3_recx', 'f3_srcy', 'f3_recy', 'f3_nrec',
        'f3_strm'
    ]

    ddict = {
        key: os.path.join(args.chunk_dir, ifile)
        for key in keys for ifile in files if key in ifile
    }

    suffix = ddict['f3_shots'].split('f3_shots')[-1]

    # First mute the data
    mute_output = os.path.join(args.chunk_dir, 'f3_mute' + suffix)
    mute_cmd = """
  python ./scripts/mute_da.py --input-data=%s \
    --srcx=%s \
    --recx=%s \
    --srcy=%s \
    --recy=%s \
    --nrec-per-shot=%s \
    --streamer-header=%s \
    --output-data=%s \
    --water-vel=%f
  """ % (ddict['f3_shots'], ddict['f3_srcx'], ddict['f3_recx'],
         ddict['f3_srcy'], ddict['f3_recy'], ddict['f3_nrec'],
         ddict['f3_strm'], mute_output, args.water_vel)
    if args.verb:
        print(mute_cmd)
    subprocess.check_call(mute_cmd, shell=True)

    # Now debubble the data
    debubble_output = os.path.join(args.chunk_dir, 'f3_debubble' + suffix)
    debubble_cmd = """
  python ./scripts/debubble_shots.py --input-data=%s \
    --input-filter=%s \
    --input-lags=%s \
    --output-data=%s \
    --verb
  """ % (mute_output, args.input_filter, args.input_lags, debubble_output)
    if args.verb:
        print(debubble_cmd)
    subprocess.check_call(debubble_cmd, shell=True)

    if args.output_data is None:
        args.output_data = os.path.join(args.chunk_dir,
                                        'f3_processed' + suffix)
    # GNC Correction
    ftype = os.path.splitext(args.output_data)[-1]
    energy_qc = "--energy-qc" if args.energy_qc else ""
    base_gnc_cmd = """
  python ./scripts/gnc_correction.py --input-data=%s \
    --time-shift=%f \
    --max-time=%f \
    --energy-level=%f %s \
    --output-data=%s
  """
    if ftype == '.npy':
        sep = seppy.sep()
        gnc_output = os.path.join(args.chunk_dir, 'f3_processed' + suffix)
        gnc_cmd = base_gnc_cmd % (debubble_output, args.time_shift,
                                  args.max_time, args.energy_level, energy_qc,
                                  gnc_output)
        if args.verb:
            print(gnc_cmd)
        subprocess.check_call(gnc_cmd, shell=True)
        # Now read in all files and write to .npz
        odict = {}
        for key, ifile in ddict.items():
            if key == 'f3_shots':
                daxes, data = sep.read_file(gnc_output)
                data = data.reshape(daxes.n, order='F').T
                odict['dt'] = daxes.d[0]
                odict[key] = np.ascontiguousarray(data).astype('float32')
            elif key == 'f3_nrec':
                daxes, data = sep.read_file(ifile)
                odict[key] = data.astype('int32')
            elif key != 'f3_strm':
                daxes, data = sep.read_file(ifile)
                odict[key] = data.astype('float32')
        np.save(args.output_data, odict)
    else:
        gnc_cmd = base_gnc_cmd % (debubble_output, args.time_shift,
                                  args.max_time, args.energy_level, energy_qc,
                                  args.output_data)
        if args.verb:
            print(gnc_cmd)
        subprocess.check_call(gnc_cmd, shell=True)
예제 #15
0
def main(args):
    sep = seppy.sep()

    # First read in srcx, srcy, nrec
    _, all_srcx = sep.read_file(args.all_srcx)
    _, all_srcy = sep.read_file(args.all_srcy)
    _, all_nrec = sep.read_file(args.all_nrec)
    all_nrec = all_nrec.astype('int32')

    _, all_recx = sep.read_file(args.all_recx)
    _, all_recy = sep.read_file(args.all_recy)
    _, all_strm = sep.read_file(args.all_strm)

    total_shots = len(all_srcx)
    nchunks = int(total_shots / args.chunk_size + 0.5)

    begsht, endsht = 0, args.chunk_size
    begtr, endtr = 0, 0
    for ichunk in tqdm(range(nchunks), desc='nchunks'):
        # Window the headers
        srcx_chunk = all_srcx[begsht:endsht]
        srcy_chunk = all_srcy[begsht:endsht]
        nrec_chunk = all_nrec[begsht:endsht]
        endtr += np.sum(nrec_chunk)
        recx_chunk = all_recx[begtr:endtr]
        recy_chunk = all_recy[begtr:endtr]
        strm_chunk = all_strm[begtr:endtr]
        # Read in a data chunk
        daxes, dat = sep.read_wind(args.all_shots,
                                   fw=begtr,
                                   nw=len(recx_chunk))
        dat = dat.reshape(daxes.n, order='F')
        # Write chunks to file
        tag = create_inttag(ichunk, nchunks)
        chunk_dir = os.path.join(args.output_dir, 'chunk_' + tag)
        if not os.path.isdir(chunk_dir):
            os.mkdir(chunk_dir)
        if not args.to_npy:
            sep.write_file(
                os.path.join(chunk_dir,
                             'f3_srcx_' + args.string_id + tag + '.H'),
                srcx_chunk.astype('float32'),
            )
            sep.write_file(
                os.path.join(chunk_dir,
                             'f3_srcy_' + args.string_id + tag + '.H'),
                srcy_chunk.astype('float32'),
            )
            sep.write_file(
                os.path.join(chunk_dir,
                             'f3_nrec_' + args.string_id + tag + '.H'),
                nrec_chunk.astype('float32'),
            )
            sep.write_file(
                os.path.join(chunk_dir,
                             'f3_recx_' + args.string_id + tag + '.H'),
                recx_chunk.astype('float32'),
            )
            sep.write_file(
                os.path.join(chunk_dir,
                             'f3_recy_' + args.string_id + tag + '.H'),
                recy_chunk.astype('float32'),
            )
            sep.write_file(
                os.path.join(chunk_dir,
                             'f3_strm_' + args.string_id + tag + '.H'),
                strm_chunk.astype('float32'),
            )
            sep.write_file(
                os.path.join(chunk_dir,
                             'f3_shots_' + args.string_id + tag + '.H'),
                dat.astype('float32'),
                os=daxes.o,
                ds=daxes.d,
            )
        else:
            odict = {}
            odict['dt'] = daxes.d[0]
            odict['f3_shots'] = np.ascontiguousarray(dat.T).astype('float32')
            odict['f3_nrec'] = nrec_chunk.astype('int32')
            odict['f3_srcx'] = srcx_chunk.astype('float32')
            odict['f3_srcy'] = srcy_chunk.astype('float32')
            odict['f3_recx'] = recx_chunk.astype('float32')
            odict['f3_recy'] = recy_chunk.astype('float32')
            np.save(
                os.path.join(chunk_dir,
                             'chunk_' + args.string_id + tag + '.npy'),
                odict,
            )
        # Update counters
        begsht = endsht
        endsht += args.chunk_size
        begtr = endtr
예제 #16
0
def main(args):
    suffixes = sorted([
        ifile.split('f3_shots')[-1] for ifile in os.listdir(args.data_dir)
        if 'f3_shots' in ifile
    ])

    sep = seppy.sep()
    keys = [
        'f3_shots', 'f3_srcx', 'f3_srcy', 'f3_recx', 'f3_recy', 'f3_nrec',
        'f3_strm'
    ]

    # Load in all of the source coordinates
    all_srcx, all_srcy = [], []
    for k, suffix in enumerate(tqdm(suffixes, desc='rank')):
        srcx_base = os.path.join(args.data_dir, 'f3_srcx')
        _, srcx = sep.read_file(srcx_base + suffix)
        srcy_base = os.path.join(args.data_dir, 'f3_srcy')
        _, srcy = sep.read_file(srcy_base + suffix)
        all_srcx.append(srcx)
        all_srcy.append(srcy)

    # Find all duplicate coordinates
    all_srcx = np.concatenate(all_srcx, axis=0)
    all_srcy = np.concatenate(all_srcy, axis=0)
    dup_dict = _find_duplicates(all_srcx, all_srcy)

    # Loop over all data
    ddict = {key: [] for key in keys}
    for k, suffix in tqdm(enumerate(suffixes),
                          desc='rank',
                          total=len(suffixes)):
        alldat = _read_data(args.data_dir, suffix, keys, sep)

        ctr = 0
        odict = {key: [] for key in keys}
        srcxs, srcys = alldat['f3_srcx'].tolist(), alldat['f3_srcy'].tolist()
        for k, (sidx, sidy) in enumerate(zip(srcxs, srcys)):
            crd = '(%d, %d)' % (sidx, sidy)
            if crd in dup_dict.keys():
                if dup_dict[crd] == 0:
                    nrec = alldat['f3_nrec'][k]
                    odict['f3_srcx'].append(alldat['f3_srcx'][k])
                    odict['f3_srcy'].append(alldat['f3_srcy'][k])
                    odict['f3_nrec'].append(nrec)
                    odict['f3_shots'].append(alldat['f3_shots'][ctr:ctr +
                                                                nrec])
                    odict['f3_recx'].append(alldat['f3_recx'][ctr:ctr + nrec])
                    odict['f3_recy'].append(alldat['f3_recy'][ctr:ctr + nrec])
                    dup_dict[crd] += 1
                else:
                    ddict['f3_srcx'].append(alldat['f3_srcx'][k])
                    ddict['f3_srcy'].append(alldat['f3_srcy'][k])
                    ddict['f3_nrec'].append(nrec)
                    ddict['f3_shots'].append(alldat['f3_shots'][ctr:ctr +
                                                                nrec])
                    ddict['f3_recx'].append(alldat['f3_recx'][ctr:ctr + nrec])
                    ddict['f3_recy'].append(alldat['f3_recy'][ctr:ctr + nrec])
            else:
                nrec = alldat['f3_nrec'][k]
                odict['f3_srcx'].append(alldat['f3_srcx'][k])
                odict['f3_srcy'].append(alldat['f3_srcy'][k])
                odict['f3_nrec'].append(nrec)
                odict['f3_shots'].append(alldat['f3_shots'][ctr:ctr + nrec])
                odict['f3_recx'].append(alldat['f3_recx'][ctr:ctr + nrec])
                odict['f3_recy'].append(alldat['f3_recy'][ctr:ctr + nrec])
            ctr += alldat['f3_nrec'][k]

        # Srcx coordinates
        usrcx = np.asarray(odict['f3_srcx'], dtype='float32')
        name = os.path.join(args.output_dir,
                            'f3_srcx') + args.output_prefix + suffix
        sep.write_file(name, usrcx)
        # Srcy coordinates
        usrcy = np.asarray(odict['f3_srcy'], dtype='float32')
        name = os.path.join(args.output_dir,
                            'f3_srcy') + args.output_prefix + suffix
        sep.write_file(name, usrcy)
        # Num receivers per shot
        unrec = np.asarray(odict['f3_nrec'], dtype='float32')
        name = os.path.join(args.output_dir,
                            'f3_nrec') + args.output_prefix + suffix
        sep.write_file(name, unrec)
        # Shots
        udata = np.concatenate(odict['f3_shots'], axis=0)
        name = os.path.join(args.output_dir,
                            'f3_shots') + args.output_prefix + suffix
        sep.write_file(name, udata.T, ds=[0.002, 1.0], os=[0.0, 0.0])
        # Recx coordinates
        urecx = np.concatenate(odict['f3_recx'], axis=0)
        name = os.path.join(args.output_dir,
                            'f3_recx') + args.output_prefix + suffix
        sep.write_file(name, urecx)
        # Recy coordinates
        urecy = np.concatenate(odict['f3_recy'], axis=0)
        name = os.path.join(args.output_dir,
                            'f3_recy') + args.output_prefix + suffix
        sep.write_file(name, urecy)
예제 #17
0
def main(args):
    sep = seppy.sep()

    # Read in the source hash map and the source coordinates
    hmap = np.load(args.src_hash_map, allow_pickle=True)[()]
    crds = np.load(args.src_coords, allow_pickle=True)[()]

    # Grid origin and sampling of the original grid
    ox, oy = 469800, 6072350
    dx, dy = 25, 25

    # Grid origin of the velocity grid
    oxv, oyv = 200, 5
    nxv, nyv = 1000, 500

    # Data sampling
    dt = 0.002

    # Windowed grid
    # Consistent with the windowing of the velocity model
    oxw = ox + oxv * dx
    oyw = oy + oyv * dy

    if args.qc:
        # Read in the migration cube
        maxes, mig = sep.read_file(args.img)
        mig = mig.reshape(maxes.n, order='F')
        # Window the migration cube
        migw = mig[:, oxv:oxv + nxv, oyv:oyv + nyv]
        # Plotting axes
        oxp, oyp = oxw * 0.001, oyw * 0.001
        dxp, dyp = dx * 0.001, dy * 0.001

    # Make a 100X100m grid and loop over each point
    oyw += dy * args.offset_y
    oxw += dx * args.offset_x  # Change coefficients of dy and dx to shift box
    sxs = np.arange(oxw, oxw + (args.nxg - 1) * dx, args.dsx)
    sys = np.arange(oyw, oyw + (args.nyg - 1) * dy, args.dsy)
    nsx = len(sxs)
    nsy = len(sys)

    fcrds = []
    # Remove the shots outside of the region
    for icrd in range(len(crds)):
        if (crds[icrd, 0] >= oyw and crds[icrd, 1] >= oxw):
            fcrds.append(crds[icrd])
    fcrds = np.asarray(fcrds)

    ctr = 0
    dmap = {}
    srcs = set()
    rsxs, rsys = [], []
    with tqdm(total=nsy * nsx, desc='nshots') as pbar:
        for isy in range(nsy):
            gsy = sys[isy]
            for isx in range(nsx):
                pbar.update(1)
                gsx = sxs[isx]
                # Compute the distance between this point and
                # all of the source coordinates
                dists = np.sqrt((gsy - fcrds[:, 0])**2 +
                                (gsx - fcrds[:, 1])**2)
                # Find this coordinate
                idx = np.argmin(dists)
                rsy, rsx = fcrds[idx]
                # If we have seen these source before, keep going
                if ((rsy, rsx) in srcs):
                    print("Saw %d %d before, not writing" % (rsy, rsx))
                    ctr += 1
                    continue
                else:
                    srcs.add((rsy, rsx))
                rsys.append(rsy)
                rsxs.append(rsx)
                # Get the key that tells us which files contain the data
                key = str(int(rsy)) + ' ' + str(int(rsx))
                recxinfo, recyinfo = [], []
                strminfo, tidcinfo = [], []
                srcdat = []
                for ifile in hmap[key]:
                    if (ifile not in dmap):
                        dmap[ifile] = segyio.open(ifile, ignore_geometry=True)
                    # Get the source coordinates
                    srcxf = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.SourceX),
                        dtype='int32',
                    )
                    srcyf = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.SourceY),
                        dtype='int32',
                    )
                    # Get the receiver coordinates
                    recxf = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.GroupX),
                        dtype='int32',
                    )
                    recyf = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.GroupY),
                        dtype='int32',
                    )
                    # Get the streamer header
                    strmr = np.asarray(
                        dmap[ifile].attributes(segyio.TraceField.CDP_TRACE),
                        dtype='int32',
                    )
                    # Get the trace identification code
                    tidcd = np.asarray(
                        dmap[ifile].attributes(
                            segyio.TraceField.TraceIdentificationCode),
                        dtype='int32',
                    )
                    # Find the traces with that source coordinate
                    scoordsf = np.zeros([len(srcxf), 2], dtype='int32')
                    scoordsf[:, 0] = srcyf
                    scoordsf[:, 1] = srcxf
                    idx1 = scoordsf == fcrds[idx]
                    s = np.sum(idx1, axis=1)
                    nidx1 = s == 2
                    # Get receiver coordinates for this shot
                    recxinfo.append(recxf[nidx1])
                    recyinfo.append(recyf[nidx1])
                    # Get the streamer header for this shot
                    strminfo.append(strmr[nidx1])
                    # Get the trace identification codes for this shot
                    tidcinfo.append(tidcd[nidx1])
                    # Get the data for this shot
                    data = dmap[ifile].trace.raw[:]
                    srcdat.append(data[nidx1, :])
                # Concatenate data from different files
                recxinfo = np.concatenate(recxinfo, axis=0)
                recyinfo = np.concatenate(recyinfo, axis=0)
                strminfo = np.concatenate(strminfo, axis=0)
                tidcinfo = np.concatenate(tidcinfo, axis=0)
                srcdat = np.concatenate(srcdat, axis=0)
                ntr, nt = srcdat.shape
                nrec = len(recxinfo)
                # Skip writing if dead traces
                if (np.all(tidcinfo == 2)):
                    print("Bad shot, not writing shot %d %d %d" %
                          (ctr, rsy, rsx))
                    ctr += 1
                    continue
                # Add the tuple to the set and make sure we have not used it
                if (nrec != len(recyinfo)):
                    print("Warning nrecx != nrecy for shot %f %f" % (rsy, rsx))
                if (isy == 0 and isx == 0):
                    sep.write_file(args.output_srcx_coords, np.asarray([rsx]))
                    sep.write_file(args.output_srcy_coords, np.asarray([rsy]))
                    sep.write_file(
                        args.output_recx_coords,
                        recxinfo.astype('float32'),
                    )
                    sep.write_file(
                        args.output_recy_coords,
                        recyinfo.astype('float32'),
                    )
                    sep.write_file(
                        args.output_nrec_per_shot,
                        np.asarray([nrec], dtype='float32'),
                    )
                    sep.write_file(
                        args.output_streamer_hdr,
                        strminfo.astype('float32'),
                    )
                    sep.write_file(
                        args.output_shots,
                        srcdat.T,
                        ds=[dt, 1.0],
                    )
                else:
                    sep.append_file(args.output_srcx_coords, np.asarray([rsx]))
                    sep.append_file(args.output_srcy_coords, np.asarray([rsy]))
                    sep.append_file(
                        args.output_recx_coords,
                        recxinfo.astype('float32'),
                    )
                    sep.append_file(
                        args.output_recy_coords,
                        recyinfo.astype('float32'),
                    )
                    sep.append_file(
                        args.output_nrec_per_shot,
                        np.asarray([nrec], dtype='float32'),
                    )
                    sep.append_file(
                        args.output_streamer_hdr,
                        strminfo.astype('float32'),
                    )
                    sep.append_file(args.output_shots, srcdat.T)
                if args.qc:
                    # Plot the source receiver geometry for this shot
                    fig = plt.figure(figsize=(10, 5))
                    ax = fig.gca()
                    ax.imshow(
                        np.flipud(migw[args.slc_idx].T),
                        extent=[oxp, oxp + nxv * dxp, oyp, oyp + nyv * dyp],
                        interpolation='bilinear',
                        cmap='gray',
                    )
                    ax.scatter(
                        np.asarray(rsxs) / 1000.0,
                        np.asarray(rsys) / 1000.0,
                        marker='*',
                        color='tab:red',
                    )
                    ax.scatter(
                        recxinfo / 1000.0,
                        recyinfo / 1000.0,
                        marker='v',
                        color='tab:green',
                    )
                    # Plot the data
                    fig = plt.figure()
                    ax = fig.gca()
                    pclip = 0.05
                    dmin = pclip * np.min(srcdat)
                    dmax = pclip * np.max(srcdat)
                    ax.imshow(
                        srcdat.T,
                        cmap='gray',
                        extent=[0, ntr, nt * dt, 0],
                        aspect='auto',
                        vmin=dmin,
                        vmax=dmax,
                    )
                    ax.set_xlabel('Receiver no', fontsize=15)
                    ax.set_ylabel('Time (s)', fontsize=15)
                    ax.tick_params(labelsize=15)
                    plt.show()
                ctr += 1

    # Close all of the opened files
    for kvp in dmap.items():
        kvp[1].close()
예제 #18
0
def main(args):
  sep = seppy.sep()
  # Read in geometry
  _, srcx = sep.read_file(args.srcx)
  srcx *= 0.001
  _, srcy = sep.read_file(args.srcy)
  srcy *= 0.001
  _, recx = sep.read_file(args.recx)
  recx *= 0.001
  _, recy = sep.read_file(args.recy)
  recy *= 0.001
  # Velocity model
  vaxes, vel = sep.read_file(args.vel_model)
  vel = vel.reshape(vaxes.n, order='F').T
  ny, nx, nz = vel.shape
  dz, dx, dy = vaxes.d
  oz, ox, oy = vaxes.o
  velw = vel[args.beg_inline_idx:args.end_inline_idx, :args.
             max_xline_idx, :args.max_depth_idx]
  nyw, nxw, nzw = velw.shape
  oyw = oy + args.beg_inline_idx * dy
  # [ny,nx,nz] -> [nz,ny,nx]
  velwt = np.ascontiguousarray(np.transpose(velw, (2, 0, 1)))

  # Image cube for context
  iaxes, img = sep.read_file(args.img_cube)
  img = img.reshape(iaxes.n, order='F').T
  img = img[:, 200:1200, 5:505]
  imgw = img[
      args.beg_inline_idx:args.end_inline_idx, :args.max_xline_idx, :1000]
  imgwt = np.ascontiguousarray(np.transpose(imgw, (2, 0, 1)))

  fig = plt.figure(figsize=(14, 7))
  ax = fig.gca()
  im = ax.imshow(
      np.flipud(velwt[args.vel_slice_idx]),
      cmap='jet',
      interpolation='bilinear',
      extent=[ox, ox + nxw * dx, oyw, oyw + nyw * dy],
      vmin=np.min(velwt),
      vmax=np.max(velwt),
  )
  ax.scatter(srcx[:4], srcy[:4], c='tab:red', marker='*')
  ax.set_xlabel('X (km)', fontsize=15)
  ax.set_ylabel('Y (km)', fontsize=15)
  ax.tick_params(labelsize=15)
  cbar_ax = fig.add_axes()
  cbar = fig.colorbar(im, cbar_ax, format='%.2f')
  cbar.ax.tick_params(labelsize=15)
  cbar.set_label('Velocity (km/s)', fontsize=15)

  fig = plt.figure(figsize=(14, 7))
  ax = fig.gca()
  im = ax.imshow(
      np.flipud(imgwt[400]),
      cmap='gray',
      interpolation='bilinear',
      extent=[ox, ox + nxw * dx, oyw, oyw + nyw * dy],
  )
  ax.scatter(srcx[:4], srcy[:4], c='tab:red', marker='*')
  ax.set_xlabel('X (km)', fontsize=15)
  ax.set_ylabel('Y (km)', fontsize=15)
  ax.tick_params(labelsize=15)

  viewcube3d(
      velwt,
      os=[0.0, ox, oyw],
      ds=[dz, dx, dy],
      cmap='jet',
      cbar=True,
      show=False,
  )
  viewcube3d(imgwt, os=[0.0, ox, oyw], ds=[dz, dx, dy])
예제 #19
0
def main(args):
  sep = seppy.sep()
  saxes, srcs = sep.read_file(args.src_coords)
  srcs = srcs.reshape(saxes.n, order='F')
  srcy = srcs[:, 0]
  srcx = srcs[:, 1]

  beg = time.time()
  usrcs = np.unique(srcs, axis=0)
  usrcy = usrcs[:, 0]
  usrcx = usrcs[:, 1]
  if args.verb:
    print("Computed unique src coordinates in %f s" % (time.time() - beg),
          flush=True)

  raxes, recs = sep.read_file(args.rec_coords)
  recs = recs.reshape(raxes.n, order='F')
  recy = recs[:, 0]
  recx = recs[:, 1]

  beg = time.time()
  urecs = np.unique(recs, axis=0)
  urecy = urecs[:, 0]
  urecx = urecs[:, 1]
  if args.verb:
    print("Computed unique rec coordinates in %f s" % (time.time() - beg),
          flush=True)

  # Calculate midpoints
  mptx = (srcx + recx) / 2.0
  mpty = (srcy + recy) / 2.0

  beg = time.time()
  mpts = np.zeros(recs.shape, dtype='float32')
  mpts[:, 0] = mpty
  mpts[:, 1] = mptx
  umpts = np.unique(mpts, axis=0)
  umpty = umpts[:, 0]
  umptx = umpts[:, 1]
  if args.verb:
    print("Computed unique mpt coordinates in %f s" % (time.time() - beg),
          flush=True)

  # Read in migration cube
  maxes, mig = sep.read_file(args.img)
  nz, nx, ny = maxes.n
  oz, ox, oy = maxes.o
  dz, dx, dy = maxes.d
  dx *= 1000
  dy *= 1000
  mig = mig.reshape(maxes.n, order='F')
  ox = 469800.0
  oy = 6072350.0

  if args.verb:
    print("Src extent: Min_Y=%d Min_X=%d Max_Y=%d Max_X=%d" %
          (np.min(srcy), np.min(srcx), np.max(srcy), np.max(srcx)))
    print("Rec extent: Min_Y=%d Min_X=%d Max_Y=%d Max_X=%d" %
          (np.min(recy), np.min(recx), np.max(recy), np.max(recx)))
    print("Mpt extent: Min_Y=%.2f Min_X=%.2f Max_Y=%.2f Max_X=%.2f" %
          (np.min(mpty), np.min(mptx), np.max(mpty), np.max(mptx)))

  fig = plt.figure(figsize=(15, 10))
  ax = fig.gca()
  ax.imshow(
      np.flipud(seppy.bytes2float(mig[args.slc_idx].T)),
      cmap='gray',
      extent=[ox, ox + nx * dx, oy, oy + ny * dy],
  )
  ax.scatter(
      usrcx[::args.skip],
      usrcy[::args.skip],
      marker='*',
      color='tab:red',
  )
  ax.set_xlabel('X (km)', fontsize=15)
  ax.set_ylabel('Y (km)', fontsize=15)
  ax.set_title('Source locations: OriginX=%.1f OriginY=%.1f' % (ox, oy),
               fontsize=15)
  ax.tick_params(labelsize=15)
  if args.show:
    plt.show()
  plt.savefig(
      args.output_src_fig,
      dpi=150,
      transparent=False,
      bbox_inches='tight',
  )
  plt.close()

  # Remove receiver below bottom boundary
  # this cannot be used in imaging as we do not
  # have the velocity here
  idx = np.where(urecy < oy)
  purecy = np.delete(urecy, idx)
  purecx = np.delete(urecx, idx)
  fig = plt.figure(figsize=(15, 10))
  ax = fig.gca()
  ax.imshow(
      np.flipud(seppy.bytes2float(mig[args.slc_idx].T)),
      cmap='gray',
      extent=[ox, ox + nx * dx, oy, oy + ny * dy],
  )
  ax.scatter(
      purecx[::args.skip],
      purecy[::args.skip],
      marker='v',
      color='tab:green',
      s=20,
  )
  ax.set_xlabel('X (km)', fontsize=15)
  ax.set_ylabel('Y (km)', fontsize=15)
  ax.tick_params(labelsize=15)
  ax.set_title('Receiver locations: OriginX=%.1f OriginY=%.1f' % (ox, oy),
               fontsize=15)
  if args.show:
    plt.show()
  plt.savefig(
      args.output_rec_fig,
      dpi=150,
      transparent=False,
      bbox_inches='tight',
  )
  plt.close()

  fig = plt.figure(figsize=(15, 10))
  ax = fig.gca()
  ax.imshow(
      np.flipud(seppy.bytes2float(mig[args.slc_idx].T)),
      cmap='gray',
      extent=[ox, ox + nx * dx, oy, oy + ny * dy],
  )
  ax.scatter(umptx[::args.skip], umpty[::args.skip], color='tab:orange', s=20)
  ax.set_xlabel('X (km)', fontsize=15)
  ax.set_ylabel('Y (km)', fontsize=15)
  ax.set_title('Midpoint locations: OriginX=%.1f OriginY=%.1f' % (ox, oy),
               fontsize=15)
  ax.tick_params(labelsize=15)
  if args.show:
    plt.show()
  plt.savefig(
      args.output_mpt_fig,
      dpi=150,
      transparent=False,
      bbox_inches='tight',
  )
  plt.close()
예제 #20
0
def main(args):
    # Read in the .npz files
    files = [
        os.path.join(args.chunk_dir, ifile)
        for ifile in os.listdir(args.chunk_dir) if '.npy' in ifile
    ]

    ddicts = [np.load(ifile, allow_pickle=True).item() for ifile in files]

    # Concatenate into arrays
    data, srcx, recx, srcy, recy, nrec = [], [], [], [], [], []
    for ddict in ddicts:
        data.append(ddict['f3_shots'])
        srcx.append(ddict['f3_srcx'])
        srcy.append(ddict['f3_srcy'])
        recx.append(ddict['f3_recx'])
        recy.append(ddict['f3_recy'])
        nrec.append(ddict['f3_nrec'])

    data = np.concatenate(data, axis=0)
    srcx = np.concatenate(srcx, axis=0)
    srcy = np.concatenate(srcy, axis=0)
    recx = np.concatenate(recx, axis=0)
    recy = np.concatenate(recy, axis=0)
    nrec = np.concatenate(nrec, axis=0)
    dt = ddict['dt']

    # Read in the image slice
    sep = seppy.sep()
    saxes, slc = sep.read_file(args.img)
    slc = slc.reshape(saxes.n, order='F')
    slcw = slc[args.slc_idx, 200:1200, 5:505]

    # Read in the velocity model slice
    vaxes, vel = sep.read_file(args.vel)
    vel = vel.reshape(vaxes.n, order='F')
    velw = vel[args.slc_idx]

    # Plot sources on velocity model and image
    plot_acq(srcx, srcy, recx, recy, slcw, recs=False, show=False)
    plot_acq(srcx, srcy, recx, recy, velw, recs=False, show=False)

    # Plot receivers on velocity model and image
    plot_acq(srcx, srcy, recx, recy, slcw, recs=True, show=False)
    plot_acq(srcx, srcy, recx, recy, velw, recs=True, show=False)

    # Interactive QC of geometry and data
    print("Press 'n' to move forward, 'm' to move back one shot")
    print("Press 'y' to move forward, 'u' to move back %d shots" %
          (args.sjump))
    qc_f3data(
        data,
        srcx,
        recx,
        srcy,
        recy,
        nrec,
        slcw,
        dt=dt,
        ntw=args.ntw,
        pclip=args.pclip / 2,
        sjump=args.sjump,
        show=True,
    )