Skip to content

Commit

Permalink
Various tweaks to plots and scripts
Browse files Browse the repository at this point in the history
- Logging: Using loguru, but removing the pint.logging dependency (I copied the pint.logging format, but not the custom filters). #84
- ENG plots:  changed name of reset rate issue #89
- SCI plots:  small changes to displayed information #88 and #14
- BKG plots: small changes (marker size, grid lines, etc) #90
- GTI sorting script:  dumps the optimal profile to a text file with option --save_profile
  • Loading branch information
sguillot committed Aug 26, 2022
1 parent 5c93d45 commit 4086bd6
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 25 deletions.
2 changes: 1 addition & 1 deletion nicer/eng_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def eng_plots(etable, args, mktable, filttable, gtitable):

# RESET RATE PER DETECTOR
if mktable is not None:
log.info("Computing reset rates")
log.info("Computing undershoot-only reset rate")
plot.subplot(sci_grid[:2, 2:4])
reset_rates = calc_nresets(mktable, IDS) / etable.meta["EXPOSURE"]
if reset_rates is not None:
Expand Down
19 changes: 12 additions & 7 deletions nicer/plotutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,16 +881,18 @@ def plot_angles(mktable, gtitable):
goodtime, moonangle, cc = convert_to_elapsed_goodtime(met, moon, gtitable)
goodtime, elvangle, cc = convert_to_elapsed_goodtime(met, elv, gtitable)

plot.scatter(goodtime, sunangle, marker=".", color="y", alpha=0.5, label="Sun")
plot.scatter(goodtime, sunangle, marker=".", s=3, color="y", alpha=0.5, label="Sun")
plot.scatter(
goodtime, earthangle, marker=".", color="b", alpha=0.5, label="Bright Earth"
goodtime, earthangle, marker=".", s=3, color="b", alpha=0.5, label="Bright Earth"
)
plot.scatter(goodtime, moonangle, marker=".", color="grey", alpha=0.5, label="Moon")
plot.scatter(goodtime, elvangle, marker=".", color="m", alpha=0.5, label="ELV")
plot.scatter(goodtime, moonangle, marker=".", s=3, color="grey", alpha=0.5, label="Moon")
plot.scatter(goodtime, elvangle, marker=".", s=3, color="m", alpha=0.5, label="ELV")
plot.legend(loc=2)
plot.ylim((0.0, 180.0))
plot.grid(True)
plot.yticks([0.0, 45.0, 90.0, 135.0, 180.0])
plot.minorticks_on()
plot.grid(which='minor', axis='y', linewidth=0.5, alpha=0.4)
plot.ylabel("Angle (deg)")

return
Expand Down Expand Up @@ -963,15 +965,18 @@ def plot_cor(mktable, gtitable):
c=np.fmod(cc, len(colornames)),
norm=norm,
cmap=cmap,
marker="^",
marker=".",
s=3,
label="COR_SAX",
)
# plot.scatter(time, lon, c = colors, cmap = cmap, marker = '_', label = 'Longitude')
plot.legend(loc=2)
plot.ylim((0.0, 20.0))
plot.axhline(5.0, linestyle="--", color="r")
plot.axhline(1.5, linestyle="--", color="r")
plot.xlabel("Elapsed Time (s)", labelpad=1)
plot.grid(True)
plot.minorticks_on()
plot.grid(which='minor', axis='y', linewidth=0.5, alpha=0.3)
plot.ylabel("GeV")
return

