-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaztec_curve.py
57 lines (47 loc) · 2.01 KB
/
aztec_curve.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
# AZTEC 1.0
# aztec(data)
# Reorders data through AZTEC space-filling curve.
# INPUTS> data: data to be reordered it should be 4^2n length.
# OUTPUTS>outputData: data reordered with Aztec curve
# aztecInd: vector with aztec indexes
# Example1: outputData, aztecInd = aztec(np.r_[0:16])
# Author(s): Diego Ayala (https://github.com/Diego0101)
# Paper: https://www.researchgate.net/publication/362386088_Aztec_curve_proposal_for_a_new_space-filling_curve
# Most of algorithm from: https://arxiv.org/abs/2207.14345v1
# Published in Github through MIT License
import numpy as np
import matplotlib.pyplot as plt
def aztec(data):
a1 = -1.5 - 1.5j;a2 = -1.5 - 0.5j;a3 = -1.5 + 0.5j;a4 = -1.5 + 1.5j; # Generate point sequence
a5 = -0.5 - 1.5j;a6 = -0.5 - 0.5j;a7 = -0.5 + 0.5j;a8 = -0.5 + 1.5j;
u = 0; #geometry=0;
order = int(np.log2(data.size) / np.log2(16))
rowNumel = int(np.sqrt(data.size))
for k in range(order):
v = -1j * np.flip(u)
u = np.array([v+a1,v+a2,v+a3,u+a4,u+a8,u-a5,u-a1,-v-a2,-u-a3,-u-a7,v-a6,-v+a7,-v+a6,-v+a5,u-a8,u-a4])/4
u=u.flatten()
width=pow(4,k+1)
u=np.reshape(u,(width,width))
newCol = np.real(u)
newRow = np.imag(u)
newCol = rowNumel * newCol + rowNumel / 2 + 0.5
newRow = rowNumel * newRow + rowNumel / 2 + 0.5
aztecInd = ((newCol - 1) * rowNumel + newRow-1).flatten().astype(int)
outputData=data.flatten()
outputData=outputData[aztecInd]
outputData=np.reshape(outputData,(width,width))
u=u.flatten()
D=plt.plot(np.real(u), np.imag(u))
return outputData, aztecInd
# Example usage
#data = np.random.randint(0, 10, (16, 16))
data = np.r_[0:256]
outputData, aztecInd = aztec(data)
print("Input data:") , print(data)
print("Output data:") , print(outputData)
#print("Aztec indices:"), print(aztecInd)
plt.show()
# Copyright (c) 2024 Diego Ayala
#The above copyright notice and this permission notice shall be included in all
#copies or substantial portions of the Software.