@classmethod
    def from_sequence(klass, seq, dim, affine=None, slice_dim=None):
        if not 0 <= dim < 5:
            raise ValueError("The argument 'dim' must be in the range [0, 5).")

        n_inputs = len(seq)
        first_input = seq[0]
        input_shape = first_input.shape

        if len(input_shape) > dim and input_shape[dim] != 1:
            raise ValueError("The dim must be singular or not exist for the "
                             "inputs.")

        output_shape = list(input_shape)
        while len(output_shape) <= dim:
            output_shape.append(1)
        output_shape[dim] = n_inputs

        if affine is None:
            affine = first_input.affine
        if slice_dim is None:
            slice_dim = first_input.slice_dim

        result = klass.make_empty(output_shape,
                                  affine,
                                  None,
                                  slice_dim)

        #Need to initialize the result with the first extension in 'seq'
        result_slc_norm = result.slice_normal
        first_slc_norm = first_input.slice_normal
        use_slices = (not result_slc_norm is None and
                      not first_slc_norm is None and
                      np.allclose(result_slc_norm, first_slc_norm))
        for classes in first_input.get_valid_classes():
            if classes[1] == 'slices' and not use_slices:
                continue
            result._content[classes[0]][classes[1]] = \
                deepcopy(first_input.get_class_dict(classes))

        #Adjust the shape to what the extension actually contains
        shape = list(result.shape)
        shape[dim] = 1
        result.shape = shape

        #Initialize reorient transform
        reorient_transform = first_input.reorient_transform

        #Add the other extensions, updating the shape as we go
        for input_ext in seq[1:]:
            #If the affines or reorient_transforms don't match, we set the
            #reorient_transform to None as we can not reliably use it to update
            #directional meta data
            if ((reorient_transform is None or
                 input_ext.reorient_transform is None) or
                not (np.allclose(input_ext.affine, affine) or
                     np.allclose(input_ext.reorient_transform,
                                 reorient_transform)
                    )
               ):
                reorient_transform = None
            result._insert(dim, input_ext)
            shape[dim] += 1
            result.shape = shape

        #Set the reorient transform
        result.reorient_transform = reorient_transform

        #Try simplifying any keys in global slices
        for key in result.get_class_dict(('global', 'slices')).keys():
            result._simplify(key)

        return result
Create an extension from a sequence of extensions.
dataset/ETHPy150Open moloney/dcmstack/src/dcmstack/dcmmeta.py/DcmMetaExtension.from_sequence