Dear Obspy users;

I have a problem trying to use the polarization algorithm from obspy. When I run polarization.eigval, I get an error:

Traceback (most recent call last):
  File "./pol.py", line 44, in <module>
  File "./pol.py", line 31, in main
    pol = polarization.eigval(trz,trn,tre,fk,1)
  File "/Applications/ObsPy.app/Contents/MacOS/lib/python2.7/site-packages/obspy/signal/polarization.py", line 57, in eigval
    leigenv1 = np.zeros(datax.shape[0], dtype='float64')
AttributeError: 'Trace' object has no attribute 'shape'

I am reading a three component sac file and the error says that the object (the trace) have no shape attribute, a numpy data attribute. How do I fix this problem, what do I have to do to the data in order to give it a shape attribute ?

I am adding the piece of code I am trying to execute.

pol.py (1.04 KB)

Hi Javier,

eigval expects the data as input not traces. The line in your code should be

pol = polarization.eigval(trz.data,trn.data,tre.data,fk,1)

Hope it helps,

Hi Javier,

you need to pass numpy arrays instead of obspy.core.Trace objects to the eigenvalue function.

  pol = polarization.eigval(trz,trn,tre,fk,1)
  pol = polarization.eigval(trz.data,trn.data,tre.data,fk,1)

Should do the trick. Take care of the component orientation!



Dear users;

I am using the polarization function from the signal package of Obspy
I get the eigen values, rectiliniarity and planarity.

What I need is azimuth and incoming angle. For such functions I need the eigen functions. Is there a way of getting the eigen functions from polarization.eigval ?
Does any body has an example of how to get azimuth and incoming angle from polarization.eigval

Thank you in advance for your help

Javier Fco. Pacheco

Dear Javier

by accident I needed the same functionality.
You can use function "polar" from
https://github.com/trichter/sito/blob/master/rf.py and adapt it to
your needs. At the moment it computes azimuth and incidence angle
averaging over the input data. Please test if it works as you expect.

Cheers, Tom

Dear all,

I'm just testing an extended version of the polarization modul in obspy:
this will include Flinn's method as well as a modified version of Vidale
(1986) (adapted window selection) as well as a simple computation of the
particle motion vector. The output will be azimuth/incidense and various
linearity values. You can check out using:


It still needs some polishing (so it needs a few more days) but seems to
work in most cases.

Cheers Jo

Thanks a lot Tom


Javier Fco. Pacheco

Great !

I use the new polarization.py and works fine, but I could not find out how do you get an array out of the function:

pol = vidaleAdapt(stream, noise_thres, fs, flow, fhigh, spoint, stime, etime)

I had to change the output of vidaleAdapt to get an np array. But I would like to know how to get from the variable pol, an array I can plot, say the azimuth or the rectiliniarity

Thank you for your help;

Javier Fco. Pacheco

Hi Javier,

you call the different methods via the module polarizationAnalysis. I
attach a python script which gets the traces (in your case prop. reading
form file), prepares the rest and does the plotting - hope that works
for you....

seishub-3C-analysis.py (4.88 KB)

Hi all,

if anybody could at some point make a short example (also usable as a
test case) for the ObsPy Tutorial (as basic as possible, probably using
the example data using read()) with a plot at the end -- that would be

Also, these new routines are not yet merged into master, so they might
still change a bit.. Have a look at the corresponding pull request to
stay up to date: https://github.com/obspy/obspy/pull/505