-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdo_alipy3.py
executable file
·50 lines (37 loc) · 2.38 KB
/
do_alipy3.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
import alipy
import glob
images_to_align = sorted(glob.glob("../ASTR101/lab2/data/sliced/*.fits"))
ref_image = "../ASTR101/lab2/data/sliced/ref.fits"
identifications = alipy.ident.run(ref_image, images_to_align, visu=False)
# That's it !
# Put visu=True to get visualizations in form of png files (nice but much slower)
# On multi-extension data, you will want to specify the hdu (see API doc).
# The output is a list of Identification objects, which contain the transforms :
for id in identifications: # list of the same length as images_to_align.
if id.ok == True: # i.e., if it worked
#This is the old Python 2 print statement:
# print "%20s : %20s, flux ratio %.2f" % (id.ukn.name, id.trans, id.medfluxratio)
print("%20s : %20s, flux ratio %.2f" % (id.ukn.name,
id.trans,
id.medfluxratio))
# print("%20s : %20s, flux ratio %.2f" % (id.ukn.name, id.trans, id.medfluxratio))
# id.trans is a alipy.star.SimpleTransform object. Instead of printing it out as a string,
# you can directly access its parameters :
#print id.trans.v # the raw data, [r*cos(theta) r*sin(theta) r*shift_x r*shift_y]
#print id.trans.matrixform()
#print id.trans.inverse() # this returns a new SimpleTransform object
else:
# print "%20s : no transformation found !" % (id.ukn.name)
print ("%20s : no transformation found !" % (id.ukn.name))
# Minimal example of how to align images :
outputshape = alipy.align.shape(ref_image)
# This is simply a tuple (width, height)... you could specify any other shape.
for id in identifications:
if id.ok == True:
# Variant 1, using only scipy and the simple affine transorm :
alipy.align.affineremap(id.ukn.filepath, id.trans, shape=outputshape, makepng=True)
# Variant 2, using geomap/gregister, correcting also for distortions :
# alipy.align.irafalign(id.ukn.filepath, id.uknmatchstars, id.refmatchstars, shape=outputshape, makepng=False)
# id.uknmatchstars and id.refmatchstars are simply lists of corresponding Star objects.
# By default, the aligned images are written into a directory "alipy_out".
# To be continued ...