A package for filtering triggers from radio astronomical matched template pulse searches.
Project description
astro-trigger-filter
A Python package for filtering radio astronomical pulse matched template searches.
Installation
pip install astro-trigger-filter
Basic Usage
Generate a set of random triggers:
import random
N = 1000
start_times = [random.uniform(0.0, 1.0) for _ in range(N)]
widths = [random.uniform(0.00, 0.01) for _ in range(N)]
DMs = [random.uniform(0.0, 100.0) for _ in range(N)]
SNRs = [random.uniform(5.0, 10.0) for _ in range(N)]
triggers = [t for t in zip(start_times, widths,DMs, SNRs)]
Make sure the list is sorted on start time. Aditional reverse sorting on DM will improve the effiency.
triggers.sort(key=lambda tup: (tup[0], -tup[2]))
Now filter the triggers:
from astrotf.radio_pulse import RadioPulseFilterGen
gen = RadioPulseFilterGen(freq_lo_mhz=1249.8, freq_hi_mhz=1549.8)
for filtered_trigger in gen(triggers):
print(filtered_trigger)
Print statistics:
print('Reduced the number of triggers from {} to {}'.format(
gen.num_in,
gen.num_out
))
Processing Pandas Dataframes
Generate a pandas dataframe with random triggers:
import pandas as pd
import random
triggers = pd.DataFrame(
[
[
random.uniform(0.0, 1.0),
random.uniform(0.0, 0.01),
random.uniform(0.0, 100.0),
random.uniform(5.0, 10.0)
]
for _ in range(N)
],
columns=['t', 'w', 'DM', 'SNR']
)
..or read a csv file from disk:
triggers = pd.read_csv('triggers.txt', delim_whitespace=True)
Sort time increasing, then DM descending, then pulse-width descending:
triggers.sort_values(
by=['t', 'DM', 'w'],
ascending=[True, False, False],
inplace=True
)
Filter and print the triggers:
gen = RadioPulseFilterGen(freq_lo_mhz, freq_hi_mhz)
for filtered_trigger in gen(
(e.t, e.w, e.DM, e.SNR)
for e in triggers.itertuples()
):
print(filtered_trigger)
Storing extra data along each trigger
You can add extra data for each trigger, as long as the first 4 elements remain [time, width, dispersion measure, signal-to-noise ratio
]. In the example below we have added a beam_id
and sample_id
. These extra columns will show up again in the filtered output.
for filtered_trigger in gen(
(
e.time,
e.w,
e.DM,
e.SNR,
e.beam_id,
e.sample_id
)
for e in triggers.itertuples()
):
print(filtered_trigger)
More settings
buffersize=0
: Limit the buffer size. The default setting is 0 which means an unlimited buffer size. A buffer size of 25 speeds up filtering while only generating marginally more false triggers.
autoflush=True
: Automatically flush the internal buffer when finished processing the input trigger. Set this to false
if you want to process triggers in chunks and not flush the buffers between each chunk.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for astro-trigger-filter-0.1.12.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34dfa83c788753c9ad2ecf97f8cdc1cc8e184d9022d2ff0ae3b15736c3db884b |
|
MD5 | 7f32d4526acf61d5f859bcd04872aede |
|
BLAKE2b-256 | f92c2bb4aa591401445a70f800d743486832e98b78cdd5c21794e02d24070e80 |
Hashes for astro_trigger_filter-0.1.12-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cf6282668fb911064728e51326de6c2b90703a5de4706af365b067a3fc370439 |
|
MD5 | 0ac3b22a7edfc21730d9453c44d1f4b4 |
|
BLAKE2b-256 | a418b3096b8777a6c4f204d011eb9133b1c37147b7445b3a2933d011af280c67 |