# Problems with the initialization of sources in: Finite difference solution of the 2D wave equation

16 views

### hans joachim

Mar 28, 2019, 1:14:47 PM3/28/19
to Fatiando a Terra
Hey,
first of all great resources on your page and i really like it.

I want to invest some more time in python and  therefore i want to understand the Finite difference solution of the 2D wave equation  code.
But somehow i am not able to initialize the source(s) in this problem. I will always get some variety of:
`---------------------------------------------------------------------------TypeError Traceback (most recent call last)<ipython-input-15-71cda1abe852> in <module>() 146 _reflexive_scalar_boundary_conditions = not_implemented 147 --> 148 class MexHatSource(object): 149 r""" 150 A wave source that vibrates as a Mexican hat (Ricker) wavelet.TypeError: Error when calling the metaclass bases list() takes at most 1 argument (3 given)`

- or some other i can´t reproduce atm :(

So could you point me into the right direction, or give me some simple example how i could call e.g. the s-wave function:

`def elastic_sh(mu, density, area, dt, iterations, sources, stations=None,    snapshot=None, padding=50, taper=0.005):  `

my take on the problem:
`#     Parameters:nx = 200nz = 200 dx = 10 dz = 10 vel = numpy.zeros([dx,dz])vel = 300.*velshape = (nz,nx)        #     * area : [xmin, xmax, zmin, zmax]area = [0,nx, 0, nz]#         The x, z limits of the simulation area, e.g., the shallowest point is#         at zmin, the deepest at zmax.#     * dt : float#         The time interval between iterationsdt = 0.02#     * iterations : int#         Number of time steps to takeiterations = 200#     * sources : list#         A list of the sources of waves#         (see :class:`~fatiando.seismic.wavefd.MexHatSource` for an example#         source)sources = [`~fatiando.seismic.wavefd.MexHatSource`]scalar(vel, area, dt, iterations, sources, stations=None,    snapshot=None, padding=50, taper=0.005)`

### Leonardo Uieda

Mar 28, 2019, 1:27:03 PM3/28/19
Hi Hans,

That looks like some problem with your install.

* How did you install Fatiando (pip, conda, github)?
* Which version of Python are you using?
* Which operating system do you have?

Note that the "fatiando" package is Python 2.7 only.

Cheers,

Leo

--
Leonardo Uieda

Visiting Research Scholar
Department of Earth Sciences - SOEST
University of Hawai'i at Mānoa
www.leouieda.com

--
You received this message because you are subscribed to the Google Groups "Fatiando a Terra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fatiando+u...@googlegroups.com.
To post to this group, send email to fati...@googlegroups.com.

### hans joachim

Mar 28, 2019, 1:43:17 PM3/28/19
to Fatiando a Terra

Hi, thanks for the fast response.

I am using anaconda:
first i installed the dependencies via:
`conda install numpy scipy matplotlib basemap imaging mayavi pip`
and then pip, but i used some command i found online to not downgrade some dependencies, which he wanted to do:

pip install fatiando -no--upgrade--xy     (something along those lines, cant find it now :) )

I am using jupyter notebooks and it says python 2 at the top right. But no explicit version.
I have a windows 10 OS.

I tried some of the cookbook codes and they worked, so i thought my installation is fine.

### Leonardo Uieda

Mar 28, 2019, 2:15:06 PM3/28/19
Thanks for the info.
It's good that you're using Anaconda. That makes things easier.

Could you please try the following:

1. Run this command to create a new conda environment with Python 2.7:   conda create --name fatiando python=2.7
2. Activate the environment:   conda activate fatiando
3. Install Fatiando from conda-forge:   conda install fatiando -c conda-forge

Creating an environment allows you to install things without impacting your main Anaconda install (like a sandbox).
Whenever you want to run a terminal using your environment, call "conda activate fatiando" to switch to that environment before running your code.
If you're using jupyter, the new environment should appear under the "Kernel -> Change kernel" options so you can run the notebook inside the environment.

Hope this helps,

Leo

--
Leonardo Uieda

Visiting Research Scholar
Department of Earth Sciences - SOEST
University of Hawai'i at Mānoa
www.leouieda.com

--

### hans joachim

Mar 28, 2019, 2:31:57 PM3/28/19
to Fatiando a Terra
Thank you. Now i get this error:

`---------------------------------------------------------------------------NameError                                 Traceback (most recent call last)<ipython-input-1-49384435cd87> in <module>()    963 # object = [100, 100,area, shape, 1, 25, 0]    964 # source =  MexHatSource(object)--> 965 sources = [`~fatiando.seismic.wavefd.MexHatSource`]    966     967 #     * stations : None or listNameError: name 'fatiando' is not defined`

Under  "Kernel -> change Kernel" the only option is "PYthon 2".

i opened a anaconda command line.
then "activate fatiando", then opened the notebook from there.

Other than that, i just copied the entire code given on this page: http://www.fatiando.org/v0.2/_modules/fatiando/seismic/wavefd.html#elastic_psv

### Leonardo Uieda

Mar 28, 2019, 2:52:38 PM3/28/19
If you open the notebook from the environment then you don't need to change kernel.
This is only if you're running the notebook from outside the environment.

Why did you copy the function code?

Also, please pay close attention to the version of fatiando and the documentation.
The version you installed from conda-forge is 0.5 but you're looking at documentation for 0.2, so naturally things wouldn't work exactly the same.
There are some example scripts in the cookbook: https://www.fatiando.org/v0.5/cookbook.html#seismology-and-seismics

Be aware that the seismic modeling code is experimental and poorly tested so I wouldn't recommend using this for serious research.

--
Leonardo Uieda

Visiting Research Scholar
Department of Earth Sciences - SOEST
University of Hawai'i at Mānoa
www.leouieda.com

--