@@ -50,15 +50,7 @@ def estimate_dm(samples):
5050 break
5151
5252 highest_difference = 0
53- '''
54- for s, samples in enumerate(samples):
55- for i, data_point in enumerate(samples):
56- if(i > highest_difference):
57- if(data_point > 10):
58- print(s, i, " - ", data_point)
59- highest_difference = i
60- break
61- '''
53+
6254 estimated_dm = last_sample [1 ] - initial_signal_point [1 ]
6355 print ("Estimated DM is" , estimated_dm )
6456 return estimated_dm
@@ -78,12 +70,7 @@ def find_initial_signal(samples):
7870 if (data_point > 5 ):
7971 print ("Initial signal found on freq, sample" , i , j , data_point )
8072 return i , j
81- '''
82- print(lowest_sample, " ", j)
83- lowest_sample = i, j
84- break
85- '''
86-
73+
8774 print ("NO INITIAL SIGNAL FOUND" )
8875 return None
8976
@@ -101,58 +88,64 @@ def find_initial_line(samples):
10188 start_sample_index = s
10289 print ("Attempting to find line on freq," , 0 , "sample" , s )
10390 line_coordinates = find_line (samples , start_sample_index , max_delay , avg_intensity )
91+
92+ # If a line is found, calculate and return the dispersion measure
10493 if (line_coordinates is not None ):
10594 dm = line_coordinates [1 ] - line_coordinates [0 ]
10695 print (dm )
10796 return dm
10897
109-
110-
11198 return None
11299
113100
114101def find_line (samples , start_sample_index , max_delay , avg_intensity ):
115-
102+ '''
103+ This method tries to find a line starting from the sample index given in the parameters
104+ it stops if there is no intensity within the max_delay higher than the avg_intensity
105+ '''
106+
116107 previous_sample_index = start_sample_index
117- break_freq_loop = True
118- break_samples_loop = False
108+ failed_to_find_line = True
119109
110+ # Loop through the frequencies
120111 for f , frequency in enumerate (samples [1 ]):
112+
113+ # Loop through previous intensity until the max delay is reached
121114 for i , intensity in enumerate (samples [:, f ][previous_sample_index :previous_sample_index + max_delay ]):
115+
116+ # Skip the first frequency, since that is where the initial sample is we are measuring from
122117 if (f == 0 ):
123- break_freq_loop = False
118+ failed_to_find_line = False
124119 break
125- #print(previous_sample_index, previous_sample_index+max_delay)
120+
121+ # If the intensity is higher than the avg_intensity, continue finding a signal
126122 if (intensity > avg_intensity ):
127123 print ("Continuing to find line on freq," , f , "sample" , previous_sample_index + i , intensity )
128124 previous_sample_index = previous_sample_index + i
129- break_freq_loop = False
130- break_samples_loop = True
125+ failed_to_find_line = False
131126 break
132127
133- if break_freq_loop :
134- break
135-
136- if break_freq_loop :
137- print ("Failed to find line" )
128+ # If there is no line found, return None
129+ if failed_to_find_line :
138130 return None
139131
140- print ( "All freqs are looped" )
132+ # If all frequencies are looped through, a line is found, so we return the start and end index of the line
141133 return start_sample_index , previous_sample_index
142134
143-
144135
145136def find_avg_intensity (samples , top = 10 ):
146137 '''
147- Finds average intensity for top x intensities
138+ This method finds the average intensity for top x intensities
139+ The avg_intensity is considered a requirement for intensities to be considered a pulsar
148140 '''
149141
150142 sum_intensities = 0
151- # Looks for the 3 highest intensities in the first 10 samples
143+
144+ # Looks for the top x highest intensities in the samples and adds them up together
152145 for sample in samples :
153- #top_samples.append((sorted([(x,i) for (i,x) in enumerate(sample)], reverse=True)[:3] ))
154146 sum_intensities += np .sum (sorted (sample , reverse = True )[:top ])
155147
148+ # Calculates the avg_intensity
156149 avg_intensity = (sum_intensities ) / (samples .shape [0 ] * top )
157150
158- return ( avg_intensity )
151+ return avg_intensity
0 commit comments