@classmethod<EOL><INDENT>def select_to_constraint(cls, dataset, selection):<DEDENT>
import iris<EOL>def get_slicer(start, end):<EOL><INDENT>def slicer(cell):<EOL><INDENT>return start <= cell.point < end<EOL><DEDENT>return slicer<EOL><DEDENT>constraint_kwargs = {}<EOL>for dim, constraint in selection.items():<EOL><INDENT>if isinstance(constraint, slice):<EOL><INDENT>constraint = (constraint.start, constraint.stop)<EOL><DEDENT>if isinstance(constraint, tuple):<EOL><INDENT>if constraint == (None, None):<EOL><INDENT>continue<EOL><DEDENT>constraint = get_slicer(*constraint)<EOL><DEDENT>dim = dataset.get_dimension(dim, strict=True)<EOL>constraint_kwargs[dim.name] = constraint<EOL><DEDENT>return iris.Constraint(**constraint_kwargs)<EOL>
Transform a selection dictionary to an iris Constraint.