예제 #1
0
파일: viz.py 프로젝트: qAp/climatools
def get_nicenround_steps(cmap_limits, Nsteps = 10):
    '''
    Readjust given colormap limits in order to have
    nice and rounded intervals between levels.
    INPUT:
    cmap_limits --- tuple of extend, min level, max level
    Nsteps --- number of intervals in the colormap
    OUTPUT:
    tuple of extend, min level, max level, interval between level
    '''
    if cmap_limits[0] == 'both':
        cmap_min, cmap_max, cmap_Nsteps = round_levels_with_zero_centred_between_two(
            vmin0 = cmap_limits[1], vmax0 = cmap_limits[2], Nsteps0 = Nsteps)
        cmap_step = (cmap_max - cmap_min) / cmap_Nsteps
        return ('both', cmap_min, cmap_max, cmap_step)
    elif cmap_limits[0] in ['min', 'max']:
        extend, cmap_min, cmap_max = cmap_limits
        rough_cmap_step = (cmap_max - cmap_min) / Nsteps
        nice_cmap_step = muths.round_to_1(rough_cmap_step)
        cmap_Nsteps = int(np.ceil((cmap_max - cmap_min) / nice_cmap_step))
        if extend == 'min':
            # align the top
            nice_cmap_min = cmap_max - cmap_Nsteps * nice_cmap_step
            return (extend, nice_cmap_min, cmap_max, nice_cmap_step)
        elif extend == 'max':
            # align the bottom
            nice_cmap_max = cmap_min + cmap_Nsteps * nice_cmap_step
            return (extend, cmap_min, nice_cmap_max, nice_cmap_step)
예제 #2
0
파일: viz.py 프로젝트: qAp/climatools
def symmetric_about_white_cmap_levels(rough_maxabs, Ncolours = 11):
    '''
    Returns min and max levels and step that will have 0 centred
    on the colour white on a diverging colourmap that diverges from
    the colour white
    INPUT:
    rough_maxabs -- rough maximum absolute value of the levels
                    (note the absolute value because max = -min
                    necessarily)
    Ncolours -- number of intervals on the colour bar
    '''
    try:
        assert Ncolours % 2 != 0
    except AssertionError:
        raise InputError('Number of colours needs to be an odd number.')

    int_dv = muths.round_to_1(2 * rough_maxabs / Ncolours)
    rough_dv = 2 * rough_maxabs / Ncolours
    ddv = int_dv - rough_dv
    maxabs = rough_maxabs + Ncolours / 2 * ddv
    return (- maxabs, maxabs, int_dv)
예제 #3
0
파일: viz.py 프로젝트: qAp/climatools
def round_levels_with_zero_centred_between_two(vmin0 = -1, vmax0 = 2, Nsteps0 = 10):
    '''
    Suppose you want to divide the range (vmin0, vmax0) into roughly Nsteps0 intervals, where vmin0 < 0 < vmax0.
    This function returns a new range(vmin, vmax) and new Nsteps that is
    as close to the desired one as possible, but are such that dv = (vmax - vmin) / Nsteps
    is a nice round value, and the value zero is centred on one of the Nsteps intervals.
    INPUT:
    vmin0 --- lower limit, must be negative.
    vmax0 --- upper limit, must be positive.
    Nsteps0 --- rough desired number of intervals between vmin0 and vmax0.
    OUTPUT:
    vmin --- lower limit
    vmax --- upper limit
    Nsteps --- number of intervals between vmin and vmax
    '''
    dv0 = (vmax0 - vmin0) / Nsteps0
    dv = muths.round_to_1(dv0)
    half_dv = .5 * dv
    vmin = 0 - dv * int(np.ceil((0 - vmin0 - half_dv) / dv)) - half_dv
    vmax = 0 + dv * int(np.ceil((vmax0 - 0 - half_dv) / dv)) + half_dv
    Nsteps = int((vmax - vmin) / dv)
    return (vmin, vmax, Nsteps)