obspy icon indicating copy to clipboard operation
obspy copied to clipboard

Access violation when using ar_pick algorithm

Open Quernon opened this issue 5 years ago • 7 comments

I am getting the following intermittent error when trying to implement the ar_pick algorithm. The location given sometimes varies but always occurs when trying to implement ar_pick.

OSError: exception: access violation reading 0x000001638B06DFFC

The call to the ar_pick algorithm is pasted below. I have put this in a class hence 'self.'. The class is passed trace_numbers as a list containing three integers as this can vary from sensor to sensor.

self.p_pick, self.s_pick = ar_pick(self.z_stream[trace_numbers[0]].data, self.n_stream[trace_numbers[1]].data, self.e_stream[trace_numbers[2]].data, self.sampling_rate, f1=1.5, f2=30.0, lta_p=0.4, sta_p=0.1, lta_s=1.5, sta_s=0.1, m_p=2, m_s=8, l_p=0.1, l_s=0.2, s_pick=True)

This is occurring on Windows 10 under an Anaconda environment which is running python 3.7. Any help on this would be much appreciated.

Quernon avatar Jun 23 '20 13:06 Quernon

I'd appreciate someone with more C-fu -- especially C-debugging-fu -- than me looking into this

megies avatar Jun 25 '20 13:06 megies

Would be difficult without a complete example.

QuLogic avatar Jun 25 '20 22:06 QuLogic

Oh yeah. Good point. xD

megies avatar Jun 26 '20 11:06 megies

This is the class I've made for to house all the sensor data. The error occurs when this class is called to create a sensor object.

# Sensor class 
class Sensor:
    def __init__(self, sensor_name, suffixes, sensor_coords, folder, trace_numbers, gain, cal_val, pick_routine):
        self.sensor_name = sensor_name
        self.sensor_coords = sensor_coords[sensor_name]
        self.angle = coord_to_angle(blast_coords, self.sensor_coords)
        self.distance = coord_to_distance(sensor_coords['Sensor C'], self.sensor_coords)
        
        # Define data location and load stream
        print('Reading sensor data for:', sensor_name)
        self.z_stream = read_sensor(self.sensor_name, suffixes[0], folder)
        print(self.z_stream)
        self.n_stream = read_sensor(self.sensor_name, suffixes[1], folder)
        print(self.n_stream)
        self.e_stream = read_sensor(self.sensor_name, suffixes[2], folder)
        print(self.e_stream)
        self.sampling_rate = self.z_stream[0].stats.sampling_rate
        
        # Slice streams to start_time and end_time as defined at top of script
        self.z_stream = self.z_stream.slice(start_time_utc, end_time_utc)
        self.n_stream = self.n_stream.slice(start_time_utc, end_time_utc)
        self.e_stream = self.e_stream.slice(start_time_utc, end_time_utc)
        
        # Apply gain and calibration values to each stream and apply bandpass
        print('Applying gain and calibration values for: ', sensor_name)
        for trace in self.z_stream:
            trace.data = trace.data * cal_val[0] / gain[0]
            trace.data = bandpass(trace.data, freqmin=1.5, freqmax=30.0, df=self.sampling_rate, corners=4, zerophase=True)
        for trace in self.n_stream:
            trace.data = trace.data * cal_val[1] / gain[1]
            trace.data = bandpass(trace.data, freqmin=1.5, freqmax=30.0, df=self.sampling_rate, corners=4, zerophase=True)
        for trace in self.e_stream:
            trace.data = trace.data * cal_val[2] / gain[2]
            trace.data = bandpass(trace.data, freqmin=1.5, freqmax=30.0, df=self.sampling_rate, corners=4, zerophase=True)
        
        # Rotate data for n and e traces
        print('Applying deterministic rotation to sensor: ', sensor_name)
        rotate_ne_rt(self.n_stream[trace_numbers[1]].data, self.e_stream[trace_numbers[2]].data, degrees(self.angle))
             
        # Use obspy automatic regression algorithm to determine p-wave and s-wave arrivals if pick_routine == ar_pick
        if pick_routine == 'ar_pick':
            print('Attempting ar_pick picking for sensor: ', sensor_name)
            self.p_pick, self.s_pick = ar_pick(self.z_stream[trace_numbers[0]].data, 
                                               self.n_stream[trace_numbers[1]].data, 
                                               self.e_stream[trace_numbers[2]].data, 
                                               self.sampling_rate, f1=1.5, f2=30.0, 
                                               lta_p=0.4, sta_p=0.1, lta_s=1.5, sta_s=0.1, 
                                               m_p=2, m_s=8, l_p=0.1, l_s=0.2, s_pick=True)

        # Convert picks to other time formats
        self.p_pick_utc = obspy.core.utcdatetime.UTCDateTime(self.z_stream[trace_numbers[0]].stats.starttime) + self.p_pick
        self.p_pick_plt = self.p_pick_utc.matplotlib_date
        self.s_pick_utc = obspy.core.utcdatetime.UTCDateTime(self.z_stream[trace_numbers[0]].stats.starttime) + self.s_pick
        self.s_pick_plt = self.s_pick_utc.matplotlib_date
        self.start_time_utc = obspy.core.utcdatetime.UTCDateTime(self.z_stream[trace_numbers[0]].stats.starttime) + self.p_pick - 1
        self.end_time_utc = obspy.core.utcdatetime.UTCDateTime(self.z_stream[trace_numbers[0]].stats.starttime) + self.s_pick + 5
        self.start_time_plt = self.start_time_utc.matplotlib_date
        self.end_time_plt = self.end_time_utc.matplotlib_date
        print('Picking complete.', self.p_pick_utc, self.s_pick_utc)

I hope that helps. I'm a novice to Python in general and classes in particular. Let me know if there's any other info I could be providing.

One thing that might be worth mentioning is that the .gcf and .mseed files I'm trying to read are often on a network drive rather than my local machine.

Quernon avatar Jun 26 '20 14:06 Quernon

Nah, we would just need the input waveform data and the ar_pick call with the exact options on it to reproduce.

megies avatar Jun 26 '20 14:06 megies

so something like..

st = read("my_file")
ar_pick(st[0], st[1], st[2], ....)

showing the error and also having the actual waveform for it

megies avatar Jun 26 '20 14:06 megies

This issue has been mentioned on ObsPy Forum. There might be relevant details there:

https://discourse.obspy.org/t/trigger-ar-pick/1398/2

obspy-bot avatar Apr 12 '22 10:04 obspy-bot