Example #1
0
def forward_model_and_store(solver, shot, sparse_greens_matrix, freq):
    generate_seismic_data([shot],
                          solver,
                          solver.model_parameters.without_padding(),
                          frequencies=freq)

    n_receivers = len(shot.receivers.receiver_list)
    source_pos = shot.sources.position
    for i in xrange(n_receivers):
        receiver = shot.receivers.receiver_list[i]
        receiver_pos = receiver.position

        recording = shot.receivers.data_dft[freq][0][i]
        sparse_greens_matrix.set_value_by_position(source_pos, receiver_pos,
                                                   recording)
Example #2
0
def adjoint_test_rho():
    import numpy as np
    from pysit import PML, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, VariableDensityAcousticWave, generate_seismic_data, PointReceiver, RickerWavelet
    from pysit.gallery.horizontal_reflector import horizontal_reflector

    # Setup

    #   Define Domain
    pmlx = PML(0.1, 1000, ftype='quadratic')
    pmlz = PML(0.1, 1000, ftype='quadratic')
    
    x_config = (0.1, 1.0, pmlx, pmlx)
    z_config = (0.1, 1.0, pmlz, pmlz)

    d = RectangularDomain( x_config, z_config )
    
    m = CartesianMesh(d, 70,80 )
    
    #   Generate true wave speed
    #   (M = C^-2 - C0^-2)
    C,C0,m,d = horizontal_reflector(m)
    w=1.3
    M = [w*C, C/w]
    M0 = [C0, C0]
    # Set up shots
    Nshots = 1
    shots = []
    
    xmin = d.x.lbound
    xmax = d.x.rbound
    nx   = m.x.n
    zmin = d.z.lbound
    zmax = d.z.rbound
    
    for i in xrange(Nshots):

        # Define source location and type
#       source = PointSource(d, (xmax*(i+1.0)/(Nshots+1.0), 0.1), RickerWavelet(10.0))
        source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0))
    
        # Define set of receivers
        zpos = zmin + (1./9.)*zmax
        xpos = np.linspace(xmin, xmax, nx)
        receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos])
    
        # Create and store the shot
        shot = Shot(source, receivers)
        shots.append(shot)
    
    # Define and configure the wave solver  
    trange=(0.,3.0)
    solver = VariableDensityAcousticWave(m,
                                         formulation='scalar',
                                         model_parameters={'kappa': M[0], 'rho' : M[1]}, 
                                         spatial_accuracy_order=2,
                                         trange=trange,
                                         use_cpp_acceleration=False,
                                         time_accuracy_order=2)
    
    # Generate synthetic Seismic data
    np.random.seed(1)
    print('Generating data...')
    wavefields=[]
    base_model = solver.ModelParameters(m,{'kappa': M[0], 'rho':M[1]})
    generate_seismic_data(shots, solver, base_model, wavefields=wavefields)
    
    tools = TemporalModeling(solver)
    m0 = solver.ModelParameters(m,{'kappa': M[0], 'rho':M[1]})
    
    m1 = m0.perturbation()
    
    v=uniform(.5,2.2,len(m0.rho)).reshape((len(m0.rho),1))  #pertubation of m2
    m1.rho=1.0/v
    

    fwdret = tools.forward_model(shot,  m0, 1, ['wavefield', 'dWaveOp', 'simdata'])
    dWaveOp0 = fwdret['dWaveOp']
    inc_field = fwdret['wavefield']
    data = fwdret['simdata']
    #data += np.random.rand(*data.shape)
    
    linfwdret = tools.linear_forward_model_rho(shot, m0, m1, ['simdata'],wavefield=inc_field)
    lindata = linfwdret['simdata']
    
    adjret = tools.adjoint_model(shot, m0, data, 1, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0,wavefield=inc_field)
    
    # multiplied adjmodel by an additional m2 model.
    adjmodel = adjret['imaging_condition'].rho
    #adjmodel = 1.0/adjmodel
    #m1_C = m1.C

    print "data space ", np.sum(data*lindata)*solver.dt
    print "model space ", np.dot(v.T, adjmodel).squeeze()*np.prod(m.deltas)
    print "their diff ", np.dot(v.T, adjmodel).squeeze()*np.prod(m.deltas)-np.sum(data*lindata)*solver.dt
