@classmethod<EOL><INDENT>def groupby(cls, dataset, dims, container_type=HoloMap, group_type=None, **kwargs):<DEDENT>
import iris<EOL>if not isinstance(dims, list): dims = [dims]<EOL>dims = [dataset.get_dimension(d, strict=True) for d in dims]<EOL>constraints = [d.name for d in dims]<EOL>slice_dims = [d for d in dataset.kdims if d not in dims]<EOL>group_kwargs = {}<EOL>group_type = dict if group_type == '<STR_LIT>' else group_type<EOL>if issubclass(group_type, Element):<EOL><INDENT>group_kwargs.update(util.get_param_values(dataset))<EOL>group_kwargs['<STR_LIT>'] = slice_dims<EOL><DEDENT>group_kwargs.update(kwargs)<EOL>drop_dim = any(d not in group_kwargs['<STR_LIT>'] for d in slice_dims)<EOL>unique_coords = product(*[cls.values(dataset, d, expanded=False)<EOL>for d in dims])<EOL>data = []<EOL>for key in unique_coords:<EOL><INDENT>constraint = iris.Constraint(**dict(zip(constraints, key)))<EOL>extracted = dataset.data.extract(constraint)<EOL>if drop_dim:<EOL><INDENT>extracted = group_type(extracted, kdims=slice_dims,<EOL>vdims=dataset.vdims).columns()<EOL><DEDENT>cube = group_type(extracted, **group_kwargs)<EOL>data.append((key, cube))<EOL><DEDENT>if issubclass(container_type, NdMapping):<EOL><INDENT>with item_check(False), sorted_context(False):<EOL><INDENT>return container_type(data, kdims=dims)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>return container_type(data)<EOL><DEDENT>
Groups the data by one or more dimensions returning a container
indexed by the grouped dimensions containing slices of the
cube wrapped in the group_type. This makes it very easy to
break up a high-dimensional dataset into smaller viewable chunks.