-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetslice_CASA_360.py
64 lines (45 loc) · 1.71 KB
/
getslice_CASA_360.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
#from sys import argv
import numpy as np
from taskinit import *
#imput_image, origin, slice_length, angle_step, output_name = argv
# origin and slice_length in pixels
# angle_step in degrees
#origin_A = 632.353 377.38
#origin_B = 607.779 377.38
#slice_length = 160 px
def get_p2(p1, slice_length, ang): #p1 = [x0,y0], slice_length in pixels, ang en degrees
x0, y0 = p1
x1 = x0 - slice_length * np.sin(ang*np.pi/180)
y1 = y0 + slice_length * np.cos(ang*np.pi/180)
return [x1,y1]
def get_pixels(dict_slice):
x = dict_slice['xpos']
y = dict_slice['ypos']
return zip(x,y)
def get_values(pixels):
values = []
for pix in pixels:
val = ia.pixelvalue([pix[0],pix[1]])['value']['value']
values.append(val)
return values
input_image = input(">>Image? ('file_in'): ")
origin = input(">>Origin Pixel? [x0,y0]: ")
slice_length = input(">>Slice lenght? (in pixels): ")
angle_step = input(">>Angle step? (in degrees): ")
output_name = input(">>Output name? ('file_out'): ")
ia.open(input_image)
info = ia.summary
bright_u = info()['unit']
pix_size = info()['incr'][1]*180/np.pi*3600 # size of a pixel in arcsec
hdrtxt='Dist (pix)\tValue({})\t(pix = {} arcsec)'.format(bright_u,pix_size) #CASA does'n uses python 3 yet
ang = np.arange(0,360,angle_step)
ptos = [get_p2(origin,slice_length,a) for a in ang]
slices = [ia.getslice([origin[0],pto[0]],[origin[1],pto[1]]) for pto in ptos]
pixels = [get_pixels(sl) for sl in slices]
values = [get_values(pix) for pix in pixels]
distance = [sl['distance'] for sl in slices]
ia.close()
for a, dist, value in zip(ang,distance,values):
out_file = output_name+'_'+str(a)+'deg.dat'
profile = zip(dist,value)
np.savetxt(out_file,profile,header=hdrtxt)