def build_basemap(lower_left=[-20,-30],upper_right=[20,10],ax=None,proj='cyl',profile=None):
    """
    First try at a building of the basemap with a 'stere' projection
    Must put in the values of the lower left corner and upper right corner (lon and lat)
    
    Defaults to draw 8 meridians and parallels

    Modified: Samuel LeBlanc, 2015-09-15, NASA Ames
            - added profile keyword that contains the basemap profile dict for plotting the corners
            - added programatic determination of basemap parallels and meridians
    """
    from map_interactive import pll
    if profile:
        upper_right = [pll(profile['Lon_range'][1]),pll(profile['Lat_range'][1])]
        lower_left = [pll(profile['Lon_range'][0]),pll(profile['Lat_range'][0])]
        
        
    m = Basemap(projection=proj,lon_0=(upper_right[0]+lower_left[0])/2.0,lat_0=(upper_right[1]+lower_left[1])/2.0,
            llcrnrlon=lower_left[0], llcrnrlat=lower_left[1],
            urcrnrlon=upper_right[0], urcrnrlat=upper_right[1],resolution='h',ax=ax)
    m.artists = []
    m.drawcoastlines()
    #m.fillcontinents(color='#AAAAAA')
    m.drawstates()
    m.drawcountries()
    round_to_5 = lambda x:(int(x/5)+1)*5 
    mer = np.arange(round_to_5(lower_left[0]),round_to_5(upper_right[0])+5,5)
    par = np.arange(round_to_5(lower_left[1]),round_to_5(upper_right[1])+5,5)
    #mer = np.linspace(-15,20,8).astype(int)
    #mer = np.linspace(lower_left[0],upper_right[0],8).astype(int)
    #par = np.linspace(-25,5,7).astype(int)
    #par = np.linspace(lower_left[1],upper_right[1],8).astype(int)
    m.artists.append(m.drawmeridians(mer,labels=[0,0,0,1]))
    m.artists.append(m.drawparallels(par,labels=[1,0,0,0]))
    return m
Example #2
0
def build_basemap(lower_left=[-20,-30],upper_right=[20,10],ax=None,proj='cyl',profile=None,larger=True):
    """
    First try at a building of the basemap with a 'stere' projection
    Must put in the values of the lower left corner and upper right corner (lon and lat)
    
    Defaults to draw 8 meridians and parallels

    Modified: Samuel LeBlanc, 2015-09-15, NASA Ames
            - added profile keyword that contains the basemap profile dict for plotting the corners
            - added programatic determination of basemap parallels and meridians
    Modified: Samuel LeBlanc, 2016-07-17, Santa Cruz, CA
            - added plotting of larger region, which is then resized, to have space to pan and zoom.
    """
    from map_interactive import pll
    if profile:
        upper_right = [pll(profile['Lon_range'][1]),pll(profile['Lat_range'][1])]
        lower_left = [pll(profile['Lon_range'][0]),pll(profile['Lat_range'][0])]

    if larger:
        dp = 30
    else:
        dp = 0
    try:
        import cPickle as pickle
        m = pickle.load(open('map_{}.pkl'.format(profile['Campaign']),'rb'))
        #print 'doing it pickle style'
        m.ax = ax
    except:
        if larger:
            dp = 30
        else:
            dp = 0
        m = Basemap(projection=proj,lon_0=(upper_right[0]+lower_left[0])/2.0,lat_0=(upper_right[1]+lower_left[1])/2.0,
                llcrnrlon=lower_left[0]-dp, llcrnrlat=lower_left[1]-dp,
                urcrnrlon=upper_right[0]+dp, urcrnrlat=upper_right[1]+dp,resolution='i',ax=ax)
    m.artists = []
    m.drawcoastlines()
    #m.fillcontinents(color='#AAAAAA')
    m.drawstates()
    m.drawcountries()
    m.large = True
    round_to_5 = lambda x:(int(x/5)+1)*5 
    round_to_2 = lambda x:(int(x/2)+1)*2
    if (upper_right[0]-lower_left[0])<20.0:
        mer = np.arange(round_to_2(lower_left[0]-dp),round_to_2(upper_right[0]+dp)+2,2)
        difx = 0.2
        m.large = False
    else:
        mer = np.arange(round_to_5(lower_left[0]-dp),round_to_5(upper_right[0]+dp)+5,5)
        difx = 1.0
    if (upper_right[1]-lower_left[1])<20.0:
        par = np.arange(round_to_2(lower_left[1]-dp),round_to_2(upper_right[1]+dp)+2,2)
        dify = 0.2
        m.large = False
    else:
        par = np.arange(round_to_5(lower_left[1]-dp),round_to_5(upper_right[1]+dp)+5,5)
        dify = 1.0
    if ax:
        ax.set_xlim(lower_left[0],upper_right[0])
        ax.set_ylim(lower_left[1],upper_right[1])
    m.artists.append(m.drawmeridians(mer,labels=[0,0,0,1]))
    m.artists.append(m.drawparallels(par,labels=[1,0,0,0]))
    # move the meridian labels to a proper position
    for aa in m.artists[0].keys():
        try:
            m.artists[0][aa][1][0].set_position((m.artists[0][aa][1][0].get_position()[0],lower_left[1]-difx))
        except:
            pass
    # move the parallels labels to a proper position
    for aa in m.artists[1].keys():
        try:
            m.artists[1][aa][1][0].set_position((lower_left[0]-dify,m.artists[1][aa][1][0].get_position()[1]))
        except:
            pass
    #import pdb; pdb.set_trace()
    if ax:
        try:
            ax.figure.show()
        except:
            try:
                ax.figure.canvas.draw()
            except:
                pass
    return m
