Skip to content

Commit 6edcbea

Browse files
authored
Merge pull request #90 from ni1o1/0.5.3
0.5.3
2 parents e37c5f5 + 01da655 commit 6edcbea

File tree

6 files changed

+31
-13
lines changed

6 files changed

+31
-13
lines changed

docs/source/conf.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
author = 'Qing Yu'
2727

2828
# The full version, including alpha/beta/rc tags
29-
release = '0.5.2'
30-
version = '0.5.2'
29+
release = '0.5.3'
30+
version = '0.5.3'
3131
html_logo = "_static/logo-wordmark-light.png"
3232
html_favicon = '_static/logo2.ico'
3333
# -- General configuration ---------------------------------------------------

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="transbigdata",
8-
version="0.5.2",
8+
version="0.5.3",
99
author="Qing Yu",
1010
author_email="[email protected]",
1111
description="A Python package developed for transportation spatio-temporal big data processing and analysis.",

src/transbigdata/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3434
"""
3535

36-
__version__ = '0.5.2'
36+
__version__ = '0.5.3'
3737
__author__ = 'Qing Yu <[email protected]>'
3838

3939
# module level doc-string

src/transbigdata/crawler.py

+12-7
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
wgs84togcj02
4949
)
5050

51+
headers={
52+
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36',
53+
}
5154

5255
def getadmin(keyword, ak, jscode='', subdistricts=False, timeout=20):
5356
'''
@@ -96,7 +99,7 @@ def getadmin(keyword, ak, jscode='', subdistricts=False, timeout=20):
9699
'sdkversion': '1.4.10'
97100
}
98101
# 发送请求
99-
response = requests.get(url,params = dict1,timeout=timeout)
102+
response = requests.get(url,params = dict1,timeout=timeout,headers = headers)
100103
result = json.loads(response.text)
101104
if result['info'] == 'INVALID_USER_SCODE':
102105
raise ValueError('缺少jscode,请将高德开放平台Key中的安全密钥以jscode参数的形式传入该方法') # pragma: no cover
@@ -181,7 +184,8 @@ def getbusdata(city, keywords, accurate=True, timeout=20):
181184
def getlineuid(keyword, c, acc=True):
182185
url = 'http://map.baidu.com/?qt=s&wd=' + \
183186
urllib.parse.quote(keyword)+'&c='+c+'&from=webmap'
184-
response = requests.get(url)
187+
response = requests.get(url, timeout=timeout,headers = headers)
188+
185189
searchinfo = json.loads(response.text)
186190
try:
187191
res = pd.DataFrame(searchinfo['content'])
@@ -197,13 +201,13 @@ def getlineuid(keyword, c, acc=True):
197201

198202
def getcitycode(c):
199203
url = 'http://map.baidu.com/?qt=s&wd='+urllib.parse.quote(c)
200-
response1 = requests.get(url, timeout=timeout)
204+
response1 = requests.get(url, timeout=timeout,headers = headers)
201205
searchinfo = json.loads(response1.text)
202206
return str(searchinfo['content']['code'])
203207

204208
def getlinegeo(uid, c):
205209
url = 'http://map.baidu.com/?qt=bsl&uid='+uid+'&c='+c+"&auth=1"
206-
response1 = requests.get(url, timeout=timeout)
210+
response1 = requests.get(url, timeout=timeout,headers = headers)
207211
searchinfo = json.loads(response1.text)
208212
linename = searchinfo['content'][0]['name']
209213
stations = searchinfo['content'][0]['stations']
@@ -247,8 +251,9 @@ def coodconvert(coo):
247251
if type(keywords) != list:
248252
keywords = [str(keywords)] # pragma: no cover
249253
for keyword in keywords:
250-
print(keyword)
254+
print('Get bus data: '+str(keyword))
251255
for uid in getlineuid(keyword, c, accurate):
256+
252257
if uid not in uids:
253258
try:
254259
linename, coo, stationnames, stationgeo = getlinegeo(
@@ -334,7 +339,7 @@ def get_isochrone_amap(lon, lat, reachtime, ak, jscode='', mode=2, timeout=20):
334339
'extensions': 'all',
335340
'strategy': str(strategy)
336341
}
337-
response = requests.get(url,params = dict1,timeout=timeout)
342+
response = requests.get(url,params = dict1,timeout=timeout,headers = headers)
338343
result = json.loads(response.text)
339344

340345
P_all = []
@@ -389,7 +394,7 @@ def get_isochrone_mapbox(lon, lat, reachtime, access_token='auto',
389394
url = 'https://api.mapbox.com/isochrone/v1/mapbox/'+mode+'/' +\
390395
str(lon)+','+str(lat)+'?contours_minutes='+str(reachtime) +\
391396
'&polygons=true&access_token='+access_token
392-
response = requests.get(url,timeout = timeout)
397+
response = requests.get(url,timeout = timeout,headers = headers)
393398
result = json.loads(response.text)
394399
isochrone = gpd.GeoDataFrame.from_features(result)
395400
isochrone['lon'] = lon

src/transbigdata/quality.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ def data_summary(data, col=['Vehicleid', 'Time'], show_sample_duration=False,
116116
fig = plt.figure(1,(8,3),dpi=300)
117117
ax = plt.subplot(111)
118118
plt.subplots_adjust(left=0.19,right=0.98,top=0.9,bottom=0.19)
119-
sns.kdeplot(sd[sd['duration']<sd['duration'].quantile(0.95)],ax=ax,legend=False)
119+
sns.kdeplot(sd[sd['duration']<sd['duration'].quantile(0.95)]['duration'],ax=ax,legend=False)
120120
from matplotlib import ticker
121121
formatter = ticker.ScalarFormatter(useMathText=True)
122122
formatter.set_scientific(True)

src/transbigdata/traj.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,7 @@ def traj_sparsify(data, col=['Vehicleid', 'Time', 'Lng', 'Lat'], timegap=15,
633633
[Vehicleid+'_new', 'utctime', 'utctime_new'], axis=1)
634634
return data1
635635

636+
636637
def traj_stay_move(data, params,
637638
col=['ID', 'dataTime', 'longitude', 'latitude'],
638639
activitytime=1800):
@@ -670,9 +671,12 @@ def traj_stay_move(data, params,
670671
stay['status_id'] = ((stay['LONCOL'] != stay['LONCOL'].shift()) |
671672
(stay['LATCOL'] != stay['LATCOL'].shift()) |
672673
(stay[uid] != stay[uid].shift())).astype(int)
674+
stay.loc[stay[uid] != stay[uid].shift(-1),'status_id'] = 1
675+
673676
stay['status_id'] = stay.groupby([uid])['status_id'].cumsum()
674677
stay = stay.drop_duplicates(
675678
subset=[uid, 'status_id'], keep='first').copy()
679+
676680
stay['etime'] = stay['stime'].shift(-1)
677681
stay = stay[stay[uid] == stay[uid].shift(-1)].copy()
678682
# Remove the duration shorter than given activitytime
@@ -681,7 +685,7 @@ def traj_stay_move(data, params,
681685
stay = stay[stay['duration'] >= activitytime].copy()
682686
stay = stay[[uid, 'stime', 'LONCOL', 'LATCOL',
683687
'etime', 'lon', 'lat', 'duration']]
684-
688+
685689
# Add the first and last two data points for each ID in the Stay dataset before conducting move detection, so that the movement patterns of individuals at the beginning and end of the study period can also be identified.
686690
first_data = data.drop_duplicates(subset=[uid],keep='first').copy()
687691
last_data = data.drop_duplicates(subset=[uid],keep='last').copy()
@@ -730,6 +734,7 @@ def traj_stay_move(data, params,
730734

731735

732736

737+
733738
def traj_to_linestring(traj_points, col=['Lng', 'Lat', 'ID'], timecol=None):
734739
'''
735740
Input trajectory, generate GeoDataFrame
@@ -785,3 +790,11 @@ def traj_to_linestring(traj_points, col=['Lng', 'Lat', 'ID'], timecol=None):
785790
traj['geometry'] = geometry
786791
traj = gpd.GeoDataFrame(traj)
787792
return traj
793+
794+
''' old namespace '''
795+
796+
import warnings
797+
798+
def points_to_traj(*args, **kwargs):
799+
warnings.warn("The 'points_to_traj' function is deprecated. Use 'traj_to_linestring' instead.", DeprecationWarning)
800+
return traj_to_linestring(*args, **kwargs)

0 commit comments

Comments
 (0)