Example #3
0
def adjoint_test():
#if __name__ == '__main__':
    import numpy as np
    from pysit import PML, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave, generate_seismic_data, PointReceiver, RickerWavelet
    from pysit.gallery import horizontal_reflector

    # Setup

    #   Define Domain
    pmlx = PML(0.1, 1000, ftype='quadratic')
    pmlz = PML(0.1, 1000, ftype='quadratic')

    x_config = (0.1, 1.0, pmlx, pmlx)
    z_config = (0.1, 0.8, pmlz, pmlz)

    d = RectangularDomain( x_config, z_config )

    m = CartesianMesh(d, 90, 70)

    #   Generate true wave speed
    #   (M = C^-2 - C0^-2)
    C0, C = horizontal_reflector(m)

    # Set up shots
    Nshots = 1
    shots = []

    xmin = d.x.lbound
    xmax = d.x.rbound
    nx   = m.x.n
    zmin = d.z.lbound
    zmax = d.z.rbound

    for i in xrange(Nshots):

        # Define source location and type
#       source = PointSource(d, (xmax*(i+1.0)/(Nshots+1.0), 0.1), RickerWavelet(10.0))
        source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0))

        # Define set of receivers
        zpos = zmin + (1./9.)*zmax
        xpos = np.linspace(xmin, xmax, nx)
        receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos])

        # Create and store the shot
        shot = Shot(source, receivers)
        shots.append(shot)

    # Define and configure the wave solver
    trange=(0.,3.0)
    solver = ConstantDensityAcousticWave(m,
                                         formulation='ode',
#                                        formulation='scalar',
                                         model_parameters={'C': C},
                                         spatial_accuracy_order=4,
#                                        spatial_shifted_differences=True,
#                                        cfl_safety=0.01,
                                         trange=trange,
                                         time_accuracy_order=4)

    # Generate synthetic Seismic data
    np.random.seed(1)
    print('Generating data...')
    wavefields=[]
    base_model = solver.ModelParameters(m,{'C': C})
    generate_seismic_data(shots, solver, base_model, wavefields=wavefields)

    tools = TemporalModeling(solver)
    m0 = solver.ModelParameters(m,{'C': C0})

    m1 = m0.perturbation()
    m1 += np.random.rand(*m1.data.shape)

    fwdret = tools.forward_model(shot, m0, ['wavefield', 'dWaveOp', 'simdata'])
    dWaveOp0 = fwdret['dWaveOp']
    inc_field = fwdret['wavefield']
    data = fwdret['simdata']
#   data += np.random.rand(*data.shape)

    linfwdret = tools.linear_forward_model(shot, m0, m1, ['simdata'])
    lindata = linfwdret['simdata']

    adjret = tools.adjoint_model(shot, m0, data, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0)

    adjmodel = adjret['imaging_condition'].asarray()
    adj_field = adjret['adjointfield']
    m1 = m1.asarray()

    print data.shape, solver.nsteps
    print np.sum(data*lindata)*solver.dt
    print np.dot(m1.T, adjmodel).squeeze()*np.prod(m.deltas)
    print np.dot(m1.T, adjmodel).squeeze()*np.prod(m.deltas)-np.sum(data*lindata)*solver.dt

    qs = adj_field

    qhat = 0.0
    dt = solver.dt
    for k in xrange(solver.nsteps):
        t = k * dt

        qhat += qs[k]*(np.exp(-1j*2.0*np.pi*10.0*t)*dt)
