Búsqueda de Sonares 3D

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368
  1. class Costas:
  2. def __init__(self):
  3. pass
  4. def BuildWelch(self, p, root):
  5. costas = [0] * (p-1)
  6. for i in range(p-1):
  7. costas[i] = pow(root, i+1) % p
  8. return costas
  9. def isCostas(self, array):
  10. a_size = len(array)
  11. for c in range(1, a_size):
  12. hash = [0] * (2 * a_size)
  13. for i in range(a_size - c):
  14. dif = array[i+c] - array[i]
  15. #print dif,
  16. if hash[dif] == 1:
  17. return 0
  18. else:
  19. hash[dif] = 1
  20. #print
  21. return 1
  22. def CostasExtendedCrossCorrelation(self, costa1, costa2, n):
  23. cross = 0
  24. for h in range(n):
  25. hash = [0] * (n - 1)
  26. for i in range(n):
  27. if costa1[(i+h) % n] == "*" or costa2[i] == "*":
  28. continue
  29. dif = (costa1[(i + h) % n] - costa2[i]) % (n- 1)
  30. hash[dif]+=1
  31. if cross < hash[dif]:
  32. cross = hash[dif]
  33. return cross
  34. def isExtendedCostas(self, costas, n):
  35. for h in range(n):
  36. if h == 0:
  37. continue
  38. hash = [0] * (n-1)
  39. for i in range(n):
  40. if costas[(i + h) % n] == "*" or costas[i] == "*":
  41. continue
  42. dif = (costas[(i+h) % n] - costas[i]) % (n-1)
  43. if hash[dif] == 1:
  44. return 0
  45. else:
  46. hash[dif] = 1
  47. return 1
  48. def CostasColumnSymetries(self, a, p):
  49. costaList = []
  50. for i in range(2, p):
  51. costas = [0] * p
  52. for x in range(p):
  53. costas[(x*i) % p] = a[x]
  54. costaList.append(costas)
  55. return costaList
  56. def is3DCostas(self, costas, n):
  57. for h1 in range(n):
  58. for h2 in range(n):
  59. if h1 == 0 and h2 == 0:
  60. continue
  61. hash = [0] * ((n*n) - 1)
  62. for i in range(n):
  63. for j in range(n):
  64. #if i == 0 and j == 0:
  65. # continue
  66. #if (i+h1) % n == 0 and (j+h2) % n == 0:
  67. # Fix for * anyware on the grid.
  68. if costas[(i+h1) % n][(j+h2) % n] == "*" or costas[i][j] == "*":
  69. continue
  70. dif = (costas[((i + h1) % n)][((j+h2) % n)]
  71. - costas[i][j]) % (pow(n,2) - 1)
  72. #print dif,
  73. if hash[dif] == 1:
  74. return 0
  75. else:
  76. hash[dif] =1
  77. #print
  78. return 1
  79. def Costas3DCrossCorrelation(self, costa1, costa2, n):
  80. cross = 0
  81. for h1 in range(n):
  82. for h2 in range(n):
  83. #if h1 == 0 and h2 == 0:
  84. # continue
  85. hash = [0] * ((n*n) - 1)
  86. for i in range(n):
  87. for j in range(n):
  88. #if i == 0 and j == 0:
  89. # continue
  90. #if (i+h1) % n == 0 and (j+h2) % n == 0:
  91. # Fix for * anyware on the grid.
  92. if costa1[(i+h1) % n][(j+h2) % n] == "*" or costa2[i][j] == "*":
  93. continue
  94. dif = (costa1[((i + h1) % n)][((j+h2) % n)]
  95. - costa2[i][j]) % (pow(n,2) - 1)
  96. #print dif,
  97. hash[dif]+=1
  98. if cross < hash[dif]:
  99. cross = hash[dif]
  100. #print
  101. #print hash
  102. return cross
  103. def is3DCostas1D(self, costas, n):
  104. for h1 in range(n):
  105. for h2 in range(n):
  106. if h1 == 0 and h2 == 0:
  107. continue
  108. hash = [0] * ((n*n) - 1)
  109. for i in range(n):
  110. for j in range(n):
  111. if i == 0 and j == 0:
  112. continue
  113. if (i+h1) % n == 0 and (j+h2) % n == 0:
  114. continue
  115. dif = (costas[ n *((i + h1) % n) + ((j+h2) % n)] - costas[n*i+j]) % (pow(n,2) - 1)
  116. #print dif,
  117. if hash[dif] == 1:
  118. return 0
  119. else:
  120. hash[dif] =1
  121. #print
  122. return 1
  123. def Costas3DRowSymetries(self, a, p):
  124. # Given a Welch 3dCostas return all its column symetries
  125. costaList = []
  126. for i in range(2,p):
  127. costas2d = []
  128. for j in range(p):
  129. costas2d.append([0] * p)
  130. for x in range(p):
  131. for y in range(p):
  132. if x == 0 and y == 0:
  133. costas2d[x][y] = "*"
  134. else:
  135. costas2d[(x*i) % p][y] = a[x][y]
  136. costaList.append(costas2d)
  137. return costaList
  138. def Costas3DRowShiftPermutation(self, a, p):
  139. # Given a Welch 3dCostas return all its row power permutations
  140. costaList = []
  141. for i in range(1,p):
  142. costas2d = []
  143. costas2d.append(a[0][:])
  144. for j in range(1, p):
  145. costas2d.append(a[j][-(((i*j)%p)) :] + a[j][:-((i*j)%p)])
  146. costaList.append(costas2d)
  147. return costaList
  148. def Costas3DColumnSymetries(self, a, p):
  149. costaList = []
  150. for i in range(2, p):
  151. costas2d = []
  152. for j in range(p):
  153. costas2d.append([0] * p)
  154. for y in range(p):
  155. for x in range(p):
  156. if x == 0 and y == 0:
  157. costas2d[x][y] = "*"
  158. else:
  159. costas2d[x][(y*i) % p] = a[x][y]
  160. costaList.append(costas2d)
  161. return costaList
  162. def Costas3DColumnShiftPermutation(self, a, p):
  163. costaList = []
  164. for i in range(1, p):
  165. costas2d = []
  166. for j in range(p):
  167. costas2d.append([0] * p)
  168. for y in range(p):
  169. for x in range(p):
  170. if x == 0 and y == 0:
  171. costas2d[x][y] = "*"
  172. else:
  173. costas2d[(x+(y*i)) % p][y] = a[x][y]
  174. costaList.append(costas2d)
  175. return costaList
  176. def CostasAdditionSymetries(self, a, p):
  177. #Given a Welch 3dCostas return all its Addition symetries excluding a
  178. costaList = []
  179. for i in range(1, p):
  180. costas2d = []
  181. for j in range(p):
  182. costas2d.append([0] * p)
  183. for x in range(p):
  184. for y in range(p):
  185. if x == 0 and y == 0:
  186. costas2d[x][y] = "*"
  187. else:
  188. costas2d[x][y] = (a[x][y] + i) % (pow(p,2)-1)
  189. costaList.append(costas2d)
  190. return costaList
  191. def CostasMultiplicationSymetries(self, a, p1, primes):
  192. costaList = []
  193. for p in primes:
  194. costas2d = []
  195. for j in range(p1):
  196. costas2d.append([0] * p1)
  197. for x in range(p1):
  198. for y in range(p1):
  199. if x == 0 and y == 0:
  200. costas2d[0][0] = "*"
  201. else:
  202. costas2d[x][y] = (a[x][y] * p) % (pow(p1,2)-1)
  203. costaList.append(costas2d)
  204. return costaList
  205. def Costas3D90DegreeSymetry(self, a, p):
  206. # Given a Welch 3DCostas return its 90Degree Symetry
  207. costas = [] * p
  208. for i in range(p):
  209. costas.append([0] * p)
  210. for i in range(p):
  211. for j in range(p):
  212. costas[i][j] = a[j][i]
  213. return costas
  214. def Costas3DDihedralSymetry(self, a, p):
  215. costas = [] * p
  216. for i in range(p):
  217. costas.append([0] * p)
  218. for i in range(p):
  219. costas[i] = a[i][:]
  220. costas[i].reverse()
  221. return costas
  222. def Costas2Legendre(self, a, p):
  223. for i in range(p):
  224. for j in range(p):
  225. if a[i][j] == "*":
  226. continue
  227. if(a[i][j] % 2 == 0):
  228. a[i][j]=1
  229. else:
  230. a[i][j]=-1
  231. def GetLegendre(self, a, p):
  232. # Given a Welch 3DCostas return its Legendre
  233. costas = [] * p
  234. for i in range(p):
  235. costas.append([0] * p)
  236. for i in range(p):
  237. for j in range(p):
  238. if a[i][j] == "*":
  239. costas[i][j] = "*"
  240. continue
  241. if(a[i][j] % 2 == 0):
  242. costas[i][j]=1
  243. else:
  244. costas[i][j]=-1
  245. return costas
  246. def IsCalabro(self, a, p):
  247. # Check if Legendre array is Calabro
  248. similar = (p-1)/2
  249. counter = [0] * p
  250. for i in range(1, p-1):
  251. for j in range(i+1, p):
  252. if a[i] == a[j]:
  253. if counter[i] == 0:
  254. counter[i]+=2
  255. else:
  256. counter[i]+=1
  257. if counter[j] == 0:
  258. counter[j]+=2
  259. else:
  260. counter[j]+=1
  261. if similar in counter:
  262. return 1, counter
  263. else:
  264. return 0, counter
  265. def LegendreCorrelation(self, legendre, p):
  266. cor = 0
  267. cor_pos = 0
  268. cor_neg = 0
  269. for h1 in range(p):
  270. for h2 in range(p):
  271. if h1 == 0 and h2 == 0:
  272. continue
  273. tmp_cor = 0
  274. for i in range(p):
  275. for j in range(p):
  276. tmp_cor += legendre[(i + h1) % p][(j + h2) % p] * legendre[i][j]
  277. if tmp_cor < 0:
  278. if tmp_cor < cor_neg:
  279. cor_neg = tmp_cor
  280. else:
  281. if tmp_cor > cor_pos:
  282. cor_pos = tmp_cor
  283. if abs(tmp_cor) > cor:
  284. cor = abs(tmp_cor)
  285. return cor, cor_neg, cor_pos
  286. def LegendreCrossCorrelation(self, legendre1, legendre2, p):
  287. cor = 0
  288. cor_pos = 0
  289. cor_neg = 0
  290. for h1 in range(p):
  291. for h2 in range(p):
  292. #if h1 == 0 and h2 == 0:
  293. # continue
  294. tmp_cor = 0
  295. for i in range(p):
  296. for j in range(p):
  297. if legendre1[(i + h1) % p][(j + h2) % p] == "*" or legendre2[i][j] == "*":
  298. continue
  299. tmp_cor += legendre1[(i + h1) % p][(j + h2) % p] * legendre2[i][j]
  300. if tmp_cor < 0:
  301. if tmp_cor < cor_neg:
  302. cor_neg = tmp_cor
  303. else:
  304. if tmp_cor > cor_pos:
  305. cor_pos = tmp_cor
  306. if abs(tmp_cor) > cor:
  307. cor = abs(tmp_cor)
  308. return cor, cor_neg, cor_pos
  309. def LegendreCrossCorrelationCoincidences(self, legendre1, legendre2, p):
  310. cor = 0
  311. for h1 in range(p):
  312. for h2 in range(p):
  313. #if h1 == 0 and h2 == 0:
  314. # continue
  315. tmp_cor = 0
  316. for i in range(p):
  317. for j in range(p):
  318. if legendre1[(i + h1) % p][(j + h2) % p] == legendre2[i][j]:
  319. tmp_cor+=1
  320. if tmp_cor > cor:
  321. cor = tmp_cor
  322. return cor
  323. #c = Costas()
  324. #print c.isCostas([4,3,2,1])