Check ternary coordinates and return the right barycentric coordinates.
(b_coords)
| 153 | |
| 154 | |
| 155 | def _prepare_barycentric_coord(b_coords): |
| 156 | """ |
| 157 | Check ternary coordinates and return the right barycentric coordinates. |
| 158 | """ |
| 159 | if not isinstance(b_coords, (list, np.ndarray)): |
| 160 | raise ValueError( |
| 161 | "Data should be either an array of shape (n,m)," |
| 162 | "or a list of n m-lists, m=2 or 3" |
| 163 | ) |
| 164 | b_coords = np.asarray(b_coords) |
| 165 | if b_coords.shape[0] not in (2, 3): |
| 166 | raise ValueError( |
| 167 | "A point should have 2 (a, b) or 3 (a, b, c)barycentric coordinates" |
| 168 | ) |
| 169 | if ( |
| 170 | (len(b_coords) == 3) |
| 171 | and not np.allclose(b_coords.sum(axis=0), 1, rtol=0.01) |
| 172 | and not np.allclose(b_coords.sum(axis=0), 100, rtol=0.01) |
| 173 | ): |
| 174 | msg = "The sum of coordinates should be 1 or 100 for all data points" |
| 175 | raise ValueError(msg) |
| 176 | |
| 177 | if len(b_coords) == 2: |
| 178 | A, B = b_coords |
| 179 | C = 1 - (A + B) |
| 180 | else: |
| 181 | A, B, C = b_coords / b_coords.sum(axis=0) |
| 182 | if np.any(np.stack((A, B, C)) < 0): |
| 183 | raise ValueError("Barycentric coordinates should be positive.") |
| 184 | return np.stack((A, B, C)) |
| 185 | |
| 186 | |
| 187 | def _compute_grid(coordinates, values, interp_mode="ilr"): |
no test coverage detected