Skip to content

y5gfunc.utils

utils

Functions:

Name Description
ranger

Generates a sequence of numbers similar to range(), but allows floats.

PickFrames

Return a new clip with frames picked from input clip from the indices array.

resolve_path

Resolves a path to an absolute path and ensures necessary directories exist.

ranger

Generates a sequence of numbers similar to range(), but allows floats.

Creates a list of numbers starting from start, incrementing by step, and stopping before end.

Parameters:

Name Type Description Default

start

Union[int, float]

The starting value of the sequence (inclusive).

required

end

Union[int, float]

The end value of the sequence (exclusive). The sequence generated will contain values strictly less than end if step is positive, or strictly greater than end if step is negative.

required

step

Union[int, float]

The step/increment between consecutive numbers. Must not be zero. Can be negative for descending sequences.

required

Returns:

Type Description
list[Union[int, float]]

A list of numbers (integers or floats) representing the generated sequence.

Raises:

Type Description
ValueError

If step is 0.

Source code in y5gfunc/utils.py
def ranger(
    start: Union[int, float], end: Union[int, float], step: Union[int, float]
) -> list[Union[int, float]]:
    """
    Generates a sequence of numbers similar to range(), but allows floats.

    Creates a list of numbers starting from `start`, incrementing by `step`, and stopping before `end`.

    Args:
        start: The starting value of the sequence (inclusive).
        end: The end value of the sequence (exclusive). The sequence generated will contain values strictly
            less than `end` if `step` is positive, or strictly greater than `end` if `step` is negative.
        step: The step/increment between consecutive numbers. Must not be zero. Can be negative for descending sequences.

    Returns:
        A list of numbers (integers or floats) representing the generated sequence.

    Raises:
        ValueError: If `step` is 0.
    """

    if step == 0:
        raise ValueError("ranger: Step cannot be zero.")
    return list(
        map(lambda i: round(start + i * step, 10), range(int((end - start) / step)))
    )

PickFrames

PickFrames(clip: VideoNode, indices: list[int]) -> VideoNode

Return a new clip with frames picked from input clip from the indices array.

Parameters:

Name Type Description Default

clip

VideoNode

Input clip where frames are from.

required

indices

list[int]

The indices array representing the frames to be picked.

required

Returns:

Type Description
VideoNode

New clip with frames picked from input clip from the indices array.

Source code in y5gfunc/utils.py
def PickFrames(clip: vs.VideoNode, indices: list[int]) -> vs.VideoNode:
    """
    Return a new clip with frames picked from input clip from the indices array.

    Args:
        clip: Input clip where frames are from.
        indices: The indices array representing the frames to be picked.

    Returns:
        New clip with frames picked from input clip from the indices array.
    """
    return clip.std.SelectEvery(cycle=clip.num_frames, offsets=indices)

resolve_path

resolve_path(path: Union[Path, str]) -> Path

Resolves a path to an absolute path and ensures necessary directories exist.

Parameters:

Name Type Description Default

path

Union[Path, str]

The input path string or Path object to resolve and for which to ensure directory structure exists.

required

Returns:

Type Description
Path

The absolute, resolved pathlib. Path object corresponding to the input path, after ensuring the relevant directory structure exists.

Source code in y5gfunc/utils.py
def resolve_path(path: Union[Path, str]) -> Path:
    """
    Resolves a path to an absolute path and ensures necessary directories exist.

    Args:
        path: The input path string or Path object to resolve and for which to ensure directory structure exists.

    Returns:
        The absolute, resolved pathlib. Path object corresponding to the input path, after ensuring the relevant directory structure exists.
    """
    path = Path(path).resolve()
    if path.suffix:
        path.parent.mkdir(parents=True, exist_ok=True)
    else:
        path.mkdir(parents=True, exist_ok=True)
    return path