This repository has been archived by the owner on May 17, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
test_hough_data.py
135 lines (105 loc) · 3.56 KB
/
test_hough_data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
from sim import wave2d
from visualize import visualize
from scikits.image.transform import hough
from scikits.image.morphology import greyscale_dilate
import numpy as np
import pylab as plt
import sunpy
def htLine(distance,angle,img):
shape = img.shape
ny = shape[0]
nx = shape[1]
eps = 1.0/float(ny)
if abs(np.sin(angle)) > eps:
gradient = - np.cos(angle) / np.sin(angle)
constant = distance / np.sin(angle)
for x in range(0,nx):
y = gradient*x + constant
if y <= ny-1 and y >= 0:
img[y,x] = 255
else:
img[:,distance] = 255
return img
m2deg = 360./(2*3.1415926*6.96e8)
cube = sunpy.make_map("/Users/schriste/Downloads/eitdata_19970512/*.fits", type = "cube")
dmap = cube[2] - cube[1]
dmap.show()
# need an even number of maps so get rid of one
cube = cube[0:4]
import util
tmap = util.map_hpc_to_hg(dmap)
ttmap = util.map_hpc_to_hg_rotate(dmap, epi_lon = 9.5, epi_lat = 20.44)
input_maps = []
for map in cube:
print("Unraveling map at "+str(map.date))
input_maps += [util.map_hpc_to_hg_rotate(map, epi_lon = 9.5, epi_lat = 20.44)]
#wave_maps = wave2d.simulate(params, verbose = True)
#visualize(wave_maps)
#
# Use Albert's wavemaps to test the hough transform as a means
# of detecting EIT waves
#
# Initial detection is based on Hough transform of absolute
# value of the running difference.
#
# Possible algorithm outline
#
# (1) Hough transform (HT) of absolute value of the running difference.
# (2) Threshold HT and transform back
# (3) Remove areas which are 'small', keep areas which are large
# (4) Use the remaining detected areas as a mask in the original data
# (5) Apply HT to masked original data
# (6) Threshold and transform back
# (7) Remove areas which are 'small', keep areas which are large
# (8) This localises the wavefront
#
ndiff = len(input_maps)-1
# difference threshold
diffthresh = 130
# Hough transform voting threshold
votethresh = 30
# shape of the data
imgShape = input_maps[0].shape
# storage for the detection
detection = []
diffs = []
diffmap = 255*(abs(input_maps[1] - input_maps[0]) > diffthresh)
for i in range(0,ndiff):
# difference map
diffmap = 255*(abs(input_maps[i+1] - input_maps[i]) > diffthresh)
# keep
diffs.append(diffmap)
# extract the image
img = diffmap
# Perform the hough transform on each of the difference maps
transform,theta,d = hough(img)
# Filter the hough transform results and find the best lines
# in the data
indices = (transform >votethresh).nonzero()
distances = d[indices[0]]
theta = theta[indices[1]]
n =len(indices[1])
print("Found " + str(n) + " lines.")
# Perform the inverse transform to get a series of rectangular
# images that show where the wavefront is.
invTransform = sunpy.map.BaseMap(input_maps[i+1])
invTransform.data = np.zeros(imgShape)
for i in range(0,n):
nextLine = htLine( distances[i],theta[i], np.zeros(shape=imgShape) )
invTransform = invTransform + nextLine
# Dump the inverse transform back into a series of maps
detection.append(invTransform)
visualize(diffs)
visualize(detection)
from matplotlib import cm
from matplotlib import colors
#wmap = sunpy.make_map(input_maps[max_steps/2], wave_maps[0], type = "composite")
#wmap.set_colors(1, cm.Reds)
#wmap.set_alpha(1,0.1)
#wmap.set_norm(1, colors.Normalize(0.1,1))
#wmap.show()
#pmap = sunpy.make_map(detection[max_steps/2],input_maps[max_steps/2], type ="composite")
#pmap.set_alpha(1,0.6)
#pmap.set_colors(0, cm.Blues)
#pmap.set_colors(1, cm.Reds)
#pmap.show()