Example #4
0
def adjoint_test():
#if __name__ == '__main__':
#   from pysit import *
    import numpy as np
    import matplotlib.pyplot as plt

    from pysit import PML, Dirichlet, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave,ConstantDensityHelmholtz, generate_seismic_data, PointReceiver, RickerWavelet
    from pysit.gallery import horizontal_reflector

    #   Define Domain
    bc = PML(0.3, 100, ftype='quadratic')
#   bc = Dirichlet()

    x_config = (0.1, 1.0, bc, bc)
    z_config = (0.1, 0.8, bc, bc)

    d = RectangularDomain( x_config, z_config )

    m = CartesianMesh(d, 90, 70)

    #   Generate true wave speed
    #   (M = C^-2 - C0^-2)
    C0, C = horizontal_reflector(m)

    # Set up shots
    Nshots = 1
    shots = []

    xmin = d.x.lbound
    xmax = d.x.rbound
    nx   = m.x.n
    zmin = d.z.lbound
    zmax = d.z.rbound

    point_approx = 'delta'

    for i in xrange(Nshots):

        # Define source location and type
        source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0), approximation=point_approx)

        # Define set of receivers
        zpos = zmin + (1./9.)*zmax
        xpos = np.linspace(xmin, xmax, nx)
        receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos])

        # Create and store the shot
        shot = Shot(source, receivers)
        shots.append(shot)

    # Define and configure the wave solver
    trange=(0.,3.0)
    solver = ConstantDensityAcousticWave(m,
                                         formulation='scalar',
                                         model_parameters={'C': C},
                                         spatial_accuracy_order=4,
                                         trange=trange,
                                         time_accuracy_order=6)

    # Generate synthetic Seismic data
    print('Generating data...')
    base_model = solver.ModelParameters(m,{'C': C})
    generate_seismic_data(shots, solver, base_model)

    solver_frequency = ConstantDensityHelmholtz(m,
                                                model_parameters={'C': C0},
                                                spatial_shifted_differences=True,
                                                spatial_accuracy_order=4)
    tools = FrequencyModeling(solver_frequency)
    m0 = solver_frequency.ModelParameters(m,{'C': C0})

    np.random.seed(0)

    m1 = m0.perturbation()
#   m1 += M
    m1  += np.random.rand(*m1.data.shape)

    freqs = [10.0, 10.5, 10.123334145252]
#   freqs = np.linspace(3,20,20)

    fwdret = tools.forward_model(shot, m0, freqs, ['wavefield', 'dWaveOp', 'simdata'])
    data = fwdret['simdata']
    dWaveOp0 = fwdret['dWaveOp']
    u0hat = fwdret['wavefield'][freqs[0]]

#   data -= shot.receivers.interpolate_data(solver.ts())
#   data *= -1

#   for nu in freqs:
#       data[nu] += np.random.rand(*data[nu].shape)

    linfwdret = tools.linear_forward_model(shot, m0, m1, freqs, ['simdata','wavefield1'])
    lindata = linfwdret['simdata']
    u1hat = linfwdret['wavefield1'][freqs[0]]

    adjret = tools.adjoint_model(shot, m0, data, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0)
    qhat = adjret['adjointfield'][freqs[0]]
    adjmodel = adjret['imaging_condition'].data

#   adjret2 = tools.adjoint_model(shot, m0, lindata_time, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0)
##  qhat = adjret['adjointfield'][freqs[0]]
#   adjmodel2 = adjret2['imaging_condition'].view(np.ndarray)

    m1 = m1.data

    temp_data_prod = 0.0
    for nu in freqs:
        temp_data_prod += np.dot(lindata[nu].reshape(data[nu].shape).T, np.conj(data[nu]))

    print temp_data_prod.squeeze()
    print np.dot(m1.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas)
    print np.dot(m1.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas) - temp_data_prod.squeeze()
