Esempio n. 1
0
                                      max_records) * 100
MERGED_clean_EDGES['frequency(%)'] = round(MERGED_clean_EDGES['frequency(%)'],
                                           0)

#############################################################################################
# create basemap
ave_LAT = 37.53988692816245
ave_LON = 15.044971594798902
my_map = folium.Map([ave_LAT, ave_LON], zoom_start=14, tiles='cartodbpositron')
###################################################

# add colors to map
my_map = plot_graph_folium_FK(MERGED_clean_EDGES,
                              graph_map=None,
                              popup_attribute=None,
                              zoom=15,
                              fit_bounds=True,
                              edge_width=2,
                              edge_opacity=0.7)
style = {'fillColor': '#00000000', 'color': '#00000000'}
# add 'u' and 'v' as highligths for each edge (in blue)
folium.GeoJson(
    # data to plot
    MERGED_clean_EDGES[
        ['u', 'v', 'frequency(%)', 'records', 'length(km)',
         'geometry']].to_json(),
    show=True,
    style_function=lambda x: style,
    highlight_function=lambda x: {
        'weight': 3,
        'color': 'blue',
    # fields to show
    tooltip=folium.features.GeoJsonTooltip(
        fields=['u', 'v', 'vulnerability']),
    ).add_to(my_map)

path = 'D:/ENEA_CAS_WORK/Catania_RAFAEL/viasat_data/vulnerability_by_days/'
# my_map.save(path + "vulnerability_pesanti_2019_Catania.html")
# my_map.save(path + "vulnerability_FEBRUARY_2019_Catania_all_vehicles.html")
# my_map.save(path + "vulnerability_AUGUST_2019_Catania_all_vehicles.html")


########################################
# make a colored map  ##################
########################################

my_map = plot_graph_folium_FK(vulnerabilty_2019, graph_map=None, popup_attribute=None,
                              zoom=15, fit_bounds=True, edge_width=3, edge_opacity=0.5)
style = {'fillColor': '#00000000', 'color': '#00000000'}
# add 'u' and 'v' as highligths for each edge (in blue)
folium.GeoJson(
    # data to plot
    vulnerabilty_2019[['u','v', 'importance', 'scales', 'vulnerability', 'geometry']].to_json(),
    show=True,
    style_function=lambda x:style,
    highlight_function=lambda x: {'weight':3,
        'color':'blue',
        'fillOpacity':0.6
    },
    # fields to show
    tooltip=folium.features.GeoJsonTooltip(
        fields=['u', 'v', 'vulnerability']
    ),
    ((merged_loads["load (%)"] / max(merged_loads["load (%)"]))), 1)
# # add colors based on 'counts'
vmin = min(merged_loads.scales)
vmax = max(merged_loads.scales)
# # Try to map values to colors in hex
norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True)
mapper = plt.cm.ScalarMappable(
    norm=norm, cmap=plt.cm.YlOrRd
)  # scales of Reds (or "coolwarm" , "bwr", °cool°)  gist_yarg --> grey to black, YlOrRd
merged_loads['color'] = merged_loads['scales'].apply(
    lambda x: mcolors.to_hex(mapper.to_rgba(x)))

my_map = plot_graph_folium_FK(merged_loads,
                              graph_map=None,
                              popup_attribute=None,
                              zoom=15,
                              fit_bounds=True,
                              edge_width=4,
                              edge_opacity=1)

style = {'fillColor': '#00000000', 'color': '#00000000'}

