예제 #1
0
파일: rim.py 프로젝트: mudtop/spacepy
def get_iono_cb(ct_name='bwr'):
    '''
    Several custom colorbars used by RIM and AMIE have become standard when
    visualizing data from these models.  These are 'blue_white_red' and 
    'white_red', used for data that have positive and negative values and
    for data that have only positive values, respectively.  This function
    builds and returns these colorbars when called with the initials of the
    color table name as the only argument.

    Other Parameters
    ================
    ct_name : str
       Select the color table.  Can be 'bwr' for blue-white-red or 'wr' for
       white-red.  Defaults to 'bwr'.

    Examples
    ========
    >>> bwr_map = get_iono_cb('bwr')
    >>> wr_map  = get_iono_cb('wr')

    '''

    from matplotlib.colors import LinearSegmentedColormap as lsc

    if ct_name == 'bwr':
        table = {
            'red': [(0., 0., .0), (.34, 0., 0.), (.5, 1., 1.), (1., 1., 1.)],
            'green': [(0., 0., 0.), (.35, 1., 1.), (.66, 1., 1.),
                      (1., 0., 0.)],
            'blue': [(0., 1., 1.), (.5, 1., 1.), (.66, 0., 0.), (.85, 0., 0.),
                     (1., .1, .1)]
        }
        cmap = lsc('blue_white_red', table)
    elif ct_name == 'wr':
        table = {
            'red': [(0., 1., 1.), (1., 1., 1.)],
            'green': [(0., 1., 1.), (1., 0., 0.)],
            'blue': [(0., 1., 1.), (1., .0, .0)]
        }
        cmap = lsc('white_red', table)

    return cmap
예제 #2
0
def get_iono_cb(ct_name='bwr'):
    '''
    Several custom colorbars used by RIM and AMIE have become standard when
    visualizing data from these models.  These are 'blue_white_red' and 
    'white_red', used for data that have positive and negative values and
    for data that have only positive values, respectively.  This function
    builds and returns these colorbars when called with the initials of the
    color table name as the only argument.

    Other Parameters
    ================
    ct_name : str
       Select the color table.  Can be 'bwr' for blue-white-red or 'wr' for
       white-red.  Defaults to 'bwr'.

    Examples
    ========
    >>> bwr_map = get_iono_cb('bwr')
    >>> wr_map  = get_iono_cb('wr')

    '''

    from matplotlib.colors import LinearSegmentedColormap as lsc

    if ct_name=='bwr':
        table = {
            'red':  [(0.,0.,.0),(.34,0.,0.),(.5,1.,1.),(1.,1.,1.)],
            'green':[(0.,0.,0.),(.35,1.,1.),(.66,1.,1.),(1.,0.,0.)],
            'blue' :[(0.,1.,1.),(.5,1.,1.),(.66,0.,0.),(.85,0.,0.),(1.,.1,.1)]
            }
        cmap = lsc('blue_white_red',table)
    elif ct_name=='wr':
        table = {
            'red':  [(0.,1.,1.),(1.,1.,1.)],
            'green':[(0.,1.,1.),(1.,0.,0.)],
            'blue' :[(0.,1.,1.),(1.,.0,.0)]
            }
        cmap = lsc('white_red',table)

    return cmap
예제 #3
0
def cmap_map(function, cmap, name='colormap_mod', N=None, gamma=None):
    """
    Modify a colormap using `function` which must operate on 3-element
    arrays of [r, g, b] values.

    You may specify the number of colors, `N`, and the opacity, `gamma`,
    value of the returned colormap. These values default to the ones in
    the input `cmap`.

    You may also specify a `name` for the colormap, so that it can be
    loaded using plt.get_cmap(name).
    """
    from matplotlib.colors import LinearSegmentedColormap as lsc
    if N is None:
        N = cmap.N
    if gamma is None:
        gamma = cmap._gamma
    cdict = cmap._segmentdata
    # Cast the steps into lists:
    step_dict = {key: list(map(lambda x: x[0], cdict[key])) for key in cdict}
    # Now get the unique steps (first column of the arrays):
    step_dicts = np.array(list(step_dict.values()))
    step_list = np.unique(step_dicts)
    # 'y0', 'y1' are as defined in LinearSegmentedColormap docstring:
    y0 = cmap(step_list)[:, :3]
    y1 = y0.copy()[:, :3]
    # Go back to catch the discontinuities, and place them into y0, y1
    for iclr, key in enumerate(['red', 'green', 'blue']):
        for istp, step in enumerate(step_list):
            try:
                ind = step_dict[key].index(step)
            except ValueError:
                # This step is not in this color
                continue
            y0[istp, iclr] = cdict[key][ind][1]
            y1[istp, iclr] = cdict[key][ind][2]
    # Map the colors to their new values:
    y0 = np.array(list(map(function, y0)))
    y1 = np.array(list(map(function, y1)))
    # Build the new colormap (overwriting step_dict):
    for iclr, clr in enumerate(['red', 'green', 'blue']):
        step_dict[clr] = np.vstack((step_list, y0[:, iclr], y1[:, iclr])).T
    # Remove alpha, otherwise crashes...
    step_dict.pop('alpha', None)
    return lsc(name, step_dict, N=N, gamma=gamma)
예제 #4
0
from matplotlib.colors import LinearSegmentedColormap as lsc

cdict = {
    'red': ((0., 1, 1), (0.05, 1, 1), (0.20, 0, 0), (0.66, 1, 1), (0.89, 1, 1),
            (1, 0.5, 0.5)),
    'green': ((0., 1, 1), (0.05, 1, 1), (0.20, 0, 0), (0.375, 1, 1),
              (0.64, 1, 1), (0.91, 0, 0), (1, 0, 0)),
    'blue': ((0., 1, 1), (0.075, 1, 1), (0.20, 1, 1), (0.34, 1, 1),
             (0.65, 0, 0), (1, 0, 0))
}
whitejet = lsc('whitejet', cdict, 256)


def plot_1sta(sim_path, staname, hypocenter, stafile, tlims=[0, 30]):
    '''
    Plot one station and it's predicted arrivals from ray tracing
    '''
    from matplotlib import pyplot as plt
    from obspy.taup import TauPyModel
    from numpy import genfromtxt, where, rad2deg
    from glob import glob
    from pyproj import Geod

    #load data
    afile = glob(sim_path + '*.' + staname + '.acc*')[0]
    a = genfromtxt(afile)
    vfile = glob(sim_path + '*.' + staname + '.vel*')[0]
    v = genfromtxt(vfile)

    #Station coordinates
    all_stations = genfromtxt(sim_path + 'param_files/' + stafile,