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