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

Slightly improve efficiency of plot_singles, add color min/max option #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
57 changes: 33 additions & 24 deletions pycbclive_plot_singles.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ def plot_gate(ax, gate):
required=True,
help='Path to output plot'
)
parser.add_argument(
'--color-minmax',
type=float,
nargs=2,
default=[6, 12],
help="Minimum/maximum values for the colorbar"
)
args = parser.parse_args()

detectors = args.detectors
Expand All @@ -107,7 +114,7 @@ def plot_gate(ax, gate):

file_segs = segmentlist([])
trig_segs = {d: segmentlist([]) for d in detectors}
triggers = {d: None for d in detectors}
triggers = {d: {'dur': [], 'time': [], 'rank': []} for d in detectors}
gates = {d: [] for d in detectors}

trigger_files = glob.glob(args.trigger_files_glob)
Expand Down Expand Up @@ -136,44 +143,45 @@ def plot_gate(ax, gate):

trig_segs[detector].append(file_segment)

trig_times = grp['end_time'][:]
trig_durs = grp['template_duration'][:]
trig_ranks = newsnr_sgveto(
grp['snr'][:],
grp['chisq'][:],
grp['sg_chisq'][:]
)
if triggers[detector] is None:
triggers[detector] = [trig_times, trig_durs, trig_ranks]
else:
triggers[detector] = [
np.concatenate((triggers[detector][0], trig_times)),
np.concatenate((triggers[detector][1], trig_durs)),
np.concatenate((triggers[detector][2], trig_ranks))
]
triggers[detector]['rank'] += list(trig_ranks)

triggers[detector]['time'] += list(grp['end_time'][:])
triggers[detector]['dur'] += list(grp['template_duration'][:])
except OSError:
logging.error(f'Failed reading {fn}, ignoring')

n_triggers = {}
for detector in detectors:
for k in ['rank', 'dur', 'time']:
triggers[detector][k] = np.array(triggers[detector][k])
n_triggers[detector] = triggers[detector]['rank'].size

logging.info('Plotting')

ar_dur = Autorange()
for detector in detectors:
if triggers[detector] is not None:
ar_dur.update(triggers[detector][1])
if n_triggers[detector]:
ar_dur.update(triggers[detector]['dur'])

file_segs.coalesce()
for detector in detectors:
trig_segs[detector].coalesce()

ax[detectors[-1]].set_xlabel('Time')


for detector in detectors:
axd = ax[detector]
if triggers[detector] is None:
if n_triggers[detector] == 0:
axd.text(
0.5,
0.5,
'No triggers',
f'{detector}: No triggers',
horizontalalignment='center',
verticalalignment='center',
transform=axd.transAxes
Expand All @@ -199,18 +207,18 @@ def plot_gate(ax, gate):
lw=3
)
# plot triggers
sorter = np.argsort(triggers[detector][2])
sorter = np.argsort(triggers[detector]['rank'])
print('Max {} rw SNR {:.2f} at {:.3f}'.format(
detector,
triggers[detector][2][sorter[-1]],
triggers[detector][0][sorter[-1]]
triggers[detector]['rank'][sorter[-1]],
triggers[detector]['time'][sorter[-1]]
))
axd.scatter(
triggers[detector][0][sorter],
triggers[detector][1][sorter],
c=triggers[detector][2][sorter],
vmin=6,
vmax=12,
triggers[detector]['time'][sorter],
triggers[detector]['dur'][sorter],
c=triggers[detector]['rank'][sorter],
vmin=args.color_minmax[0],
vmax=args.color_minmax[1],
cmap='magma_r',
s=4,
lw=0
Expand Down Expand Up @@ -262,7 +270,8 @@ def plot_gate(ax, gate):
# add colorbar
cb = fig.colorbar(
matplotlib.cm.ScalarMappable(
matplotlib.colors.Normalize(vmin=6, vmax=12),
matplotlib.colors.Normalize(vmin=args.color_minmax[0],
vmax=args.color_minmax[1]),
cmap='magma_r'
),
cax=ax['cb'],
Expand Down