コード例 #1
0
def init_plot(m, start_lon='14 38.717E', start_lat='22 58.783S', color='red'):
    lat0, lon0 = mi.pll(start_lat), mi.pll(start_lon)
    x0, y0 = m(lon0, lat0)
    line, = m.plot([x0], [y0], 'o-', color=color, linewidth=3)
    text = ('Press s to stop interaction\\n'
            'Press i to restart interaction\\n')
    return line
コード例 #2
0
def init_plot(m,start_lon='14 38.717E',start_lat='22 58.783S',color='red'):
    lat0,lon0 = mi.pll(start_lat), mi.pll(start_lon)
    x0,y0 = m(lon0,lat0)
    line, = m.plot([x0],[y0],'o-',color=color,linewidth=3)
    text = ('Press s to stop interaction\\n'
            'Press i to restart interaction\\n')
    return line
コード例 #3
0
ファイル: map_interactive.py プロジェクト: samuelleblanc/fp
def get_sat_tracks(datestr,kml):
    """
    Program that goes and fetches the satellite tracks for the day
    For the day defined with datestr
    kml is the parsed kml structure with pykml
    """
    from map_interactive import pll
    sat = dict()
    # properly format datestr
    day = datestr.replace('-','')
    for i in range(4):
        name = str(kml.Document.Document[i].name).split(':')[1].lstrip(' ')
        for j in range(1,kml.Document.Document[i].countchildren()-1):
            if str(kml.Document.Document[i].Placemark[j].name).find(day) > 0:
                pos_str = str(kml.Document.Document[i].Placemark[j].LineString.coordinates)
                post_fl = pos_str.split(' ')
                lon,lat = [],[]
                for s in post_fl:
                    try:
                        x,y = s.split(',')
                        lon.append(pll(x))
                        lat.append(pll(y))
                    except:
                        pass
        try:
            sat[name] = (lon,lat)
        except UnboundLocalError:
            print 'Skipping %s; no points downloaded' %name
    return sat
コード例 #4
0
ファイル: map_interactive.py プロジェクト: millercommamatt/fp
def get_sat_tracks(datestr, kml):
    """
    Program that goes and fetches the satellite tracks for the day
    For the day defined with datestr
    kml is the parsed kml structure with pykml
    """
    from map_interactive import pll
    sat = dict()
    # properly format datestr
    day = datestr.replace('-', '')
    for i in range(4):
        name = str(kml.Document.Document[i].name).split(':')[1].lstrip(' ')
        for j in range(1, kml.Document.Document[i].countchildren() - 1):
            if str(kml.Document.Document[i].Placemark[j].name).find(day) > 0:
                pos_str = str(kml.Document.Document[i].Placemark[j].LineString.
                              coordinates)
                post_fl = pos_str.split(' ')
                lon, lat = [], []
                for s in post_fl:
                    try:
                        x, y = s.split(',')
                        lon.append(pll(x))
                        lat.append(pll(y))
                    except:
                        pass
        try:
            sat[name] = (lon, lat)
        except UnboundLocalError:
            print 'Skipping %s; no points downloaded' % name
    return sat
コード例 #5
0
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
コード例 #6
0
ファイル: map_interactive.py プロジェクト: samuelleblanc/fp
def load_map_labels(filename,skip_lines=0):
    """
    Program to load map labels from a text file, csv
    with format: Label, lon, lat, style
    returns list of dictionary with each key as the label
    """
    out = []
    with open(filename,'r') as f:
        for i in range(skip_lines):
            next(f)
        for line in f:
            sp = line.split(',')
            if sp[0].startswith('#'):
                continue
            out.append({'label':sp[0],'lon':mi.pll(sp[1]),'lat':mi.pll(sp[2]),'marker':sp[3].rstrip('\n')})
    return out
コード例 #7
0
def load_map_labels(filename,skip_lines=0):
    """
    Program to load map labels from a text file, csv
    with format: Label, lon, lat, style
    returns list of dictionary with each key as the label
    """
    out = []
    with open(filename,'r') as f:
        for i in range(skip_lines):
            next(f)
        for line in f:
            sp = line.split(',')
            if sp[0].startswith('#'):
                continue
            out.append({'label':sp[0],'lon':mi.pll(sp[1]),'lat':mi.pll(sp[2]),'marker':sp[3].rstrip('\n')})
    return out
コード例 #8
0
def Create_interaction(**kwargs):
    #fig,ax = plt.subplots()
    m = mi.build_basemap()
    plt.gca().set_title('line segments')
    lat0, lon0 = mi.pll('22 58.783S'), mi.pll('14 38.717E')
    x0, y0 = m(lon0, lat0)
    line, = m.plot([x0], [y0], 'ro-')
    text = ('Press s to stop interaction\\n'
            'Press i to restart interaction\\n')
    #plt.text(1.0,0.1,text)
    wb = ex.dict_position(**kwargs)
    lines = mi.LineBuilder(line, m=m, ex=wb)
    print 'after line builder'
    plt.show()
    print 'after show'
    plt.gcf().canvas._tkcanvas.master.geometry("900x1000")
    print 'after canvas'
    g = gui.gui(lines)
    g.make_gui()
    print 'after gui'
    return lines
コード例 #9
0
def Create_interaction(**kwargs):
    #fig,ax = plt.subplots()
    m = mi.build_basemap()
    plt.gca().set_title('line segments')
    lat0,lon0 = mi.pll('22 58.783S'), mi.pll('14 38.717E')
    x0,y0 = m(lon0,lat0)
    line, = m.plot([x0],[y0],'ro-')
    text = ('Press s to stop interaction\\n'
            'Press i to restart interaction\\n')
    #plt.text(1.0,0.1,text)
    wb = ex.dict_position(**kwargs)
    lines = mi.LineBuilder(line,m=m,ex=wb)
    print 'after line builder'
    plt.show()
    print 'after show'
    plt.gcf().canvas._tkcanvas.master.geometry("900x1000")
    print 'after canvas'
    g = gui.gui(lines)
    g.make_gui()
    print 'after gui'
    return lines
コード例 #10
0
ファイル: map_interactive.py プロジェクト: samuelleblanc/fp
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
コード例 #11
0
ファイル: map_interactive.py プロジェクト: millercommamatt/fp
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