Skip to content

Commit 6599839

Browse files
committed
Changed some hard_coded values to parameters + general changes
1 parent 456fa35 commit 6599839

File tree

1 file changed

+24
-21
lines changed

1 file changed

+24
-21
lines changed

dedisperse/dedisperse.py

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
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
10+
The maximum_delay specifies between the currently considered pulsar signal and the next pulsar
11+
signal should be
12+
The highest_x specifies the amount of intensities that are used for estimating the minimum
13+
pulsar intensity
1214
'''
1315

1416
# Check if parameters contain a DM, if not, estimate one
@@ -42,15 +44,16 @@ def find_dm(samples, pulsar_intensity, max_delay):
4244
# Loop through the samples to find a pulsar intensity to start calculating from
4345
for s, sample in enumerate(samples[:, 0]):
4446

45-
# If the sample meets the minimum intensity, attempt to find a line continuing from this intensity
46-
if(sample > pulsar_intensity):
47+
# If the sample meets the minimum intensity, attempt to find a line continuing from
48+
# this intensity
49+
if sample > pulsar_intensity:
4750
start_sample_index = s
4851

49-
# Attempt to find a line, line_coordinates contains the first and last index of the pulsar
52+
# Attempt to find a line, line_coordinates contains first and last index of the pulsar
5053
line_coordinates = find_line(samples, start_sample_index, max_delay, pulsar_intensity)
51-
54+
5255
# If a line is found, calculate and return the dispersion measure
53-
if(line_coordinates is not None):
56+
if line_coordinates is not None:
5457
dm = line_coordinates[1] - line_coordinates[0]
5558
return dm
5659

@@ -63,42 +66,42 @@ def find_line(samples, start_sample_index, max_delay, pulsar_intensity):
6366
it stops if there is no intensity within the max_delay higher than the average_intensity
6467
'''
6568

66-
previous_sample_index = start_sample_index
69+
previous_index = start_sample_index
6770

6871
failed_to_find_line = True
6972

7073
# Loop through the frequencies
71-
for f, frequency in enumerate(samples[1]):
74+
for f, _ in enumerate(samples[1]):
7275

7376
# Loop through previous intensity until the max delay is reached
74-
for i, intensity in enumerate(samples[:, f][previous_sample_index:previous_sample_index + max_delay]):
77+
for i, intensity in enumerate(samples[:, f][previous_index:previous_index + max_delay]):
7578

76-
# Skip the first frequency, since that is where the initial sample is we are measuring from
77-
if(f == 0):
79+
# Skip the first frequency, since we start measuring from the first intensity
80+
if f == 0:
7881
failed_to_find_line = False
7982
break
8083

8184
# If the intensity is higher than the pulsar_intensity, continue finding a signal
82-
if(intensity > pulsar_intensity):
83-
previous_sample_index = previous_sample_index + i
85+
if intensity > pulsar_intensity:
86+
previous_index = previous_index + i
8487
failed_to_find_line = False
8588
break
8689

8790
# If there is no line found, return None
88-
if failed_to_find_line:
91+
if failed_to_find_line:
8992
return None
9093

91-
# If all frequencies are looped through, a line is found, so we return the start and end index of the line
92-
return start_sample_index, previous_sample_index
93-
94+
# If all frequencies are looped, a continuous signal is found,
95+
# so we return the first and last index of the line
96+
return start_sample_index, previous_index
9497

9598
def find_estimation_intensity(samples, highest_x):
9699
'''
97100
This method finds the average intensity for the highest x intensities
98-
The average_intensity is considered a requirement for intensities to be considered a pulsar
101+
The average_intensity is considered a requirement for intensities to be considered a pulsar
99102
'''
100103

101-
# Sum of all intensitiesg
104+
# Sum of all intensities
102105
sum_intensities = 0
103106

104107
# Looks for the top x highest intensities in the samples and adds them up together
@@ -108,4 +111,4 @@ def find_estimation_intensity(samples, highest_x):
108111
# Calculates the average_intensity
109112
average_intensity = (sum_intensities) / (samples.shape[0] * highest_x)
110113

111-
return average_intensity
114+
return average_intensity

0 commit comments

Comments
 (0)