<commit_before>#!/usr/bin/env python
# Version: 1.0
# Author: <NAME> (updated by <NAME>)

from __future__ import division, print_function
import sys, math, os
import numpy as np
import scipy.stats
from scipy.stats import chi2
import datetime
import matplotlib.pyplot as plt
import glob
from collections import deque
import astropy.units as u
from astropy import log
from astropy.io import fits
from astropy.time import Time
from nicer.values import *
from pint.fits_utils import read_fits_event_mjds
from pint.eventstats import h2sig,hm,sig2sigma
import argparse

desc= """
Read one or more event files 
to sort GTI by background rate 
and evaluate H-test
"""

def local_h2sig(h):
    h = np.atleast_1d(h)
    rvals = np.zeros_like(h)
    for ix,x in enumerate(h):
        if x > 0:
            rvals[ix] = h2sig(x)
    return rvals

plt.rc('font', size=14)          # controls default text sizes
plt.rc('axes', labelsize=13)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=13)    # fontsize of the tick labels
plt.rc('ytick', labelsize=13)    # fontsize of the tick labels
plt.rc('legend', fontsize=14)    # legend fontsize
plt.rc('axes', linewidth=1.5)
plt.rc('xtick.major', size=4, width=1.5)
plt.rc('ytick.major', size=4, width=1.5)


parser = argparse.ArgumentParser(description = desc)
#parser.add_argument("evt", help="Input event files using glob.glob (e.g.'10010101*_Proc/cleanfilt_par.evt')")
parser.add_argument("infile", help="file or text file with list of event file", nargs='+')
parser.add_argument("outfile", help="name for output files")
parser.add_argument("--emin", help="Minimum energy to include (keV, default=0.25)", type=float, default=0.25)
parser.add_argument("--emax", help="Maximum energy to include (keV, default=2.00)", type=float, default=2.00)
parser.add_argument("--maxemin", help="Maximum emin to use in fine grid search (keV, default=1.00)", type=float, default=1.00)
parser.add_argument("--minemax", help="Minimum emax to use in fine grid search (keV, default=1.00)", type=float, default=1.00)
parser.add_argument("--gridsearch", help="Search over energies to find max H-test", action="store_true",default=False)
parser.add_argument("--coarsegridsearch", help="Search over energies to find max H-test", action="store_true",default=False)
parser.add_argument("--minbw", help="Minimum fractional bandwidth used during energy grid searching.  E.g., --minbw=0.5 would allow a 1.0 to 1.5 (50%) keV energy range, but not a 2.0 to 2.2 (10%) range.", type=float,default=None)
parser.add_argument("--minexp", help="Minimum exposure allowed for a candidate cut, expressed as a fraction of the total.  E.g., --minexp=0.2 would allow a cut that throws away 80% of the GTI.", type=float,default=None)
parser.add_argument("--nopulsetest", help="Only use the predicted S/N to determine the GTIs to use.", action="store_true",default=False)
parser.add_argument("--verbosity", help="Verbosity (0=quiet,1=default,2=verbose,3=very verbose).", type=int, default=1)
parser.add_argument("--savefile", help="Saving optimized event file", action="store_true",default=False)
parser.add_argument("--usez", help="Use Z^2_2 test instead of H test.", action="store_true",default=False)
parser.add_argument("--nbins", help="Number of bins for plotting pulse profile (default=16)", type=int, default=16)
parser.add_argument("--name", help="Pulsar name for output figure", type=str, default='')
args = parser.parse_args()

def load_files(fnames):
    # make a comprehensive list of gtis/rates
    
    gtis = deque()
    times = deque()
    pis = deque()
    phases = deque()
    for fname in fnames:
        f = fits.open(fname)
        t0s = f['gti'].data.field('start')
        t1s = f['gti'].data.field('stop')
        for t0,t1 in zip(t0s,t1s):
            gtis.append([t0,t1])<commit_msg>Fix %s in argparse help messages<commit_after>#!/usr/bin/env python
# Version: 1.0
# Author: <NAME> (updated by <NAME>)

