Skip to content
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

Move all file-load code into iris.io.loading. #6199

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
520 changes: 9 additions & 511 deletions lib/iris/__init__.py

Large diffs are not rendered by default.

83 changes: 0 additions & 83 deletions lib/iris/cube.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,89 +60,6 @@
XML_NAMESPACE_URI = "urn:x-iris:cubeml-0.2"


class _CubeFilter:
"""A constraint, paired with a list of cubes matching that constraint."""

def __init__(self, constraint, cubes=None):
self.constraint = constraint
if cubes is None:
cubes = CubeList()
self.cubes = cubes

def __len__(self):
return len(self.cubes)

def add(self, cube):
"""Add the appropriate (sub)cube to the list of cubes where it matches the constraint."""
sub_cube = self.constraint.extract(cube)
if sub_cube is not None:
self.cubes.append(sub_cube)

def combined(self, unique=False):
"""Return a new :class:`_CubeFilter` by combining the list of cubes.

Combines the list of cubes with :func:`~iris._combine_load_cubes`.

Parameters
----------
unique : bool, default=False
If True, raises `iris.exceptions.DuplicateDataError` if
duplicate cubes are detected.

"""
from iris import _combine_load_cubes

return _CubeFilter(
self.constraint,
_combine_load_cubes(self.cubes, merge_require_unique=unique),
)


class _CubeFilterCollection:
"""A list of _CubeFilter instances."""

@staticmethod
def from_cubes(cubes, constraints=None):
"""Create a new collection from an iterable of cubes, and some optional constraints."""
constraints = iris._constraints.list_of_constraints(constraints)
pairs = [_CubeFilter(constraint) for constraint in constraints]
collection = _CubeFilterCollection(pairs)
for c in cubes:
collection.add_cube(c)
return collection

def __init__(self, pairs):
self.pairs = pairs

def add_cube(self, cube):
"""Add the given :class:`~iris.cube.Cube` to all of the relevant constraint pairs."""
for pair in self.pairs:
pair.add(cube)

def cubes(self):
"""Return all the cubes in this collection in a single :class:`CubeList`."""
from iris.cube import CubeList

result = CubeList()
for pair in self.pairs:
result.extend(pair.cubes)
return result

def combined(self, unique=False):
"""Return a new :class:`_CubeFilterCollection` by combining all the cube lists of this collection.

Combines each list of cubes using :func:`~iris._combine_load_cubes`.

Parameters
----------
unique : bool, default=False
If True, raises `iris.exceptions.DuplicateDataError` if
duplicate cubes are detected.

"""
return _CubeFilterCollection([pair.combined(unique) for pair in self.pairs])


class CubeList(list):
"""All the functionality of a standard :class:`list` with added "Cube" context."""

Expand Down
Loading
Loading