#!/usr/bin/env python

import numpy as np
from seppyio import *
import math

nsou=from_header('souloc','n2')
souloc=read('souloc',(nsou,5))

if searchArgv("ox")==False:
    ox=np.amin(souloc[:,0])
else: 
    ox=get_param("ox")

if searchArgv("oy")==False:
    oy=np.amin(souloc[:,1])
else: 
    oy=get_param("oy")

if searchArgv("maxx")==False:
    maxx=np.amax(souloc[:,0])
else: 
    maxx=get_param("maxx")

if searchArgv("maxy")==False:
    maxy=np.amax(souloc[:,1])
else: 
    maxy=get_param("maxy")

dx,dy=get_param("dx","dy")
nx=int(math.ceil((maxx-ox)/dx+1))
ny=int(math.ceil((maxy-oy)/dy+1))

shotid=[]
for j in range(ny):
    for i in range(nx):
        shotx=ox+i*dx
        shoty=oy+j*dy
        distx=souloc[:,0]-shotx
        disty=souloc[:,1]-shoty
        dist=np.sqrt(distx*distx+disty*disty)
        k=np.argmin(dist)
        print k,shotx,shoty,souloc[k,0],souloc[k,1]
        shotid.append(k)

shotid1=np.asarray(shotid)
write("shotid",shotid1)
to_header("shotid","n1",shotid1.shape[0],"o1",0,"d1",1)


6f65e56b7c1f699774e37538318f05da4e734f58
#!/usr/bin/env python

import numpy as np
from seppyio import *
import math

nsou=from_header('souloc','n2')
souloc=read('souloc',(nsou,5))

if searchArgv("ox")==False:
    ox=np.amin(souloc[:,0])
else: 
    ox=get_param("ox")

if searchArgv("oy")==False:
    oy=np.amin(souloc[:,1])
else: 
    oy=get_param("oy")

if searchArgv("maxx")==False:
    maxx=np.amax(souloc[:,0])
else: 
    maxx=get_param("maxx")

if searchArgv("maxy")==False:
    maxy=np.amax(souloc[:,1])
else: 
    maxy=get_param("maxy")

dx,dy=get_param("dx","dy")
nx=int(math.ceil((maxx-ox)/dx+1))
ny=int(math.ceil((maxy-oy)/dy+1))

shotid=[]
for j in range(ny):
    for i in range(nx):
        shotx=ox+i*dx
        shoty=oy+j*dy
        distx=souloc[:,0]-shotx
        disty=souloc[:,1]-shoty
        dist=np.sqrt(distx*distx+disty*disty)
        k=np.argmin(dist)
        print k,shotx,shoty,souloc[k,0],souloc[k,1]
        shotid.append(k)

shotid1=np.asarray(shotid)
write("shotid",shotid1)
to_header("shotid","n1",shotid1.shape[0],"o1",0,"d1",1)

