-
Notifications
You must be signed in to change notification settings - Fork 297
Move experimental equalise_attributes #3527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
* The :func:`iris.experimental.equalise_cubes.equalise_attributes` function has been moved from the | ||
:mod:`iris.experimental` module into the :mod:`iris.util` module. Please use the :func:`iris.util.equalise_attributes` | ||
function instead. |
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,8 +4,7 @@ | |
# See COPYING and COPYING.LESSER in the root of the repository for full | ||
# licensing details. | ||
""" | ||
Unit tests for the :func:`iris.experimental.equalise_cubes.equalise_attributes` | ||
function. | ||
Unit tests for the :func:`iris.util.equalise_attributes` function. | ||
|
||
""" | ||
|
||
|
@@ -16,7 +15,7 @@ | |
import numpy as np | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The doc string in the file header still references "experimental". I think it should be iris.util.equalise_attributes: """ |
||
|
||
from iris.cube import Cube | ||
from iris.experimental.equalise_cubes import equalise_attributes | ||
from iris.util import equalise_attributes | ||
import iris.tests.stock | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1794,3 +1794,37 @@ def mask_cube(cube, points_to_mask): | |
cube.data = ma.masked_array(cube.data) | ||
cube.data[points_to_mask] = ma.masked | ||
return cube | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I checked this file: It is identical to before, except for syntax over multiple lines :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @abooton Yup, that's the magic of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👻 👿 🙈 |
||
|
||
def equalise_attributes(cubes): | ||
""" | ||
Delete cube attributes that are not identical over all cubes in a group. | ||
|
||
This function simply deletes any attributes which are not the same for | ||
all the given cubes. The cubes will then have identical attributes. The | ||
given cubes are modified in-place. | ||
|
||
Args: | ||
|
||
* cubes (iterable of :class:`iris.cube.Cube`): | ||
A collection of cubes to compare and adjust. | ||
|
||
""" | ||
# Work out which attributes are identical across all the cubes. | ||
common_keys = list(cubes[0].attributes.keys()) | ||
for cube in cubes[1:]: | ||
cube_keys = list(cube.attributes.keys()) | ||
common_keys = [ | ||
key | ||
for key in common_keys | ||
if ( | ||
key in cube_keys | ||
and np.all(cube.attributes[key] == cubes[0].attributes[key]) | ||
) | ||
] | ||
|
||
# Remove all the other attributes. | ||
for cube in cubes: | ||
for key in list(cube.attributes.keys()): | ||
if key not in common_keys: | ||
del cube.attributes[key] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohhh our first
f-string
🎉Welcome to the wonderful world of Python3 (finally!)