scicm/tools.py
def stitch(cmapinlist,vlims,tpoints,name_newcmap=None):
    '''Stich together the selected crops from the given list of colour maps. Can also register the
    new colour map with matplotlib.
    
    Parameters
    ----------
    cmapinlist : list
        Each element must be either a string with the name of each colour map or the
        colour map objects.
    vlims : numpy.ndarray
        A (N,2) array that contains the vmin and vmax values used for cropping the colour maps
        and setting the ranges that each crop will take on the new colour map. vlims[:,0] are
        the low limits (vmin) and vlims[:,1] the high limits (vmax).
    tpoints : list, tuple or numpy.ndarray
        Contains the transition points where the new colour map will transition from one input
        colour map to the next.
    name_newcmap : str, optional
        If given, defines the name to register with matplotlib.
    Returns
    -------
    newcmap
        Colourmap object with the new colour map.
    '''
    
    if not isinstance(cmapinlist,list):
        raise TypeError('cmapinlist must be a list')
    if not isinstance(vlims,np.ndarray):
        vlims=np.array(vlims)
    for vcheck in vlims:
        if vcheck[0]>vcheck[1]:
            raise ValueError('The value of vmin must be lower than vmax')
    if np.sum((vlims<0.0)|(vlims>1.0))>0:
        raise ValueError('The values in vlims must be in the closed range [0,1]')
    if not isinstance(tpoints,np.ndarray):
        tpoints=np.array(tpoints)
    if np.sum(np.diff(tpoints)<0)>1:
        raise ValueError('tpoints must be monotonically increasing in value')
    if np.sum((tpoints<=0.0)|(tpoints>=1.0)):
        raise ValueError('The values of tpoints must be in the open range (0,1)')
    if not isinstance(name_newcmap,str) and name_newcmap is not None:
        raise TypeError('name_newcmap must be a string')
    
    cmapinlist=[cm.get_cmap(cmapin) if isinstance(cmapin,str) else cmapin for cmapin in cmapinlist]
    
    tpoints=np.array([0]+list(tpoints)+[1])
    nstep=np.empty(len(cmapinlist))
    test_range=np.linspace(0,1,256)
    for i in range(len(cmapinlist)):
        nstep[i]=np.sum((test_range>tpoints[i])&(test_range<tpoints[i+1]))
    nstep=np.where(nstep<1,1,nstep)
    if np.sum(nstep)!=256:
        nstep[-1]+=256-np.sum(nstep)
    nstep=nstep.astype('int')
    
    cmaplist_data=[cmapinlist[i](np.linspace(vlims[i,0],vlims[i,1],nstep[i]))
                   for i in range(len(cmapinlist))]
    cmap_data=np.concatenate(cmaplist_data,axis=0)
    
    if name_newcmap:
        newcmap=LSC.from_list(name_newcmap,cmap_data,N=cmap_data.shape[0])
        cm.register_cmap(name_newcmap,newcmap)
    else:
        newcmap=LSC.from_list('newcmap',cmap_data,N=cmap_data.shape[0])
    
    return newcmap
Stich together the selected crops from the given list of colour maps. Can also register the
    new colour map with matplotlib.
    
    Parameters
    ----------
    cmapinlist : list
        Each element must be either a string with the name of each colour map or the
        colour map objects.
    vlims : numpy.ndarray
        A (N,2) array that contains the vmin and vmax values used for cropping the colour maps
        and setting the ranges that each crop will take on the new colour map. vlims[:,0] are
        the low limits (vmin) and vlims[:,1] the high limits (vmax).
    tpoints : list, tuple or numpy.ndarray
        Contains the transition points where the new colour map will transition from one input
        colour map to the next.
    name_newcmap : str, optional
        If given, defines the name to register with matplotlib.
    Returns
    -------
    newcmap
        Colourmap object with the new colour map.
    
Stich together the selected crops from the given list of colour maps. Can also register the
new colour map with matplotlib.

Parameters

cmapinlist : list
Each element must be either a string with the name of each colour map or the
colour map objects.
vlims : numpy.ndarray
A (N,2) array that contains the vmin and vmax values used for cropping the colour maps
and setting the ranges that each crop will take on the new colour map. vlims[:,0] are
the low limits (vmin) and vlims[:,1] the high limits (vmax).
tpoints : list, tuple or numpy.ndarray
Contains the transition points where the new colour map will transition from one input
colour map to the next.
name_newcmap : str, optional
If given, defines the name to register with matplotlib.
Returns

