# Path: pygeo/coord.py
# def reduceToLocal (origpoints, angle=0., about=[0.,0.,0.]):
#   about = np.array(about)
#   return rotationPlan(origpoints, angle, about) - about


import numpy as np
import sys
from pygeo.segyread import SEGYFile
from pygeo.coord import reduceToLocal
from optparse import OptionParser
scalco = scalco / unit

if (trh0['scalel'] < 0):
  scalel = 1./abs(trh0['scalel'])
else:
  scalel = trh0['scalel']

scalel = scalel / unit

# Use SEGYFile internal to calculate shot-gather boundaries
sys.stdout.write('Calculating ensemble boundaries...\n')
sys.stdout.flush()
sf._calcEnsembles()

# Find the number of ensembles, and order them by occurrence in the SEG-Y file
ngathers = len(sf.ensembles)
ordering = np.argsort(sf.ensembles.values())
shotnums = np.array(sf.ensembles.keys())[ordering]

# Assume that SEG-Y file is set up for position-consistent receivers
nrecs = sf.ensembles[shotnums[1]]

rectrh = np.array([(float(trh['gx'])*scalco,float(trh['gy'])*scalco,zantithesis*float(trh['gelev'])*scalel) for trh in sf.trhead[:nrecs]], dtype=np.float32)
newrectrh = reduceToLocal(rectrh, angle, basis)

reclines = []
for i in xrange(len(rectrh)):
  reclines.append(output_format%(i+1,newrectrh[i,0],newrectrh[i,1],newrectrh[i,2],1.))

shottrh = np.array([(float(trh['sx'])*scalco,float(trh['sy'])*scalco,zantithesis*float(trh['selev'])*scalel) for trh in [sf.trhead[sf.ensembles[sn]] for sn in shotnums]])

# Path: pygeo/coord.py
# def reduceToLocal (origpoints, angle=0., about=[0.,0.,0.]):
#   about = np.array(about)
#   return rotationPlan(origpoints, angle, about) - about


# Path: util/geom2fullwv.py
import numpy as np
import sys
from pygeo.segyread import SEGYFile
from pygeo.coord import reduceToLocal
from optparse import OptionParser

scalco = scalco / unit

if (trh0['scalel'] < 0):
  scalel = 1./abs(trh0['scalel'])
else:
  scalel = trh0['scalel']

scalel = scalel / unit

# Use SEGYFile internal to calculate shot-gather boundaries
sys.stdout.write('Calculating ensemble boundaries...\n')
sys.stdout.flush()
sf._calcEnsembles()

# Find the number of ensembles, and order them by occurrence in the SEG-Y file
ngathers = len(sf.ensembles)
ordering = np.argsort(sf.ensembles.values())
shotnums = np.array(sf.ensembles.keys())[ordering]

# Assume that SEG-Y file is set up for position-consistent receivers
nrecs = sf.ensembles[shotnums[1]]

rectrh = np.array([(float(trh['gx'])*scalco,float(trh['gy'])*scalco,zantithesis*float(trh['gelev'])*scalel) for trh in sf.trhead[:nrecs]], dtype=np.float32)
newrectrh = reduceToLocal(rectrh, angle, basis)

reclines = []
for i in xrange(len(rectrh)):
  reclines.append(output_format%(i+1,newrectrh[i,0],newrectrh[i,1],newrectrh[i,2],1.))

shottrh = np.array([(float(trh['sx'])*scalco,float(trh['sy'])*scalco,zantithesis*float(trh['selev'])*scalel) for trh in [sf.trhead[sf.ensembles[sn]] for sn in shotnums]])

newshottrh = reduceToLocal(shottrh, angle, basis)