|
16 | 16 | import cf_units
|
17 | 17 | import dask.array as da
|
18 | 18 | import numpy as np
|
| 19 | +import numpy.ma as ma |
19 | 20 | import pytest
|
20 | 21 |
|
21 | 22 | import iris
|
@@ -701,6 +702,112 @@ def test_lazy_3_bounds(self):
|
701 | 702 | self.assertArrayAlmostEqual(collapsed_coord.points, da.array([2.0]))
|
702 | 703 | self.assertArrayAlmostEqual(collapsed_coord.bounds, da.array([[0.0, 4.0]]))
|
703 | 704 |
|
| 705 | + def test_string_masked(self): |
| 706 | + points = ma.array(["foo", "bar", "bing"], mask=[0, 1, 0], dtype=str) |
| 707 | + coord = AuxCoord(points) |
| 708 | + |
| 709 | + collapsed_coord = coord.collapsed(0) |
| 710 | + |
| 711 | + expected = "foo|--|bing" |
| 712 | + self.assertEqual(collapsed_coord.points, expected) |
| 713 | + |
| 714 | + def test_string_nd_first(self): |
| 715 | + self.setupTestArrays((3, 4)) |
| 716 | + coord = AuxCoord(self.pts_real.astype(str)) |
| 717 | + |
| 718 | + collapsed_coord = coord.collapsed(0) |
| 719 | + expected = [ |
| 720 | + "0.0|40.0|80.0", |
| 721 | + "10.0|50.0|90.0", |
| 722 | + "20.0|60.0|100.0", |
| 723 | + "30.0|70.0|110.0", |
| 724 | + ] |
| 725 | + |
| 726 | + self.assertArrayEqual(collapsed_coord.points, expected) |
| 727 | + |
| 728 | + def test_string_nd_second(self): |
| 729 | + self.setupTestArrays((3, 4)) |
| 730 | + coord = AuxCoord(self.pts_real.astype(str)) |
| 731 | + |
| 732 | + collapsed_coord = coord.collapsed(1) |
| 733 | + expected = [ |
| 734 | + "0.0|10.0|20.0|30.0", |
| 735 | + "40.0|50.0|60.0|70.0", |
| 736 | + "80.0|90.0|100.0|110.0", |
| 737 | + ] |
| 738 | + |
| 739 | + self.assertArrayEqual(collapsed_coord.points, expected) |
| 740 | + |
| 741 | + def test_string_nd_both(self): |
| 742 | + self.setupTestArrays((3, 4)) |
| 743 | + coord = AuxCoord(self.pts_real.astype(str)) |
| 744 | + |
| 745 | + collapsed_coord = coord.collapsed() |
| 746 | + expected = ["0.0|10.0|20.0|30.0|40.0|50.0|60.0|70.0|80.0|90.0|100.0|110.0"] |
| 747 | + |
| 748 | + self.assertArrayEqual(collapsed_coord.points, expected) |
| 749 | + |
| 750 | + def test_string_nd_bounds_first(self): |
| 751 | + self.setupTestArrays((3, 4)) |
| 752 | + coord = AuxCoord(self.pts_real.astype(str), bounds=self.bds_real.astype(str)) |
| 753 | + |
| 754 | + collapsed_coord = coord.collapsed(0) |
| 755 | + |
| 756 | + # Points handling is as for non bounded case. So just check bounds. |
| 757 | + expected_lower = [ |
| 758 | + "-2.0|38.0|78.0", |
| 759 | + "8.0|48.0|88.0", |
| 760 | + "18.0|58.0|98.0", |
| 761 | + "28.0|68.0|108.0", |
| 762 | + ] |
| 763 | + |
| 764 | + expected_upper = [ |
| 765 | + "2.0|42.0|82.0", |
| 766 | + "12.0|52.0|92.0", |
| 767 | + "22.0|62.0|102.0", |
| 768 | + "32.0|72.0|112.0", |
| 769 | + ] |
| 770 | + |
| 771 | + self.assertArrayEqual(collapsed_coord.bounds[:, 0], expected_lower) |
| 772 | + self.assertArrayEqual(collapsed_coord.bounds[:, 1], expected_upper) |
| 773 | + |
| 774 | + def test_string_nd_bounds_second(self): |
| 775 | + self.setupTestArrays((3, 4)) |
| 776 | + coord = AuxCoord(self.pts_real.astype(str), bounds=self.bds_real.astype(str)) |
| 777 | + |
| 778 | + collapsed_coord = coord.collapsed(1) |
| 779 | + |
| 780 | + # Points handling is as for non bounded case. So just check bounds. |
| 781 | + expected_lower = [ |
| 782 | + "-2.0|8.0|18.0|28.0", |
| 783 | + "38.0|48.0|58.0|68.0", |
| 784 | + "78.0|88.0|98.0|108.0", |
| 785 | + ] |
| 786 | + |
| 787 | + expected_upper = [ |
| 788 | + "2.0|12.0|22.0|32.0", |
| 789 | + "42.0|52.0|62.0|72.0", |
| 790 | + "82.0|92.0|102.0|112.0", |
| 791 | + ] |
| 792 | + |
| 793 | + self.assertArrayEqual(collapsed_coord.bounds[:, 0], expected_lower) |
| 794 | + self.assertArrayEqual(collapsed_coord.bounds[:, 1], expected_upper) |
| 795 | + |
| 796 | + def test_string_nd_bounds_both(self): |
| 797 | + self.setupTestArrays((3, 4)) |
| 798 | + coord = AuxCoord(self.pts_real.astype(str), bounds=self.bds_real.astype(str)) |
| 799 | + |
| 800 | + collapsed_coord = coord.collapsed() |
| 801 | + |
| 802 | + # Points handling is as for non bounded case. So just check bounds. |
| 803 | + expected_lower = ["-2.0|8.0|18.0|28.0|38.0|48.0|58.0|68.0|78.0|88.0|98.0|108.0"] |
| 804 | + expected_upper = [ |
| 805 | + "2.0|12.0|22.0|32.0|42.0|52.0|62.0|72.0|82.0|92.0|102.0|112.0" |
| 806 | + ] |
| 807 | + |
| 808 | + self.assertArrayEqual(collapsed_coord.bounds[:, 0], expected_lower) |
| 809 | + self.assertArrayEqual(collapsed_coord.bounds[:, 1], expected_upper) |
| 810 | + |
704 | 811 |
|
705 | 812 | class Test_is_compatible(tests.IrisTest):
|
706 | 813 | def setUp(self):
|
|
0 commit comments