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

Fix plot_singles and optimize memory #4566

Merged
merged 4 commits into from
Nov 15, 2023
Merged
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
39 changes: 30 additions & 9 deletions bin/plotting/pycbc_plot_singles_vs_params
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,29 @@ opts = parser.parse_args()

logging.basicConfig(format='%(asctime)s %(message)s', level=logging.INFO)

snr_filter = '(self.snr>%f)' % (opts.min_snr) if opts.min_snr > 0. else None
filts = [f for f in [snr_filter, opts.filter_string] if f is not None]
filter_func = ' & '.join(filts) if filts else None

trigs = pycbc.io.SingleDetTriggers(opts.single_trig_file, opts.bank_file,
opts.veto_file, opts.segment_name, filter_func, opts.detector)
data_mask = None
if opts.min_snr > 0:
with pycbc.io.HFile(opts.single_trig_file, 'r') as trig_file:
n_triggers_orig = trig_file[f'{opts.detector}/snr'].size
logging.info("Trigger file has %d triggers", n_triggers_orig)
logging.info('Generating trigger mask (on SNR)')
idx, _ = trig_file.select(
lambda snr: snr >= opts.min_snr,
f'{opts.detector}/snr',
return_indices=True
)
data_mask = np.zeros(n_triggers_orig, dtype=bool)
data_mask[idx] = True

trigs = pycbc.io.SingleDetTriggers(
opts.single_trig_file,
opts.bank_file,
opts.veto_file,
opts.segment_name,
opts.filter_string,
opts.detector,
premask=data_mask
)

x = getattr(trigs, opts.x_var)
y = getattr(trigs, opts.y_var)
Expand All @@ -108,10 +125,14 @@ y = y[mask]

hexbin_style = {
'gridsize': opts.grid_size,
# hexbin shows bins with *less* than mincnt as blank
'mincnt': 0,
'linewidths': 0.03
}

# In earlier versions mpl will try to take the max over bins with 0 triggers
# and fail, unless we tell it to leave these blank by setting mincnt
if matplotlib.__version__ < '3.8.1':
hexbin_style['mincnt'] = 0

if opts.log_x:
hexbin_style['xscale'] = 'log'
if opts.log_y:
Expand All @@ -137,7 +158,7 @@ elif opts.z_var in ranking.sngls_ranking_function_dict:
max_z = z.max() if opts.max_z is None else opts.max_z
if max_z / min_z > 10:
cb_style['ticks'] = LogLocator(subs=range(10))
hb = ax.hexbin(x, y, C=z, reduce_C_function=max, **hexbin_style)
hb = ax.hexbin(x, y, C=z, reduce_C_function=np.max, **hexbin_style)
fig.colorbar(hb, **cb_style)
else:
raise RuntimeError('z_var = %s is not recognized!' % (opts.z_var))
Expand Down
Loading