newcmap
Colourmap object with the new colour map.
Stich together the selected crops from the given list of colour maps . Can also register the new colour map with matplotlib . Parameters cmapinlist : list Each element must be either a string with the name of each colour map or the colour map objects . vlims : numpy . ndarray A ( N 2 ) array that contains the vmin and vmax values used for cropping the colour maps and setting the ranges that each crop will take on the new colour map . vlims [ : 0 ] are the low limits ( vmin ) and vlims [ : 1 ] the high limits ( vmax ) . tpoints : list tuple or numpy . ndarray Contains the transition points where the new colour map will transition from one input colour map to the next . name_newcmap : str optional If given defines the name to register with matplotlib . Returns newcmap Colourmap object with the new colour map .
def stitch(cmapinlist,vlims,tpoints,name_newcmap=None):
    if not isinstance(cmapinlist,list):
        raise TypeError('cmapinlist must be a list')
    if not isinstance(vlims,np.ndarray):
        vlims=np.array(vlims)
    for vcheck in vlims:
        if vcheck[0]>vcheck[1]:
            raise ValueError('The value of vmin must be lower than vmax')
    if np.sum((vlims<0.0)|(vlims>1.0))>0:
        raise ValueError('The values in vlims must be in the closed range [0,1]')
    if not isinstance(tpoints,np.ndarray):
        tpoints=np.array(tpoints)
    if np.sum(np.diff(tpoints)<0)>1:
        raise ValueError('tpoints must be monotonically increasing in value')
    if np.sum((tpoints<=0.0)|(tpoints>=1.0)):
        raise ValueError('The values of tpoints must be in the open range (0,1)')
    if not isinstance(name_newcmap,str) and name_newcmap is not None:
        raise TypeError('name_newcmap must be a string')
    cmapinlist=[cm.get_cmap(cmapin) if isinstance(cmapin,str) else cmapin for cmapin in cmapinlist]
    tpoints=np.array([0]+list(tpoints)+[1])
    nstep=np.empty(len(cmapinlist))
    test_range=np.linspace(0,1,256)
    for i in range(len(cmapinlist)):
        nstep[i]=np.sum((test_range>tpoints[i])&(test_range<tpoints[i+1]))
    nstep=np.where(nstep<1,1,nstep)
    if np.sum(nstep)!=256:
        nstep[-1]+=256-np.sum(nstep)
    nstep=nstep.astype('int')
    cmaplist_data=[cmapinlist[i](np.linspace(vlims[i,0],vlims[i,1],nstep[i]))
                   for i in range(len(cmapinlist))]
    cmap_data=np.concatenate(cmaplist_data,axis=0)
    if name_newcmap:
        newcmap=LSC.from_list(name_newcmap,cmap_data,N=cmap_data.shape[0])
        cm.register_cmap(name_newcmap,newcmap)
    else:
        newcmap=LSC.from_list('newcmap',cmap_data,N=cmap_data.shape[0])
    return newcmap
def stitch ( cmapinlist , vlims , tpoints , name_newcmap = None ) : if not isinstance ( cmapinlist , list ) : raise TypeError ( 'cmapinlist must be a list' ) if not isinstance ( vlims , np . ndarray ) : vlims = np . array ( vlims ) for vcheck in vlims : if vcheck [ 0 ] > vcheck [ 1 ] : raise ValueError ( 'The value of vmin must be lower than vmax' ) if np . sum ( ( vlims < 0.0 ) | ( vlims > 1.0 ) ) > 0 : raise ValueError ( 'The values in vlims must be in the closed range [0,1]' ) if not isinstance ( tpoints , np . ndarray ) : tpoints = np . array ( tpoints ) if np . sum ( np . diff ( tpoints ) < 0 ) > 1 : raise ValueError ( 'tpoints must be monotonically increasing in value' ) if np . sum ( ( tpoints <= 0.0 ) | ( tpoints >= 1.0 ) ) : raise ValueError ( 'The values of tpoints must be in the open range (0,1)' ) if not isinstance ( name_newcmap , str ) and name_newcmap is not None : raise TypeError ( 'name_newcmap must be a string' ) cmapinlist = [ cm . get_cmap ( cmapin ) if isinstance ( cmapin , str ) else cmapin for cmapin in cmapinlist ] tpoints = np . array ( [ 0 ] + list ( tpoints ) + [ 1 ] ) nstep = np . empty ( len ( cmapinlist ) ) test_range = np . linspace ( 0 , 1 , 256 ) for i in range ( len ( cmapinlist ) ) : nstep [ i ] = np . sum ( ( test_range > tpoints [ i ] ) & ( test_range < tpoints [ i + 1 ] ) ) nstep = np . where ( nstep < 1 , 1 , nstep ) if np . sum ( nstep ) != 256 : nstep [ - 1 ] += 256 - np . sum ( nstep ) nstep = nstep . astype ( 'int' ) cmaplist_data = [ cmapinlist [ i ] ( np . linspace ( vlims [ i , 0 ] , vlims [ i , 1 ] , nstep [ i ] ) ) for i in range ( len ( cmapinlist ) ) ] cmap_data = np . concatenate ( cmaplist_data , axis = 0 ) if name_newcmap : newcmap = LSC . from_list ( name_newcmap , cmap_data , N = cmap_data . shape [ 0 ] ) cm . register_cmap ( name_newcmap , newcmap ) else : newcmap = LSC . from_list ( 'newcmap' , cmap_data , N = cmap_data . shape [ 0 ] ) return newcmap
Stich together the selected crops from the given list of colour maps.
Stich together the selected crops from the given list of colour maps .
'''Stich together the selected crops from the given list of colour maps. Can also register the
    new colour map with matplotlib.
    
    Parameters
    ----------
    cmapinlist : list
        Each element must be either a string with the name of each colour map or the
        colour map objects.
    vlims : numpy.ndarray
        A (N,2) array that contains the vmin and vmax values used for cropping the colour maps
        and setting the ranges that each crop will take on the new colour map. vlims[:,0] are
        the low limits (vmin) and vlims[:,1] the high limits (vmax).
    tpoints : list, tuple or numpy.ndarray
        Contains the transition points where the new colour map will transition from one input
        colour map to the next.
    name_newcmap : str, optional
        If given, defines the name to register with matplotlib.
    Returns
    -------
    newcmap
        Colourmap object with the new colour map.
    '''
cmapinlist
vlims
tpoints
name_newcmap