Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 17 additions & 14 deletions lib/iris/analysis/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,6 @@
from iris.util import broadcast_to_shape


def _ones_like(cube):
"""
Return a copy of cube with the same mask, but all data values set to 1.

The operation is non-lazy.
"""
ones_cube = cube.copy()
ones_cube.data = np.ones_like(cube.data)
ones_cube.rename("unknown")
ones_cube.units = 1
return ones_cube


def pearsonr(
cube_a,
cube_b,
Expand Down Expand Up @@ -91,14 +78,30 @@ def pearsonr(
cube_1 = cube_a
cube_2 = cube_b

smaller_shape = cube_2.shape

dim_coords_1 = [coord.name() for coord in cube_1.dim_coords]
dim_coords_2 = [coord.name() for coord in cube_2.dim_coords]
common_dim_coords = list(set(dim_coords_1) & set(dim_coords_2))
# If no coords passed then set to all common dimcoords of cubes.
if corr_coords is None:
corr_coords = common_dim_coords

smaller_shape = cube_2.shape
def _ones_like(cube):
# Return a copy of cube with the same mask, but all data values set to 1.
# The operation is non-lazy.
# For safety we also discard any cell-measures and ancillary-variables, to
# avoid cube arithmetic possibly objecting to them, or inadvertently retaining
# them in the result where they might be inappropriate.
ones_cube = cube.copy()
ones_cube.data = np.ones_like(cube.data)
ones_cube.rename("unknown")
ones_cube.units = 1
for cm in ones_cube.cell_measures():
ones_cube.remove_cell_measure(cm)
for av in ones_cube.ancillary_variables():
ones_cube.remove_ancillary_variable(av)
return ones_cube

# Match up data masks if required.
if common_mask:
Expand Down