type Image; type MosaicData; type Table; type JPEG; type Status; type BackgroundStruct { string fname; float a; float b; float c; }; type DiffStruct { int cntr1; int cntr2; Image plus; Image minus; Image diff; }; app ( Image mos ) mAdd( Image imgs[], Table img_tbl, MosaicData hdr ) { mAdd "-p" @dirname( imgs[0] ) "-n" @img_tbl @hdr @mos; } app ( Image bg_img ) mBackground( Image img, float a, float b, float c ) { mBackground "-n" @img @bg_img a b c; } app ( Table corr_tbl ) mBgModel( Table img_tbl, Table fits_tbl ) { mBgModel @img_tbl @fits_tbl @corr_tbl; } app ( Table fits_tbl ) mConcatFit( Table status_tbl, Status stats[] ) { mConcatFit @status_tbl @fits_tbl @dirname( stats[0] ); } app ( Image diff_img ) mDiff( Image proj_img_1, Image proj_img_2, MosaicData hdr ) { // mDiff "-n" @proj_img_1 @proj_img_2 @diff_img @hdr; mDiff_wrap "-n" @proj_img_1 @proj_img_2 @diff_img @hdr; } app ( Status stat ) mFitplane( Image diff_img ) { // mFitplane "-s" @stat @diff_img; mFitplane_wrap "-s" @stat @diff_img; } app ( Table img_tbl ) mImgtbl( Image imgs[] ) { mImgtbl @dirname( imgs[0] ) @img_tbl; } app ( MosaicData hdr ) mMakeHdr( Table img_tbl ) { mMakeHdr @img_tbl @hdr; } app ( JPEG mos_img_jpg ) mJPEG( Image mos_img ) { mJPEG "-gray" @mos_img "20%" "99.98%" "loglog" "-out" @mos_img_jpg; } app ( Table diff_tbl ) mOverlaps( Table img_tbl ) { mOverlaps @img_tbl @diff_tbl; } app ( Image proj_img ) mProjectPP( Image raw_img, MosaicData hdr ) { mProjectPP "-X" @raw_img @proj_img @hdr; } app ( Image proj_img ) mProject( Image raw_img, MosaicData hdr ) { mProject "-X" @raw_img @proj_img @hdr; } /*----------------------------------------------------------------------------------*/ /* */ /* Util Scripts */ /* */ /*----------------------------------------------------------------------------------*/ app ( Table back_tbl ) Background_list( Table imgs_tbl, Table corrs_tbl ) { Background_list @imgs_tbl @corrs_tbl @back_tbl; } app ( Table stat_tbl ) create_status_table( Table diff_tbl ) { create_status_table @diff_tbl @stat_tbl; } ( Image corr_imgs[] ) mBgBatch( Image bg_imgs[], Table img_tbl, Table corr_tbl ) { Table tmp <"back_tmp.tbl">; tmp = Background_list( img_tbl, corr_tbl ); BackgroundStruct back_struct[] = readData2( tmp ); foreach background_entry, i in back_struct { Image proj_img ; Image corr_img ; float a = background_entry.a; float b = background_entry.b; float c = background_entry.c; corr_img = mBackground( proj_img, a, b, c ); corr_imgs[ i ] = corr_img; } } ( Image diff_imgs[] ) mDiffBatch( Table diff_tbl, MosaicData hdr ) { DiffStruct diffs[] ; foreach d_entry, i in diffs { /* Not always going to be in proj_dir. Maybe read diff_tbl for directory. */ /* Not sure if the information is there. */ Image proj_1 ; Image proj_2 ; Image diff_img ; diff_img = mDiff( proj_1, proj_2, hdr ); diff_imgs[ i ] = diff_img; } } ( Table fits_tbl ) mFitBatch( Image diff_imgs[], Table diff_tbl ) { Status stats[] ; Table status_tbl <"stats.tbl">; status_tbl = create_status_table( diff_tbl ); foreach img, i in stats { stats[ i ] = mFitplane ( diff_imgs[i] ); } fits_tbl = mConcatFit( status_tbl, stats ); } ( Image proj_imgs[] ) mProjectBatch( Image raw_imgs[], MosaicData hdr ) { foreach img, i in raw_imgs { Image proj_img ; proj_img = mProjectPP( img, hdr ); // proj_img = mProject( img, hdr ); proj_imgs[ i ] = proj_img; } } MosaicData template <"template.hdr">; Table images_tbl <"images.tbl">; Table difference_tbl <"diffs.tbl">; Table fits_images_tbl <"fits.tbl">; Table corrections_tbl <"corrections.tbl">; Table stat_tbl <"stats.tbl">; Image uncorrected_mos <"final/uncorrected.fits">; JPEG uncorrected_jpg_img <"final/uncorrected.jpg">; Image corrected_mos <"final/corrected.fits">; JPEG corrected_jpg_img <"final/corrected.jpg">; Image raw_image_files[] ; Image projected_images[]; Image difference_images[]; Image corrected_images[]; projected_images = mProjectPPBatch( raw_image_files, template ); images_tbl = mImgtbl( projected_images ); uncorrected_mos = mAdd( projected_images, images_tbl, template ); uncorrected_jpg_img = mJPEG( uncorrected_mos ); difference_tbl = mOverlaps( images_tbl ); difference_images = mDiffBatch( difference_tbl, template ); fits_images_tbl = mFitBatch( difference_images, difference_tbl ); corrections_tbl = mBgModel( images_tbl, fits_images_tbl ); corrected_images = mBgBatch( projected_images, images_tbl, corrections_tbl ); corrected_mos = mAdd( corrected_images, images_tbl, template ); corrected_jpg_img = mJPEG( corrected_mos );