Skip to content

Commit dbfa8d7

Browse files
committed
changes`
1 parent 8b0bba4 commit dbfa8d7

File tree

3 files changed

+54
-66
lines changed

3 files changed

+54
-66
lines changed

dedisperse/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
"""
22
import file for dedisperse.py
33
"""
4-
from .dedisperse import dedisperse, estimate_dm, find_initial_signal, find_initial_line
4+
from .dedisperse import dedisperse, find_dm

dedisperse/dedisperse.py

Lines changed: 35 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ def dedisperse(samples, dm=None):
99
This method performs dedispersion on the filterbank data
1010
'''
1111

12+
# Check if parameters contain a DM, if not, estimate one
1213
if dm is None:
1314
print("Finding possible DM's")
14-
dm = find_initial_line(samples)
15+
dm = find_dm(samples)
1516

1617
# Distribute the DM over the amount of samples
1718
delays_per_sample = np.round(np.linspace(dm, 0, samples.shape[1])).astype(int)
@@ -30,64 +31,31 @@ def dedisperse(samples, dm=None):
3031

3132
return samples
3233

33-
34-
def estimate_dm(samples):
34+
def find_dm(samples):
3535
'''
3636
This method attempts to find a dispersion measure
3737
'''
38-
39-
# Tuple of frequency index and sample index
40-
initial_signal_point = find_initial_signal(samples)
41-
last_sample = initial_signal_point
42-
43-
for i, frequency in enumerate(samples[1]):
44-
for j, data_point in enumerate(samples[:, i]):
45-
#print(samples[:, i][previous_time_sample:].shape[0])
46-
if(j > last_sample[1]):
47-
if(data_point > 10):
48-
last_sample = i, j
49-
print("At Frequency ", i, " found on Time sample ", j, " - ", data_point)
50-
break
51-
52-
highest_difference = 0
5338

54-
estimated_dm = last_sample[1] - initial_signal_point[1]
55-
print("Estimated DM is", estimated_dm)
56-
return estimated_dm
57-
39+
# Estimates the minimum for an intensity to be considered a pulsar
40+
pulsar_intensity = find_estimation_intensity(samples)
5841

59-
def find_initial_signal(samples):
60-
'''
61-
This method attempts to find a viable data point to start estimating a dispersion measure from
62-
'''
63-
64-
# Tuple of frequency index and sample index
65-
lowest_sample = 0, samples.shape[0]
66-
67-
for i, frequency in enumerate(samples[1]):
68-
for j, data_point in enumerate(samples[:, i]):
69-
if(j < lowest_sample[1]):
70-
if(data_point > 5):
71-
print("Initial signal found on freq, sample", i, j, data_point)
72-
return i, j
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)
7345

74-
print("NO INITIAL SIGNAL FOUND")
75-
return None
76-
77-
78-
def find_initial_line(samples):
79-
'''
80-
This method attempts to find a line to dedisperse
81-
'''
46+
print(max_delay)
8247

83-
avg_intensity = find_avg_intensity(samples, 10)
84-
max_delay = 10
48+
#max_delay = 100
8549

50+
# Loop through the samples to find
8651
for s, sample in enumerate(samples[:, 0]):
87-
if(sample > avg_intensity):
52+
53+
# If the sample meets the minimum intensity, attempt to find a line continuing from this intensity
54+
if(sample > pulsar_intensity):
8855
start_sample_index = s
89-
print("Attempting to find line on freq,", 0, "sample", s)
90-
line_coordinates = find_line(samples, start_sample_index, max_delay, avg_intensity)
56+
#print("\n\nAttempting to find line on freq,", 0, "sample", s)
57+
# Attempt to find a line, line_coordinates contains the first and last index of the pulsar
58+
line_coordinates = find_line(samples, start_sample_index, max_delay, pulsar_intensity)
9159

9260
# If a line is found, calculate and return the dispersion measure
9361
if(line_coordinates is not None):
@@ -98,15 +66,17 @@ def find_initial_line(samples):
9866
return None
9967

10068

101-
def find_line(samples, start_sample_index, max_delay, avg_intensity):
69+
def find_line(samples, start_sample_index, max_delay, average_intensity):
10270
'''
10371
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
72+
it stops if there is no intensity within the max_delay higher than the average_intensity
10573
'''
10674

10775
previous_sample_index = start_sample_index
76+
10877
failed_to_find_line = True
10978

79+
11080
# Loop through the frequencies
11181
for f, frequency in enumerate(samples[1]):
11282

@@ -118,34 +88,40 @@ def find_line(samples, start_sample_index, max_delay, avg_intensity):
11888
failed_to_find_line = False
11989
break
12090

121-
# If the intensity is higher than the avg_intensity, continue finding a signal
122-
if(intensity > avg_intensity):
123-
print("Continuing to find line on freq,", f, "sample", previous_sample_index + i, intensity)
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)
12494
previous_sample_index = previous_sample_index + i
12595
failed_to_find_line = False
12696
break
12797

12898
# If there is no line found, return None
12999
if failed_to_find_line:
100+
print(average_intensity)
130101
return None
131102

132103
# If all frequencies are looped through, a line is found, so we return the start and end index of the line
133104
return start_sample_index, previous_sample_index
134105

135106

136-
def find_avg_intensity(samples, top = 10):
107+
def find_estimation_intensity(samples):
137108
'''
138109
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
110+
The average_intensity is considered a requirement for intensities to be considered a pulsar
140111
'''
141112

113+
# Sum of all intensities
142114
sum_intensities = 0
143115

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

148-
# Calculates the avg_intensity
149-
avg_intensity = (sum_intensities) / (samples.shape[0] * top)
124+
# Calculates the average_intensity
125+
average_intensity = (sum_intensities) / (samples.shape[0] * top)
150126

151-
return avg_intensity
127+
return average_intensity

examples/dedisperse_stream.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,25 @@
1919
from clipping import clipping
2020

2121
# Read filterbank data
22-
special_pspm = fb.Filterbank(filename = "../data/my_uber_pspm.fil")
22+
23+
# Standard file
24+
#special_pspm = fb.Filterbank(filename = "../data/my_special_pspm.fil")
25+
26+
# 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+
30+
# File with 10000 samples
31+
#special_pspm = fb.Filterbank(filename = "../data/pspm_4_2.fil")
32+
33+
# File with 10000 samples with low signal to noise ratio
34+
#special_pspm = fb.Filterbank(filename = "../data/pspm_4_1.fil")
2335

2436
special_pspm.read_filterbank()
2537

2638
frequencies, samples = special_pspm.select_data()
2739

28-
40+
# Plot the original data
2941
plt.subplot(2,1,1)
3042
data, extent = waterfall_plot(samples, frequencies)
3143

@@ -37,6 +49,8 @@
3749
extent=extent,
3850
cmap='cubehelix')
3951

52+
plt.colorbar()
53+
4054
time_series = []
4155

4256
for sample_set in samples:
@@ -47,12 +61,10 @@
4761
plt.plot(time_series)
4862
plt.show()
4963

50-
#clipped_samples = clipping(frequencies, samples)
64+
# Dedisperse the samples
5165
samples = dedisperse.dedisperse(samples)
52-
#samples = dedisperse.find_lowest_pulsar(samples)
53-
#samples = dedisperse.estimate_dm(samples)
54-
#samples = dedisperse.find_initial_line(samples)
5566

67+
# Plot the dedispersed data
5668
plt.subplot(2,1,1)
5769
data, extent = waterfall_plot(samples, frequencies)
5870

0 commit comments

Comments
 (0)