Expand Down Expand Up @@ -1004,7 +1009,7 @@ def calc_nresets(mktable, IDS):
def plot_resetrate(IDS, reset_rates):
"Plots reset rates"
reset = plot.bar(IDS, reset_rates, width=0.85)
plot.title("Reset Rate by Detector")
plot.title("Undershoot-only reset rate by Detector")
plot.ylabel("Reset Rate [Hz]")
plot.xlabel("DET_ID")
# plot.ylim([0, np.max(reset_rates)+2])
Expand Down
39 changes: 33 additions & 6 deletions nicer/sci_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,50 @@ def sci_plots(etable, gtitable, args):
plt.figtext(
0.07,
0.93,
"Start time is {0}, End time is {1}".format(tstart.iso, tend.iso),
"Start time: {0} - End time: {1}".format(tstart.iso, tend.iso),
fontsize=10,
)
plt.figtext(
0.07,
0.90,
"Exposure is {0:.1f} s, Good time fraction is {1:.3f}".format(
"Total clock time between start and stop: {0:.1f} s".format(
float(etable.meta["TSTOP"]) - float(etable.meta["TSTART"])
),
fontsize=10,
)
plt.figtext(
0.07,
0.87,
"Exposure: {0:.1f} s --> Coverage fraction is {1:.3f}".format(
exposure, fraction
),
fontsize=10,
)
plt.figtext(0.07, 0.87, "Mean count rate {0:.3f} c/s".format(meanrate), fontsize=10)
plt.figtext(0.07, 0.84, "Mean count rate: {0:.3f} c/s".format(meanrate), fontsize=10)
# plt.figtext(.07, .84, etable.meta['FILT_STR'], fontsize=10)
if args.mask:
plt.figtext(0.07, 0.81, "IDS {0} are masked".format(args.mask), fontsize=10)
plt.figtext(0.5, 0.77, str(gtitable["START"][:]), fontsize=9)
plt.figtext(0.58, 0.77, str(gtitable["STOP"][:]), fontsize=9)
plt.figtext(0.66, 0.77, str(gtitable["DURATION"][:]), fontsize=9)

stringtable_start = str(gtitable["START"][:]).split('\n')
stringtable_stop = str(gtitable["STOP"][:]).split('\n')
stringtable_duration = str(gtitable["DURATION"][:]).split('\n')

# Bit of formatting of the duration table
stringtable_duration[0:2] = [" {}".format(i) for i in stringtable_duration[0:2]]
stringtable_duration[2] = "---{}".format(stringtable_duration[2])
stringtable_duration[3:] = [" {}".format(i) for i in stringtable_duration[3:]]

# omits GTIs in the display table if there are more than 7 (the first 3 lines are for the table header)
if len(stringtable_start)> 10:
stringtable_start = stringtable_start[0:6] + ['...'] + stringtable_start[-3:]
stringtable_stop = stringtable_stop[0:6] + ['...'] + stringtable_stop[-3:]
stringtable_duration = stringtable_duration[0:6] + ['({:9.1f})'.format(np.sum(list(map(float, stringtable_duration[7:-3]))))] + stringtable_duration[-3:]
stringtable_start ='\n'.join(stringtable_start)
stringtable_stop ='\n'.join(stringtable_stop)
stringtable_duration ='\n'.join(stringtable_duration)

plt.figtext(0.5, 0.77, stringtable_start, fontsize=10, fontname='Courier')
plt.figtext(0.58, 0.77, stringtable_stop, fontsize=10, fontname='Courier')
plt.figtext(0.66, 0.77, stringtable_duration, fontsize=10, fontname='Courier')

return figure2
13 changes: 13 additions & 0 deletions scripts/ni_Htest_sortgti.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@
action="store_true",
default=False,
)

parser.add_argument(
"--save_profile",
help="export optimal profile as ascii file",
action="store_true",
default=False,
)
parser.add_argument(
"--usez",
help="Use Z^2_2 test instead of H test.",
Expand Down Expand Up @@ -811,6 +818,12 @@ def make_sn(data, rate=0.1, usez=False, snonly=False, minexp=None):
)
log.info(" for {} events".format(len(select_ph)))

if args.save_profile:
output_data = np.array([bbins - (0.5 / nbins), fullprof, fullprof**0.5]).T
np.savetxt("{}_profile.txt".format(args.outfile),
output_data,
header='Phase Counts ErrorBar')

# output summary results to text file
a50 = int(round(len(gti_rts_s) * 0.5))
a90 = int(round(len(gti_rts_s) * 0.9))
Expand Down
10 changes: 5 additions & 5 deletions scripts/nicerql.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
import os, sys
import pint.logging
#import pint.logging
from loguru import logger as log

pint.logging.setup(level=pint.logging.script_level)
#pint.logging.setup(level=pint.logging.script_level)


# Hack to add this to pythonpath
Expand Down Expand Up @@ -165,8 +165,8 @@
sys.stderr,
level=args.loglevel,
colorize=True,
format=pint.logging.format,
filter=pint.logging.LogFilter(),
format='<level>{level: <8}</level> ({name: <30}): <level>{message}</level>'
#filter=pint.logging.LogFilter(),
)

# ------------------------------Getting the data and concatenating------------------------------
Expand Down Expand Up @@ -534,7 +534,7 @@

# Map plot is overshoot and undershoot rates on maps
if args.map:
log.info("I'M THE MAP I'M THE MAP I'M THE MAAAAP")
#log.info("I'M THE MAP I'M THE MAP I'M THE MAAAAP")
# if eventovershoots is not None:
# figure3 = cartography(hkmet, eventovershoots, args, eventundershoots,
# filttable, mktable, gtitable)
Expand Down
4 changes: 2 additions & 2 deletions scripts/photon_toa.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@
from pint.observatory import get_observatory
from pint.observatory.special_locations import T2SpacecraftObs

import pint.logging
#import pint.logging
from loguru import logger as log

pint.logging.setup(level=pint.logging.script_level)
#pint.logging.setup(level=pint.logging.script_level)


def local_load_NICER_TOAs(eventname):
Expand Down
8 changes: 4 additions & 4 deletions scripts/psrpipe.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env python
import os, sys
import pint.logging
#import pint.logging
from loguru import logger as log

pint.logging.setup(level=pint.logging.script_level)
#pint.logging.setup(level=pint.logging.script_level)

import numpy as np
import argparse
Expand Down Expand Up @@ -182,8 +182,8 @@
sys.stderr,
level=args.loglevel,
colorize=True,
format=pint.logging.format,
filter=pint.logging.LogFilter(),
format='<level>{level: <8}</level> ({name: <30}): <level>{message}</level>'
#filter=pint.logging.LogFilter(),
)


Expand Down

3 comments on commit 4086bd6

@paulray
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@sguillot
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this branch can now be merged into the master.

@paulray
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great! Feel free to do the merge!

Please sign in to comment.