-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrotate.jl
129 lines (108 loc) · 2.89 KB
/
rotate.jl
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
#...this script reads in a set of ~large cubic data at uniform resolution (e.g. B-field components) and written in .fits files,
#...and rotates them of an arbitrary combination of angles, so that the resulting rotated cubes have the new 3D-components projected
#...along the rotate axes and/or the projected maps show the projection of the rotated vectors along the rotated coordinates.
fold="/Users/francovazza/Desktop/data/DATA/CHRONOS/new_clusters/E18B/snap/"
file1="Bx.fits" #input files
file2="By.fits"
file3="Bz.fits"
using FITSIO
fbx=FITS(string(fold,file1),"r")
fby=FITS(string(fold,file2),"r")
fbz=FITS(string(fold,file3),"r")
bx=read(fbx[1],100:299,100:299,100:299) #focus on some innermost region
by=read(fby[1],100:299,100:299,100:299)
bz=read(fbz[1],100:299,100:299,100:299)
bxr=similar(bx)
byr=similar(by)
bzr=similar(bz)
using CoordinateTransformations
using StaticArrays
using Rotations
#for aa in 1:50 #...uncomment this to produce movies
ang1=0.0
ang2=0.0
ang3=-π/2.*45/90. #...multiply by a*something here to change ang3 in the loop.
rot=LinearMap(RotX(ang3))
x = SVector(200, 200, 200) #..for a 400^3 box
rot_around_x = recenter(rot, x)
n=200
for l in 1:n
for j in 1:n
@simd for i in 1:n
@inbounds p3=[bx[i,j,l],by[i,j,l],bz[i,j,l]]
x3=[i,j,l]
pnew=rot(p3)
xnew=rot_around_x(x3)
x1=convert(Int32,trunc(xnew[1]))
x2=convert(Int32,trunc(xnew[2]))
x3=convert(Int32,trunc(xnew[3]))
if x1 < 1
x1=1
end
if x2 < 1
x2=1
end
if x3 < 1
x3=1
end
if x1 > n
x1=n
end
if x2 > n
x2=n
end
if x3 > n
x3=n
end
@inbounds bxr[x1,x2,x3]=pnew[1]
@inbounds byr[x1,x2,x3]=pnew[2]
@inbounds bzr[x1,x2,x3]=pnew[3]
end
end
end
bx=nothing
by=nothing
bz=nothing
#...maps of field along the LOS
mapx=Array{Float64}(n,n)
mapy=Array{Float64}(n,n)
mapz=Array{Float64}(n,n)
mapz[:]=0.
mapy[:]=0.
mapx[:]=0.
@inbounds @simd for i in 1:n
@views mapx[:,:]+=bxr[:,:,i]
@views mapz[:,:]+=bzr[:,:,i]
@views mapy[:,:]+=byr[:,:,i]
end
for i in eachindex(mapx)
mapx[i]=sqrt(mapx[i]^2.+mapy[i]^2.+mapz[i]^2.)
end
file_out=string(fold,"RMx_test2.fits")
f = FITS(file_out, "w");
write(f,mapx)
close(f)
#end #uncomment this for the movie-making
error()
file_out=string(fold,"RMz_test2.fits")
f = FITS(file_out, "w");
write(f,mapz)
close(f)
file_out=string(fold,"RMy_test2.fits")
f = FITS(file_out, "w");
write(f,mapy)
close(f)
error()
#...this is to write out the rotated 3D fileds as fits files.
file_out1=string(fold,"Bx_rot_test.fits")
file_out2=string(fold,"By_rot_test.fits")
file_out3=string(fold,"Bz_rot_test.fits")
f = FITS(file_out1, "w");
write(f,bxr)
close(f)
f = FITS(file_out2, "w");
write(f,byr)
close(f)
f = FITS(file_out3, "w");
write(f,bzr)
close(f)