Hello! I’m trying to determine peircing points using rf. I’m new to python and I’m not quite sure I understood the doc correctly. Can anyone help me out?
Here’s my code:
from rf import read_rf
stream = read_rf('ev1.SAC')
stream.ppoints(50,'P')
Here’s the error:
C:\Users\Maureen\anaconda3\lib\site-packages\obspy\core\trace.py:220: UserWarning: Calibration factor set to 0.0!
warnings.warn(msg, UserWarning)
Traceback (most recent call last):
File "C:\Users\Maureen\Documents\M1 Stage\Python\PyTauP_test.py", line 11, in <module>
stream.ppoints(50,'P')
File "C:\Users\Maureen\anaconda3\lib\site-packages\rf\rfstream.py", line 391, in ppoints
model.ppoint(tr.stats, pp_depth, phase=pp_phase)
File "C:\Users\Maureen\anaconda3\lib\site-packages\rf\simple_model.py", line 229, in ppoint
dr = self.ppoint_distance(depth, stats['slowness'], phase=phase)
File "C:\Users\Maureen\anaconda3\lib\site-packages\obspy\core\trace.py", line 235, in __getitem__
return super(Stats, self).__getitem__(key, default)
File "C:\Users\Maureen\anaconda3\lib\site-packages\obspy\core\util\attribdict.py", line 74, in __getitem__
return self.__dict__[name]
KeyError: 'slowness'
To calculate the piercing point the slowness of the ray has to be known.
Can you upload your file ev1.SAC or post the output of print(stream[0].stats)?
Thanks for your answer. Ok, I thought that the module was using as input iasp97 (or something like that ) as a velocity model I’ve uploaded the file. But it seems that I have a problem because now I get an error “no module named rf” when I run the previous code… I’m the right environment but something’s wrong and I can’t understand why…When I run conda activate rfenv, sets path for LIB and CPATH or does this mean that I missed a step in the installation process? I’m using spyder as python interpreter.
Yes the iasp model is used by default, but to calculate piercing points you need to know something about the incoming ray.
I think when you want to use rf in spyder, you need to install rf into the same environment spyder is installed in. You can check the installed packages with conda list.
It’s weird because it was working fine with spyder until now… Anyway is the slowness vp/vs? I used TauP once and I don’t remember entering any slowness parameter…
I do not see rf in the list of installed packages.
Everything does nicely work with your provided file. You just have to calculate the slowness with the rfstats function:
from rf import read_rf, rfstats
s = read_rf('ev1.SAC')
rfstats(s)
s.ppoints(50)
Please take some time and find out what this slowness is about. It’s not the vp/vs ratio, but the ray parameter. If you have no resource at hand, in the rf doc you will find a link to a dissertation with some information about receiver functions.
OK, you were right, I reinstalled and now it works! Thank you so much for your help😀! Just a quick question, is it possible to make loop in order to have all the events done at the same time?
Sorry to bother you again but I tried to put a pathname to read all the sac files but I get an error “permission denied”. I tried to find a way to join my sac files into one through ObsPy but I can’t find it either… I’m a little lost…
Hi! it’s me again: I tried to import all my files with glob using two methods but none of them seems to be working. One returns only 9 piercing points out of
77 and with the wrong coordinates and the other returns an empty array… Here’s the codes for both methods:
method A:
e=[]
from rf import read_rf, rfstats
import os, glob
folder_path='Users\Maureen\Documents\M1 Stage\Python\LN14'
for filename in glob.glob(os.path.join(folder_path,'*.SAC')):
with open(filename, 'r') as f:
s =read_rf()
rfstats(s)
e.append(s.ppoints(50,'P'))
print(e)
return : []
I know those coordinates are wrong because the station is located in Tanzania and those points are not… I’m leaning towards a problem using glob: the program works for one event… Do you know if I can use an ascii file or a .txt file or use pandas? I built a txt file with pandas that contains backazimut and the distance between the event and the station, and I seem to remember that TauP was capable of finding the piercing points with those parameters…
Even when I use file and filename it doesn’t work… It’s problem with the pathname… The quickest solution was to work in the directory😊
Thanks for your help