misc
- class misc.Op(*args)[source]
Bases:
FunctionCustom symbolic wrapper for pseudo-differential operators in Fourier space. Usage: Op(symbol_expr, u)
- default_assumptions = {}
- nargs = {2}
- misc.circle_function(x, y)
- misc.cross_function(x, y)
- misc.ellipse_function(x, y)
- misc.image_to_sound(image_path, output_wav='son_from_image.wav', sr=22050, hop_length=256, n_iter=64, scale_log_freq=True, use_hsv=True, gain=5.0, show_plot=True)[source]
Convert an 2D image into stereo sound by interpreting it as a spectrogram.
The input image is treated as a time–frequency representation: - The vertical axis corresponds to frequency bins. - The horizontal axis corresponds to time frames. - The image is split into two halves along the horizontal axis:
the left half is converted into the LEFT audio channel, the right half into the RIGHT channel.
- Parameters:
image_path (str) – Path to the input image file. Can be grayscale or RGB. If RGB and use_hsv=True, the HSV color space is used for mapping.
output_wav (str, optional) – Filename of the output WAV file (default: “son_from_image.wav”).
sr (int, optional) – Target audio sampling rate in Hz (default: 22050). Lower values produce lower-pitched sounds.
hop_length (int, optional) – Number of samples between successive STFT frames (default: 256). Smaller values produce a longer audio signal.
n_iter (int, optional) – Number of Griffin–Lim iterations for phase reconstruction (default: 64).
scale_log_freq (bool, optional) – If True, the frequency axis of the image is remapped to a logarithmic scale before reconstruction (default: True).
use_hsv (bool, optional) – If True and the image is RGB, the HSV color model is used: - Hue → frequency mapping, - Saturation → timbre, - Value → amplitude. Otherwise, the grayscale intensity is used (default: True).
gain (float, optional) – Global amplification factor for the spectrogram intensity (default: 5.0).
show_plot (bool, optional) – If True, displays: - The original image (as interpreted spectrogram), - The reconstructed spectrograms of LEFT and RIGHT channels (default: True).
- Returns:
y_stereo (np.ndarray, shape (n_samples, 2)) – Stereo audio signal: left and right channels as columns.
sr (int) – Sampling rate of the generated audio.
Notes
The function always outputs a stereo WAV file, even for grayscale images.
The stereo split is based on the horizontal axis of the image: left side → left ear, right side → right ear.
Griffin–Lim is an iterative algorithm, so reconstruction is approximate.
- misc.make_symbol(g=None, b=None, V=None)[source]
Assemble a 2D psiOp symbol from: - g: a symmetric metric tensor g = [[g_xx, g_xy], [g_yx, g_yy]] (functions or strings) - b: a vector b = [b_x, b_y] (functions or strings) - V: a scalar potential V(x, y) (function or string)
Returns a SymPy expression representing the symbol sigma(x, y, xi, eta).
- misc.make_video_with_sound(u, Lt, Lx, outfile='solution_with_sound.mp4', samplerate=44100)[source]
Create a video of the solution u(t,x) with synchronized sound tracks.
- Parameters:
u (ndarray (Nt, Nx)) – Solution of the PDE.
Nt (int) – Number of points in time and space.
Nx (int) – Number of points in time and space.
Lt (float) – Total length in time and space.
Lx (float) – Total length in time and space.
outfile (str) – Name of the output MP4 file.
samplerate (int) – Audio sampling rate.
- Returns:
Path to the generated video file.
- Return type:
str
- class misc.psiOp(*args)[source]
Bases:
FunctionSymbolic wrapper for PseudoDifferentialOperator. Usage: psiOp(symbol_expr, u)
- default_assumptions = {}
- nargs = {2}
- misc.ramp_function(x, y, point1, point2, direction='increasing')[source]
Creates a ramp (generalized Heaviside) function between two points. :param x: meshgrid arrays :param y: meshgrid arrays :param point1: (x1, y1), first point on the ramp axis :param point2: (x2, y2), second point on the ramp axis :param direction: ‘increasing’ (from point1 to point2) or ‘decreasing’
- Returns:
A 2D array with values in [0, 1]
- misc.rectangle_function(x, y)
- misc.sonify_solution(u, Nt, Nx, Lt, Lx, method='pan', samplerate=44100, outfile='sonification.wav')[source]
Enhanced stereo sonification of a PDE solution with rich, percussive, and original sounds.
- Parameters:
u (ndarray (Nt, Nx)) – Solution of the PDE.
Nt (int) – Number of points in time and space.
Nx (int) – Number of points in time and space.
Lt (float) – Total length in time and in space.
Lx (float) – Total length in time and in space.
method (str) – “pan” (dynamic barycenter), “fft” (spatial modes), “events” (percussions)
samplerate (int) – Audio sampling rate.
outfile (str) – Name of the output WAV file.