Skip to content

Commit

Permalink
Merge pull request #35 from traja-team/remove-rpy2
Browse files Browse the repository at this point in the history
Remove rpy2, fix actogram plotting and test
  • Loading branch information
WolfByttner authored Jan 4, 2021
2 parents 574d5f1 + ff641f6 commit 506b806
Show file tree
Hide file tree
Showing 9 changed files with 17 additions and 243 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ cache: pip

before_install:
- sudo apt-get update
- sudo mkdir -p /usr/local/lib/R/site-library
- echo 'R_LIBS=/usr/local/lib/R/library:/usr/local/lib/R/site-library/' > ~/.Renviron
- sudo chmod 2777 /usr/local/lib/R/site-library

install:
- wget https://repo.continuum.io/miniconda/Miniconda3-latest-Linux-x86_64.sh
Expand Down
3 changes: 3 additions & 0 deletions docs/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ networkx
seaborn
torch
pytest
pytest-cov
codecov
readline
h5py
ipython
1 change: 0 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@
"doc_module": ("traja",),
"reference_url": {
"numpy": "http://docs.scipy.org/doc/numpy",
"scipy": "http://docs.scipy.org/doc/scipy/reference",
"geopandas": "https://geopandas.readthedocs.io/en/latest/",
},
"sphinx_gallery": None,
Expand Down
65 changes: 0 additions & 65 deletions docs/source/rinterface.rst

This file was deleted.

3 changes: 0 additions & 3 deletions environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: traja
channels:
- conda-forge
- pytorch
- r
dependencies:
- ipython
- pytorch-cpu
Expand All @@ -17,5 +16,3 @@ dependencies:
- scipy
- sphinx
- pillow
- r-essentials
- r-base
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def find_version(*file_paths):

requirements = ["matplotlib", "pandas", "numpy", "shapely", "scipy", "tzlocal"]

extras_requirements = {"all": ["torch", "rpy2", "tzlocal", "fastdtw"]}
extras_requirements = {"all": ["torch", "tzlocal", "fastdtw"]}

this_dir = os.path.abspath(os.path.dirname(__file__))
with open(os.path.join(this_dir, "README.rst"), encoding="utf-8") as f:
Expand Down
14 changes: 11 additions & 3 deletions traja/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -890,22 +890,29 @@ def _process_after_plot_args(**after_plot_args):


def color_dark(
series: pd.Series, ax: matplotlib.axes.Axes, start: int = 19, end: int = 7
series: pd.Series, ax: matplotlib.axes.Axes = None, start: int = 19, end: int = 7
):
"""Color dark phase in plot."""
assert is_datetime_or_timedelta_dtype(
series.index
), f"Series must have datetime index but has {type(series.index)}"

if not ax:
ax = plt.gca()

# get boundaries for dark times
dark_mask = (series.index.hour >= start) | (series.index.hour < end)
run_values, run_starts, run_lengths = find_runs(dark_mask)

# highlighting
for idx, is_dark in enumerate(run_values):
if is_dark:
start = run_starts[idx]
end = run_starts[idx] + run_lengths[idx] - 1
ax.axvspan(series.index[start], series.index[end], alpha=0.5, color="gray")

return ax


def find_runs(x: pd.Series) -> (np.ndarray, np.ndarray, np.ndarray):
"""Find runs of consecutive items in an array.
Expand All @@ -920,7 +927,6 @@ def find_runs(x: pd.Series) -> (np.ndarray, np.ndarray, np.ndarray):
# handle empty array
if n == 0:
return np.array([]), np.array([]), np.array([])

else:
# find run starts
loc_run_start = np.empty(n, dtype=bool)
Expand Down Expand Up @@ -984,10 +990,12 @@ def plot_actogram(
Curr Protoc Mouse Biol. 2015;5(3):271-281. Published 2015 Sep 1. doi:10.1002/9780470942390.mo140229
"""
after_plot_args, _ = _get_after_plot_args(**kwargs)
assert isinstance(series, pd.Series)
assert is_datetime_or_timedelta_dtype(
series.index
), f"Series must have datetime index but has {type(series.index)}"

after_plot_args, _ = _get_after_plot_args(**kwargs)

ax = series.plot(ax=ax)
ax.set_ylabel(series.name)
Expand Down
156 changes: 0 additions & 156 deletions traja/rutils.py

This file was deleted.

13 changes: 2 additions & 11 deletions traja/tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,6 @@ def test_stylize_axes():
traja.plotting.stylize_axes(collection.axes)


def test_color_dark():
df = traja.generate(n=10)
index = pd.DatetimeIndex(range(10))
df.index = index
traja.plot(df, interactive=False)
ax = plt.gca()
traja.color_dark(df.x, ax)


def test_sans_serif():
traja.plotting.sans_serif()

Expand Down Expand Up @@ -64,8 +55,8 @@ def test_label_axes():


def test_plot_actogram():
df = traja.generate(n=10)
index = pd.DatetimeIndex(range(10))
df = traja.generate(n=1000)
index = pd.date_range("2018-01-01", periods=1000, freq="T")
df.index = index
activity = traja.calc_displacement(df)
activity.name = "activity"
Expand Down

0 comments on commit 506b806

Please sign in to comment.