Skip to content

Commit

Permalink
process_irs: write data file metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
tomjnixon committed Feb 16, 2024
1 parent d53cc0a commit eb7634e
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
20 changes: 18 additions & 2 deletions bear/process_irs/Snakefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,21 @@ rule find_global_delays:
shell:
"python -m bear.process_irs.find_global_delays {params.args} --tf-in {input[0]} {params.in_delays} --out {output}"

def get_meta_args(wildcards):
metadata = config["params"][wildcards.params].get("metadata", {}).get(wildcards.sofa, {})
label = metadata.get("label", wildcards.sofa)
description = metadata.get("description")

args = ["--label", label]

if description is not None:
args.extend(["--description", description])

if metadata.get("released", False):
args.append("--released")

return args

rule finalise:
input:
"irs/{params}/{sofa}.tf",
Expand All @@ -49,9 +64,10 @@ rule finalise:
"bear_data/{params}/{sofa}.tf",
"finalise_extra/{params}/{sofa}.tf",
params:
args=lambda w: config["params"][w.params].get("finalise_args", "")
args=lambda w: config["params"][w.params].get("finalise_args", ""),
meta_args=get_meta_args,
shell:
"python -m bear.process_irs.finalise {params.args} --tf-in {input[0]} --delays {input[1]} --tf-out {output[0]} --hoa-decoder {input[2]} --extra-out {output[1]}"
"python -m bear.process_irs.finalise {params.args} {params.meta_args:q} --tf-in {input[0]} --delays {input[1]} --tf-out {output[0]} --hoa-decoder {input[2]} --extra-out {output[1]}"

rule report:
input:
Expand Down
12 changes: 12 additions & 0 deletions bear/process_irs/finalise.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ def parse_args():
help="enable gain normalisation factors",
)

parser.add_argument('--label', help="label for metadata", required=True)
parser.add_argument('--description', help="description for metadata")
parser.add_argument('--released', help=argparse.SUPPRESS, action="store_true")

return parser.parse_args()


Expand Down Expand Up @@ -381,8 +385,16 @@ def main(args):
# select front loudspeaker idx
front_loudspeaker = np.argmin(np.linalg.norm(positions - [0, 1, 0], axis=1))

metadata = dict(
label=args.label,
released=args.released,
)
if args.description is not None:
metadata["description"] = args.description

output = dict(
bear_data_version=0,
metadata=metadata,
views=views.astype(np.float32),
# shape (view, loudspeaker, ear, sample)
brirs=irs.astype(np.float32),
Expand Down
2 changes: 1 addition & 1 deletion doc/ir_processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ final data file.

For BRIRs:

python -m bear.process_irs.finalise --tf-in irs.tf --delays global_delays.npy --tf-out bear_data.tf --hoa-decoder bear/process_irs/data/AmbiHOA3_magLS.sofa --extra-out finalise_extra.tf
python -m bear.process_irs.finalise --label "example v1" --tf-in irs.tf --delays global_delays.npy --tf-out bear_data.tf --hoa-decoder bear/process_irs/data/AmbiHOA3_magLS.sofa --extra-out finalise_extra.tf

For HRIRs, add "--window none" to disable windowing.

Expand Down

0 comments on commit eb7634e

Please sign in to comment.