This code snippet shows how to use the provided API to perform event recordings from a Geiger counter which output is fed through the sound card of a computer
%matplotlib inline
import matplotlib.pyplot as plt
from counter import Recorder
First decide which will the input device (can be a simple microphone, or the Geiger counter audio jack)
Recorder.list_devices()
[u'Built-in Microph', u'Built-in Output', u'Aggregate Device']
Instantiate the Recorder object, 1 channel, sampling rate at 44100Hz, recording buffer at 1024 events, input device is Built-in Microph
recorder = Recorder(channels=1,rate=44100,frames_per_buffer=1024,input_device_index=0)
Record for 5 seconds and display the waveform
recorder.record(5)
recorder.visualize()
[+] Started recording on Built-in Microph, channels=1, rate=44100, frames per buffer=1024 [-] Stopped recording
Record for 5 seconds, and trigger on a raising slope above $y=0.1$
fig,ax = plt.subplots()
t,y = recorder.record_above_threshold(5,threshold=0.1,slope="raising",save_waveform=True)
recorder.visualize(fig=fig,ax=ax)
recorder.ax.scatter(t,y,color="red")
[+] Started recording on Built-in Microph, channels=1, rate=44100, frames per buffer=1024 [-] Stopped recording [+] Found 15 events on raising threshold=1.00e-01
<matplotlib.collections.PathCollection at 0x10881f6d0>
The timings of the above threshold events (in seconds) are saved in the variable $t$
t
array([ 1.34606379, 1.34642752, 1.34690491, 1.34735957, 1.34783696, 1.34829162, 3.29455091, 3.2948919 , 3.29498284, 3.2953011 , 3.29557389, 3.29605129, 3.29648321, 3.29684694, 3.2968924 ])
You can also run the whole recording pipeline automatically: you just have to specify your preferences in a configuration file (or use the default one if you wish)
cat config
[counter] num_channels = 1 rate = 44100 frames_per_buffer = 1024 recording_time = 5 [output] events_file = events.txt save_full_waveform = True
run geiger.py
[*] Reading configuration from config: [+] Number of channels: 1 [+] Acquisition rate: 44100Hz [+] Frame buffer size: 1024 Enter the recording time in seconds (5.0s) --> 5.0 [+] Recording time set to 5.0s [*] Select a recording device (0-2) among: 0: Built-in Microph 1: Built-in Output 2: Aggregate Device -->0 [+] Selected device 0: Built-in Microph [*] Select a threshold: 0.01 [+] Threshold set to 1.00e-02 [*] Select a triggering slope (raising, descending): raising [+] Slope set to raising [+] According to the configuration, you want to save the whole waveform [*] Select a file to write the whole waveform to: waveform_environment.npy [+] The full waveform will be saved to: waveform_environment.npy [*] Press <enter> to start recording: [+] Started recording on Built-in Microph, channels=1, rate=44100, frames per buffer=1024 [-] Stopped recording [+] Found 4 events on raising threshold=1.00e-02 [*] Specify a file on which to save the events (events.txt) -->counts_environment.txt [+] Saving events to counts_environment.txt [+] Saving full waveform (t,y) to waveform_environment.npy [*] Do you want to plot the waveform? (y/n)y [+] Plotting waveform to waveform_environment.png [-] Event recording complete, bye
And here is the log of the events above threshold
cat counts_environment.txt
1.452067562345131568e+00 1.453567937438905000e+00 1.468276159949078119e+00 3.234831435131510169e+00