<commit_before>#!/usr/bin/env python

"""
Run CIAO tool vtpdetect to find sources in areas listed as potential transients
"""

import argparse
import os
import sys
import astropy.io.fits as pyfits
from astropy.coordinates import SkyCoord
import numpy as np

from chandra_suli.unique_list import unique_list
from chandra_suli.sanitize_filename import sanitize_filename
from chandra_suli import find_files
from chandra_suli.run_command import CommandRunner
from chandra_suli import logging_system

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description="Run vtpdetect to find sources in regions given by xtdac")

    parser.add_argument("--masterfile", help="Path to file containing list of transients in this set",
                        required=True, type=str)
    parser.add_argument("--outfile", help="Name of output file which will contain modified list of transients")
    parser.add_argument("--data_dir", help="Path to directory containing data of all obsids", required=True,
                        type=str)
    parser.add_argument("--outdir", help="Directory where output files will go", required=True, type=str)

    # Get logger for this command

    logger = logging_system.get_logger(os.path.basename(sys.argv[0]))

    # Instance the command runner

    runner = CommandRunner(logger)

    args = parser.parse_args()

    masterfile = sanitize_filename(args.masterfile)
    data_dir = sanitize_filename(args.data_dir)
    outdir = sanitize_filename(args.outdir)
    outfile = os.path.join(outdir, sanitize_filename(args.outfile))

    # Get data from master list
    master_data = np.array(np.recfromtxt(masterfile, names=True), ndmin=1)
    vtpdetect_data = []

    for i in range(len(master_data)):

        obsid = master_data['Obsid'][i]
        ra = master_data['RA'][i]
        dec = master_data['Dec'][i]
        ccd = master_data['CCD'][i]
        candidate = master_data['Candidate'][i]
        tstart = master_data['Tstart'][i]
        tstop = master_data['Tstop'][i]
        obsid_dir = os.path.join(data_dir,str(obsid))

        all_regions_file = find_files.find_files(obsid_dir, '%s_all_regions.fits' %(obsid))[0]
        evtfile = find_files.find_files(obsid_dir, 'ccd_%s_%s_filtered.fits' %(ccd,obsid))[0]
        expfile = find_files.find_files(obsid_dir, '*%s*exp3*' %obsid)[0]

        expfile_new = os.path.join(outdir, "%s_cheesemask.fits" % obsid)
<commit_msg>Fix write file error<commit_after>#!/usr/bin/env python

"""
Run CIAO tool vtpdetect to find sources in areas listed as potential transients
"""

import argparse
import os
import sys
import astropy.io.fits as pyfits
from astropy.coordinates import SkyCoord
import numpy as np

from chandra_suli.unique_list import unique_list
from chandra_suli.sanitize_filename import sanitize_filename
from chandra_suli import find_files
from chandra_suli.run_command import CommandRunner
from chandra_suli import logging_system

if __name__ == "__main__":

    parser = argparse.ArgumentParser(description="Run vtpdetect to find sources in regions given by xtdac")

    parser.add_argument("--masterfile", help="Path to file containing list of transients in this set",
                        required=True, type=str)
    parser.add_argument("--outfile", help="Name of output file which will contain modified list of transients")
    parser.add_argument("--data_dir", help="Path to directory containing data of all obsids", required=True,
                        type=str)
    parser.add_argument("--outdir", help="Directory where output files will go", required=True, type=str)

    # Get logger for this command

    logger = logging_system.get_logger(os.path.basename(sys.argv[0]))

    # Instance the command runner

    runner = CommandRunner(logger)

    args = parser.parse_args()

    masterfile = sanitize_filename(args.masterfile)
    data_dir = sanitize_filename(args.data_dir)
    outdir = sanitize_filename(args.outdir)
    outfile = os.path.join(outdir, sanitize_filename(args.outfile))

    # Get data from master list
    master_data = np.array(np.recfromtxt(masterfile, names=True), ndmin=1)
    vtpdetect_data = master_data.tolist()

    for i in range(len(master_data)):

        obsid = master_data['Obsid'][i]
        ra = master_data['RA'][i]
        dec = master_data['Dec'][i]
        ccd = master_data['CCD'][i]
        candidate = master_data['Candidate'][i]
        tstart = master_data['Tstart'][i]
        tstop = master_data['Tstop'][i]
        obsid_dir = os.path.join(data_dir,str(obsid))

        all_regions_file = find_files.find_files(obsid_dir, '%s_all_regions.fits' %(obsid))[0]
        evtfile = find_files.find_files(obsid_dir, 'ccd_%s_%s_filtered.fits' %(ccd,obsid))[0]
        expfile = find_files.find_files(obsid_dir, '*%s*exp3*' %obsid)[0]

        expfile_new = os.path.join(outdir, "%s_cheesemask.fits" % obsid)

{'fraction_non_alphanumeric': 0.10750256937307297, 'fraction_numerical': 0.0024665981500513875, 'mean_word_length': 3.9401015228426397, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1051022', 'n_tokens_mistral': 1576, 'n_tokens_neox': 1549, 'n_words': 368}