Skip to content

Commit

Permalink
Dropped support for Python 3.7 and incorporated latest rpy2 changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Sebastian Luque committed Oct 21, 2022
1 parent c72765c commit dbec0ea
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 25 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/builds.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.7, 3.8, 3.9]
python-version: ["3.8", "3.9", "3.10"]
env:
PY_LATEST: 3.9
PY_LATEST: "3.10"

steps:
- name: Checkout
Expand Down Expand Up @@ -100,7 +100,7 @@ jobs:
name: dist-pkg

- name: Publish GitHub Pages
uses: JamesIves/github-pages-deploy-action@v4.3.0
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages
folder: docs/build/html
2 changes: 1 addition & 1 deletion .github/workflows/testpypi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
name: Build and publish to TestPyPI
runs-on: ubuntu-latest
env:
PY_LATEST: 3.9
PY_LATEST: "3.10"

steps:
- uses: actions/checkout@v3
Expand Down
Binary file modified docs/source/.static/video/gert_body_20170810T120654.mp4
Binary file not shown.
Binary file modified docs/source/.static/video/gert_imu_20170810T120654.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ def get_requirements():
setup(
name="scikit-diveMove",
version=__version__,
python_requires=">=3.7",
python_requires=">=3.8",
packages=PACKAGES,
include_package_data=True,
# Below is redundant but safe
Expand Down
4 changes: 1 addition & 3 deletions skdiveMove/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,6 @@ def _one_dive_stats(x, interval, has_speed=False):
"""
xx = x.iloc[:, 1:]
rstr = "one_dive_stats_fun <- diveMove::oneDiveStats"
one_dive_stats_fun = robjs.r(rstr)
onames_speed = ["begdesc", "enddesc", "begasc", "desctim", "botttim",
"asctim", "divetim", "descdist", "bottdist", "ascdist",
"bottdep_mean", "bottdep_median", "bottdep_sd",
Expand All @@ -173,7 +171,7 @@ def _one_dive_stats(x, interval, has_speed=False):

with cv.localconverter(robjs.default_converter +
pandas2ri.converter):
res = one_dive_stats_fun(xx, interval, has_speed)
res = diveMove.oneDiveStats(xx, interval, has_speed)

if has_speed:
onames = onames_speed
Expand Down
24 changes: 13 additions & 11 deletions skdiveMove/imutools/imu.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .vector import rotate_vector

_TIME_NAME = "timestamp"
_DEPTH_NAMES = ["depth", ]
_DEPTH_NAME = "depth"
_ACCEL_NAME = "acceleration"
_OMEGA_NAME = "angular_velocity"
_MAGNT_NAME = "magnetic_density"
Expand Down Expand Up @@ -83,7 +83,8 @@ def __init__(self, dataset,
angular_velocity_name=_OMEGA_NAME,
magnetic_density_name=_MAGNT_NAME,
time_name=_TIME_NAME,
has_depth=False, imu_filename=None):
has_depth=False, depth_name=_DEPTH_NAME,
imu_filename=None):
"""Set up attributes for IMU objects
Parameters
Expand All @@ -100,8 +101,9 @@ def __init__(self, dataset,
time_name : str, optional
Name of the time dimension in the dataset.
has_depth : bool, optional
Whether input data include depth measurements. Variable must
be named "depth".
Whether input data include depth measurements.
depth_name : str, optional
Name of the depth ``DataArray`` in the ``Dataset``.
imu_filename : str, optional
Name of the file from which ``dataset`` originated.
Expand All @@ -111,11 +113,9 @@ def __init__(self, dataset,
self.imu_var_names = [acceleration_name,
angular_velocity_name,
magnetic_density_name]
depth_var = [x for x in list(self.imu.data_vars.keys())
if has_depth and x in _DEPTH_NAMES]
if (len(depth_var) > 0) and has_depth:
if has_depth:
self.has_depth = True
self.depth_name = depth_var[0]
self.depth_name = depth_name
else:
self.has_depth = False
self.depth_name = None
Expand All @@ -129,7 +129,8 @@ def read_netcdf(cls, imu_file,
angular_velocity_name=_OMEGA_NAME,
magnetic_density_name=_MAGNT_NAME,
time_name=_TIME_NAME,
has_depth=False, **kwargs):
has_depth=False, depth_name=_DEPTH_NAME,
**kwargs):
"""Instantiate object by loading Dataset from NetCDF file
Provided all ``DataArray`` in the NetCDF file have the same
Expand All @@ -148,8 +149,9 @@ def read_netcdf(cls, imu_file,
dimension_names : list, optional
Names of the dimensions of the data in each of the sensors.
has_depth : bool, optional
Whether input data include depth measurements. Variable must
be named "depth".
Whether input data include depth measurements.
depth_name : str, optional
Name of the depth ``DataArray`` in the ``Dataset``.
**kwargs : optional keyword arguments
Arguments passed to :func:`xarray.load_dataset`.
Expand Down
4 changes: 2 additions & 2 deletions skdiveMove/imutools/imucalibrate.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import xarray as xr
from skdiveMove.tdrsource import _load_dataset
from .imu import (IMUBase,
_ACCEL_NAME, _OMEGA_NAME, _MAGNT_NAME, _DEPTH_NAMES)
_ACCEL_NAME, _OMEGA_NAME, _MAGNT_NAME, _DEPTH_NAME)

_TRIAXIAL_VARS = [_ACCEL_NAME, _OMEGA_NAME, _MAGNT_NAME]
_MONOAXIAL_VARS = _DEPTH_NAMES + ["light_levels"]
_MONOAXIAL_VARS = [_DEPTH_NAME, "light_levels"]
_AXIS_NAMES = list("xyz")

logger = logging.getLogger(__name__)
Expand Down
17 changes: 13 additions & 4 deletions skdiveMove/tdr.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,14 @@ def dive_stats(self, depth_deriv=True):
idx_name = phases_df.index.name

# calib_speed=False if no fit object
tdr = self.get_tdr(calib_depth=True,
calib_speed=bool(self.speed_calib_fit))
if self.has_speed:
tdr = (self.get_tdr(calib_depth=True,
calib_speed=bool(self.speed_calib_fit))
[[self.depth_name, self.speed_name]])
else:
tdr = (self.get_tdr(calib_depth=True,
calib_speed=bool(self.speed_calib_fit))
[[self.depth_name]])

intvl = (get_var_sampling_interval(tdr[self.depth_name])
.total_seconds())
Expand All @@ -191,8 +197,11 @@ def dive_stats(self, depth_deriv=True):
.groupby("postdive_id")
.apply(lambda x: x.iloc[-1] - x.iloc[0]))

# Enforce UTC, as otherwise rpy2 uses our locale in the output of
# OneDiveStats
tdrf = (pd.concat((phases_df[["dive_id", "dive_phase"]][ok],
tdr[ok]), axis=1).reset_index())
tdr.loc[ok.index[ok]]), axis=1)
.tz_localize("UTC").reset_index())

# Ugly hack to re-order columns for `diveMove` convention
names0 = ["dive_id", "dive_phase", idx_name, self.depth_name]
Expand All @@ -205,7 +214,7 @@ def dive_stats(self, depth_deriv=True):

ones_list = []
for name, grp in tdrf_grp:
res = _one_dive_stats(grp, interval=intvl,
res = _one_dive_stats(grp.loc[:, names0], interval=intvl,
has_speed=self.has_speed)
# Rename to match dive number
res = res.rename({0: name})
Expand Down

0 comments on commit dbec0ea

Please sign in to comment.