diff --git a/bin/plotting/pycbc_plot_bank_compression b/bin/plotting/pycbc_plot_bank_compression index 4400e5a04c4..ab59d698a25 100644 --- a/bin/plotting/pycbc_plot_bank_compression +++ b/bin/plotting/pycbc_plot_bank_compression @@ -16,6 +16,7 @@ import sys import pycbc from pycbc.io import HFile from pycbc.results import save_fig_with_metadata +from pycbc.waveform import bank import pycbc.tmpltbank as tmpltbank parser = argparse.ArgumentParser() @@ -88,6 +89,10 @@ if comparison_parameter not in tmpltbank.conversion_options: pycbc.init_logging(args.verbose) +# Quieten the matplotlib logger +plt.set_loglevel("info" if args.verbose else "warning") +logging.getLogger('matplotlib.font_manager').setLevel(logging.ERROR) + logging.info("Getting information from the bank") # The three things we want from the banks: @@ -102,23 +107,35 @@ for i, bank_fname in enumerate(args.bank_files): len(args.bank_files), bank_fname ) + with HFile(bank_fname, "r") as bank_f: compressed_grp = bank_f["compressed_waveforms"] + thashes = bank_f["template_hash"][:] + hash_order = np.argsort(thashes) + # These will be in hash order: + logging.debug("Getting compression factors") compression_factor += [ - compressed_grp[str(thash)].attrs["compression_factor"] - for thash in bank_f["template_hash"][:] + compressed_grp[comp_grp].attrs["compression_factor"] + for comp_grp in compressed_grp.keys() ] - approximants += [apx.decode() for apx in bank_f["approximant"][:]] + logging.debug("Getting approximants") + # These are in template_id order, so use hash_order to get them back: + approximants += [apx.decode() for apx in bank_f["approximant"][:][hash_order]] + logging.debug("Getting comparison values: %s", comparison_parameter) comparison_values += list(tmpltbank.get_bank_property( comparison_parameter, bank_f, - template_ids=np.arange(bank_f["template_hash"].size) + template_ids=hash_order )) approximants = np.array(approximants) comparison_values = np.array(comparison_values) compression_factor = np.array(compression_factor) +print(approximants.size) +print(comparison_values.size) +print(compression_factor.size) + # Store the max/min factors, as these are used for setting # histogram / plot limits max_factor = compression_factor.max() diff --git a/bin/workflows/pycbc_make_bank_compression_workflow b/bin/workflows/pycbc_make_bank_compression_workflow index ba3404823e5..3e635051d7f 100644 --- a/bin/workflows/pycbc_make_bank_compression_workflow +++ b/bin/workflows/pycbc_make_bank_compression_workflow @@ -103,7 +103,7 @@ os.chdir(args.output_dir) rdir = layout.SectionNumber( 'results', - ['compression', 'workflow',], + ['workflow',], ) wf.makedir(rdir.base) @@ -153,13 +153,18 @@ rejoined_banks = wf.make_combine_split_banks( ) # Make a plot of the compression factor of the templates -wf.make_bank_compression_plot( +plots = wf.make_bank_compression_plots( workflow, rejoined_banks, - out_dir=rdir['compression'], + out_dir=rdir.base, tags=None, ) +layout.single_layout( + rdir.base, + plots, +) + # Create versioning information wf.make_versioning_page( workflow, diff --git a/pycbc/workflow/plotting.py b/pycbc/workflow/plotting.py index 5d171ce1a3b..ee2134c04c2 100644 --- a/pycbc/workflow/plotting.py +++ b/pycbc/workflow/plotting.py @@ -575,25 +575,29 @@ def make_template_bin_table(workflow, dq_file, out_dir, tags=None): return node.output_files[0] -def make_bank_compression_plot(workflow, bank_files, out_dir, tags=None): +def make_bank_compression_plots(workflow, bank_files, out_dir, tags=None): tags = [] if tags is None else tags makedir(out_dir) - node = PlotExecutable( - workflow.cp, - "plot_bank_compression", - ifos=workflow.ifos, - out_dir=out_dir, - tags=tags).create_node() - - node.add_input_list_opt( - "--bank-files", - bank_files - ) - - node.new_output_file_opt( - workflow.analysis_time, - '.png', - '--output-file' - ) - workflow += node - return node.output_files[0] + secs = workflow.cp.get_subsections("plot_bank_compression") + files = FileList([]) + for tag in secs: + node = PlotExecutable( + workflow.cp, + "plot_bank_compression", + ifos=workflow.ifos, + out_dir=out_dir, + tags=[tag] + tags + ).create_node() + node.add_input_list_opt( + "--bank-files", + bank_files + ) + + node.new_output_file_opt( + workflow.analysis_time, + '.png', + '--output-file' + ) + workflow += node + files += node.output_files + return files