from __future__ import division, print_function
import sys, math, os
import numpy as np
import scipy.stats
from scipy.stats import chi2
import datetime
import matplotlib.pyplot as plt
import glob
from collections import deque
import astropy.units as u
from astropy import log
from astropy.io import fits
from astropy.time import Time
from nicer.values import *
from pint.fits_utils import read_fits_event_mjds
from pint.eventstats import h2sig,hm,sig2sigma
import argparse

desc= """
Read one or more event files 
to sort GTI by background rate 
and evaluate H-test
"""

def local_h2sig(h):
    h = np.atleast_1d(h)
    rvals = np.zeros_like(h)
    for ix,x in enumerate(h):
        if x > 0:
            rvals[ix] = h2sig(x)
    return rvals

plt.rc('font', size=14)          # controls default text sizes
plt.rc('axes', labelsize=13)    # fontsize of the x and y labels
plt.rc('xtick', labelsize=13)    # fontsize of the tick labels
plt.rc('ytick', labelsize=13)    # fontsize of the tick labels
plt.rc('legend', fontsize=14)    # legend fontsize
plt.rc('axes', linewidth=1.5)
plt.rc('xtick.major', size=4, width=1.5)
plt.rc('ytick.major', size=4, width=1.5)


parser = argparse.ArgumentParser(description = desc)
#parser.add_argument("evt", help="Input event files using glob.glob (e.g.'10010101*_Proc/cleanfilt_par.evt')")
parser.add_argument("infile", help="file or text file with list of event file", nargs='+')
parser.add_argument("outfile", help="name for output files")
parser.add_argument("--emin", help="Minimum energy to include (keV, default=0.25)", type=float, default=0.25)
parser.add_argument("--emax", help="Maximum energy to include (keV, default=2.00)", type=float, default=2.00)
parser.add_argument("--maxemin", help="Maximum emin to use in fine grid search (keV, default=1.00)", type=float, default=1.00)
parser.add_argument("--minemax", help="Minimum emax to use in fine grid search (keV, default=1.00)", type=float, default=1.00)
parser.add_argument("--gridsearch", help="Search over energies to find max H-test", action="store_true",default=False)
parser.add_argument("--coarsegridsearch", help="Search over energies to find max H-test", action="store_true",default=False)
parser.add_argument("--minbw", help="Minimum fractional bandwidth used during energy grid searching.  E.g., --minbw=0.5 would allow a 1.0 to 1.5 (50%%) keV energy range, but not a 2.0 to 2.2 (10%%) range.", type=float,default=None)
parser.add_argument("--minexp", help="Minimum exposure allowed for a candidate cut, expressed as a fraction of the total.  E.g., --minexp=0.2 would allow a cut that throws away 80%% of the GTI.", type=float,default=None)
parser.add_argument("--nopulsetest", help="Only use the predicted S/N to determine the GTIs to use.", action="store_true",default=False)
parser.add_argument("--verbosity", help="Verbosity (0=quiet,1=default,2=verbose,3=very verbose).", type=int, default=1)
parser.add_argument("--savefile", help="Saving optimized event file", action="store_true",default=False)
parser.add_argument("--usez", help="Use Z^2_2 test instead of H test.", action="store_true",default=False)
parser.add_argument("--nbins", help="Number of bins for plotting pulse profile (default=16)", type=int, default=16)
parser.add_argument("--name", help="Pulsar name for output figure", type=str, default='')
args = parser.parse_args()

def load_files(fnames):
    # make a comprehensive list of gtis/rates
    
    gtis = deque()
    times = deque()
    pis = deque()
    phases = deque()
    for fname in fnames:
        f = fits.open(fname)
        t0s = f['gti'].data.field('start')
        t1s = f['gti'].data.field('stop')
        for t0,t1 in zip(t0s,t1s):
            gtis.append([t0,t1])
{'fraction_non_alphanumeric': 0.14102564102564102, 'fraction_numerical': 0.02511773940345369, 'mean_word_length': 4.756777108433735, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '3367502', 'n_tokens_mistral': 2648, 'n_tokens_neox': 2505, 'n_words': 756}