Esempio n. 1
0
    def visualize_sequence_on_map(self, sequence: list):
        """
        Visualizes the resulting sequence of cities on a open source map.
        :param sequence: list [int]
        :return:
        """

        self.sequence = sequence

        # Get Marker positions and create map with markers:
        markers = self._create_markers(sequence)
        m = Map(center=markers[0].location, zoom=7, scroll_wheel_zoom=True)
        marker_cluster = MarkerCluster(markers=markers)
        m.add_layer(marker_cluster)

        # Create line between cities:
        line = Polyline(locations=[x.location for x in markers],
                        color="red",
                        fill=False)
        m.add_layer(line)

        m.layout.width = '100vw'
        m.layout.height = '100vh'
        # Save file and show in webbrowser:
        fname = "utils/tmp/map.html"
        realpath = os.path.realpath(fname)
        m.save(fname)
        # webbrowser.open_new_tab(fname)
        webbrowser.open_new_tab("file://" + realpath)

        print(
            "...Opening interactive streetmap in browser. If browser does not show the map correctly, try opening "
            "the saved HTML-file ({n}) manually.".format(n=realpath))
Esempio n. 2
0
    reqPassing = urllib2.Request(
        "http://api.open-notify.org/iss-pass.json?lat=48.634566&lon=8.09760")
    responsePassing = urllib2.urlopen(reqPassing)
    fetchPassing = json.loads(responsePassing.read())
    passTime = int(fetchPassing['request']['datetime'])
    passTimeCounts = fetchPassing['request']['passes']

    for i in range(passTimeCounts):
        riseTime = int(fetchPassing['response'][i]['risetime'])
        print(
            "ISS Overflight " + str(i + 1) + ": " +
            datetime.utcfromtimestamp(passTime).strftime('%Y-%m-%d %H:%M:%S'))
        i = +1

    m = Map(basemap=basemaps.Esri.WorldImagery,
            center=(lat, long),
            zoom=2,
            scroll_wheel_zoom=True)
    m.add_layer(
        Marker(
            location=(lat, long),
            title="ISS",
            icon=Icon(icon_url=
                      "https://img.icons8.com/fluent/48/000000/gps-device.png",
                      icon_size=[20, 20])))
    m.add_control(FullScreenControl())
    m.add_control(ScaleControl(position='bottomleft'))
    m.save('current state.html', title="Space Radar")
    driver.refresh()
    time.sleep(30.0)
Esempio n. 3
0
 def plotmap(self, metric, climatedf, coorddf, filepath, filename='Map'):
     sel_cols = ['Location', 'Year', metric]
     climatedf = climatedf[sel_cols]
     climatedf = climatedf.reindex(columns=climatedf.columns.tolist() +
                                   ['color'])
     color = []
     for (i, j) in climatedf.iterrows():
         value = (j[metric] - climatedf[metric].min()) / (
             climatedf[metric].max() - climatedf[metric].min())
         if (value > 0 and value <= (1 / 6)):
             color.append('darkblue')
         elif (value > (1 / 6) and value <= (2 / 6)):
             color.append('blue')
         elif (value > (2 / 6) and value <= (3 / 6)):
             color.append('green')
         elif (value > (3 / 6) and value <= (4 / 6)):
             color.append('orange')
         elif (value > (4 / 6) and value <= (5 / 6)):
             color.append('red')
         else:
             color.append('darkred')
     climatedf['color'] = color
     gps_color = pd.merge(climatedf, coorddf, on=['Location'])
     gps_color.head()
     newdata = pd.DataFrame([])
     for (index, row) in gps_color.iterrows():
         row['Latitude'] += random.uniform(0.1, 0.9)
         row['Longitude'] += random.uniform(0.1, 0.9)
         newdata = newdata.append(row)
     center = [39.0119, -98.4842]
     zoom = 3
     i = 0
     m = Map(basemap=basemaps.Esri.WorldImagery, center=center, zoom=zoom)
     for (index, row) in newdata.iterrows():
         icon = AwesomeIcon(
             name='tint',
             marker_color=row.loc['color'],  #'#583470'
             icon_color='black',
             spin=False)
         loc = [row.loc['Latitude'], row.loc['Longitude']]
         marker = Marker(location=loc, draggable=False, icon=icon)
         m.add_layer(marker)
         i += 1
     m.add_control(FullScreenControl())
     m.save(filepath + "/" + filename + '.html', title=filename)
     mpl.rcParams.update({'font.size': 10})
     fig = plt.figure(figsize=(8, 3))
     ax = fig.add_subplot(111)
     vals = []
     for i in range(7):
         vals.append(((
             (climatedf[metric].max() - climatedf[metric].min()) / 6) * i) +
                     climatedf[metric].min())
     cmap = mpl.colors.ListedColormap([
         'darkblue', 'deepskyblue', 'limegreen', 'orange', 'red', 'darkred'
     ])
     norm = mpl.colors.BoundaryNorm(vals, cmap.N)
     cb = mpl.colorbar.ColorbarBase(ax,
                                    cmap=cmap,
                                    norm=norm,
                                    spacing='uniform',
                                    orientation='horizontal',
                                    extend='neither',
                                    ticks=vals)
     cb.set_label(metric)
     ax.set_position((0.1, 0.45, 0.8, 0.1))
     plt.savefig(filepath + "/" + 'legend.jpg',
                 dpi=2000,
                 bbox_inches="tight")
     file = codecs.open(filepath + "/" + filename + '.html', "r", "utf-8")
     file_list = file.read().split("\n")
     file.close()
     print(file_list)
     file_list.insert(
         -3, "<img src='legend.jpg' alt='Plot Legend' style='width:35%;'>")
     file = codecs.open(filepath + "/" + filename + '.html', "w", "utf-8")
     file.write("\n".join(file_list))
     file.close()
     return m, fig
Esempio n. 4
0
from itertools import cycle, islice
import numpy as np
import folium

cols_list = [
    '#e6194b', '#3cb44b', '#ffe119', '#4363d8', '#f58231', '#911eb4',
    '#46f0f0', '#f032e6', '#bcf60c', '#fabebe', '#008080', '#e6beff',
    '#9a6324', '#fffac8', '#800000', '#aaffc3', '#808000', '#ffd8b1',
    '#000075', '#808080'
]

colors = np.array(list(islice(cycle(cols_list), int(max(labels) + 1))))
m = Map(center=[data['Lat'].mean(), data['Long'].mean()],
        zoom=5,
        basemap=basemaps.OpenStreetMap.Mapnik)

for _, row in data.iterrows():

    marker = Marker(
        location=[row["Lat"], row['Long']],
        draggable=False,
        title='Lat:{}, Long:{}, Cluster:{}, ClusterSize:{}, Index:{}'.format(
            row["Lat"], row['Long'], labels[row.name], sizes[labels[row.name]],
            row.name),
        #tooltip = labels[row.name],
        #color = colors[labels[row.name]]
    )
    m.add_layer(marker)

m.save('my.html', title='My Map')