Example #5
0
def adjoint_test_rho():
    import numpy as np
    from pysit import PML, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, VariableDensityAcousticWave, generate_seismic_data, PointReceiver, RickerWavelet
    from pysit.gallery.horizontal_reflector import horizontal_reflector

    # Setup

    #   Define Domain
    pmlx = PML(0.1, 1000, ftype='quadratic')
    pmlz = PML(0.1, 1000, ftype='quadratic')
    
    x_config = (0.1, 1.0, pmlx, pmlx)
    z_config = (0.1, 1.0, pmlz, pmlz)

    d = RectangularDomain( x_config, z_config )
    
    m = CartesianMesh(d, 70,80 )
    
    #   Generate true wave speed
    #   (M = C^-2 - C0^-2)
    C,C0,m,d = horizontal_reflector(m)
    w=1.3
    M = [w*C, C/w]
    M0 = [C0, C0]
    # Set up shots
    Nshots = 1
    shots = []
    
    xmin = d.x.lbound
    xmax = d.x.rbound
    nx   = m.x.n
    zmin = d.z.lbound
    zmax = d.z.rbound
    
    for i in xrange(Nshots):

        # Define source location and type
#       source = PointSource(d, (xmax*(i+1.0)/(Nshots+1.0), 0.1), RickerWavelet(10.0))
        source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0))
    
        # Define set of receivers
        zpos = zmin + (1./9.)*zmax
        xpos = np.linspace(xmin, xmax, nx)
        receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos])
    
        # Create and store the shot
        shot = Shot(source, receivers)
        shots.append(shot)
    
    # Define and configure the wave solver  
    trange=(0.,3.0)
    solver = VariableDensityAcousticWave(m,
                                         formulation='scalar',
                                         model_parameters={'kappa': M[0], 'rho' : M[1]}, 
                                         spatial_accuracy_order=2,
                                         trange=trange,
                                         use_cpp_acceleration=False,
                                         time_accuracy_order=2)
    
    # Generate synthetic Seismic data
    np.random.seed(1)
    print('Generating data...')
    wavefields=[]
    base_model = solver.ModelParameters(m,{'kappa': M[0], 'rho':M[1]})
    generate_seismic_data(shots, solver, base_model, wavefields=wavefields)
    
    tools = TemporalModeling(solver)
    m0 = solver.ModelParameters(m,{'kappa': M[0], 'rho':M[1]})
    
    m1 = m0.perturbation()
    
    v=uniform(.5,2.2,len(m0.rho)).reshape((len(m0.rho),1))  #pertubation of m2
    m1.rho=1.0/v
    

    fwdret = tools.forward_model(shot,  m0, 1, ['wavefield', 'dWaveOp', 'simdata'])
    dWaveOp0 = fwdret['dWaveOp']
    inc_field = fwdret['wavefield']
    data = fwdret['simdata']
    #data += np.random.rand(*data.shape)
    
    linfwdret = tools.linear_forward_model_rho(shot, m0, m1, ['simdata'],wavefield=inc_field)
    lindata = linfwdret['simdata']
    
    adjret = tools.adjoint_model(shot, m0, data, 1, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0,wavefield=inc_field)
    
    # multiplied adjmodel by an additional m2 model.
    adjmodel = adjret['imaging_condition'].rho
    #adjmodel = 1.0/adjmodel
    #m1_C = m1.C

    print "data space ", np.sum(data*lindata)*solver.dt
    print "model space ", np.dot(v.T, adjmodel).squeeze()*np.prod(m.deltas)
    print "their diff ", np.dot(v.T, adjmodel).squeeze()*np.prod(m.deltas)-np.sum(data*lindata)*solver.dt
