Skip to content

Commit 16cd51c

Browse files
committed
Changed some hard_coded values to parameters + general changes
1 parent dbfa8d7 commit 16cd51c

File tree

2 files changed

+33
-42
lines changed

2 files changed

+33
-42
lines changed

dedisperse/dedisperse.py

Lines changed: 19 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
'''
2-
Dedisperses data
2+
Dedisperses data
33
'''
44
# pylint: disable-msg=C0103
55
import numpy as np
66

7-
def dedisperse(samples, dm=None):
7+
def dedisperse(samples, highest_x=None, max_delay=None, dm=None):
88
'''
99
This method performs dedispersion on the filterbank data
10+
The maximum_delay specifies between the currently considered pulsar signal and the next pulsar signal should be
11+
The highest_x specifies the amount of intensities that are used for estimating the minimum pulsar intensity
1012
'''
1113

1214
# Check if parameters contain a DM, if not, estimate one
1315
if dm is None:
14-
print("Finding possible DM's")
15-
dm = find_dm(samples)
16+
# Estimates the minimum for an intensity to be considered a pulsar
17+
pulsar_intensity = find_estimation_intensity(samples, highest_x)
18+
dm = find_dm(samples, pulsar_intensity, max_delay)
1619

1720
# Distribute the DM over the amount of samples
1821
delays_per_sample = np.round(np.linspace(dm, 0, samples.shape[1])).astype(int)
@@ -31,42 +34,30 @@ def dedisperse(samples, dm=None):
3134

3235
return samples
3336

34-
def find_dm(samples):
37+
def find_dm(samples, pulsar_intensity, max_delay):
3538
'''
3639
This method attempts to find a dispersion measure
3740
'''
38-
39-
# Estimates the minimum for an intensity to be considered a pulsar
40-
pulsar_intensity = find_estimation_intensity(samples)
41-
42-
# Determine what the maximum delay between the currently considered pulsar signal
43-
# and the next pulsar signal should be
44-
max_delay = round(samples.shape[0] / 50)
45-
46-
print(max_delay)
47-
48-
#max_delay = 100
49-
50-
# Loop through the samples to find
41+
42+
# Loop through the samples to find a pulsar intensity to start calculating from
5143
for s, sample in enumerate(samples[:, 0]):
5244

5345
# If the sample meets the minimum intensity, attempt to find a line continuing from this intensity
5446
if(sample > pulsar_intensity):
5547
start_sample_index = s
56-
#print("\n\nAttempting to find line on freq,", 0, "sample", s)
48+
5749
# Attempt to find a line, line_coordinates contains the first and last index of the pulsar
5850
line_coordinates = find_line(samples, start_sample_index, max_delay, pulsar_intensity)
5951

6052
# If a line is found, calculate and return the dispersion measure
6153
if(line_coordinates is not None):
6254
dm = line_coordinates[1] - line_coordinates[0]
63-
print(dm)
6455
return dm
65-
56+
6657
return None
6758

6859

69-
def find_line(samples, start_sample_index, max_delay, average_intensity):
60+
def find_line(samples, start_sample_index, max_delay, pulsar_intensity):
7061
'''
7162
This method tries to find a line starting from the sample index given in the parameters
7263
it stops if there is no intensity within the max_delay higher than the average_intensity
@@ -76,7 +67,6 @@ def find_line(samples, start_sample_index, max_delay, average_intensity):
7667

7768
failed_to_find_line = True
7869

79-
8070
# Loop through the frequencies
8171
for f, frequency in enumerate(samples[1]):
8272

@@ -88,40 +78,34 @@ def find_line(samples, start_sample_index, max_delay, average_intensity):
8878
failed_to_find_line = False
8979
break
9080

91-
# If the intensity is higher than the average_intensity, continue finding a signal
92-
if(intensity > average_intensity):
93-
#print("Continuing to find line on freq,", f, "sample", previous_sample_index + i, intensity)
81+
# If the intensity is higher than the pulsar_intensity, continue finding a signal
82+
if(intensity > pulsar_intensity):
9483
previous_sample_index = previous_sample_index + i
9584
failed_to_find_line = False
9685
break
9786

9887
# If there is no line found, return None
9988
if failed_to_find_line:
100-
print(average_intensity)
10189
return None
10290

10391
# If all frequencies are looped through, a line is found, so we return the start and end index of the line
10492
return start_sample_index, previous_sample_index
10593

10694

107-
def find_estimation_intensity(samples):
95+
def find_estimation_intensity(samples, highest_x):
10896
'''
109-
This method finds the average intensity for top x intensities
97+
This method finds the average intensity for the highest x intensities
11098
The average_intensity is considered a requirement for intensities to be considered a pulsar
11199
'''
112100

113101
# Sum of all intensities
114102
sum_intensities = 0
115103

116-
# Top x intensities used to estimate
117-
#top = round((samples.shape[0]) / 50)
118-
top = 10
119-
120104
# Looks for the top x highest intensities in the samples and adds them up together
121105
for sample in samples:
122-
sum_intensities += np.sum(sorted(sample, reverse=True)[:top])
106+
sum_intensities += np.sum(sorted(sample, reverse=True)[:highest_x])
123107

124108
# Calculates the average_intensity
125-
average_intensity = (sum_intensities) / (samples.shape[0] * top)
109+
average_intensity = (sum_intensities) / (samples.shape[0] * highest_x)
126110

127111
return average_intensity

examples/dedisperse_stream.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,27 @@
1818

1919
from clipping import clipping
2020

21-
# Read filterbank data
21+
# Read filterbank data,
2222

2323
# Standard file
24-
#special_pspm = fb.Filterbank(filename = "../data/my_special_pspm.fil")
24+
special_pspm = fb.Filterbank(filename = "../data/my_special_pspm.fil")
25+
highest_x=10
26+
max_delay=10
2527

2628
# Files with low signal to noise ratio
27-
#special_pspm = fb.Filterbank(filename = "../data/new_pspm_2.fil")
28-
#special_pspm = fb.Filterbank(filename = "../data/my_uber_pspm.fil")
29+
# special_pspm = fb.Filterbank(filename = "../data/my_uber_pspm.fil")
30+
# highest_x=10
31+
# max_delay=10
2932

3033
# File with 10000 samples
31-
#special_pspm = fb.Filterbank(filename = "../data/pspm_4_2.fil")
34+
# special_pspm = fb.Filterbank(filename = "../data/pspm_4_2.fil")
35+
# highest_x=10
36+
# max_delay=100
3237

3338
# File with 10000 samples with low signal to noise ratio
34-
#special_pspm = fb.Filterbank(filename = "../data/pspm_4_1.fil")
39+
# special_pspm = fb.Filterbank(filename = "../data/pspm_4_1.fil")
40+
# highest_x=10
41+
# max_delay=100
3542

3643
special_pspm.read_filterbank()
3744

@@ -62,7 +69,7 @@
6269
plt.show()
6370

6471
# Dedisperse the samples
65-
samples = dedisperse.dedisperse(samples)
72+
samples = dedisperse.dedisperse(samples, highest_x, max_delay)
6673

6774
# Plot the dedispersed data
6875
plt.subplot(2,1,1)

0 commit comments

Comments
 (0)