Skip to content

Commit

Permalink
Some fixes to allow the joined bank to be plotted
Browse files Browse the repository at this point in the history
  • Loading branch information
GarethCabournDavies committed Nov 13, 2024
1 parent 9b10b85 commit 643552e
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
25 changes: 21 additions & 4 deletions bin/plotting/pycbc_plot_bank_compression
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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:
Expand All @@ -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()
Expand Down
11 changes: 8 additions & 3 deletions bin/workflows/pycbc_make_bank_compression_workflow
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ os.chdir(args.output_dir)

rdir = layout.SectionNumber(
'results',
['compression', 'workflow',],
['workflow',],
)

wf.makedir(rdir.base)
Expand Down Expand Up @@ -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,
Expand Down
44 changes: 24 additions & 20 deletions pycbc/workflow/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 643552e

Please sign in to comment.