-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from aestream/kinectograph
Kinectograph
- Loading branch information
Showing
72 changed files
with
2,881 additions
and
175 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
) |
Oops, something went wrong.