Skip to content

Commit

Permalink
Fix "colour.TriSpectralPowerDistribution.items" method.
Browse files Browse the repository at this point in the history
Closes #331.
  • Loading branch information
KelSolaar committed Jun 10, 2017
1 parent 9df0d43 commit 9208148
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
12 changes: 10 additions & 2 deletions colour/colorimetry/spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2682,13 +2682,21 @@ def items(self):
Property for **self.items** attribute. This is a convenient attribute
used to iterate over the tri-spectral power distribution.
Notes
-----
- In contrast to :func:`SpectralPowerDistribution.items` method,
:func:`TriSpectralPowerDistribution.items` returns a `list` as it
is not possible to convert its output to a `ndarray`. It is
possible to separate wavelengths from data by unpacking the return
value into the `zip` definition as follows: `zip(*tri_spd.items)`.
Returns
-------
ndarray
list
Tri-spectral power distribution data.
"""

return np.array(list(self.__iter__()))
return list(self.__iter__())

@items.setter
def items(self, value):
Expand Down
24 changes: 24 additions & 0 deletions colour/colorimetry/tests/tests_spectrum.py
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,16 @@ def test_values(self):
self._spd.values,
[v for k, v in sorted(SAMPLE_SPD_DATA.items())])

def test_items(self):
"""
Tests :attr:`colour.colorimetry.spectrum.\
SpectralPowerDistribution.items` attribute.
"""

np.testing.assert_array_equal(
self._spd.items,
tstack((self._spd.wavelengths, self._spd.values)))

def test_shape(self):
"""
Tests :attr:`colour.colorimetry.spectrum.\
Expand Down Expand Up @@ -2598,6 +2608,20 @@ def test_values(self):
[v for k, v in sorted(
CIE_1931_2_DEGREE_STANDARD_OBSERVER['z_bar'].items())])))

def test_items(self):
"""
Tests :attr:`colour.colorimetry.spectrum.\
TriSpectralPowerDistribution.items` attribute.
"""

np.testing.assert_array_equal(
list(zip(*self._tri_spd.items))[0],
self._tri_spd.wavelengths)

np.testing.assert_array_equal(
list(zip(*self._tri_spd.items))[1],
self._tri_spd.values)

def test_shape(self):
"""
Tests :attr:`colour.colorimetry.spectrum.\
Expand Down

0 comments on commit 9208148

Please sign in to comment.