Created
May 28, 2015 23:05
-
-
Save sirpercival/cc220342a8a9d15721a4 to your computer and use it in GitHub Desktop.
Minimal python & kivy script for spectral reduction
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fast_fits as extract | |
from datatypes import FitsImage, ExtractedSpectrum, Robust2D | |
import sys | |
from kivy.garden.graph import Graph, SmoothLinePlot | |
from custom_widgets import ImagePane | |
from kivy.base import runTouchApp | |
from image_arithmetic import im_divide, im_subtract | |
if __name__ == '__main__': | |
widget = ImagePane() | |
dither1 = FitsImage(sys.argv[1], load=True) | |
dither2 = FitsImage(sys.argv[2], load=True) | |
flats = FitsImage(sys.argv[3], load=True) | |
tracedir = int(sys.argv[4]) | |
diff_image1 = im_subtract(im_divide(dither1, flats), | |
im_divide(dither2, flats)) | |
diff_image1.change_parameters({'mode':'asinh'}) | |
widget.load_data(diff_image1) | |
runTouchApp(widget) | |
#region = map(int,raw_input('Region pixel coords> ').split()) | |
region = [141,245,1023,285] | |
dither1 = im_divide(dither1.data_array[region[0]:region[2], | |
region[1]:region[3]], | |
flats.data_array[region[0]:region[2], | |
region[1]:region[3]]) | |
dither2 = im_divide(dither2.data_array[region[0]:region[2], | |
region[1]:region[3]], | |
flats.data_array[region[0]:region[2], | |
region[1]:region[3]]) | |
diff_image0 = im_subtract(dither1, dither2) | |
peak1 = extract.find_peak_2d(diff_image0, tracedir=tracedir) | |
peak2 = extract.find_peak_2d(diff_image0, tracedir=tracedir, pn='neg') | |
cross_section = Robust2D(diff_image0, index=True).combine(axis=(tracedir+1)%2, method='median') | |
mmx = cross_section.minmax | |
widget2 = Graph(xlabel='Pixel', ylabel='Mean counts', x_ticks_minor=5, | |
x_ticks_major=10, y_ticks_minor=5, y_ticks_major=10, | |
x_grid_label=True, y_grid_label=True, xlog=False, | |
ylog=False, x_grid=False, y_grid=False, xmin=0, | |
xmax=diff_image0.shape[tracedir], ymin=float(mmx[0]), | |
ymax=float(mmx[1])) | |
trace = SmoothLinePlot(points=zip(cross_section, cross_section.x), | |
color=[1,0,0,1]) | |
widget2.add_plot(trace) | |
runTouchApp(widget2) | |
cens = map(float,raw_input('Trace centers> ').split()) | |
p_init = [(cross_section.interp(x), x, 3.) for x in cens] | |
spec, telluric = extract.reduce_dither_pair(dither1, dither2, p_init, | |
trace_direction=tracedir) | |
spec = ExtractedSpectrum(spec) | |
spec.save() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment