Commit 6893eb0f authored by Niels-Oliver Walkowski's avatar Niels-Oliver Walkowski
Browse files

feat(mod): Add task parser for missing components

Add a method that identifies missing components in the corpus such as
missing data or diagrams and generates a task dictionary that can be
used by other methods in order to create these components.
parent 32df3c1d
......@@ -54,7 +54,7 @@ class Monochromatic(Contrast):
return lightness
def redniss_lab(self):
def rednisslab(self):
"""Returns the redness contrast on the basis of CIE Lab
The a channel of the representation the image in CIE Lab is
......@@ -4,11 +4,11 @@ import numpy as np
from .movie import Movie
_summary = {'seqmean': {'monochromatic': ['luminance'],
'saturation': ['saturation', 'colourfulness'],
'hue': ['hsV', 'labHcl']},
'distribution': {'monochromatic': ['luminance'],
'saturation': ['saturation', 'colourfulness'],
'hue': ['hsV', 'labHcl']}}
'saturation': ['saturation', 'colourfulness'],
'hue': ['hsV', 'labHcl']},
'distribution': {'monochromatic': ['luminance'],
'saturation': ['saturation', 'colourfulness'],
'hue': ['hsV', 'labHcl']}}
class Corpus(object):
......@@ -91,7 +91,7 @@ class Corpus(object):
return movies
def extract(self):
"""Exctracts missing frame images and contrast data for each movie
"""Exctracts missing images and data from movies in the corpus
The method looks for missing frame images and contrast data in the
object's status dictionary and extracts them from the movie file and
......@@ -100,26 +100,72 @@ class Corpus(object):
tasks = self._extraction_tasks()
return tasks
def _extraction_tasks(self):
without_frames = {k: v for (k, v) in self.status.items()
if v['frames'] == 0}
tasks = {}
for m in self.status.keys():
for view in _summary.keys():
if view not in self.status[m]['data'].keys():
tasks[view] = _summary[view]
for contrast in _summary[view].keys():
if contrast not in self.status[m]['data'][view].keys():
tasks.setdefault(view, {})[contrast] = (_summary[view][contrast])
for method in _summary[view][contrast]:
if method not in self.status[m]['data'][view][contrast].keys():
tasks.setdefault(view, {}).setdefault(contrast, []).append(method)
"""Identifies which images and data for which movies are missing
def task_parser(component):
"""Identifies tasks by comparing the status and the _summary dict()
Incrementally walks through elements of a specific component in
the _summary dictionary of the module and looks if
corresponding elements are registered in the status dictionary.
If this is not the case the element is added to the dictionary
of tasks for this component.
missing = {}
for m in self.status.keys():
# For each view, look out if a key for that view already exist.
# If it doesnt, no element for that view is available for movie
# m. Hence, copy the whole branch of elements for that view to
# the task dictionary. Otherwise begin to compare available
# contrsts.
for view in _summary.keys():
if view not in self.status[m][component].keys():
missing[m] = {component: {view: _summary[view]}}
# For each contrast in the current view, look out if a
# key for that contrast already exist. If it doesn't,
# copy the whole branch of that contrast to the task
# dictionary.
for contrast in _summary[view].keys():
ctrst_keys = self.status[m][component][view].keys()
if contrast not in ctrst_keys:
missing.setdefault(m, {component: {}})
missing[m][component].setdefault(view, {})
missing[m][component][view][contrast] = (_summary[view][contrast])
# For each method in the crrent view and
# contrast look out if a key for that method
# exist already. If not add that method to the
# task dictionary
for method in _summary[view][contrast]:
meth_keys = self.status[m][component][view][contrast].keys()
if method not in meth_keys:
missing.setdefault(m, {component: {}})
missing[m][component].setdefault(view, {})
missing[m][component][view].setdefault(contrast, [])
return missing
# Movies without frames
without_frames = {k: {'frames': 0} for (k, v) in self.status.items()
if v['frames'] is None}
# Movies with missing data
missing_data = task_parser('data')
# Movies with missing visuals
missing_visuals = task_parser('visuals')
# Build extraction tasks dictionary
tasks = without_frames
[tasks.setdefault(k, {}).update(v) for k, v in missing_data.items()]
[tasks.setdefault(k, {}).update(v) for k, v in missing_visuals.items()]
return tasks
def _extract_frames(self):
......@@ -130,7 +130,7 @@ class Movie(object):
method: the method by which the peculiar contrast is calculated.
Possible values depend on the contrast type and include:
luminance, value, lightness, redniss_lab (monochromatic)
luminance, value, lightness, rednisslab (monochromatic)
saturation, colourfulness (saturation)
hsV, labHcl (hue)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment