-
Notifications
You must be signed in to change notification settings - Fork 284
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Re-write pearsonr to use Resolve * add test for weight transposing case * Fix single coordinate case * use lenient coord handling * Move coordinate handling tests to separate class These do not need real and lazy versions * Make some syntax highlighters happier Co-authored-by: Martin Yeo <[email protected]> * Initial review actions * Clearer comment Co-authored-by: Martin Yeo <[email protected]> * assign reviewer blame * first attempt at benchmarks * directly use resolve for weight wrangling * Add note about maths broadcasting rules * use lhs/rhs instead of 1/2 for consistency * convert tests to pytest * check dask's compute is not called * revert now redundant resolve change * Improvements to pearsonr docstring. --------- Co-authored-by: Martin Yeo <[email protected]> Co-authored-by: Martin Yeo <[email protected]>
- Loading branch information
1 parent
67bb5ae
commit fe46e05
Showing
4 changed files
with
252 additions
and
141 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Copyright Iris contributors | ||
# | ||
# This file is part of Iris and is released under the BSD license. | ||
# See LICENSE in the root of the repository for full licensing details. | ||
"""Stats benchmark tests.""" | ||
|
||
import iris | ||
from iris.analysis.stats import pearsonr | ||
import iris.tests | ||
|
||
|
||
class PearsonR: | ||
def setup(self): | ||
cube_temp = iris.load_cube( | ||
iris.tests.get_data_path( | ||
("NetCDF", "global", "xyt", "SMALL_total_column_co2.nc") | ||
) | ||
) | ||
|
||
# Make data non-lazy. | ||
cube_temp.data | ||
|
||
self.cube_a = cube_temp[:6] | ||
self.cube_b = cube_temp[20:26] | ||
self.cube_b.replace_coord(self.cube_a.coord("time")) | ||
for name in ["latitude", "longitude"]: | ||
self.cube_b.coord(name).guess_bounds() | ||
self.weights = iris.analysis.cartography.area_weights(self.cube_b) | ||
|
||
def time_real(self): | ||
pearsonr(self.cube_a, self.cube_b, weights=self.weights) | ||
|
||
def time_lazy(self): | ||
for cube in self.cube_a, self.cube_b: | ||
cube.data = cube.lazy_data() | ||
|
||
result = pearsonr(self.cube_a, self.cube_b, weights=self.weights) | ||
result.data |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.