Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster merge.py #30

Merged
merged 5 commits into from
Mar 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 32 additions & 19 deletions scripts/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
parser.add_argument("outroot", help="root of the output filenames", type=str)
parser.add_argument("outdir", help="Name of output directory", type=str)
parser.add_argument("--par", help="Par file to use for phases (in nicerql.py)")
parser.add_argument("--ephem", help="Ephem to use with photonphase", default="DE421")
parser.add_argument("--orb", help="text file containing the paths to all orbits files")
parser.add_argument("--cut", help="perform count rate cut at the end", action='store_true')
parser.add_argument("--clobber", help="replace existing merged files", action='store_true')
Expand Down Expand Up @@ -133,24 +134,36 @@ def runcmd(cmd):
runcmd(cmd)

# Make final merged clean plot
log.info('Making Science Plots of merged event file')
cmd = ["nicerql.py", "--save", "--merge",
"--sci", outname, "--lcbinsize", "4.0","--allspec","--alllc",
"--basename", path.splitext(outname)[0]]
if args.par is not None:
cmd.append("--par")
cmd.append("{0}".format(args.par))
cmd.append("--orb")
cmd.append("@{0}".format(args.orb))
runcmd(cmd)

# Make Phaseogram
if args.par is not None:
plotfile = path.join(pipedir,"{}_phaseogram.png".format(args.outroot))
cmd = ["photonphase", "--fix", "--orb", "@{0}".format(args.orb) ,
"--plot", "--plotfile", plotfile, "--addphase", outname, args.par]
# load merged events file
merged_table = Table.read(outname,hdu=1)

# Check if column 'PULSE_PHASE' exists:
if 'PULSE_PHASE' in merged_table.colnames:
log.info('Making Phaseogram with niphaseogram.py, since PULSE_PHASE columns exists')
plotfile = path.join(pipedir,"{}_niphaseogram.png".format(args.outroot))
cmd = ["niphaseogram.py","--outfile={}".format(plotfile),outname]
runcmd(cmd)
else:
if args.par is not None:
# calculate phases
log.info("Calculating the PULSE_PHASE with pint.photonphase")
cmd = ["photonphase", "--ephem", args.ephem, "--orb", "@{0}".format(args.orb),
"--addphase", outname, args.par]
runcmd(cmd)
log.info('Making Phaseogram with niphaseogram.py')
plotfile = path.join(pipedir,"{}_niphaseogram.png".format(args.outroot))
cmd = ["niphaseogram.py","--outfile={}".format(plotfile),outname]
runcmd(cmd)


# Extract simple PHA file and light curve
log.info('Extracting Spectrum and Light Curve')
phafile = path.join(pipedir,"{}.pha".format(args.outroot))
lcfile = path.join(pipedir,"{}.lc".format(args.outroot))
cmd = ["extractor", outname, "eventsout=none", "imgfile=none",
Expand All @@ -160,6 +173,7 @@ def runcmd(cmd):
"ycolh=RAWY", "gti=GTI"]
runcmd(cmd)


# Call to cr_cut.py
if args.cut:
cmd = ["cr_cut.py", "{}".format(outname), "--plotfilt"]
Expand All @@ -171,21 +185,20 @@ def runcmd(cmd):
cmd = ["nicerql.py", "--save", "--merge",
"--sci", outname_cut, "--lcbinsize", "4.0","--allspec","--alllc",
"--basename", path.splitext(outname_cut)[0]]
if args.par is not None:
cmd.append("--par")
cmd.append("{0}".format(args.par))
cmd.append("--orb")
cmd.append("@{0}".format(args.orb))
runcmd(cmd)

# Make Phaseogram_Cut
if args.par is not None:
# load merged_cut events file
merged_cut_table = Table.read(outname_cut,hdu=1)

# Check if column 'PULSE_PHASE' exists:
if 'PULSE_PHASE' in merged_cut_table.colnames:
log.info('Making Phaseogram with niphaseogram.py after the count rate cut')
plotfile = path.join(pipedir,"{}_cut_phaseogram.png".format(args.outroot))
cmd = ["photonphase", "--fix", "--orb", "@{0}".format(args.orb) ,
"--plot", "--plotfile", plotfile, "--addphase", outname_cut, args.par]
cmd = ["niphaseogram.py","--outfile={}".format(plotfile),outname_cut]
runcmd(cmd)

# Extract simple PHA file and light curve
log.info('Extracting Spectrum and Light Curve after the count rate cut')
phafile_cut = path.join(pipedir,"{}_cut.pha".format(args.outroot))
lcfile_cut = path.join(pipedir,"{}_cut.lc".format(args.outroot))
cmd = ["extractor", outname_cut, "eventsout=none", "imgfile=none",
Expand Down
1 change: 0 additions & 1 deletion scripts/ni_data_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,6 @@ def untar(obsid,outdir):

def decrypt(passwd,obsid_dir,gpg_v):
cmd = "find {} -name '*.gpg' -exec {} --batch --yes --passphrase '{}' {{}} \; -delete".format(obsid_dir, gpg_v, passwd)
print(obsid_dir)
try:
os.remove("{}/ni-gpg-call.log".format(obsid_dir))
except OSError:
Expand Down