@@ -0,0 +1,2614 @@
+#!/usr/bin/env python%0A%0A%22%22%22%0AGenerate lightcurves for each candidate given a list of candidates%0A%22%22%22%0A%0Aimport argparse%0Aimport os%0Aimport sys%0Aimport numpy as np%0Aimport astropy.io.fits as pyfits%0Aimport matplotlib.pyplot as plt%0Aimport seaborn as sbs%0A%0Afrom chandra_suli import find_files%0Afrom chandra_suli import logging_system%0Afrom chandra_suli.run_command import CommandRunner%0Afrom chandra_suli.sanitize_filename import sanitize_filename%0A%0Aif __name__==%22__main__%22:%0A%0A    parser = argparse.ArgumentParser(description='Generate gifs to visualize transient')%0A%0A    parser.add_argument(%22--masterfile%22, help=%22Path to file containing list of transients%22,%0A                        required=True, type=str)%0A    parser.add_argument(%22--data_path%22, help=%22Path to directory containing data of all obsids%22, required=True,%0A                        type=str)%0A%0A    # Get the logger%0A    logger = logging_system.get_logger(os.path.basename(sys.argv%5B0%5D))%0A%0A    # Get the command runner%0A    runner = CommandRunner(logger)%0A%0A    args = parser.parse_args()%0A%0A    data_path = sanitize_filename(args.data_path)%0A    masterfile = sanitize_filename(args.masterfile)%0A%0A    transient_data = np.array(np.recfromtxt(masterfile, names=True), ndmin=1)%0A%0A    for transient in transient_data:%0A%0A        obsid = transient%5B'Obsid'%5D%0A        ccd = transient%5B'CCD'%5D%0A        candidate = transient%5B'Candidate'%5D%0A        tstart = transient%5B'Tstart'%5D%0A        tstop = transient%5B'Tstop'%5D%0A%0A        duration = tstop-tstart%0A%0A        event_file = find_files.find_files(os.path.join(data_path, str(obsid)), %22ccd_%25s_%25s_filtered.fits%22 %25 (ccd, obsid))%5B0%5D%0A%0A        intervals = %5Btstart, tstop%5D%0A%0A        # get start and stop time of observation%0A        with pyfits.open(event_file, memmap=False) as reg:%0A            tmin = reg%5B'EVENTS'%5D.header%5B'TSTART'%5D%0A            tmax = reg%5B'EVENTS'%5D.header%5B'TSTOP'%5D%0A%0A        # Ensure that there will only be a maximum of 5 frames%0A        if len(intervals) %3C= 7:%0A%0A            # this loop creates a list of time intervals with which to create gif from%0A%0A            if tmin %3C intervals%5B0%5D - duration:%0A%0A                intervals%5B0%5D = intervals%5B0%5D - duration%0A%0A            if tmax %3E intervals%5B-1%5D + duration:%0A%0A                    intervals%5B-1%5D = intervals%5B-1%5D + duration%0A%0A%0A        evt_names = os.path.splitext(event_file)%0A%0A        # Create individual time interval files%0A        for i in range(len(intervals)-1):%0A%0A            outfile = %22%25s_TI_%25s%25s%22 %25(evt_names%5B0%5D, i+1, evt_names%5B1%5D)%0A%0A            cmd_line = 'ftcopy %5C%22%25s%5B(TIME %3E= %25s) && (TIME %3C= %25s)%5D%5C%22 %25s clobber=yes ' %5C%0A                       %25 (event_file, intervals%5Bi%5D, intervals%5Bi+1%5D, outfile)%0A%0A        %0A

Create interval files