Example #3
0
def build_basemap(lower_left=[-20, -30],
                  upper_right=[20, 10],
                  ax=None,
                  proj='cyl',
                  profile=None,
                  larger=True):
    """
    First try at a building of the basemap with a 'stere' projection
    Must put in the values of the lower left corner and upper right corner (lon and lat)
    
    Defaults to draw 8 meridians and parallels

    Modified: Samuel LeBlanc, 2015-09-15, NASA Ames
            - added profile keyword that contains the basemap profile dict for plotting the corners
            - added programatic determination of basemap parallels and meridians
    Modified: Samuel LeBlanc, 2016-07-17, Santa Cruz, CA
            - added plotting of larger region, which is then resized, to have space to pan and zoom.
    """
    from map_interactive import pll
    if profile:
        upper_right = [
            pll(profile['Lon_range'][1]),
            pll(profile['Lat_range'][1])
        ]
        lower_left = [
            pll(profile['Lon_range'][0]),
            pll(profile['Lat_range'][0])
        ]

    if larger:
        dp = 30
    else:
        dp = 0
    try:
        import cPickle as pickle
        m = pickle.load(open('map_{}.pkl'.format(profile['Campaign']), 'rb'))
        #print 'doing it pickle style'
        m.ax = ax
    except:
        if larger:
            dp = 30
        else:
            dp = 0
        m = Basemap(projection=proj,
                    lon_0=(upper_right[0] + lower_left[0]) / 2.0,
                    lat_0=(upper_right[1] + lower_left[1]) / 2.0,
                    llcrnrlon=lower_left[0] - dp,
                    llcrnrlat=lower_left[1] - dp,
                    urcrnrlon=upper_right[0] + dp,
                    urcrnrlat=upper_right[1] + dp,
                    resolution='i',
                    ax=ax)
    m.artists = []
    m.drawcoastlines()
    #m.fillcontinents(color='#AAAAAA')
    m.drawstates()
    m.drawcountries()
    m.large = True
    round_to_5 = lambda x: (int(x / 5) + 1) * 5
    round_to_2 = lambda x: (int(x / 2) + 1) * 2
    if (upper_right[0] - lower_left[0]) < 20.0:
        mer = np.arange(round_to_2(lower_left[0] - dp),
                        round_to_2(upper_right[0] + dp) + 2, 2)
        difx = 0.2
        m.large = False
    else:
        mer = np.arange(round_to_5(lower_left[0] - dp),
                        round_to_5(upper_right[0] + dp) + 5, 5)
        difx = 1.0
    if (upper_right[1] - lower_left[1]) < 20.0:
        par = np.arange(round_to_2(lower_left[1] - dp),
                        round_to_2(upper_right[1] + dp) + 2, 2)
        dify = 0.2
        m.large = False
    else:
        par = np.arange(round_to_5(lower_left[1] - dp),
                        round_to_5(upper_right[1] + dp) + 5, 5)
        dify = 1.0
    if ax:
        ax.set_xlim(lower_left[0], upper_right[0])
        ax.set_ylim(lower_left[1], upper_right[1])
    m.artists.append(m.drawmeridians(mer, labels=[0, 0, 0, 1]))
    m.artists.append(m.drawparallels(par, labels=[1, 0, 0, 0]))
    # move the meridian labels to a proper position
    for aa in m.artists[0].keys():
        try:
            m.artists[0][aa][1][0].set_position(
                (m.artists[0][aa][1][0].get_position()[0],
                 lower_left[1] - difx))
        except:
            pass
    # move the parallels labels to a proper position
    for aa in m.artists[1].keys():
        try:
            m.artists[1][aa][1][0].set_position(
                (lower_left[0] - dify,
                 m.artists[1][aa][1][0].get_position()[1]))
        except:
            pass
    #import pdb; pdb.set_trace()
    if ax:
        try:
            ax.figure.show()
        except:
            try:
                ax.figure.canvas.draw()
            except:
                pass
    return m