Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/jmrplens/phonometry. Standards-conformant acoustics library for Python: measurement and metrology, docs.jmrp.io/phonometry
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899# Copyright (c) 2026. Jose Manuel Requena Plens"""A video written on a real node: the result equals the local run, the file decodes.
Runs only where ``PHONOMETRY_TEST_NODE`` names a node in the hosts file: theCI job "Remote simulation on a localhost node", which serves the cpu stage ofthe node image (with its pinned ffmpeg build and the figure stack) builtwith the pins of the job, so the run steps the same numbers, and installsthe ffprobe that decodes the video here."""
from __future__ import annotations
import dataclassesimport osimport shutilimport subprocessfrom typing import TYPE_CHECKING
import numpy as npimport pytest
from phonometry.io import VideoOptionsfrom phonometry.simulation import ( AnimationFrame, Compute, FDTDRecording, FDTDRun, GaussianPulse, fdtd_simulation, write_fdtd_animation,)from phonometry.simulation._remote import package
if TYPE_CHECKING: from pathlib import Path
_NODE = os.environ.get("PHONOMETRY_TEST_NODE", "")
pytestmark = [ pytest.mark.skipif( not _NODE or shutil.which("ffprobe") is None, reason="needs a node named by PHONOMETRY_TEST_NODE and ffprobe here; the remote-node CI job has both", ), pytest.mark.xdist_group("localhost-node"),]
def test_a_node_s_video_and_result(tmp_path: Path) -> None: run = FDTDRun( c=343.0, dx=0.01, duration_s=2e-3, shape=(60, 80), sources=[GaussianPulse(ix=40, iy=30, half_width_s=4e-5)], recording=FDTDRecording(probes=[(10, 10), (70, 50)], snapshot_every=10), ) target = tmp_path / "node.webm" res = write_fdtd_animation( target, run, compute=Compute(host=_NODE), frame=AnimationFrame(size=(480, 246)), video=VideoOptions(encoder="cpu"), ) local = fdtd_simulation(run) assert np.array_equal(res.pressures, local.pressures) assert np.array_equal(res.times, local.times) assert res.snapshots is None assert res.provenance.host == _NODE assert res.provenance.package_sha256 == package.installed_package().digest assert ( dataclasses.replace(res.provenance, host=None, package_sha256=None) == local.provenance ) shown = subprocess.run( [ "ffprobe", "-v", "error", "-count_frames", "-select_streams", "v:0", "-show_entries", "stream=codec_name,width,height,nb_read_frames", "-of", "default=noprint_wrappers=1", str(target), ], capture_output=True, text=True, timeout=60, check=True, ).stdout probe = dict(line.split("=", 1) for line in shown.splitlines()) # The node image's pinned ffmpeg carries SVT-AV1, so the CPU writes AV1. assert probe["codec_name"] == "av1" assert (probe["width"], probe["height"]) == ("480", "246") assert int(probe["nb_read_frames"]) == (res.times.size - 1) // 10 + 1