@@ -0,0 +1,2249 @@
+#!/usr/bin/env python%0A%0A%22%22%22%0ARun CIAO's celldetect tool%0A%22%22%22%0A%0Aimport argparse%0Aimport os%0Aimport sys%0Aimport numpy as np%0A%0A%0Afrom chandra_suli import find_files%0Afrom chandra_suli.run_command import CommandRunner%0Afrom chandra_suli import logging_system%0A%0Aif __name__==%22__main__%22:%0A%0A    parser = argparse.ArgumentParser(description=%22Check to see if transient candidates are actually hot pixels%22)%0A%0A    parser.add_argument(%22--masterfile%22,help=%22Name of file containing master list of all potential transients%22,%0A                        required=True, type=str)%0A    parser.add_argument(%22--ranks%22,help=%22Ranks in file that you want to run%22,nargs=%22+%22,required=True,type=int)%0A    parser.add_argument(%22--data_dir%22, help=%22Path to directory containing data of all obsids%22, required=True,%0A                        type=str)%0A    parser.add_argument(%22--outdir%22,help=%22Directory where output files will go%22,required=True, type=str)%0A%0A    # Get logger for this command%0A%0A    logger = logging_system.get_logger(os.path.basename(sys.argv%5B0%5D))%0A%0A    # Instance the command runner%0A%0A    runner = CommandRunner(logger)%0A%0A    args = parser.parse_args()%0A%0A    # Get data from master list%0A    master_data = np.array(np.recfromtxt(args.masterfile, names=True), ndmin=1)%0A%0A    for rank in args.ranks:%0A%0A        # index of object in question will be one less than the rank (first source is index 0, etc)%0A        idx = rank - 1%0A%0A        obsid = master_data%5B'Obsid'%5D%5Bidx%5D%0A        ccd = master_data%5B'CCD'%5D%5Bidx%5D%0A        candidate = master_data%5B'Candidate'%5D%5Bidx%5D%0A        tstart = master_data%5B'Tstart'%5D%5Bidx%5D%0A        tstop = master_data%5B'Tstop'%5D%5Bidx%5D%0A        obsid_dir = os.path.join(args.data_dir,str(obsid))%0A%0A        evtfile = find_files.find_files(obsid_dir, 'ccd_%25s_%25s_filtered.fits' %25(ccd,obsid))%5B0%5D%0A        regfile = find_files.find_files(obsid_dir, 'ccd_%25s_%25s_filtered_candidate_%25s.reg' %25(ccd,obsid,candidate))%5B0%5D%0A%0A        regfile_name = os.path.splitext(os.path.basename(regfile))%5B0%5D%0A        outfile = %22%25s_celldetect.fits%22 %25regfile_name%0A        outfile_path = os.path.join(args.outdir,outfile)%0A%0A        cmd_line = 'ftcopy %5C%22%25s%5Bregfilter(%5C'%25s%5C') && (TIME %3E= %25s) && (TIME %3C= %25s)%5D%5C%22 %25s clobber=yes '%5C%0A                   %25(evtfile, regfile, tstart, tstop, outfile_path)%0A%0A        runner.run(cmd_line)%0A%0A%0A

Copy region file