Skip to content

Commit

Permalink
Merge pull request #18 from aestream/kinectograph
Browse files Browse the repository at this point in the history
Kinectograph
  • Loading branch information
aMarcireau authored Nov 23, 2024
2 parents 470bb4b + bc42d87 commit a61c907
Show file tree
Hide file tree
Showing 72 changed files with 2,881 additions and 175 deletions.
101 changes: 99 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ fontdue = "0.9.2"
image = {version = "0.25.1", default-features = false, features = ["png"]}
lz4 = "1.28.0"
mp4 = "0.14.0"
mustache = "0.9.0"
neuromorphic-types = "0.4.0"
numpy = {version = "0.22.0"}
pyo3 = {version = "0.22.0", features = ["extension-module"]}
roxmltree = "0.20.0"
serde = {version = "1.0", features = ["derive"]}
serde_json = "1.0"
toml = "0.8.19"
thiserror = "1.0"
zstd = "0.13.2"

Expand Down
8 changes: 2 additions & 6 deletions examples/crop_and_slice.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import pathlib

import faery

dirname = pathlib.Path(__file__).resolve().parent

(
faery.events_stream_from_file(
dirname.parent / "tests" / "data" / "dvs.es",
faery.dirname.parent / "tests" / "data" / "dvs.es",
)
.crop(
left=110,
Expand All @@ -20,6 +16,6 @@
zero=True,
)
.to_file(
dirname.parent / "tests" / "data_generated" / "dvs_crop_and_slice.csv",
faery.dirname.parent / "tests" / "data_generated" / "dvs_crop_and_slice.csv",
)
)
12 changes: 4 additions & 8 deletions examples/custom_colormap.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
import pathlib

import faery

dirname = pathlib.Path(__file__).resolve().parent

colormap = faery.Colormap.diverging_from_triplet(
name="The Son of Man",
start="#FF0000",
middle="#000000",
end="#00FF00",
)
colormap.to_file(
dirname.parent / "tests" / "data_generated" / "custom_colormap.png",
"The Son of Man",
faery.dirname.parent / "tests" / "data_generated" / "custom_colormap.png"
)

(
faery.events_stream_from_file(
dirname.parent / "tests" / "data" / "dvs.es",
faery.dirname.parent / "tests" / "data" / "dvs.es",
)
.regularize(frequency_hz=60.0)
.envelope(
Expand All @@ -25,7 +21,7 @@
)
.colorize(colormap=colormap)
.to_files(
dirname.parent
faery.dirname.parent
/ "tests"
/ "data_generated"
/ "dvs_frames_custom_colormap"
Expand Down
93 changes: 93 additions & 0 deletions examples/dynamic_tasks.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import inspect
import pathlib

import faery


def create_kinectograph(colormap: faery.Colormap) -> faery.Task:

@faery.task(suffix=".png", icon="🎨", name=f"kinectograph_{colormap.name}")
def kinectograph(
input: pathlib.Path,
output: pathlib.Path,
start: faery.Time,
end: faery.Time,
):
(
faery.events_stream_from_file(input)
.time_slice(start=start, end=end)
.to_kinectograph(on_progress=faery.progress_bar_fold)
.scale()
.colorize(colormap=colormap)
.to_file(path=output)
)

return kinectograph


# Generate tasks with decorators dynamically.
cyclic_colormaps_tasks: list[faery.Task] = []
for colormap in faery.colormaps_list():
if colormap.type == "cyclic":
# The decorated `kinectograph` task captures the `colormap` variable but evaluates it later
# (when job_manager executes the task as part of its "run" function).
# If we declared the task below instead of using a wrapper function (`create_kinectograph`),
# the variable `colormap` would always have the value `faery.colormaps.vik_o`.
# See https://docs.python-guide.org/writing/gotchas/#late-binding-closures for details.
cyclic_colormaps_tasks.append(create_kinectograph(colormap))


# Generate tasks with classes dynamically.
# This is equivalent to the decorator method.
# Classes are more verbose but they can be more convenient in some cases.
# Internally, decorators declare classes.
sequential_colormaps_tasks: list[faery.Task] = []
for colormap in faery.colormaps_list():
if colormap.type == "sequential":

class Kinectograph(faery.Task):

def __init__(self, colormap: faery.Colormap):
self.colormap = colormap

def suffix(self) -> str:
return ".png"

def icon(self) -> str:
return "🎨"

def name(self) -> str:
return f"kinectograph_{self.colormap.name}"

def __call__(
self,
input: pathlib.Path,
output: pathlib.Path,
start: faery.Time,
end: faery.Time,
):
(
faery.events_stream_from_file(input)
.time_slice(start=start, end=end)
.to_kinectograph(on_progress=faery.progress_bar_fold)
.scale()
.colorize(colormap=self.colormap)
.to_file(path=output)
)

# There is no late binding issue here since we pass `colormap` to Kinectograph's `__init__` function.
sequential_colormaps_tasks.append(Kinectograph(colormap=colormap))


job_manager = faery.JobManager(
output_directory=faery.dirname.parent / "tests" / "data_generated" / "renders"
)

job_manager.add(
faery.dirname.parent / "tests" / "data" / "dvs.es",
"00:00:00.000000",
"00:00:00.999001",
cyclic_colormaps_tasks + sequential_colormaps_tasks,
)

job_manager.run()
12 changes: 6 additions & 6 deletions examples/events_to_frames.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
import pathlib

import faery

dirname = pathlib.Path(__file__).resolve().parent

(
faery.events_stream_from_file(
dirname.parent / "tests" / "data" / "dvs.es",
faery.dirname.parent / "tests" / "data" / "dvs.es",
)
.regularize(frequency_hz=60.0)
.envelope(
Expand All @@ -15,6 +11,10 @@
)
.colorize(colormap=faery.colormaps.managua.flipped())
.to_files(
dirname.parent / "tests" / "data_generated" / "dvs_frames" / "{index:04}.png",
faery.dirname.parent
/ "tests"
/ "data_generated"
/ "dvs_frames"
/ "{index:04}.png",
)
)
8 changes: 2 additions & 6 deletions examples/events_to_video.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
import pathlib

import faery

dirname = pathlib.Path(__file__).resolve().parent

(
faery.events_stream_from_file(
dirname.parent / "tests" / "data" / "dvs.es",
faery.dirname.parent / "tests" / "data" / "dvs.es",
)
.regularize(frequency_hz=60.0)
.envelope(
decay="exponential",
tau="00:00:00.200000",
)
.colorize(colormap=faery.colormaps.managua.flipped())
.to_file(dirname.parent / "tests" / "data_generated" / "dvs.mp4")
.to_file(faery.dirname.parent / "tests" / "data_generated" / "dvs.mp4")
)
Loading

0 comments on commit a61c907

Please sign in to comment.