Commit 32df3c1d authored by Niels-Oliver Walkowski's avatar Niels-Oliver Walkowski
Browse files

feat(module): Add movie tableaus to Corpus class

Tableaus can now not only be created for diagrams accross the corpus
taht refer to a peculiar contrast but also for all diagrams of a movie.
parent e6b6d417
...@@ -127,10 +127,8 @@ class Corpus(object): ...@@ -127,10 +127,8 @@ class Corpus(object):
def _extract_contrast(self): def _extract_contrast(self):
pass pass
def tableau(self, def tableau(self, mode='contrast',
shape='distribution', select=['distribution', 'monochromatic', 'luminance'],
ctrst='monochromatic',
meth='luminance',
write=True): write=True):
"""Creates a tableau of available diagrams for a given contrast """Creates a tableau of available diagrams for a given contrast
...@@ -139,12 +137,20 @@ class Corpus(object): ...@@ -139,12 +137,20 @@ class Corpus(object):
will only show diagrams from movies in the corpus that exist already. will only show diagrams from movies in the corpus that exist already.
Keyword Arguments: Keyword Arguments:
shape {str} -- The shape of the data in the diagram. Can be one of mode {str} -- Defines the type of components that are drawn
seqmean or distribution (default: {'distribution'}) together in the tableau. 'contrast' selects diagrams from all
ctrst {str} -- The name of the contrast. the movies in the corpus which represents the contrast, defined
(default: {'monochromatic'}) in the select argument. 'movie' creates one tableau with all
meth {str} -- The method used in order to calculate the contrast diagrams for each movie, defined in the select argument.
(default: {'luminance'}) (default: {'contrast'})
select {[str]} -- Describes the components selected for the
tableau. If the mode is 'contrast' the argument requires a list
of 3 strings, refering to the moment, contrast and method in
order to count the contrast ([moment, contrast, method]). If
mode 'movie' is given the select argument requires a list of
1 to many strings, referring to the movie slugs of movies in
the corpus. (default: {['distribution', 'monochromatic',
'luminance']}
write {bool} -- Decide, if the tableau image should be written to write {bool} -- Decide, if the tableau image should be written to
disk in the corpus folder or not. (default: {True}) disk in the corpus folder or not. (default: {True})
...@@ -153,51 +159,69 @@ class Corpus(object): ...@@ -153,51 +159,69 @@ class Corpus(object):
showing the tableau as an image. showing the tableau as an image.
Todo: Todo:
FEATURE Allow to create tableaus for all diagrams available for a FIXME Instead of an if/else statement, create tableau class in the
specific movie visuals module and subclass it for movies and contrasts.
FIXME Move tableau methods to the visuals module Especially the movie table should also be provided as a method
for the Movie class.
""" """
components = self._filter_diagrams(shape=shape, ctrst=ctrst, meth=meth)
layout = self.layout_tableau(len(components)) if mode == 'contrast':
tableau = self._fit_components(components, layout) components = self._filter_diagrams(mode=mode, select=select)
if write: layout = self.layout_tableau(len(components))
file_name = self.basedir / (shape + '_' + ctrst + '_' + tableau = self._fit_components(components, layout)
meth + '.png') if write:
imwrite(str(file_name), tableau) file_name = self.basedir / (select[0] + '_' + select[1] + '_' +
select[2] + '.png')
imwrite(str(file_name), tableau)
elif mode == 'movie':
for movie in select:
components = self._filter_diagrams(mode=mode, select=movie)
layout = self.layout_tableau(len(components))
tableau = self._fit_components(components, layout)
if write:
Path(self.basedir / movie / 'visuals' / 'tableau').mkdir(
parents=True, exist_ok=True)
folder_name = Path(self.basedir / movie / 'visuals' /
'tableau')
file_name = folder_name / (movie + '_tableau.png')
imwrite(str(file_name), tableau)
return tableau return tableau
def _filter_diagrams(self, def _filter_diagrams(self, mode, select):
shape='distribution',
ctrst='monochromatic',
meth='luminance'):
"""Filters which diagrams in a corpus belong to a specific contrast """Filters which diagrams in a corpus belong to a specific contrast
The filter looks for diagrams represented in *.png files only The filter looks for diagrams represented in *.png files only
Keyword Arguments: Keyword Arguments:
shape {str} -- The shape of the data in the diagram. Can be one of mode {str} -- Where to look for diagrams (see tableau)
seqmean or distribution (default: {'distribution'}) select {[str]} -- For which movies or contrasts should diagrams be
ctrst {str} -- The name of the contrast. selected (see tableau)
(default: {'monochromatic'})
meth {str} -- The method used in order to calculate the contrast
(default: {'luminance'})
Returns: Returns:
[pathlib.Path] -- A list of file paths to the diagrams that match [pathlib.Path] -- A list of file paths to the diagrams that match
the selected contrast visualization. the selected contrast visualization.
Todo: Todo:
* FEATURE Parametize the file-format instead of looking at png FEATURE Parametize the file-format instead of looking at png
files only. files only.
""" """
diagrams = [] diagrams = []
for k, v in self.status.items(): if mode == 'contrast':
if shape in v['visuals'].keys(): shape, ctrst, meth = select
if ctrst in v['visuals'][shape].keys(): for k, v in self.status.items():
if meth in v['visuals'][shape][ctrst].keys(): if shape in v['visuals'].keys():
diagrams.append(Path((self.basedir / k) / if ctrst in v['visuals'][shape].keys():
(k + '_' + shape + '_' + ctrst + '_' + if meth in v['visuals'][shape][ctrst].keys():
meth + '_4fps.png'))) diagrams.append(Path((self.basedir / k) /
(k + '_' + shape + '_' + ctrst +
'_' + meth + '_4fps.png')))
elif mode == 'movie':
for moment, i in self.status[select]['visuals'].items():
for ctrst, j in i.items():
for meth, k in j.items():
diagrams.append(Path(self.basedir / select /
(select + '_' + moment + '_' +
ctrst + '_' + meth + '_4fps.png')))
return diagrams return diagrams
@staticmethod @staticmethod
...@@ -219,6 +243,8 @@ class Corpus(object): ...@@ -219,6 +243,8 @@ class Corpus(object):
tableau. tableau.
""" """
cols, r = divmod(n, ratio) cols, r = divmod(n, ratio)
if cols == 0:
cols, r = (1, 0)
rows = divmod(n, cols)[0] rows = divmod(n, cols)[0]
if r > 0: if r > 0:
rows += 1 rows += 1
......
Supports Markdown
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