Skip to content
Merged
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Publish Docker image

on:
push:
branches:
- main
tags:
- v*


jobs:
push_to_registry:
name: Push Docker image to Docker Hub
runs-on: ubuntu-latest
steps:
- name: Check out the repo
uses: actions/checkout@v4
with:
lfs: true

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
Comment thread Fixed

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
Comment thread Fixed

- name: Log in to Docker Hub
uses: docker/login-action@v3
Comment thread Fixed
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}


- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5.5.1
Comment thread Fixed
Comment thread Fixed
with:
images: adamsanto/wristpy


- name: Build and push Docker image
uses: docker/build-push-action@v5.1.0
Comment thread Fixed
with:
platforms: linux/amd64,linux/arm64
context: .
file: ./Dockerfile
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
Comment thread Fixed
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pip install wristpy

## Quick start

`wristpy` provides three flexible interfaces: a command-line tool for direct execution, an importable Python library, and a Docker image for containerized deployment.

### Using Wristpy through the command-line:
#### Run single files:
```sh
Expand Down Expand Up @@ -117,6 +119,60 @@ nonwear_array = subject1.nonwear_epoch
sleep_windows = subject1.sleep_windows_epoch
```

### Using Wristpy Through Docker


1. **Install Docker**: Ensure you have Docker installed on your system. [Get Docker](https://docs.docker.com/get-docker/)

2. **Pull the Docker image**:
```bash
docker pull adamsanto/wristpy:latest
```

3. **Run the Docker image** with your data:
```bash
docker run -it --rm \
-v "/local/path/to/data:/data" \
-v "/local/path/to/output:/output" \
adamsanto/wristpy
```
Replace `/local/path/to/data` with the path to your input data directory and `/local/path/to/output` with where you want results saved.
Comment thread
Asanto32 marked this conversation as resolved.

### Customizing the Pipeline:

The Docker image supports multiple environment variables to customize processing. You can set these using the `-e` flag:

```bash
docker run -it --rm \
-v "$(pwd)/my_data:/data" \
-v "$(pwd)/results:/output" \
-e CALIBRATOR=ggir \
-e ACTIVITY_METRIC=mad \
-e NONWEAR=ggir,cta \
-e THRESHOLDS=0.1,1.0,1.5 \
-e EPOCH_LENGTH=10 \
-e VERBOSITY=1 \
adamsanto/wristpy
```

### Available Environment Variables:

| Variable | Description | Default | Options |
|----------|-------------|---------|---------|
| `INPUT_DIR` | Path for input data inside container | `/data` | Any valid path |
| `OUTPUT_DIR` | Path for output data inside container | `/output` | Any valid path |
| `OUTPUT_TYPE` | Format for output files | `csv` | `csv`, `parquet` |
| `CALIBRATOR` | Calibration method | `none` | `none`, `ggir`, `gradient` |
| `ACTIVITY_METRIC` | Activity metric for analysis | `enmo` | `enmo`, `mad`, `ag_count` |
| `EPOCH_LENGTH` | Sampling rate in seconds | `5` | Any integer ≥ 1 |
| `NONWEAR` | Non-wear detection algorithm(s) | `ggir` | `ggir`, `cta`, `detach` or comma-separated list. |
| `THRESHOLDS` | Activity level thresholds | `""` | Specify three threshold values as comma-separated numbers. |



For more details on available options, see the [orchestrator documentation](https://childmindresearch.github.io/wristpy/wristpy/core/orchestrator.html#run).


## References
1. van Hees, V.T., Sabia, S., Jones, S.E. et al. Estimating sleep parameters
using an accelerometer without sleep diary. Sci Rep 8, 12975 (2018).
Expand Down
31 changes: 31 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
FROM python:3.11-buster

WORKDIR /app
COPY . /app/
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make this copy more specific, or add a .dockerignore, to avoid copying unnecessary large files like the documentation pngs into the docker image?



ENV INPUT_DIR=/data
ENV OUTPUT_DIR=/output
ENV OUTPUT_TYPE=.csv
ENV CALIBRATOR=none
ENV ACTIVITY_METRIC=enmo
ENV EPOCH_LENGTH=5
ENV NONWEAR=ggir
ENV THRESHOLDS=""


RUN apt-get update && apt-get install -y \
build-essential \
gfortran \
&& rm -rf /var/lib/apt/lists/*

RUN pip install poetry && \
poetry config virtualenvs.create false && \
poetry install --only main

RUN mkdir -p $INPUT_DIR $OUTPUT_DIR

COPY entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh

ENTRYPOINT ["/entrypoint.sh"]
31 changes: 31 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/bin/bash
# Wristpy Docker Entrypoint Script

CMD="poetry run wristpy $INPUT_DIR --output $OUTPUT_DIR"


if [ -n "$OUTPUT_TYPE" ]; then
CMD="$CMD --output-filetype $OUTPUT_TYPE"
fi

CMD="$CMD --calibrator $CALIBRATOR"
CMD="$CMD --activity-metric $ACTIVITY_METRIC"
CMD="$CMD --epoch-length $EPOCH_LENGTH"


if [ -n "$NONWEAR" ]; then
IFS="," read -ra ALGOS <<< "$NONWEAR"
for algo in "${ALGOS[@]}"; do
CMD="$CMD --nonwear-algorithm $algo"
done
fi

if [ -n "$THRESHOLDS" ]; then
THRESHOLD_VALUES=$(echo $THRESHOLDS | tr "," " ")
if [ -n "$THRESHOLD_VALUES" ]; then
CMD="$CMD --thresholds $THRESHOLD_VALUES"
fi
fi

echo "Running: $CMD"
exec $CMD
Loading