-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
143 lines (122 loc) · 2.46 KB
/
utils.py
File metadata and controls
143 lines (122 loc) · 2.46 KB
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
136
137
138
139
140
141
142
143
import os, sys
import numpy as np
import matplotlib.pyplot as plt
# NOTE:
from astropy import (
units,
constants,
)
# NOTE:
from scipy import (
ndimage,
interpolate,
)
def extract(
cube,
x,
y,
order=1,
visualize=False
):
nz = cube.shape[0]
nx = len(x)
ny = len(y)
# NOTE:
zi = np.outer(
np.arange(nz, dtype=int),
np.ones(nx)
)
xi = np.outer(
np.ones(nz),
x
)
yi = np.outer(
np.ones(nz),
y
)
# # NOTE:
# if visualize:
# for i in range(cube.shape[0]):
# plt.imshow(
# cube[i, :, :],
# cmap="jet",
# aspect="auto",
# )
# plt.plot(
# xi, yi,
# marker="o",
# markersize=10,
# color="black"
# )
# plt.show()
# exit()
return ndimage.map_coordinates(
cube,
[zi, yi, xi],
#[zi, xi, yi], # NOTE: WRONG???
order=order,
cval=np.nan
)
def major_axis(
phi,
centre,
n_pixels,
pixel_scale,
dx=0.1,
):
a = np.tan((phi - 90.0) * units.deg.to(units.rad))
x1 = n_pixels / 2.0 - centre[0] / pixel_scale
y1 = n_pixels / 2.0 + centre[1] / pixel_scale
print(x1, y1, "|", "")
x = np.arange(0, n_pixels + 1, dx)
y = a * x + (y1 - a * x1)
idx = np.logical_and(
np.logical_and(y > 0, y < n_pixels),
np.logical_and(x > 0, x < n_pixels)
)
x = x[idx]
y = y[idx]
return x, y, x1, y1
def extract_from_major_axis(
cube,
phi,
centre,
n_pixels,
pixel_scale,
dx=0.1,
order=1,
visualize=False
):
x, y, _, _ = major_axis(
phi=phi,
centre=centre,
n_pixels=n_pixels,
pixel_scale=pixel_scale,
dx=dx,
)
return extract(
cube=cube,
x=x,
y=y,
order=order,
visualize=visualize
)
# def minor_axis(phi, centre, n_pixels, pixel_scale):
#
# a = np.tan((phi - 180.0) * units.deg.to(units.rad))
#
# x1 = centre[1] / pixel_scale + n_pixels / 2.0
# y1 = -centre[0] / pixel_scale + n_pixels / 2.0
#
# x = np.arange(0, n_pixels + 1, 1)
# y = a * x + (y1 - a * x1)
#
# idx = np.logical_and(
# np.logical_and(y > 0, y < n_pixels),
# np.logical_and(x > 0, x < n_pixels)
# )
#
# x = x[idx]
# y = y[idx]
#
# return x, y, x1, y1