Skip to content

Commit

Permalink
Merge pull request #157 from tobac-project/dev
Browse files Browse the repository at this point in the history
Merge `dev` into `main` for v1.3.2
  • Loading branch information
freemansw1 committed Jul 18, 2022
2 parents e6e8fc3 + 72d70fa commit da710bb
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .coveragerc
@@ -0,0 +1,3 @@
[run]
source=tobac
omit = tobac/tests/*
33 changes: 33 additions & 0 deletions .github/workflows/codecov-CI.yml
@@ -0,0 +1,33 @@
name: Codecov CI

on: [push, pull_request]

jobs:
run:
runs-on: ubuntu-latest
env:
OS: ubuntu-latest
PYTHON: '3.9'
steps:
- uses: actions/checkout@v2
# Similar to MetPy install-conda action
- name: Set up conda
uses: conda-incubator/setup-miniconda@v2
with:
miniforge-version: latest
miniforge-variant: mambaforge
channel-priority: strict
channels: conda-forge
show-channel-urls: true
use-only-tar-bz2: true

- name: Install dependencies and generate report
shell: bash -l {0}
run: mamba install --quiet --yes --file conda-requirements.txt coverage pytest-cov &&
python -m coverage run -m pytest --cov=./ --cov-report=xml
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v2
with:
fail_ci_if_error: true
flags: unittests

13 changes: 13 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,18 @@
### Tobac Changelog

_**Version 1.3.2:**_

**Bug fixes**

- Fixed a bug with Feature Detection that caused it to fail when using `weighted_abs` position [#148](https://github.com/tobac-project/tobac/pull/148)
- Fixed a bug where adaptive_search within `linking_trackpy` was not working correctly [#140](https://github.com/tobac-project/tobac/pull/140)

**Repository enhancements**

- Added automatic code coverage reports [#124](https://github.com/tobac-project/tobac/pull/124)
- Added automatic building of readthedocs documentation on pull requests


_**Version 1.3.1:**_

**Enhancements**
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -2,7 +2,7 @@

setup(
name="tobac",
version="1.3.1",
version="1.3.2",
description="Tracking and object-based analysis of clouds",
url="http://github.com/tobac-project/tobac",
author=[
Expand Down
2 changes: 1 addition & 1 deletion tobac/feature_detection.py
Expand Up @@ -90,7 +90,7 @@ def feature_position(

elif position_threshold == "weighted_abs":
# get position as centre of identified region, weighted by absolute values if the field:
weights = abs(track_data[region_small])
weights = abs(track_data_region[region_small])
if sum(weights) == 0:
weights = None
hdim1_index = np.average(hdim1_indices, weights=weights)
Expand Down
15 changes: 15 additions & 0 deletions tobac/tests/Dockerfile-coverage
@@ -0,0 +1,15 @@
FROM mambaorg/micromamba
ARG MAMBA_DOCKERFILE_ACTIVATE=1

RUN micromamba install -y -n base -c conda-forge numpy \
scipy scikit-image pandas pytables matplotlib iris \
cf-units xarray cartopy trackpy numba pytest pip \
pytest-cov coverage

COPY . ./

RUN pip install .

RUN coverage run -m pytest --cov-report=xml &&\
mv coverage.xml shared

39 changes: 35 additions & 4 deletions tobac/tests/test_feature_detection.py
@@ -1,4 +1,4 @@
import tobac.testing
import tobac.testing as tbtest
import tobac.feature_detection as feat_detect
import pytest

Expand All @@ -8,7 +8,6 @@ def test_feature_detection_multithreshold_timestep():
Tests ```tobac.feature_detection.feature_detection_multithreshold_timestep
"""
import numpy as np
from tobac import testing
from tobac import feature_detection

# start by building a simple dataset with a single feature and seeing
Expand All @@ -26,15 +25,15 @@ def test_feature_detection_multithreshold_timestep():
test_min_num = 2

test_data = np.zeros(test_dset_size)
test_data = testing.make_feature_blob(
test_data = tbtest.make_feature_blob(
test_data,
test_hdim_1_pt,
test_hdim_2_pt,
h1_size=test_hdim_1_sz,
h2_size=test_hdim_2_sz,
amplitude=test_amp,
)
test_data_iris = testing.make_dataset_from_arr(test_data, data_type="iris")
test_data_iris = tbtest.make_dataset_from_arr(test_data, data_type="iris")
fd_output = feature_detection.feature_detection_multithreshold_timestep(
test_data_iris, 0, threshold=test_threshs, n_min_threshold=test_min_num
)
Expand All @@ -44,3 +43,35 @@ def test_feature_detection_multithreshold_timestep():
# Make sure that the location of the feature is correct
assert fd_output.iloc[0]["hdim_1"] == pytest.approx(test_hdim_1_pt)
assert fd_output.iloc[0]["hdim_2"] == pytest.approx(test_hdim_2_pt)


@pytest.mark.parametrize(
"position_threshold", [("center"), ("extreme"), ("weighted_diff"), ("weighted_abs")]
)
def test_feature_detection_position(position_threshold):
"""
Tests to make sure that all feature detection position_thresholds work.
"""
import numpy as np

test_dset_size = (50, 50)

test_data = np.zeros(test_dset_size)

test_data[0:5, 0:5] = 3
test_threshs = [
1.5,
]
test_min_num = 2

test_data_iris = tbtest.make_dataset_from_arr(test_data, data_type="iris")

fd_output = feat_detect.feature_detection_multithreshold_timestep(
test_data_iris,
0,
threshold=test_threshs,
n_min_threshold=test_min_num,
position_threshold=position_threshold,
)

pass
7 changes: 6 additions & 1 deletion tobac/tracking.py
Expand Up @@ -89,7 +89,12 @@ def linking_trackpy(

# If subnetwork size given, set maximum subnet size
if subnetwork_size is not None:
tp.linking.Linker.MAX_SUB_NET_SIZE = subnetwork_size
# Choose the right parameter depending on the use of adaptive search
if adaptive_step is None and adaptive_stop is None:
tp.linking.Linker.MAX_SUB_NET_SIZE = subnetwork_size
else:
tp.linking.Linker.MAX_SUB_NET_SIZE_ADAPTIVE = subnetwork_size

# deep copy to preserve features field:
features_linking = deepcopy(features)

Expand Down

0 comments on commit da710bb

Please sign in to comment.