
# Pipeline for Target lamp

all: stage-overscan stage-ydist stage-xdist stage-xdist-copy stage-wdist stage-wdist-copy stage-copy-lamp ../targ_lamp

stage-overscan:
# Overscan Subtraction, Trimming, and Image Reorientation.
	echo Stage:  Overscan Subtraction, Trimming, and Image Reorientation.
	magebias /data1/Data/MagE/processed_2d/../ut170530_31/mage0007.fits lamp_lamp0007.fits
	touch stage-overscan

stage-ydist: stage-overscan
# Measuring the Y Distortion.
	echo Stage:  Measuring the Y Distortion.
	mageIdentify lamp_lamp0007.fits
	mageDistortion lamp_lamp0007.fits -d lamp_lamp0007.ps/vcps
	touch stage-ydist

stage-xdist: stage-ydist
# Get X Distortion.
	echo Stage:  Get X Distortion.
	efits lamp_lamp0007.fits '(i1-VTKMedianSmooth(i1,32,8,numret=1))*equal(VTKConvolve(1.*greater(i1,60e3),k=5,numret=1),0)' lamp_lamp0007b.fits
	getrect -xdist -ydist lamp_lamp0007b.fits -nx 8 -dy 3 -x 1 -nsub2 3 -y 1 -b 4
	globalrect lamp_lamp0007b.fits -maxo 2 -go -s 11.000000 -d lamp_lamp0007bglob.ps/vcps
	maprect -xdist lamp_lamp0007b.fits
	touch stage-xdist

stage-xdist-copy: stage-xdist
# Copying X Distortion.
	echo Stage:  Copying X Distortion.
	copyrect -xdist lamp_lamp0007b.fits lamp_lamp0007.fits
	touch stage-xdist-copy

stage-wdist: stage-xdist-copy
# Do the Wavelength Calibration.
	echo Stage:  Do the Wavelength Calibration.
	mageMatchOrders lamp_lamp0007b.fits

	mageFindLines lamp_lamp0007bspecs.fits -fwhm 3.000000 -th 5.000000

	mageMatchLamps lamp_lamp0007bspecs.fits -x 4 -o 4
	touch stage-wdist

stage-wdist-copy: stage-wdist
	copyecords lamp_lamp0007bspecs.fits lamp_lamp0007.fits
	copyecords lamp_lamp0007bspecs.fits lamp_lamp0007b.fits

	copyrect -wdist lamp_lamp0007bspecs.fits lamp_lamp0007.fits

	copyrect -edist lamp_lamp0007bspecs.fits lamp_lamp0007.fits
	touch stage-wdist-copy

stage-copy-lamp: stage-wdist-copy
# Copying Lamp Information.
	echo Stage:  Copying Lamp Information.
	cp lamp_lamp0007.fits lamp.fits
	cp lamp_lamp0007-y-dist.fits lamp-y-dist.fits
	cp lamp_lamp0007b-x-rect.fits lamp-x-rect.fits
	addkeys lamp.fits y-dist lamp-y-dist.fits
	addkeys lamp-y-dist.fits y-dist lamp-y-dist.fits
	addkeys lamp.fits x-rect lamp-x-rect.fits
	addkeys lamp-x-rect.fits x-rect lamp-x-rect.fits
	touch stage-copy-lamp

../targ_lamp:
	touch ../targ_lamp

clean:
	rm -f lamp_lamp0007.fits

veryclean:
	rm -f stage-overscan stage-ydist stage-xdist stage-xdist-copy stage-wdist stage-wdist-copy stage-copy-lamp