Example #6
0
def adjoint_test():
#if __name__ == '__main__':
    import numpy as np
    from pysit import PML, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave, generate_seismic_data, PointReceiver, RickerWavelet
    from pysit.gallery import horizontal_reflector

    # Setup

    #   Define Domain
    pmlx = PML(0.1, 1000, ftype='quadratic')
    pmlz = PML(0.1, 1000, ftype='quadratic')

    x_config = (0.1, 1.0, pmlx, pmlx)
    z_config = (0.1, 0.8, pmlz, pmlz)

    d = RectangularDomain( x_config, z_config )

    m = CartesianMesh(d, 90, 70)

    #   Generate true wave speed
    #   (M = C^-2 - C0^-2)
    C0, C = horizontal_reflector(m)

    # Set up shots
    Nshots = 1
    shots = []

    xmin = d.x.lbound
    xmax = d.x.rbound
    nx   = m.x.n
    zmin = d.z.lbound
    zmax = d.z.rbound

    for i in xrange(Nshots):

        # Define source location and type
#       source = PointSource(d, (xmax*(i+1.0)/(Nshots+1.0), 0.1), RickerWavelet(10.0))
        source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0))

        # Define set of receivers
        zpos = zmin + (1./9.)*zmax
        xpos = np.linspace(xmin, xmax, nx)
        receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos])

        # Create and store the shot
        shot = Shot(source, receivers)
        shots.append(shot)

    # Define and configure the wave solver
    trange=(0.,3.0)
    solver = ConstantDensityAcousticWave(m,
                                         formulation='ode',
#                                        formulation='scalar',
                                         model_parameters={'C': C},
                                         spatial_accuracy_order=4,
#                                        spatial_shifted_differences=True,
#                                        cfl_safety=0.01,
                                         trange=trange,
                                         time_accuracy_order=4)

    # Generate synthetic Seismic data
    np.random.seed(1)
    print('Generating data...')
    wavefields=[]
    base_model = solver.ModelParameters(m,{'C': C})
    generate_seismic_data(shots, solver, base_model, wavefields=wavefields)

    tools = TemporalModeling(solver)
    m0 = solver.ModelParameters(m,{'C': C0})

    m1 = m0.perturbation()
    m1 += np.random.rand(*m1.data.shape)

    fwdret = tools.forward_model(shot, m0, ['wavefield', 'dWaveOp', 'simdata'])
    dWaveOp0 = fwdret['dWaveOp']
    inc_field = fwdret['wavefield']
    data = fwdret['simdata']
#   data += np.random.rand(*data.shape)

    linfwdret = tools.linear_forward_model(shot, m0, m1, ['simdata'])
    lindata = linfwdret['simdata']

    adjret = tools.adjoint_model(shot, m0, data, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0)

    adjmodel = adjret['imaging_condition'].asarray()
    adj_field = adjret['adjointfield']
    m1 = m1.asarray()

    print data.shape, solver.nsteps
    print np.sum(data*lindata)*solver.dt
    print np.dot(m1.T, adjmodel).squeeze()*np.prod(m.deltas)
    print np.dot(m1.T, adjmodel).squeeze()*np.prod(m.deltas)-np.sum(data*lindata)*solver.dt

    qs = adj_field

    qhat = 0.0
    dt = solver.dt
    for k in xrange(solver.nsteps):
        t = k * dt

        qhat += qs[k]*(np.exp(-1j*2.0*np.pi*10.0*t)*dt)
Example #7
0
def adjoint_test():
#if __name__ == '__main__':
#   from pysit import *
    import numpy as np
    import matplotlib.pyplot as plt

    from pysit import PML, Dirichlet, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave,ConstantDensityHelmholtz, generate_seismic_data, PointReceiver, RickerWavelet
    from pysit.gallery import horizontal_reflector

    #   Define Domain
    bc = PML(0.3, 100, ftype='quadratic')