# add 'u' and 'v' as highligths for each edge (in blue)
folium.GeoJson(
    # data to plot
    merged_loads[['u', 'v', 'load (%)', 'geometry']].to_json(),
    show=True,
    style_function=lambda x: style,
    highlight_function=lambda x: {
        'weight': 3,
        'color': 'blue',
Esempio n. 4
0
# add colors based on 'frequency'
vmin = min(all_counts_uv.scales)
vmax = max(all_counts_uv.scales)
# Try to map values to colors in hex
norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True)
mapper = plt.cm.ScalarMappable(
    norm=norm, cmap=plt.cm.YlOrRd
)  # scales of Reds (or "coolwarm" , "bwr", °cool°)  gist_yarg --> grey to black, YlOrRd
all_counts_uv['color'] = all_counts_uv['scales'].apply(
    lambda x: mcolors.to_hex(mapper.to_rgba(x)))

# add colors to map
my_map = plot_graph_folium_FK(all_counts_uv,
                              graph_map=None,
                              popup_attribute=None,
                              zoom=15,
                              fit_bounds=True,
                              edge_width=3.5,
                              edge_opacity=0.5)
style = {'fillColor': '#00000000', 'color': '#00000000'}
# add 'u' and 'v' as highligths for each edge (in blue)
folium.GeoJson(
    # data to plot
    all_counts_uv[['u', 'v', 'scales', 'frequency(%)', 'geometry']].to_json(),
    show=True,
    style_function=lambda x: style,
    highlight_function=lambda x: {
        'weight': 3,
        'color': 'blue',
        'fillOpacity': 0.6
    },
# add colors based on 'congestion_index'
vmin = min(speed_PHF_and_SCARICA.scales)
vmax = max(speed_PHF_and_SCARICA.scales)
# Try to map values to colors in hex
norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True)
mapper = plt.cm.ScalarMappable(norm=norm, cmap=plt.cm.YlOrRd)  # scales of Reds (or "coolwarm" , "bwr", °cool°)  gist_yarg --> grey to black, YlOrRd
speed_PHF_and_SCARICA['color'] = speed_PHF_and_SCARICA['scales'].apply(lambda x: mcolors.to_hex(mapper.to_rgba(x)))

# get only congestion index < 1
# speed_PHF_and_SCARICA = speed_PHF_and_SCARICA[speed_PHF_and_SCARICA.congestion_index < 1]
## normalize "congestion index"
# speed_PHF_and_SCARICA["congestion"] = round(speed_PHF_and_SCARICA["congestion_index"]/max(speed_PHF_and_SCARICA["congestion_index"]),2)


# add colors to map
my_map = plot_graph_folium_FK(speed_PHF_and_SCARICA, graph_map=None, popup_attribute=None,
                              zoom=15, fit_bounds=True, edge_width=4, edge_opacity=0.5)
style = {'fillColor': '#00000000', 'color': '#00000000'}
# add 'u' and 'v' as highligths for each edge (in blue)
folium.GeoJson(
    # data to plot
    speed_PHF_and_SCARICA[['u','v', 'scales', 'congestion', 'length', 'geometry']].to_json(),
    show=True,
    style_function=lambda x:style,
    highlight_function=lambda x: {'weight':3,
        'color':'blue',
        'fillOpacity':0.6
    },
    # fields to show
    tooltip=folium.features.GeoJsonTooltip(
        fields=['u', 'v', 'congestion', 'length']
    ),
Esempio n. 6
0
# add colors based on 'congestion_index'
vmin = min(LPIR_RESILIENT.scales)
vmax = max(LPIR_RESILIENT.scales)
# Try to map values to colors in hex
norm = matplotlib.colors.Normalize(vmin=vmin, vmax=vmax, clip=True)
mapper = plt.cm.ScalarMappable(
    norm=norm, cmap=plt.cm.YlGnBu
)  # scales of Reds (or "coolwarm" , "bwr", °cool°)  gist_yarg --> grey to black, YlOrRd
LPIR_RESILIENT['color'] = LPIR_RESILIENT['scales'].apply(
    lambda x: mcolors.to_hex(mapper.to_rgba(x)))

# add colors to map
my_map = plot_graph_folium_FK(LPIR_RESILIENT,
                              graph_map=None,
                              popup_attribute=None,
                              zoom=15,
                              fit_bounds=True,
                              edge_width=3.5,
                              edge_opacity=0.5)
style = {'fillColor': '#00000000', 'color': '#00000000'}
# add 'u' and 'v' as highligths for each edge (in blue)
folium.GeoJson(
    # data to plot
    LPIR_RESILIENT[['u', 'v', 'scales', 'resilience', 'length',
                    'geometry']].to_json(),
    show=True,
    style_function=lambda x: style,
    highlight_function=lambda x: {
        'weight': 3,
        'color': 'blue',
        'fillOpacity': 0.6
# create basemap
ave_LAT = 37.53988692816245
ave_LON = 15.044971594798902
my_map = folium.Map([ave_LAT, ave_LON], zoom_start=11, tiles='cartodbpositron')
#############################################################################################
'''
clean_edges_matched_route.geometry.to_file(filename='clean_matched_route.geojson', driver='GeoJSON')
folium.GeoJson('clean_matched_route.geojson').add_to(my_map)
my_map.save("clean_matched_route.html")
'''

# add colors to map
my_map = plot_graph_folium_FK(MERGED_clean_EDGES,
                              graph_map=None,
                              popup_attribute=None,
                              zoom=1,
                              fit_bounds=True,
                              edge_width=4,
                              edge_opacity=1)  # tiles='cartodbpositron'
my_map.save("clean_matched_route.html")

######################################################################
######################## COLORBAR ####################################
######################################################################

import matplotlib as mpl
COLORS_by_records = pd.DataFrame(
    MERGED_clean_EDGES.drop_duplicates(['records',
                                        'color']))[['records', 'color']]
# sort by ascending order of the column records
COLORS_by_records = COLORS_by_records.sort_values(by=['records'])
Esempio n. 8
0
mapper = plt.cm.ScalarMappable(norm=norm, cmap=plt.cm.YlOrRd)  # scales of Reds (or "coolwarm" , "bwr", °cool°)
TIME_EDGES['color'] = TIME_EDGES['importance'].apply(lambda x: mcolors.to_hex(mapper.to_rgba(x)))

# save again...
TIME_EDGES.to_file(filename='TIME_EDGES_importance.geojson', driver='GeoJSON')


#############################################################################################
# create basemap
ave_LAT = 37.53988692816245
ave_LON = 15.044971594798902
my_map = folium.Map([ave_LAT, ave_LON], zoom_start=11, tiles='cartodbpositron')
#############################################################################################

# add colors to map
my_map = plot_graph_folium_FK(TIME_EDGES, graph_map=None, popup_attribute=None,
                              zoom=1, fit_bounds=True, edge_width=2, edge_opacity=1)
style = {'fillColor': '#00000000', 'color': '#00000000'}
# add 'u' and 'v' as highligths for each edge (in blue)
folium.GeoJson(
    # data to plot
    TIME_EDGES[['u', 'v', 'importance', 'geometry']].to_json(),
    show=True,
    style_function=lambda x:style,
    highlight_function=lambda x: {'weight':3,
        'color':'blue',
        'fillOpacity':1
    },
    # fields to show
    tooltip=folium.features.GeoJsonTooltip(
        fields=['u', 'v', 'importance']
    ),