Skip to content

Commit

Permalink
Merge pull request #90 from ni1o1/0.5.3
Browse files Browse the repository at this point in the history
0.5.3
  • Loading branch information
ni1o1 authored Oct 28, 2023
2 parents e37c5f5 + 01da655 commit 6edcbea
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 13 deletions.
4 changes: 2 additions & 2 deletions docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
author = 'Qing Yu'

# The full version, including alpha/beta/rc tags
release = '0.5.2'
version = '0.5.2'
release = '0.5.3'
version = '0.5.3'
html_logo = "_static/logo-wordmark-light.png"
html_favicon = '_static/logo2.ico'
# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="transbigdata",
version="0.5.2",
version="0.5.3",
author="Qing Yu",
author_email="qingyu0815@foxmail.com",
description="A Python package developed for transportation spatio-temporal big data processing and analysis.",
Expand Down
2 changes: 1 addition & 1 deletion src/transbigdata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
"""

__version__ = '0.5.2'
__version__ = '0.5.3'
__author__ = 'Qing Yu <yuq@sustech.edu.cn>'

# module level doc-string
Expand Down
19 changes: 12 additions & 7 deletions src/transbigdata/crawler.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
wgs84togcj02
)

headers={
'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',
}

def getadmin(keyword, ak, jscode='', subdistricts=False, timeout=20):
'''
Expand Down Expand Up @@ -96,7 +99,7 @@ def getadmin(keyword, ak, jscode='', subdistricts=False, timeout=20):
'sdkversion': '1.4.10'
}
# 发送请求
response = requests.get(url,params = dict1,timeout=timeout)
response = requests.get(url,params = dict1,timeout=timeout,headers = headers)
result = json.loads(response.text)
if result['info'] == 'INVALID_USER_SCODE':
raise ValueError('缺少jscode,请将高德开放平台Key中的安全密钥以jscode参数的形式传入该方法') # pragma: no cover
Expand Down Expand Up @@ -181,7 +184,8 @@ def getbusdata(city, keywords, accurate=True, timeout=20):
def getlineuid(keyword, c, acc=True):
url = 'http://map.baidu.com/?qt=s&wd=' + \
urllib.parse.quote(keyword)+'&c='+c+'&from=webmap'
response = requests.get(url)
response = requests.get(url, timeout=timeout,headers = headers)

searchinfo = json.loads(response.text)
try:
res = pd.DataFrame(searchinfo['content'])
Expand All @@ -197,13 +201,13 @@ def getlineuid(keyword, c, acc=True):

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

def getlinegeo(uid, c):
url = 'http://map.baidu.com/?qt=bsl&uid='+uid+'&c='+c+"&auth=1"
response1 = requests.get(url, timeout=timeout)
response1 = requests.get(url, timeout=timeout,headers = headers)
searchinfo = json.loads(response1.text)
linename = searchinfo['content'][0]['name']
stations = searchinfo['content'][0]['stations']
Expand Down Expand Up @@ -247,8 +251,9 @@ def coodconvert(coo):
if type(keywords) != list:
keywords = [str(keywords)] # pragma: no cover
for keyword in keywords:
print(keyword)
print('Get bus data: '+str(keyword))
for uid in getlineuid(keyword, c, accurate):

if uid not in uids:
try:
linename, coo, stationnames, stationgeo = getlinegeo(
Expand Down Expand Up @@ -334,7 +339,7 @@ def get_isochrone_amap(lon, lat, reachtime, ak, jscode='', mode=2, timeout=20):
'extensions': 'all',
'strategy': str(strategy)
}
response = requests.get(url,params = dict1,timeout=timeout)
response = requests.get(url,params = dict1,timeout=timeout,headers = headers)
result = json.loads(response.text)

P_all = []
Expand Down Expand Up @@ -389,7 +394,7 @@ def get_isochrone_mapbox(lon, lat, reachtime, access_token='auto',
url = 'https://api.mapbox.com/isochrone/v1/mapbox/'+mode+'/' +\
str(lon)+','+str(lat)+'?contours_minutes='+str(reachtime) +\
'&polygons=true&access_token='+access_token
response = requests.get(url,timeout = timeout)
response = requests.get(url,timeout = timeout,headers = headers)
result = json.loads(response.text)
isochrone = gpd.GeoDataFrame.from_features(result)
isochrone['lon'] = lon
Expand Down
2 changes: 1 addition & 1 deletion src/transbigdata/quality.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def data_summary(data, col=['Vehicleid', 'Time'], show_sample_duration=False,
fig = plt.figure(1,(8,3),dpi=300)
ax = plt.subplot(111)
plt.subplots_adjust(left=0.19,right=0.98,top=0.9,bottom=0.19)
sns.kdeplot(sd[sd['duration']<sd['duration'].quantile(0.95)],ax=ax,legend=False)
sns.kdeplot(sd[sd['duration']<sd['duration'].quantile(0.95)]['duration'],ax=ax,legend=False)
from matplotlib import ticker
formatter = ticker.ScalarFormatter(useMathText=True)
formatter.set_scientific(True)
Expand Down
15 changes: 14 additions & 1 deletion src/transbigdata/traj.py
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,7 @@ def traj_sparsify(data, col=['Vehicleid', 'Time', 'Lng', 'Lat'], timegap=15,
[Vehicleid+'_new', 'utctime', 'utctime_new'], axis=1)
return data1


def traj_stay_move(data, params,
col=['ID', 'dataTime', 'longitude', 'latitude'],
activitytime=1800):
Expand Down Expand Up @@ -670,9 +671,12 @@ def traj_stay_move(data, params,
stay['status_id'] = ((stay['LONCOL'] != stay['LONCOL'].shift()) |
(stay['LATCOL'] != stay['LATCOL'].shift()) |
(stay[uid] != stay[uid].shift())).astype(int)
stay.loc[stay[uid] != stay[uid].shift(-1),'status_id'] = 1

stay['status_id'] = stay.groupby([uid])['status_id'].cumsum()
stay = stay.drop_duplicates(
subset=[uid, 'status_id'], keep='first').copy()

stay['etime'] = stay['stime'].shift(-1)
stay = stay[stay[uid] == stay[uid].shift(-1)].copy()
# Remove the duration shorter than given activitytime
Expand All @@ -681,7 +685,7 @@ def traj_stay_move(data, params,
stay = stay[stay['duration'] >= activitytime].copy()
stay = stay[[uid, 'stime', 'LONCOL', 'LATCOL',
'etime', 'lon', 'lat', 'duration']]

# 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.
first_data = data.drop_duplicates(subset=[uid],keep='first').copy()
last_data = data.drop_duplicates(subset=[uid],keep='last').copy()
Expand Down Expand Up @@ -730,6 +734,7 @@ def traj_stay_move(data, params,




def traj_to_linestring(traj_points, col=['Lng', 'Lat', 'ID'], timecol=None):
'''
Input trajectory, generate GeoDataFrame
Expand Down Expand Up @@ -785,3 +790,11 @@ def traj_to_linestring(traj_points, col=['Lng', 'Lat', 'ID'], timecol=None):
traj['geometry'] = geometry
traj = gpd.GeoDataFrame(traj)
return traj

''' old namespace '''

import warnings

def points_to_traj(*args, **kwargs):
warnings.warn("The 'points_to_traj' function is deprecated. Use 'traj_to_linestring' instead.", DeprecationWarning)
return traj_to_linestring(*args, **kwargs)

0 comments on commit 6edcbea

Please sign in to comment.