#   bc = Dirichlet()

    x_config = (0.1, 1.0, bc, bc)
    z_config = (0.1, 0.8, bc, bc)

    d = RectangularDomain( x_config, z_config )

    m = CartesianMesh(d, 90, 70)

    #   Generate true wave speed
    #   (M = C^-2 - C0^-2)
    C0, C = horizontal_reflector(m)

    # Set up shots
    Nshots = 1
    shots = []

    xmin = d.x.lbound
    xmax = d.x.rbound
    nx   = m.x.n
    zmin = d.z.lbound
    zmax = d.z.rbound

    point_approx = 'delta'

    for i in xrange(Nshots):

        # Define source location and type
        source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0), approximation=point_approx)

        # Define set of receivers
        zpos = zmin + (1./9.)*zmax
        xpos = np.linspace(xmin, xmax, nx)
        receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos])

        # Create and store the shot
        shot = Shot(source, receivers)
        shots.append(shot)

    # Define and configure the wave solver
    trange=(0.,3.0)
    solver = ConstantDensityAcousticWave(m,
                                         formulation='scalar',
                                         model_parameters={'C': C},
                                         spatial_accuracy_order=4,
                                         trange=trange,
                                         time_accuracy_order=6)

    # Generate synthetic Seismic data
    print('Generating data...')
    base_model = solver.ModelParameters(m,{'C': C})
    generate_seismic_data(shots, solver, base_model)

    solver_frequency = ConstantDensityHelmholtz(m,
                                                model_parameters={'C': C0},
                                                spatial_shifted_differences=True,
                                                spatial_accuracy_order=4)
    tools = FrequencyModeling(solver_frequency)
    m0 = solver_frequency.ModelParameters(m,{'C': C0})

    np.random.seed(0)

    m1 = m0.perturbation()
#   m1 += M
    m1  += np.random.rand(*m1.data.shape)

    freqs = [10.0, 10.5, 10.123334145252]
#   freqs = np.linspace(3,20,20)

    fwdret = tools.forward_model(shot, m0, freqs, ['wavefield', 'dWaveOp', 'simdata'])
    data = fwdret['simdata']
    dWaveOp0 = fwdret['dWaveOp']
    u0hat = fwdret['wavefield'][freqs[0]]

#   data -= shot.receivers.interpolate_data(solver.ts())
#   data *= -1

#   for nu in freqs:
#       data[nu] += np.random.rand(*data[nu].shape)

    linfwdret = tools.linear_forward_model(shot, m0, m1, freqs, ['simdata','wavefield1'])
    lindata = linfwdret['simdata']
    u1hat = linfwdret['wavefield1'][freqs[0]]

    adjret = tools.adjoint_model(shot, m0, data, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0)
    qhat = adjret['adjointfield'][freqs[0]]
    adjmodel = adjret['imaging_condition'].data

#   adjret2 = tools.adjoint_model(shot, m0, lindata_time, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0)
##  qhat = adjret['adjointfield'][freqs[0]]
#   adjmodel2 = adjret2['imaging_condition'].view(np.ndarray)

    m1 = m1.data

    temp_data_prod = 0.0
    for nu in freqs:
        temp_data_prod += np.dot(lindata[nu].reshape(data[nu].shape).T, np.conj(data[nu]))

    print temp_data_prod.squeeze()
    print np.dot(m1.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas)
    print np.dot(m1.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas) - temp_data_prod.squeeze()
Example #8
0
def adjoint_test_rho():
#if __name__ == '__main__':
#   from pysit import *
    import numpy as np
    import matplotlib.pyplot as plt
    from numpy.random import uniform
    from pysit import PML, Dirichlet, RectangularDomain, CartesianMesh, PointSource, ReceiverSet, Shot, ConstantDensityAcousticWave,VariableDensityHelmholtz, generate_seismic_data, PointReceiver, RickerWavelet
    from pysit.gallery.horizontal_reflector import horizontal_reflector

    #   Define Domain
    bc = PML(0.3, 100, ftype='quadratic')
