-
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/zhao2009' into develop
- Loading branch information
Showing
7 changed files
with
287 additions
and
4 deletions.
There are no files selected for viewing
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,84 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Defines unit tests for :mod:`colour_datasets.loaders.zhao2009` module. | ||
""" | ||
|
||
from __future__ import division, unicode_literals | ||
|
||
import unittest | ||
|
||
from colour import SpectralShape | ||
|
||
from colour_datasets.loaders import DatasetLoader_Zhao2009, build_Zhao2009 | ||
|
||
__author__ = 'Colour Developers' | ||
__copyright__ = 'Copyright (C) 2019-2020 - Colour Developers' | ||
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause' | ||
__maintainer__ = 'Colour Developers' | ||
__email__ = 'colour-developers@colour-science.org' | ||
__status__ = 'Production' | ||
|
||
__all__ = ['TestDatasetLoader_Zhao2009', 'TestBuildZhao2009'] | ||
|
||
|
||
class TestDatasetLoader_Zhao2009(unittest.TestCase): | ||
""" | ||
Defines :class:`colour_datasets.loaders.zhao2009.DatasetLoader_Zhao2009` | ||
class unit tests methods. | ||
""" | ||
|
||
def test_required_attributes(self): | ||
""" | ||
Tests presence of required attributes. | ||
""" | ||
|
||
required_attributes = ('ID', ) | ||
|
||
for attribute in required_attributes: | ||
self.assertIn(attribute, dir(DatasetLoader_Zhao2009)) | ||
|
||
def test_required_methods(self): | ||
""" | ||
Tests presence of required methods. | ||
""" | ||
|
||
required_methods = ('__init__', 'load') | ||
|
||
for method in required_methods: | ||
self.assertIn(method, dir(DatasetLoader_Zhao2009)) | ||
|
||
def test_load(self): | ||
""" | ||
Tests :func:`colour_datasets.loaders.zhao2009.\ | ||
DatasetLoader_Zhao2009.load` method. | ||
""" | ||
|
||
dataset = DatasetLoader_Zhao2009() | ||
self.assertEqual( | ||
sorted(dataset.load().keys()), | ||
sorted([ | ||
'SONY DXC 930', 'KODAK DCS 420', 'NIKON D1X', 'SONY DXC 9000', | ||
'CANON 10D', 'NIKON D70', 'KODAK DCS 460', 'CANON 400D', | ||
'CANON 5D', 'CANON 5D Mark 2', 'Ladybug2', 'KODAK DCS 200' | ||
])) | ||
self.assertEqual(dataset.content['SONY DXC 930'].shape, | ||
SpectralShape(400, 700, 4)) | ||
|
||
|
||
class TestBuildZhao2009(unittest.TestCase): | ||
""" | ||
Defines :func:`colour_datasets.loaders.zhao2009.build_Zhao2009` | ||
definition unit tests methods. | ||
""" | ||
|
||
def test_build_Zhao2009(self): | ||
""" | ||
Tests :func:`colour_datasets.loaders.zhao2009.build_Zhao2009` | ||
definition. | ||
""" | ||
|
||
self.assertIs(build_Zhao2009(), build_Zhao2009()) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |
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,157 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Spectral Sensitivity Database - Zhao et al. (2009) | ||
================================================== | ||
Defines the objects implementing support for *Zhao, Kawakami, Tan and Ikeuchi | ||
(2009)* *Spectral Sensitivity Database* dataset loading: | ||
- :class:`colour_datasets.loaders.DatasetLoader_Zhao2009` | ||
- :func:`colour_datasets.loaders.build_Zhao2009` | ||
References | ||
---------- | ||
- :cite:`Zhao2009` : Zhao, H., Kawakami, R., Tan, R. T., & Ikeuchi, K. | ||
(2009). Estimating basis functions for spectral sensitivity of digital | ||
cameras. 7. | ||
""" | ||
|
||
from __future__ import division, unicode_literals | ||
|
||
import numpy as np | ||
import os | ||
from collections import OrderedDict | ||
|
||
from colour.characterisation import RGB_CameraSensitivities | ||
|
||
from colour_datasets.records import datasets | ||
from colour_datasets.loaders import AbstractDatasetLoader | ||
|
||
__author__ = 'Colour Developers' | ||
__copyright__ = 'Copyright (C) 2019-2020 - Colour Developers' | ||
__license__ = 'New BSD License - https://opensource.org/licenses/BSD-3-Clause' | ||
__maintainer__ = 'Colour Developers' | ||
__email__ = 'colour-developers@colour-science.org' | ||
__status__ = 'Production' | ||
|
||
__all__ = ['DatasetLoader_Zhao2009', 'build_Zhao2009'] | ||
|
||
|
||
class DatasetLoader_Zhao2009(AbstractDatasetLoader): | ||
""" | ||
Defines the *Zhao et al. (2009)* *Spectral Sensitivity Database* | ||
dataset loader. | ||
Attributes | ||
---------- | ||
- :attr:`colour_datasets.loaders.DatasetLoader_Zhao2009.ID` | ||
Methods | ||
------- | ||
- :meth:`colour_datasets.loaders.DatasetLoader_Zhao2009.__init__` | ||
- :meth:`colour_datasets.loaders.DatasetLoader_Zhao2009.load` | ||
References | ||
---------- | ||
:cite:`Zhao2009` | ||
""" | ||
|
||
ID = '4297288' | ||
""" | ||
Dataset record id, i.e. the *Zenodo* record number. | ||
ID : unicode | ||
""" | ||
|
||
def __init__(self): | ||
super(DatasetLoader_Zhao2009, | ||
self).__init__(datasets()[DatasetLoader_Zhao2009.ID]) | ||
|
||
def load(self): | ||
""" | ||
Syncs, parses, converts and returns the *Zhao et al. (2009)* | ||
*Spectral Sensitivity Database* dataset content. | ||
Returns | ||
------- | ||
OrderedDict | ||
*Zhao et al. (2009)* *Spectral Sensitivity Database* | ||
dataset content. | ||
Examples | ||
-------- | ||
>>> from colour_datasets.utilities import suppress_stdout | ||
>>> dataset = DatasetLoader_Zhao2009() | ||
>>> with suppress_stdout(): | ||
... dataset.load() | ||
>>> len(dataset.content.keys()) | ||
12 | ||
""" | ||
|
||
super(DatasetLoader_Zhao2009, self).sync() | ||
|
||
cameras = [ | ||
'SONY DXC 930', | ||
'KODAK DCS 420', | ||
'NIKON D1X', | ||
'SONY DXC 9000', | ||
'CANON 10D', | ||
'NIKON D70', | ||
'KODAK DCS 460', | ||
'CANON 400D', | ||
'CANON 5D', | ||
'CANON 5D Mark 2', | ||
'Ladybug2', | ||
'KODAK DCS 200', | ||
] | ||
|
||
self._content = OrderedDict() | ||
|
||
for i, camera in enumerate(cameras): | ||
data = np.loadtxt( | ||
os.path.join(self.record.repository, 'dataset', | ||
'camera_{0}.spectra'.format(i))) | ||
self._content[camera] = RGB_CameraSensitivities( | ||
data[..., 1:], data[..., 0], name=camera) | ||
|
||
return self._content | ||
|
||
|
||
_DATASET_LOADER_JIANG2009 = None | ||
""" | ||
Singleton instance of the *Zhao et al. (2009)* | ||
*Spectral Sensitivity Database* dataset loader. | ||
_DATASET_LOADER_JIANG2009 : DatasetLoader_Zhao2009 | ||
""" | ||
|
||
|
||
def build_Zhao2009(load=True): | ||
""" | ||
Singleton factory that builds the *Zhao et al. (2009)* | ||
*Spectral Sensitivity Database* dataset loader. | ||
Parameters | ||
---------- | ||
load : bool, optional | ||
Whether to load the dataset upon instantiation. | ||
Returns | ||
------- | ||
DatasetLoader_Zhao2009 | ||
Singleton instance of the *Zhao et al. (2009)* | ||
*Spectral Sensitivity Database* dataset loader. | ||
References | ||
---------- | ||
:cite:`Zhao2009` | ||
""" | ||
|
||
global _DATASET_LOADER_JIANG2009 | ||
|
||
if _DATASET_LOADER_JIANG2009 is None: | ||
_DATASET_LOADER_JIANG2009 = DatasetLoader_Zhao2009() | ||
if load: | ||
_DATASET_LOADER_JIANG2009.load() | ||
|
||
return _DATASET_LOADER_JIANG2009 |
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