Commit a24528c6 authored by Archit Tamarapu's avatar Archit Tamarapu
Browse files

update plotting code to filter to IVAS bitrates and cleanup

parent 6e30d0ce
Loading
Loading
Loading
Loading
+29 −6
Original line number Diff line number Diff line
@@ -12,6 +12,22 @@ from ivas_processing_scripts.utils import progressbar_update
if os.environ.get("CI") or not sys.stdout.isatty():
    sys.stdout.reconfigure(line_buffering=True)

VALID_BITRATES_IVAS = [
    13.2,
    16.4,
    24.4,
    32,
    48,
    64,
    80,
    96,
    128,
    160,
    192,
    256,
    384,
    512,
]
LOUDNESS_DATA_FILENAME = "loudness.csv"


@@ -33,7 +49,7 @@ def plot_loudness_by_bandwidth(df, in_fmt, out_fmt, out_dir):
        input_loudness = None

    y_min, y_max = -36, -16
    y_ticks = np.arange(y_min, y_max + 0.5, 0.5)
    y_ticks = np.arange(y_min, y_max + 5, 5)

    # get unique bitrates and sort them
    bitrates = sorted(df["bitrate"].unique())
@@ -62,7 +78,7 @@ def plot_loudness_by_bandwidth(df, in_fmt, out_fmt, out_dir):
                x_positions = [bitrate_to_idx[br] for br in subset["bitrate"]]
                y_values = subset["output_loudness"]

                marker = "o" if dtx_val else "s"
                marker = "x" if dtx_val else "o"
                label = f"dtx={dtx_val}" if show_legend else None
                ax.scatter(
                    x_positions, y_values, label=label, marker=marker, s=80, alpha=0.7
@@ -81,15 +97,21 @@ def plot_loudness_by_bandwidth(df, in_fmt, out_fmt, out_dir):
            )

        ax.set_xticks(range(len(bitrates)))
        ax.set_xticklabels(bitrates, rotation=45, ha="right")
        ax.set_xticklabels(
            [int(br) if br == int(br) else round(br, 2) for br in bitrates],
            rotation=45,
            ha="right",
        )

        ax.set_ylim(y_min, y_max)
        ax.set_yticks(y_ticks)
        ax.set_yticks(np.arange(y_min, y_max + 1, 1), minor=True)

        ax.set_xlabel("Bitrate (kbps)", fontsize=11)
        ax.set_ylabel("Output Loudness (LKFS)", fontsize=11)
        ax.set_title(f"{bw.upper()}", fontsize=12)
        ax.grid(True, alpha=0.3)
        ax.grid(True, which="minor", alpha=0.3)
        ax.grid(True, which="major", alpha=0.5)

        # only show legend if there are multiple DTX values
        if show_legend:
@@ -100,13 +122,14 @@ def plot_loudness_by_bandwidth(df, in_fmt, out_fmt, out_dir):

    plt.tight_layout(rect=[0, 0, 1, 0.96])
    plt.savefig(out_file)
    # plt.show()
    plt.close()


out_dir = Path(__file__).parent.parent.joinpath("plots")
out_dir.mkdir(parents=True, exist_ok=True)

df = pd.read_csv(LOUDNESS_DATA_FILENAME)
df = df[df["bitrate"].isin(VALID_BITRATES_IVAS)]

for in_fmt in df["format"].unique():
    print(f"Processing {in_fmt}: ")
@@ -114,4 +137,4 @@ for in_fmt in df["format"].unique():
    progressbar_update(0, len(out_fmts), width=50)
    for idx, out_fmt in enumerate(out_fmts):
        plot_loudness_by_bandwidth(df, in_fmt, out_fmt, out_dir)
        progressbar_update(idx, len(out_fmts), width=50)
        progressbar_update(idx + 1, len(out_fmts), width=50)