#   bc = Dirichlet()
    
    x_config = (0.1, 1.0, bc, bc)
    z_config = (0.1, 0.8, bc, bc)

    d = RectangularDomain( x_config, z_config )
    
    m = CartesianMesh(d, 70, 90)

    #   Generate true wave speed
    #   (M = C^-2 - C0^-2)
    C,C0,m,d = horizontal_reflector(m)
    w=1.3
    M = [w*C, C/w]
    M0 = [C0, C0]

    # Set up shots
    Nshots = 1
    shots = []
    
    xmin = d.x.lbound
    xmax = d.x.rbound
    nx   = m.x.n
    zmin = d.z.lbound
    zmax = d.z.rbound
    
    point_approx = 'delta'
    
    for i in xrange(Nshots):

        # Define source location and type
        source = PointSource(m, (.188888, 0.18888), RickerWavelet(10.0), approximation=point_approx)
    
        # Define set of receivers
        zpos = zmin + (1./9.)*zmax
        xpos = np.linspace(xmin, xmax, nx)
        receivers = ReceiverSet(m, [PointReceiver(m, (x, zpos)) for x in xpos])
    
        # Create and store the shot
        shot = Shot(source, receivers)
        shots.append(shot)
    
    # Define and configure the wave solver
    #trange=(0.,3.0)
    freqs = [3.0,5.0,7.0]
    solver = VariableDensityHelmholtz(m,
                                                model_parameters={'kappa': M[0], 'rho' : M[1]},
                                                spatial_shifted_differences=False,
                                                spatial_accuracy_order=2)
    # Generate synthetic Seismic data
    print('Generating data...')
    base_model = solver.ModelParameters(m,{'kappa': M[0], 'rho' : M[1]})
    generate_seismic_data(shots, solver, base_model,frequencies=freqs)
    
    
    tools = FrequencyModeling(solver)
    m0 = solver.ModelParameters(m,{'kappa': M[0], 'rho' : M[1]})
    
    np.random.seed(0)
    
    m1 = m0.perturbation()

    # v is pertubation of model 1/rho. (which we have declared as m1). Thus, rho is 1/v. 
    v = uniform(0.5,1.5,len(m0.rho)).reshape((len(m0.rho),1))
    
    m1.rho  += 1.0/v
    
    
#   freqs = np.linspace(3,20,20)
        
    fwdret = tools.forward_model(shot, m0, freqs, ['wavefield', 'dWaveOp', 'simdata'])
    data = fwdret['simdata']
    dWaveOp0 = fwdret['dWaveOp']
    u0hat = fwdret['wavefield']

#   data -= shot.receivers.interpolate_data(solver.ts())
#   data *= -1  

#   for nu in freqs:
#       data[nu] += np.random.rand(*data[nu].shape)
        
    linfwdret = tools.linear_forward_model_rho(shot, m0, m1, freqs, ['simdata','wavefield1'], wavefield=u0hat)
    lindata = linfwdret['simdata']
    #u1hat = linfwdret['wavefield1'][freqs[0]]
    
    adjret = tools.adjoint_model(shot, m0, data, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0,wavefield=u0hat)
    qhat = adjret['adjointfield'][freqs[0]]
    adjmodel = adjret['imaging_condition'].rho
    
#   adjret2 = tools.adjoint_model(shot, m0, lindata_time, freqs, return_parameters=['imaging_condition', 'adjointfield'], dWaveOp=dWaveOp0)
##  qhat = adjret['adjointfield'][freqs[0]]
#   adjmodel2 = adjret2['imaging_condition'].view(np.ndarray)
    
    temp_data_prod = 0.0
    for nu in freqs:
        temp_data_prod += np.dot(lindata[nu].reshape(data[nu].shape).T, np.conj(data[nu]))
    
    print "data space: ", temp_data_prod.squeeze()
    print "model space: ", np.dot(v.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas)
    print "their diff: ", np.dot(v.T, np.conj(adjmodel)).squeeze()*np.prod(m.deltas) - temp_data_prod.squeeze()