| 6466 | # at the midpoints between the grid centers and then use the |
| 6467 | # flat algorithm. |
| 6468 | def _interp_grid(X, require_monotonicity=False): |
| 6469 | # helper for below. To ensure the cell edges are calculated |
| 6470 | # correctly, when expanding columns, the monotonicity of |
| 6471 | # X coords needs to be checked. When expanding rows, the |
| 6472 | # monotonicity of Y coords needs to be checked. |
| 6473 | if np.shape(X)[1] > 1: |
| 6474 | dX = np.diff(X, axis=1) * 0.5 |
| 6475 | if (require_monotonicity and |
| 6476 | not (np.all(dX >= 0) or np.all(dX <= 0))): |
| 6477 | _api.warn_external( |
| 6478 | f"The input coordinates to {funcname} are " |
| 6479 | "interpreted as cell centers, but are not " |
| 6480 | "monotonically increasing or decreasing. " |
| 6481 | "This may lead to incorrectly calculated cell " |
| 6482 | "edges, in which case, please supply " |
| 6483 | f"explicit cell edges to {funcname}.") |
| 6484 | |
| 6485 | hstack = np.ma.hstack if np.ma.isMA(X) else np.hstack |
| 6486 | X = hstack((X[:, [0]] - dX[:, [0]], |
| 6487 | X[:, :-1] + dX, |
| 6488 | X[:, [-1]] + dX[:, [-1]])) |
| 6489 | else: |
| 6490 | # This is just degenerate, but we can't reliably guess |
| 6491 | # a dX if there is just one value. |
| 6492 | X = np.hstack((X, X)) |
| 6493 | return X |
| 6494 | |
| 6495 | if ncols == Nx: |
| 6496 | X = _interp_grid(X, require_monotonicity=True) |