Lv0_psrpipe.py
def psrpipe(eventfile,flags):
    """
    Running psrpipe on the observation, to make more cuts! I decided not to
    put in pre-determined options for fully flexibility. Though standard flags
    would be ['--emin','0.3','--emax','12.0','--shrinkelvcut'], though there are
    others. Check out "psrpipe.py -h"! Also made sure that I moved $OBSID_pipe from
    the working directory to where NICERSOFT_DATADIR is, though I need to temporarily
    store the output folder in the working directory.

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    flags - a LIST of input flags for psrpipe
    """
    if type(eventfile) != str:
        raise TypeError("eventfile should be a string!")
    if type(flags) != list:
        raise TypeError("flags should be a list! Not even an array.")

    event = fits.open(eventfile)
    obsid = event[0].header['OBS_ID']
    logfile = obsid + '_psrpipe.log'

    if os.path.isdir(Lv0_dirs.NICERSOFT_DATADIR+obsid+'_pipe'): #to prevent duplicate files ; not likely to be the case, but just in case...
        subprocess.run(['rm','-r',Lv0_dirs.NICERSOFT_DATADIR+obsid+'_pipe'])

    with open(logfile,'w') as logtextfile:
        command = ['psrpipe.py',Lv0_dirs.NICER_DATADIR+obsid] + flags
        output = subprocess.run(command,capture_output=True,text=True)
        logtextfile.write(output.stdout)
        logtextfile.write('*------------------------------* \n')
        logtextfile.write(output.stderr)
        logtextfile.close()

    subprocess.run(['mv',obsid+'_pipe/',Lv0_dirs.NICERSOFT_DATADIR+obsid+'_pipe/'])
    subprocess.run(['mv',obsid+'_psrpipe.log',Lv0_dirs.NICERSOFT_DATADIR+obsid+'_pipe/'])
    #done later because the log file was created BEFORE $OBSID_pipe is created

    return

    Running psrpipe on the observation, to make more cuts! I decided not to
    put in pre-determined options for fully flexibility. Though standard flags
    would be ['--emin','0.3','--emax','12.0','--shrinkelvcut'], though there are
    others. Check out "psrpipe.py -h"! Also made sure that I moved $OBSID_pipe from
    the working directory to where NICERSOFT_DATADIR is, though I need to temporarily
    store the output folder in the working directory.

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    flags - a LIST of input flags for psrpipe
    
Running psrpipe on the observation, to make more cuts. I decided not to
put in pre-determined options for fully flexibility.

path to the event file. Will extract ObsID from this for the NICER files.
flags - a LIST of input flags for psrpipe
Running psrpipe on the observation to make more cuts . I decided not to put in pre - determined options for fully flexibility . path to the event file . Will extract ObsID from this for the NICER files . flags - a LIST of input flags for psrpipe
def psrpipe(eventfile,flags):
    if type(eventfile) != str:
        raise TypeError("eventfile should be a string!")
    if type(flags) != list:
        raise TypeError("flags should be a list! Not even an array.")
    event = fits.open(eventfile)
    obsid = event[0].header['OBS_ID']
    logfile = obsid + '_psrpipe.log'
    if os.path.isdir(Lv0_dirs.NICERSOFT_DATADIR+obsid+'_pipe'): 
        subprocess.run(['rm','-r',Lv0_dirs.NICERSOFT_DATADIR+obsid+'_pipe'])
    with open(logfile,'w') as logtextfile:
        command = ['psrpipe.py',Lv0_dirs.NICER_DATADIR+obsid] + flags
        output = subprocess.run(command,capture_output=True,text=True)
        logtextfile.write(output.stdout)
        logtextfile.write('*------------------------------* \n')
        logtextfile.write(output.stderr)
        logtextfile.close()
    subprocess.run(['mv',obsid+'_pipe/',Lv0_dirs.NICERSOFT_DATADIR+obsid+'_pipe/'])
    subprocess.run(['mv',obsid+'_psrpipe.log',Lv0_dirs.NICERSOFT_DATADIR+obsid+'_pipe/'])
    return
def psrpipe ( eventfile , flags ) : if type ( eventfile ) != str : raise TypeError ( "eventfile should be a string!" ) if type ( flags ) != list : raise TypeError ( "flags should be a list! Not even an array." ) event = fits . open ( eventfile ) obsid = event [ 0 ] . header [ 'OBS_ID' ] logfile = obsid + '_psrpipe.log' if os . path . isdir ( Lv0_dirs . NICERSOFT_DATADIR + obsid + '_pipe' ) : subprocess . run ( [ 'rm' , '-r' , Lv0_dirs . NICERSOFT_DATADIR + obsid + '_pipe' ] ) with open ( logfile , 'w' ) as logtextfile : command = [ 'psrpipe.py' , Lv0_dirs . NICER_DATADIR + obsid ] + flags output = subprocess . run ( command , capture_output = True , text = True ) logtextfile . write ( output . stdout ) logtextfile . write ( '*------------------------------* \n' ) logtextfile . write ( output . stderr ) logtextfile . close ( ) subprocess . run ( [ 'mv' , obsid + '_pipe/' , Lv0_dirs . NICERSOFT_DATADIR + obsid + '_pipe/' ] ) subprocess . run ( [ 'mv' , obsid + '_psrpipe.log' , Lv0_dirs . NICERSOFT_DATADIR + obsid + '_pipe/' ] ) return
Running psrpipe on the observation, to make more cuts!
Running psrpipe on the observation to make more cuts!
"""
    Running psrpipe on the observation, to make more cuts! I decided not to
    put in pre-determined options for fully flexibility. Though standard flags
    would be ['--emin','0.3','--emax','12.0','--shrinkelvcut'], though there are
    others. Check out "psrpipe.py -h"! Also made sure that I moved $OBSID_pipe from
    the working directory to where NICERSOFT_DATADIR is, though I need to temporarily
    store the output folder in the working directory.

    eventfile - path to the event file. Will extract ObsID from this for the NICER files.
    flags - a LIST of input flags for psrpipe
    """ #to prevent duplicate files ; not likely to be the case, but just in case... #done later because the log file was created BEFORE $OBSID_pipe is created
eventfile
flags