esmvaltool/diag_scripts/ocean/diagnostic_tools.py
def make_cube_layer_dict(cube):
    """
    Take a cube and return a dictionairy layer:cube

    Each item in the dict is a layer with a separate cube for each layer.
    ie:
        cubes[depth] = cube from specific layer

    Cubes with no depth component are returns as:
        cubes[''] = cube with no depth component.
    """
    #####
    # Check layering:
    coords = cube.coords()
    layers = []
    for coord in coords:
        if coord.standard_name in ['depth', 'region']:
            layers.append(coord)

    cubes = {}
    if layers == []:
        cubes[''] = cube
        return cubes

    if len(layers) > 1:
        # This field has a strange number of layer dimensions.
        # depth and regions?
        raise ValueError('This cube has both `depth` & `region` coordinates.')

    # iris stores coords as a list with one entry:
    layer_dim = layers[0]
    if len(layer_dim.points) in [1, ]:
        cubes[''] = cube
        return cubes

    if layer_dim.standard_name == 'depth':
        coord_dim = cube.coord_dims('depth')[0]
        for layer_index, layer in enumerate(layer_dim.points):
            slices = [slice(None) for index in cube.shape]
            slices[coord_dim] = layer_index
            cubes[layer] = cube[tuple(slices)]

    if layer_dim.standard_name == 'region':
        coord_dim = cube.coord_dims('region')[0]
        for layer_index, layer in enumerate(layer_dim.points):
            slices = [slice(None) for index in cube.shape]
            slices[coord_dim] = layer_index
            layer = layer.replace('_', ' ').title()
            cubes[layer] = cube[tuple(slices)]
    return cubes

    Take a cube and return a dictionairy layer:cube

    Each item in the dict is a layer with a separate cube for each layer.
    ie:
        cubes[depth] = cube from specific layer

    Cubes with no depth component are returns as:
        cubes[''] = cube with no depth component.
    
Take a cube and return a dictionairy layer:cube
Each item in the dict is a layer with a separate cube for each layer.
ie:
cubes[depth] = cube from specific layer

Cubes with no depth component are returns as:
cubes[''] = cube with no depth component.
Take a cube and return a dictionairy layer : cube Each item in the dict is a layer with a separate cube for each layer . ie : cubes [ depth ] = cube from specific layer Cubes with no depth component are returns as : cubes [ ' ' ] = cube with no depth component .
def make_cube_layer_dict(cube):
    coords = cube.coords()
    layers = []
    for coord in coords:
        if coord.standard_name in ['depth', 'region']:
            layers.append(coord)
    cubes = {}
    if layers == []:
        cubes[''] = cube
        return cubes
    if len(layers) > 1:
        raise ValueError('This cube has both `depth` & `region` coordinates.')
    layer_dim = layers[0]
    if len(layer_dim.points) in [1, ]:
        cubes[''] = cube
        return cubes
    if layer_dim.standard_name == 'depth':
        coord_dim = cube.coord_dims('depth')[0]
        for layer_index, layer in enumerate(layer_dim.points):
            slices = [slice(None) for index in cube.shape]
            slices[coord_dim] = layer_index
            cubes[layer] = cube[tuple(slices)]
    if layer_dim.standard_name == 'region':
        coord_dim = cube.coord_dims('region')[0]
        for layer_index, layer in enumerate(layer_dim.points):
            slices = [slice(None) for index in cube.shape]
            slices[coord_dim] = layer_index
            layer = layer.replace('_', ' ').title()
            cubes[layer] = cube[tuple(slices)]
    return cubes
def make_cube_layer_dict ( cube ) : coords = cube . coords ( ) layers = [ ] for coord in coords : if coord . standard_name in [ 'depth' , 'region' ] : layers . append ( coord ) cubes = { } if layers == [ ] : cubes [ '' ] = cube return cubes if len ( layers ) > 1 : raise ValueError ( 'This cube has both `depth` & `region` coordinates.' ) layer_dim = layers [ 0 ] if len ( layer_dim . points ) in [ 1 , ] : cubes [ '' ] = cube return cubes if layer_dim . standard_name == 'depth' : coord_dim = cube . coord_dims ( 'depth' ) [ 0 ] for layer_index , layer in enumerate ( layer_dim . points ) : slices = [ slice ( None ) for index in cube . shape ] slices [ coord_dim ] = layer_index cubes [ layer ] = cube [ tuple ( slices ) ] if layer_dim . standard_name == 'region' : coord_dim = cube . coord_dims ( 'region' ) [ 0 ] for layer_index , layer in enumerate ( layer_dim . points ) : slices = [ slice ( None ) for index in cube . shape ] slices [ coord_dim ] = layer_index layer = layer . replace ( '_' , ' ' ) . title ( ) cubes [ layer ] = cube [ tuple ( slices ) ] return cubes
Take a cube and return a dictionairy layer:cube
Each item in the dict is a layer with a separate cube for each layer.
Take a cube and return a dictionairy layer : cube Each item in the dict is a layer with a separate cube for each layer .
"""
    Take a cube and return a dictionairy layer:cube

    Each item in the dict is a layer with a separate cube for each layer.
    ie:
        cubes[depth] = cube from specific layer

    Cubes with no depth component are returns as:
        cubes[''] = cube with no depth component.
    """ ##### # Check layering: # This field has a strange number of layer dimensions. # depth and regions? # iris stores coords as a list with one entry:
cube