feat: adds output binning and revises cli arguments
All checks were successful
gitea-physics/tantri/pipeline/head This commit looks good
All checks were successful
gitea-physics/tantri/pipeline/head This commit looks good
This commit is contained in:
parent
402f6bd275
commit
f31b6aa6b1
@ -1,3 +1,7 @@
|
||||
"""
|
||||
Binning data.
|
||||
"""
|
||||
from tantri.binning.binning import bin_lists, BinConfig, BinSummary, BinSummaryValue
|
||||
|
||||
|
||||
__all__ = ["bin_lists", "BinConfig", "BinSummary", "BinSummaryValue"]
|
||||
|
@ -4,6 +4,7 @@ import tantri
|
||||
import numpy
|
||||
import tantri.cli.input_files.write_dipoles
|
||||
import tantri.cli.file_importer
|
||||
import tantri.binning
|
||||
import json
|
||||
import tantri.dipoles
|
||||
import tantri.dipoles.event_time_series
|
||||
@ -255,12 +256,25 @@ def _write_time_series(
|
||||
help="A seed to use to create an override default rng. You should set this.",
|
||||
)
|
||||
@click.option(
|
||||
"output_file",
|
||||
"--output-file",
|
||||
"-o",
|
||||
type=click.Path(path_type=pathlib.Path),
|
||||
help="The output file to write, in csv format",
|
||||
required=True,
|
||||
)
|
||||
@click.option(
|
||||
"--binned-output-file",
|
||||
"-b",
|
||||
type=click.Path(path_type=pathlib.Path),
|
||||
help="Optional binned output file",
|
||||
)
|
||||
@click.option(
|
||||
"--bin-widths",
|
||||
type=float,
|
||||
default=1,
|
||||
show_default=True,
|
||||
help="The default log(!) bin width, 1 means widths of a decade",
|
||||
)
|
||||
@click.option("--header-row/--no-header-row", default=False, help="Write a header row")
|
||||
def write_apsd(
|
||||
dipoles_file,
|
||||
@ -271,6 +285,8 @@ def write_apsd(
|
||||
num_time_series,
|
||||
time_series_rng_seed,
|
||||
output_file,
|
||||
binned_output_file,
|
||||
bin_widths,
|
||||
header_row,
|
||||
):
|
||||
"""
|
||||
@ -285,6 +301,8 @@ def write_apsd(
|
||||
num_time_series,
|
||||
time_series_rng_seed,
|
||||
output_file,
|
||||
binned_output_file,
|
||||
bin_widths,
|
||||
header_row,
|
||||
)
|
||||
|
||||
@ -298,6 +316,8 @@ def _write_apsd(
|
||||
num_time_series,
|
||||
time_series_rng_seed,
|
||||
output_file,
|
||||
binned_output_file,
|
||||
bin_widths,
|
||||
header_row,
|
||||
):
|
||||
_logger.debug(
|
||||
@ -343,6 +363,30 @@ def _write_apsd(
|
||||
for freq, values in zip(apsd.freqs, values_list):
|
||||
value_string = ", ".join(str(v) for v in values)
|
||||
out.write(f"{freq}, {value_string}\n")
|
||||
if binned_output_file is not None:
|
||||
with binned_output_file.open("w") as out:
|
||||
if header_row:
|
||||
value_labels = ["mean bin f (Hz)"]
|
||||
for label in labels:
|
||||
value_labels.append(f"{value_name}_{label}_mean")
|
||||
value_labels.append(f"{value_name}_{label}_stdev")
|
||||
value_labels_text = ", ".join(value_labels)
|
||||
out.write(value_labels_text + "\n")
|
||||
binned = tantri.binning.bin_lists(
|
||||
apsd.freqs,
|
||||
apsd.psd_dict,
|
||||
tantri.binning.BinConfig(
|
||||
True, bin_width=bin_widths, bin_min=1e-6, min_points_required=2
|
||||
),
|
||||
)
|
||||
for bin_result in binned:
|
||||
summary = bin_result.summary_point()
|
||||
out_list = [str(summary.mean_x)]
|
||||
for label in labels:
|
||||
out_list.append(str(summary.summary_values[label].mean_y))
|
||||
out_list.append(str(summary.summary_values[label].stdev_y))
|
||||
out_string = ", ".join(out_list) + "\n"
|
||||
out.write(out_string)
|
||||
|
||||
|
||||
@cli.command()
|
||||
|
Loading…
x
Reference in New Issue
Block a user