Skip to content

Commit deffdef

Browse files
authored
Merge pull request #164 from InsightLab/developer
Bump version: 2.5.2 → 2.6.0
2 parents ce2a153 + 7135041 commit deffdef

File tree

11 files changed

+268
-377
lines changed

11 files changed

+268
-377
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.5.2
2+
current_version = 2.6.0
33
allow_dirty = True
44
tag_name = version-{new_version}
55
tag = True

pymove/_version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '2.5.2'
1+
__version__ = '2.6.0'

pymove/core/pandas.py

Lines changed: 0 additions & 219 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
)
1313

1414
import numpy as np
15-
from matplotlib import pyplot as plt
16-
from matplotlib.pyplot import figure
1715
from pandas import DataFrame, DateOffset, Series, Timedelta
1816

1917
from pymove.core.dataframe import MoveDataFrame
@@ -1384,223 +1382,6 @@ def get_bbox(self) -> Tuple[float, float, float, float]:
13841382

13851383
return bbox_
13861384

1387-
def plot_all_features(
1388-
self,
1389-
dtype: Optional[Callable] = np.float64,
1390-
figsize: Optional[Tuple[float, float]] = (21, 15),
1391-
return_fig: Optional[bool] = True,
1392-
save_fig: Optional[bool] = False,
1393-
name: Optional[Text] = 'features.png',
1394-
) -> Optional[figure]:
1395-
"""
1396-
Generate a visualization for each columns that type is equal dtype.
1397-
1398-
Parameters
1399-
----------
1400-
dtype : callable, optional
1401-
Represents column type, by default np.float64
1402-
figsize : tuple(float, float), optional
1403-
Represents dimensions of figure, by default (21, 15)
1404-
return_fig : bool, optional
1405-
Represents whether or not to return the generated picture, by default True
1406-
save_fig : bool, optional
1407-
Represents whether or not to save the generated picture, by default False
1408-
name : str, optional
1409-
Represents name of a file, by default 'features.png'
1410-
1411-
Returns
1412-
-------
1413-
figure
1414-
The generated picture or None
1415-
1416-
Raises
1417-
------
1418-
AttributeError
1419-
If there are no columns with the specified type
1420-
1421-
"""
1422-
1423-
operation = begin_operation('plot_all_features')
1424-
1425-
try:
1426-
col_dtype = self.select_dtypes(include=[dtype]).columns
1427-
tam = col_dtype.size
1428-
if not tam:
1429-
raise AttributeError('No columns with dtype %s.' % dtype)
1430-
1431-
fig, ax = plt.subplots(tam, 1, figsize=figsize)
1432-
ax_count = 0
1433-
for col in col_dtype:
1434-
ax[ax_count].set_title(col)
1435-
self[col].plot(subplots=True, ax=ax[ax_count])
1436-
ax_count += 1
1437-
1438-
if save_fig:
1439-
plt.savefig(fname=name, fig=fig)
1440-
1441-
self.last_operation = end_operation(operation)
1442-
1443-
if return_fig:
1444-
return fig
1445-
except Exception as e:
1446-
self.last_operation = end_operation(operation)
1447-
raise e
1448-
1449-
def plot_trajs(
1450-
self,
1451-
markers: Optional[Text] = 'o',
1452-
markersize: Optional[float] = 12,
1453-
figsize: Optional[Tuple[float, float]] = (10, 10),
1454-
return_fig: Optional[bool] = True,
1455-
save_fig: Optional[bool] = False,
1456-
name: Optional[Text] = 'trajectories.png',
1457-
) -> Optional[figure]:
1458-
"""
1459-
Generate a visualization that show trajectories.
1460-
1461-
Parameters
1462-
----------
1463-
markers : str, optional
1464-
Represents visualization type marker, by default 'o'
1465-
markersize : float, optional
1466-
Represents visualization size marker, by default 12
1467-
figsize : tuple(float, float), optional
1468-
Represents dimensions of figure, by default (10, 10)
1469-
return_fig : bool, optional
1470-
Represents whether or not to return the generated picture, by default True
1471-
save_fig : bool, optional
1472-
Represents whether or not to save the generated picture, by default False
1473-
name : str, optional
1474-
Represents name of a file, by default 'trajectories.png'
1475-
1476-
Returns
1477-
-------
1478-
figure
1479-
The generated picture or None
1480-
"""
1481-
1482-
operation = begin_operation('plot_trajs')
1483-
1484-
fig = plt.figure(figsize=figsize)
1485-
1486-
ids = self['id'].unique()
1487-
for id_ in ids:
1488-
self_id = self[self['id'] == id_]
1489-
plt.plot(
1490-
self_id[LONGITUDE],
1491-
self_id[LATITUDE],
1492-
markers,
1493-
markersize=markersize,
1494-
)
1495-
1496-
if save_fig:
1497-
plt.savefig(fname=name, fig=fig)
1498-
1499-
self.last_operation = end_operation(operation)
1500-
1501-
if return_fig:
1502-
return fig
1503-
1504-
def plot_traj_id(
1505-
self,
1506-
tid: Union[int, Text],
1507-
label: Optional[Text] = TID,
1508-
feature: Optional[Text] = None,
1509-
value: Optional[Any] = None,
1510-
markersize: Optional[float] = 20,
1511-
figsize: Optional[Tuple[float, float]] = (10, 10),
1512-
return_fig: Optional[bool] = True,
1513-
save_fig: Optional[bool] = False,
1514-
name: Optional[Text] = None,
1515-
) -> Optional[figure]:
1516-
"""
1517-
Generate a visualization that shows a trajectory with the specified tid.
1518-
1519-
Parameters
1520-
----------
1521-
tid : int, str
1522-
Represents the trajectory tid
1523-
label : str, optional
1524-
Feature with trajectories tids, by default TID
1525-
feature : str, optional
1526-
Name of the feature to highlight on plot, by default None
1527-
value : any, optional
1528-
Value of the feature to be highlighted as green marker, by default None
1529-
markersize : float, optional
1530-
Represents visualization size marker, by default 20
1531-
figsize : tuple(float, float), optional
1532-
Represents dimensions of figure, by default (10, 10)
1533-
return_fig : bool, optional
1534-
Represents whether or not to return the generated picture, by default True
1535-
save_fig : bool, optional
1536-
Represents whether or not to save the generated picture, by default False
1537-
name : str, optional
1538-
Represents name of a file, by default None
1539-
1540-
Returns
1541-
-------
1542-
PandasMoveDataFrame', figure
1543-
Trajectory with the specified tid.
1544-
The generated picture.
1545-
1546-
Raises
1547-
------
1548-
KeyError
1549-
If the dataframe does not contains the TID feature
1550-
IndexError
1551-
If there is no trajectory with the tid passed
1552-
1553-
"""
1554-
1555-
operation = begin_operation('plot_traj_id')
1556-
1557-
if label not in self:
1558-
self.last_operation = end_operation(operation)
1559-
raise KeyError('%s feature not in dataframe' % label)
1560-
1561-
df_ = self[self[label] == tid]
1562-
1563-
if not len(df_):
1564-
self.last_operation = end_operation(operation)
1565-
raise IndexError(f'No trajectory with tid {tid} in dataframe')
1566-
1567-
fig = plt.figure(figsize=figsize)
1568-
1569-
plt.plot(
1570-
df_.iloc[0][LONGITUDE], df_.iloc[0][LATITUDE], 'yo', markersize=markersize
1571-
) # start point
1572-
plt.plot(
1573-
df_.iloc[-1][LONGITUDE], df_.iloc[-1][LATITUDE], 'yX', markersize=markersize
1574-
) # end point
1575-
1576-
if (not feature) or (not value) or (feature not in df_):
1577-
plt.plot(df_[LONGITUDE], df_[LATITUDE])
1578-
plt.plot(
1579-
df_.loc[:, LONGITUDE], df_.loc[:, LATITUDE],
1580-
'r.', markersize=markersize / 2
1581-
)
1582-
else:
1583-
filter_ = df_[feature] == value
1584-
df_nodes = df_.loc[filter_]
1585-
df_points = df_.loc[~filter_]
1586-
plt.plot(df_[LONGITUDE], df_[LATITUDE], linewidth=3)
1587-
plt.plot(
1588-
df_nodes[LONGITUDE], df_nodes[LATITUDE], 'gs', markersize=markersize / 2
1589-
)
1590-
plt.plot(
1591-
df_points[LONGITUDE], df_points[LATITUDE], 'r.', markersize=markersize / 2
1592-
)
1593-
1594-
if save_fig:
1595-
if not name:
1596-
name = 'trajectory_%s.png' % tid
1597-
plt.savefig(fname=name, fig=fig)
1598-
1599-
self.last_operation = end_operation(operation)
1600-
1601-
if return_fig:
1602-
return fig
1603-
16041385
def show_trajectories_info(self):
16051386
"""
16061387
Show dataset information from dataframe, this is number of rows,

pymove/tests/baseline/features.png

12.6 KB
Loading

pymove/tests/baseline/traj_id.png

22.2 KB
Loading
1.45 KB
Loading

pymove/tests/test_core_pandas.py

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from datetime import date
33

44
from dask.dataframe import DataFrame as DaskDataFrame
5-
from matplotlib.testing.compare import compare_images
65
from numpy import nan, ndarray
76
from numpy.testing import assert_allclose, assert_array_equal
87
from pandas import DataFrame, Series, Timedelta, Timestamp
@@ -1163,30 +1162,6 @@ def test_get_bbox():
11631162
)
11641163

11651164

1166-
def test_plot_traj_id(tmpdir):
1167-
move_df = _default_move_df()
1168-
move_df[TID] = ['1', '2', '3', '4']
1169-
1170-
d = tmpdir.mkdir('core')
1171-
1172-
file_write_default = d.join('traj_id.png')
1173-
filename_write_default = os.path.join(
1174-
file_write_default.dirname, file_write_default.basename
1175-
)
1176-
1177-
move_df.plot_traj_id('1', save_fig=True, name=filename_write_default)
1178-
1179-
test_dir = os.path.abspath(os.path.dirname(__file__))
1180-
data_dir = os.path.join(test_dir, 'baseline/traj_id.png')
1181-
1182-
compare_images(
1183-
data_dir,
1184-
filename_write_default,
1185-
0.0001,
1186-
in_decorator=False
1187-
)
1188-
1189-
11901165
def test_min():
11911166
move_df = _default_move_df()
11921167

@@ -1792,8 +1767,6 @@ def test_rename():
17921767

17931768
assert isinstance(new_move_df, PandasMoveDataFrame)
17941769

1795-
new_move = move_df.rename({0: 'a', 1: 'b'}, axis='index', inplace=False)
1796-
17971770
assert_frame_equal(new_move_df, expected_index)
17981771

17991772
assert isinstance(new_move_df, PandasMoveDataFrame)
@@ -1833,58 +1806,3 @@ def test_rename():
18331806
)
18341807
except AttributeError:
18351808
pass
1836-
1837-
1838-
def test_plot_all_features(tmpdir):
1839-
1840-
move_df = _default_move_df()
1841-
1842-
d = tmpdir.mkdir('core')
1843-
1844-
file_write_default = d.join('features.png')
1845-
filename_write_default = os.path.join(
1846-
file_write_default.dirname, file_write_default.basename
1847-
)
1848-
1849-
move_df.plot_all_features(save_fig=True, name=filename_write_default)
1850-
1851-
test_dir = os.path.abspath(os.path.dirname(__file__))
1852-
data_dir = os.path.join(test_dir, 'baseline/features.png')
1853-
1854-
compare_images(data_dir,
1855-
filename_write_default,
1856-
0.0001,
1857-
in_decorator=False)
1858-
1859-
move_df['lat'] = move_df['lat'].astype('float32')
1860-
move_df['lon'] = move_df['lon'].astype('float32')
1861-
1862-
try:
1863-
move_df.plot_all_features(name=filename_write_default)
1864-
raise AssertionError(
1865-
'AttributeError error not raised by MoveDataFrame'
1866-
)
1867-
except AttributeError:
1868-
pass
1869-
1870-
1871-
def test_plot_trajs(tmpdir):
1872-
1873-
move_df = _default_move_df()
1874-
1875-
d = tmpdir.mkdir('core')
1876-
1877-
file_write_default = d.join('trajectories.png')
1878-
filename_write_default = os.path.join(
1879-
file_write_default.dirname, file_write_default.basename
1880-
)
1881-
1882-
move_df.plot_trajs(save_fig=True, name=filename_write_default)
1883-
1884-
test_dir = os.path.abspath(os.path.dirname(__file__))
1885-
data_dir = os.path.join(test_dir, 'baseline/trajectories.png')
1886-
1887-
compare_images(data_dir,
1888-
filename_write_default,
1889-
0.0001,
1890-
in_decorator=False)

0 commit comments

Comments
 (0)