Skip to content

Commit

Permalink
Use np.testing.assert_allclose definition.
Browse files Browse the repository at this point in the history
  • Loading branch information
KelSolaar committed Dec 20, 2023
1 parent 8b7dd66 commit 76b4229
Show file tree
Hide file tree
Showing 8 changed files with 50 additions and 42 deletions.
25 changes: 13 additions & 12 deletions colour_datasets/loaders/tests/test_asano2015.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import numpy as np
from colour import SpectralShape
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

from colour_datasets.loaders import DatasetLoader_Asano2015, build_Asano2015

Expand Down Expand Up @@ -60,7 +61,7 @@ def test_load(self):
SpectralShape(390, 780, 5),
)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.content["Categorical Observers"][1].XYZ_2[390],
np.array(
[
Expand All @@ -69,10 +70,10 @@ def test_load(self):
0.017705556255144,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.content["Categorical Observers"][10].LMS_10[780],
np.array(
[
Expand All @@ -81,23 +82,23 @@ def test_load(self):
0.000000000000000,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertAlmostEqual(
np.testing.assert_allclose(
dataset.content["Categorical Observers"][5].parameters[
"Shift in S [nm]"
],
0.233255808,
places=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertEqual(
dataset.content["Colour Normal Observers"][1].XYZ_2.shape,
SpectralShape(390, 780, 5),
)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.content["Colour Normal Observers"][1].XYZ_2[390],
np.array(
[
Expand All @@ -106,10 +107,10 @@ def test_load(self):
0.007492391403616,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.content["Colour Normal Observers"][10].LMS_10[780],
np.array(
[
Expand All @@ -118,15 +119,15 @@ def test_load(self):
0.000000000000000,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertAlmostEqual(
np.testing.assert_allclose(
dataset.content["Colour Normal Observers"][5].parameters[
"Shift in S [nm]"
],
0.000649602695013,
places=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertEqual(
Expand Down
17 changes: 9 additions & 8 deletions colour_datasets/loaders/tests/test_dyer2017.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import numpy as np
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

from colour_datasets.loaders import DatasetLoader_Dyer2017, build_Dyer2017

Expand Down Expand Up @@ -54,7 +55,7 @@ def test_load(self):
["camera", "cmf", "illuminant", "training"],
)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["camera"]["canon eos 5d mark ii"][555],
np.array(
[
Expand All @@ -63,9 +64,9 @@ def test_load(self):
0.028300000000000,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["cmf"]["cie-1931"][555],
np.array(
[
Expand All @@ -74,14 +75,14 @@ def test_load(self):
0.005749999000000,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["illuminant"]["iso7589"][555],
np.array([0.485000000000000]),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["training"]["190-patch"][555],
np.array(
[
Expand Down Expand Up @@ -277,7 +278,7 @@ def test_load(self):
0.158126080000000,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)


Expand Down
13 changes: 7 additions & 6 deletions colour_datasets/loaders/tests/test_ebner1998.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import numpy as np
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

from colour_datasets.loaders import DatasetLoader_Ebner1998, build_Ebner1998

Expand Down Expand Up @@ -74,7 +75,7 @@ def test_load(self):
],
)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["Constant Perceived-Hue Data"][96].XYZ_r,
np.array(
[
Expand All @@ -83,9 +84,9 @@ def test_load(self):
1.088100000000000,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["Constant Perceived-Hue Data"][96].XYZ_cr,
np.array(
[
Expand All @@ -94,9 +95,9 @@ def test_load(self):
0.211200000000000,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["Constant Perceived-Hue Data"][96].XYZ_ct,
np.array(
[
Expand All @@ -122,7 +123,7 @@ def test_load(self):
[0.704427000000000, 0.763034000000000, 0.112490000000000],
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)


Expand Down
13 changes: 7 additions & 6 deletions colour_datasets/loaders/tests/test_hung1995.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import numpy as np
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

from colour_datasets.loaders import DatasetLoader_Hung1995, build_Hung1995

Expand Down Expand Up @@ -78,7 +79,7 @@ def test_load(self):
],
)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["Constant Hue Loci Data - CL"]["Cyan"].XYZ_r,
np.array(
[
Expand All @@ -87,9 +88,9 @@ def test_load(self):
1.182249493927126,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["Constant Hue Loci Data - CL"]["Cyan"].XYZ_cr,
np.array(
[
Expand All @@ -98,9 +99,9 @@ def test_load(self):
1.149029086144775,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["Constant Hue Loci Data - CL"]["Cyan"].XYZ_ct,
np.array(
[
Expand All @@ -110,7 +111,7 @@ def test_load(self):
[0.495500000000000, 0.722700000000000, 1.149100000000000],
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)


Expand Down
9 changes: 5 additions & 4 deletions colour_datasets/loaders/tests/test_kuopio.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import numpy as np
from colour import SpectralShape
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

from colour_datasets.loaders.kuopio import (
DatasetLoader_AgfaIT872Set, # pyright: ignore
Expand Down Expand Up @@ -59,7 +60,7 @@ def test_read_sds_from_mat_file_KuopioUniversity(self):
sds = read_sds_from_mat_file_KuopioUniversity(mat_file, metadata)
self.assertEqual(len(sds), 32)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
sds["5R 6/8 (3)"].values,
np.array(
[
Expand Down Expand Up @@ -96,7 +97,7 @@ def test_read_sds_from_mat_file_KuopioUniversity(self):
51.890000000000000,
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)


Expand Down Expand Up @@ -3614,10 +3615,10 @@ def test_load(self):
}
for dataset_loader, values in dataset_loaders.items():
self.assertEqual(len(dataset_loader.load()[values[0]]), values[1])
np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset_loader.content[values[0]][values[2]].values,
values[3],
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)


Expand Down
5 changes: 3 additions & 2 deletions colour_datasets/loaders/tests/test_luo1997.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import numpy as np
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

from colour_datasets.loaders import DatasetLoader_Luo1997, build_Luo1997

Expand Down Expand Up @@ -51,7 +52,7 @@ def test_load(self):
dataset = DatasetLoader_Luo1997()
self.assertEqual(len(dataset.load().keys()), 8)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.content["R-HL"].phases["1"].JQCH_v,
np.array(
[
Expand Down Expand Up @@ -162,7 +163,7 @@ def test_load(self):
[45.66667000, 61.23224000, 387.50000000],
]
),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertEqual(
Expand Down
5 changes: 3 additions & 2 deletions colour_datasets/loaders/tests/test_luo1999.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import unittest

import numpy as np
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

from colour_datasets.loaders import DatasetLoader_Luo1999, build_Luo1999

Expand Down Expand Up @@ -51,7 +52,7 @@ def test_load(self):
dataset = DatasetLoader_Luo1999()
self.assertEqual(len(dataset.load().keys()), 37)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.content["CSAJ-C - da"].XYZ_ct,
np.array(
[
Expand Down Expand Up @@ -145,7 +146,7 @@ def test_load(self):
]
)
/ 100,
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)

self.assertEqual(
Expand Down
5 changes: 3 additions & 2 deletions colour_datasets/loaders/tests/test_winquist2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import unittest

import numpy as np
from colour.constants import TOLERANCE_ABSOLUTE_TESTS

from colour_datasets.loaders import (
DatasetLoader_Winquist2022,
Expand Down Expand Up @@ -59,10 +60,10 @@ def test_load(self):
dataset = DatasetLoader_Winquist2022()
self.assertEqual(len(dataset.load().keys()), 17)

np.testing.assert_array_almost_equal(
np.testing.assert_allclose(
dataset.load()["Canon EOS_1DX_Mark_II"][555],
np.array([0.27472975, 0.88354587, 0.08992765]),
decimal=7,
atol=TOLERANCE_ABSOLUTE_TESTS,
)


Expand Down

0 comments on commit 76b4229

Please sign in to comment.