def test_multi_signals_unpack_data(self): """ Tests :func:`colour.continuous.multi_signals.MultiSignals.\ multi_signals_unpack_data` method. """ signals = MultiSignals.multi_signals_unpack_data(self._range_1) self.assertListEqual(list(signals.keys()), [0]) np.testing.assert_array_equal(signals[0].domain, self._domain_1) np.testing.assert_array_equal(signals[0].range, self._range_1) signals = MultiSignals.multi_signals_unpack_data( self._range_1, self._domain_2) self.assertListEqual(list(signals.keys()), [0]) np.testing.assert_array_equal(signals[0].domain, self._domain_2) np.testing.assert_array_equal(signals[0].range, self._range_1) signals = MultiSignals.multi_signals_unpack_data( self._range_2, self._domain_2) self.assertListEqual(list(signals.keys()), [0, 1, 2]) np.testing.assert_array_equal(signals[0].range, self._range_1) np.testing.assert_array_equal(signals[1].range, self._range_1 + 10) np.testing.assert_array_equal(signals[2].range, self._range_1 + 20) signals = MultiSignals.multi_signals_unpack_data( dict(zip(self._domain_2, self._range_2))) self.assertListEqual(list(signals.keys()), [0, 1, 2]) np.testing.assert_array_equal(signals[0].range, self._range_1) np.testing.assert_array_equal(signals[1].range, self._range_1 + 10) np.testing.assert_array_equal(signals[2].range, self._range_1 + 20) signals = MultiSignals.multi_signals_unpack_data( MultiSignals.multi_signals_unpack_data( dict(zip(self._domain_2, self._range_2)))) self.assertListEqual(list(signals.keys()), [0, 1, 2]) np.testing.assert_array_equal(signals[0].range, self._range_1) np.testing.assert_array_equal(signals[1].range, self._range_1 + 10) np.testing.assert_array_equal(signals[2].range, self._range_1 + 20) if is_pandas_installed(): from pandas import DataFrame, Series signals = MultiSignals.multi_signals_unpack_data( Series(dict(zip(self._domain_1, self._range_1)))) self.assertListEqual(list(signals.keys()), [0]) np.testing.assert_array_equal(signals[0].domain, self._domain_1) np.testing.assert_array_equal(signals[0].range, self._range_1) data = dict(zip(['a', 'b', 'c'], tsplit(self._range_2))) signals = MultiSignals.multi_signals_unpack_data( DataFrame(data, self._domain_1)) self.assertListEqual(list(signals.keys()), ['a', 'b', 'c']) np.testing.assert_array_equal(signals['a'].range, self._range_1) np.testing.assert_array_equal(signals['b'].range, self._range_1 + 10) np.testing.assert_array_equal(signals['c'].range, self._range_1 + 20)
def read(self): """ Reads and parses the spectral data JSON file path. Returns ------- bool Definition success. """ with open(self._path, 'r') as json_file: content = json.load(json_file) self._header = SpectralDataHeader_AMPAS(**content['header']) for attribute in ('units', 'reflection_geometry', 'transmission_geometry', 'bandwidth_FWHM', 'bandwidth_corrected'): setattr(self, '_{0}'.format(attribute), content['spectral_data'][attribute]) index = content['spectral_data']['index']['main'] data = content['spectral_data']['data']['main'] if len(index) == 1: self.domain, self.range = Signal.signal_unpack_data( {k: v[0] for k, v in data.items()}) else: self.signals = MultiSignals.multi_signals_unpack_data(data, labels=index) # TODO: Re-instate "manufacturer", "model", "illuminant" and "type" # attributes according to outcome of # https://github.com/ampas/rawtoaces/issues/114. if ('manufacturer' in self._header._kwargs and 'model' in self._header._kwargs): self.name = '{0} {1}'.format(self._header._kwargs['manufacturer'], self._header._kwargs['model']) elif 'illuminant' in self._header._kwargs: self.name = self._header._kwargs['illuminant'] elif 'type' in self._header._kwargs: self.name = self._header._kwargs['type'] return self
def test_multi_signals_unpack_data(self): """ Test :func:`colour.continuous.multi_signals.MultiSignals.\ multi_signals_unpack_data` method. """ signals = MultiSignals.multi_signals_unpack_data(self._range_1) self.assertListEqual(list(signals.keys()), ["0"]) np.testing.assert_array_equal(signals["0"].domain, self._domain_1) np.testing.assert_array_equal(signals["0"].range, self._range_1) signals = MultiSignals.multi_signals_unpack_data( self._range_1, self._domain_2) self.assertListEqual(list(signals.keys()), ["0"]) np.testing.assert_array_equal(signals["0"].domain, self._domain_2) np.testing.assert_array_equal(signals["0"].range, self._range_1) signals = MultiSignals.multi_signals_unpack_data( self._range_1, dict(zip(self._domain_2, self._range_1)).keys()) np.testing.assert_array_equal(signals["0"].domain, self._domain_2) signals = MultiSignals.multi_signals_unpack_data( self._range_2, self._domain_2) self.assertListEqual(list(signals.keys()), ["0", "1", "2"]) np.testing.assert_array_equal(signals["0"].range, self._range_1) np.testing.assert_array_equal(signals["1"].range, self._range_1 + 10) np.testing.assert_array_equal(signals["2"].range, self._range_1 + 20) signals = MultiSignals.multi_signals_unpack_data( list( MultiSignals.multi_signals_unpack_data( dict(zip(self._domain_2, self._range_2))).values())[0]) np.testing.assert_array_equal(signals["0"].range, self._range_1) signals = MultiSignals.multi_signals_unpack_data( MultiSignals.multi_signals_unpack_data( dict(zip(self._domain_2, self._range_2))).values()) np.testing.assert_array_equal(signals["0"].range, self._range_1) np.testing.assert_array_equal(signals["1"].range, self._range_1 + 10) np.testing.assert_array_equal(signals["2"].range, self._range_1 + 20) signals = MultiSignals.multi_signals_unpack_data( dict(zip(self._domain_2, self._range_2))) self.assertListEqual(list(signals.keys()), ["0", "1", "2"]) np.testing.assert_array_equal(signals["0"].range, self._range_1) np.testing.assert_array_equal(signals["1"].range, self._range_1 + 10) np.testing.assert_array_equal(signals["2"].range, self._range_1 + 20) signals = MultiSignals.multi_signals_unpack_data( MultiSignals.multi_signals_unpack_data( dict(zip(self._domain_2, self._range_2)))) self.assertListEqual(list(signals.keys()), ["0", "1", "2"]) np.testing.assert_array_equal(signals["0"].range, self._range_1) np.testing.assert_array_equal(signals["1"].range, self._range_1 + 10) np.testing.assert_array_equal(signals["2"].range, self._range_1 + 20) if is_pandas_installed(): from pandas import DataFrame, Series signals = MultiSignals.multi_signals_unpack_data( Series(dict(zip(self._domain_1, self._range_1)))) self.assertListEqual(list(signals.keys()), ["0"]) np.testing.assert_array_equal(signals["0"].domain, self._domain_1) np.testing.assert_array_equal(signals["0"].range, self._range_1) data = dict(zip(["a", "b", "c"], tsplit(self._range_2))) signals = MultiSignals.multi_signals_unpack_data( DataFrame(data, self._domain_1)) self.assertListEqual(list(signals.keys()), ["a", "b", "c"]) np.testing.assert_array_equal(signals["a"].range, self._range_1) np.testing.assert_array_equal(signals["b"].range, self._range_1 + 10) np.testing.assert_array_equal(signals["c"].range, self._range_1 + 20)