<jupyter_start><jupyter_text>Package loading and basic configurations<jupyter_code>%load_ext autoreload
%autoreload 2

# load dependencies'
import pandas as pd
import geopandas as gpd

from envirocar import TrackAPI, DownloadClient, BboxSelector, ECConfig

# create an initial but optional config and an api client
config = ECConfig()
track_api = TrackAPI(api_client=DownloadClient(config=config))<jupyter_output><empty_output><jupyter_text>Querying enviroCar Tracks The following cell queries tracks from the enviroCar API. It defines a bbox for the area of Münster (Germany) and requests 50 tracks. The result is a GeoDataFrame, which is a geo-extended Pandas dataframe from the GeoPandas library. It contains all information of the track in a flat dataframe format including a specific geometry column.  Select data from dataframe* https://geopandas.org/indexing.html* https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html<jupyter_code># set boundary
bbox = BboxSelector([    
    7.5777467, # min_x
    51.9514909, # min_y
    7.6544357, # max_x
    51.9693827  # max_y
])
# issue a query
track_df = track_api.get_tracks(bbox=bbox,num_results=50) # requesting 50 tracks inside the bbox
# retrieve data in a temporal period
track_df20 = track_df.loc[lambda track_df:track_df['time']>'2020-01-01-T00:00:00,:']
track_df20
track_df20.plot(figsize=(8, 10))<jupyter_output><empty_output><jupyter_text>Generating single tracks<jupyter_code># filter out unique track id
track_id = track_df20['track.id'].unique()
tracks = []
# store single tracks
for i in track_id:
    some_track=track_df20[track_df20['track.id']==i]
    tracks.extend([some_track])
tracks[0]<jupyter_output><empty_output><jupyter_text>Generate data for pathlayer<jupyter_code>import random
def color(arr):
    colorlist = []
    n = arr.size
    for i in range(n):
        colorlist.append(tuple([random.randint(0,255),random.randint(0,255),random.randint(0,255)]))
    return colorlist
# generate data for pathlayer
unitrack={'track.id':[],'track.begin':[],'track.end':[],'track.length':[],'sensor.fuelType':[],'sensor.constructionYear':[],'sensor.manufacturer':[],'path':[]}
for i in tracks:
    unitrack['track.id'].extend(i[0:1]['track.id'])
    unitrack['track.begin'].extend(i[0:1]['track.begin'])
    unitrack['track.end'].extend(i[0:1]['track.end'])
    unitrack['track.length'].extend(i[0:1]['track.length'])
    unitrack['sensor.fuelType'].extend(i[0:1]['sensor.fuelType'])
    unitrack['sensor.constructionYear'].extend(i[0:1]['sensor.constructionYear'])
    unitrack['sensor.manufacturer'].extend(i[0:1]['sensor.manufacturer'])
     # convert points in path formate [[x,y]]
    coords = i['geometry'].apply(lambda coord:[coord.x,coord.y])
    path = []   
    for j in coords:
        path.append(j)
    unitrack['path'].append(path)
pathdata = pd.DataFrame(unitrack)
# add color column for visualization
pathdata['color']=pd.Series(color(track_id))
pathdata<jupyter_output><empty_output><jupyter_text>Visualization with pydeck pathlayer* https://github.com/uber/deck.gl/tree/master/bindings/pydeck/examples<jupyter_code>import pydeck as pdk
# set view parameters
view_state = pdk.ViewState(
    longitude=7.5963592529296875,
    latitude=51.96246168188569,
    zoom=10,
    min_zoom=5,
    max_zoom=15,
    pitch=40.5,
    bearing=-27.36)
# use pathlayer
pathlayer = pdk.Layer(
    type="PathLayer",
    data=pathdata,
    pickable=True,
    get_color='color',
    width_scale=10,
    width_min_pixels=2,
    get_path="path",
    get_width=0.5,
)
# add layer, view parameters on map panels
r = pdk.Deck(layers=[pathlayer], initial_view_state=view_state,mapbox_key="<KEY>")
# layout 
r.to_html("path_layer.html", iframe_width=900)<jupyter_output><empty_output><jupyter_text>Summary Statistics<jupyter_code>arr=pathdata['sensor.manufacturer']
arr.unique()
tol=[]
for i in arr.unique():
    ta=sum(arr.str.count(i))
    tol.append(ta)
print('Track number',pathdata['track.id'].size)
print('Survey time',pathdata['track.begin'].min(),'to',pathdata['track.end'].max())
print('Length','\n','min:',pathdata['track.length'].min(),'\n', 'max:',pathdata['track.length'].max(),'\n','mean',pathdata['track.length'].mean())
print('Car number by Manufacturer')
for i in pathdata['sensor.manufacturer'].unique():
    print(' ',i,sum(pathdata['sensor.manufacturer'].str.count(i)))
print('Car number by production year')
for i in pathdata['sensor.constructionYear'].unique():     
    print(' ',i,list(pathdata['sensor.constructionYear']).count(i))
print('Car number by fueltype')
for i in pathdata['sensor.fuelType'].unique():
    print(' ',i,sum(pathdata['sensor.fuelType'].str.count(i)))<jupyter_output>Track number 16
Survey time 2020-01-04T15:24:53Z to 2020-04-06T22:31:45Z
Length 
 min: 1.0502307779995348 
 max: 171.92873411934082 
 mean 45.13037754770366
Car number by Manufacturer
  Dodge 9
  BMW 3
  Volkswagen 2
  Ford 1
  VW 1
Car number by production year
  2007 9
  2012 3
  2018 2
  2019 1
  2000 1
Car number by fueltype
  gasoline 13
  diesel 3
{'fraction_non_alphanumeric': 0.1464867010718539, 'fraction_numerical': 0.05220325526002382, 'mean_word_length': 5.604193971166448, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 26, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '124155', 'license': 'MIT', 'n_tokens_mistral': 1925, 'n_tokens_neox': 1744, 'n_words': 355, 'path': 'examples/Assignment1_duckravel.ipynb', 'repo_name': 'duckravel/envirocar-py', 'size': '5125'}