MCPcopy Index your code
hub / github.com/pydata/xarray / test_divergentcontrol

Method test_divergentcontrol

xarray/tests/test_plot.py:1065–1141  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1063 assert_array_equal(cmap_params["levels"], orig_levels)
1064
1065 def test_divergentcontrol(self) -> None:
1066 neg = self.data - 0.1
1067 pos = self.data
1068
1069 # Default with positive data will be a normal cmap
1070 cmap_params = _determine_cmap_params(pos)
1071 assert cmap_params["vmin"] == 0
1072 assert cmap_params["vmax"] == 1
1073 assert cmap_params["cmap"] == "viridis"
1074
1075 # Default with negative data will be a divergent cmap
1076 cmap_params = _determine_cmap_params(neg)
1077 assert cmap_params["vmin"] == -0.9
1078 assert cmap_params["vmax"] == 0.9
1079 assert cmap_params["cmap"] == "RdBu_r"
1080
1081 # Setting vmin or vmax should prevent this only if center is false
1082 cmap_params = _determine_cmap_params(neg, vmin=-0.1, center=False)
1083 assert cmap_params["vmin"] == -0.1
1084 assert cmap_params["vmax"] == 0.9
1085 assert cmap_params["cmap"] == "viridis"
1086 cmap_params = _determine_cmap_params(neg, vmax=0.5, center=False)
1087 assert cmap_params["vmin"] == -0.1
1088 assert cmap_params["vmax"] == 0.5
1089 assert cmap_params["cmap"] == "viridis"
1090
1091 # Setting center=False too
1092 cmap_params = _determine_cmap_params(neg, center=False)
1093 assert cmap_params["vmin"] == -0.1
1094 assert cmap_params["vmax"] == 0.9
1095 assert cmap_params["cmap"] == "viridis"
1096
1097 # However, I should still be able to set center and have a div cmap
1098 cmap_params = _determine_cmap_params(neg, center=0)
1099 assert cmap_params["vmin"] == -0.9
1100 assert cmap_params["vmax"] == 0.9
1101 assert cmap_params["cmap"] == "RdBu_r"
1102
1103 # Setting vmin or vmax alone will force symmetric bounds around center
1104 cmap_params = _determine_cmap_params(neg, vmin=-0.1)
1105 assert cmap_params["vmin"] == -0.1
1106 assert cmap_params["vmax"] == 0.1
1107 assert cmap_params["cmap"] == "RdBu_r"
1108 cmap_params = _determine_cmap_params(neg, vmax=0.5)
1109 assert cmap_params["vmin"] == -0.5
1110 assert cmap_params["vmax"] == 0.5
1111 assert cmap_params["cmap"] == "RdBu_r"
1112 cmap_params = _determine_cmap_params(neg, vmax=0.6, center=0.1)
1113 assert cmap_params["vmin"] == -0.4
1114 assert cmap_params["vmax"] == 0.6
1115 assert cmap_params["cmap"] == "RdBu_r"
1116
1117 # But this is only true if vmin or vmax are negative
1118 cmap_params = _determine_cmap_params(pos, vmin=-0.1)
1119 assert cmap_params["vmin"] == -0.1
1120 assert cmap_params["vmax"] == 0.1
1121 assert cmap_params["cmap"] == "RdBu_r"
1122 cmap_params = _determine_cmap_params(pos, vmin=0.1)

Callers

nothing calls this directly

Calls 1

_determine_cmap_paramsFunction · 0.90

Tested by

no test coverage detected