Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add ability to add features to existing track without retracking #461

Open
wants to merge 26 commits into
base: RC_v1.5.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
0bc0e5b
added type hints for tracking
freemansw1 Sep 4, 2024
d203e20
moved calculation of search range outside of main tracking function.
freemansw1 Sep 4, 2024
95b3059
added typing to generate_single_feature
freemansw1 Sep 6, 2024
d5ca3af
updates to generate_single_feature to support pre-made lists
freemansw1 Sep 9, 2024
efc21f1
updates to add a new combine_single_features function
freemansw1 Sep 11, 2024
037396d
committing to include updates. Not yet working properly.
freemansw1 Sep 12, 2024
34a83ab
I have append random tracking working. Append predictive tracking is …
freemansw1 Sep 12, 2024
34623e0
some modifications to take a stab at predict tracking
freemansw1 Sep 12, 2024
ff7c8e3
predictive tracking appends seem to be largely working correctly. Nee…
freemansw1 Oct 7, 2024
bd09a0b
adding more tests for predictive tracking.
freemansw1 Oct 7, 2024
308f29c
tests for memory seem to be working.
freemansw1 Oct 9, 2024
3c2dd18
cleaning and simplifying tracking functions
freemansw1 Oct 10, 2024
28c344b
add additional debug information to append tracks
freemansw1 Oct 10, 2024
cc9fe1f
add additional debug information to append tracks
freemansw1 Oct 15, 2024
8edb67c
Merge branch 'RC_v1.5.x' into append_features_for_time
freemansw1 Oct 17, 2024
4549cf1
update for formatting
freemansw1 Oct 17, 2024
113cf5f
Merge branch 'RC_v1.5.x' into append_features_for_time
freemansw1 Oct 25, 2024
310aeef
bugfixes for append tracks
freemansw1 Oct 25, 2024
3e17cdc
removed ability to work with memory due to trackpy issue
freemansw1 Oct 25, 2024
e2cac6c
fixed a call bug with trackpy to allow for older versions to be used
freemansw1 Oct 25, 2024
bc073c8
add printing of libraries to enable testing
freemansw1 Oct 30, 2024
21b79ea
add export of environment to codecov CI
freemansw1 Oct 31, 2024
d2663b8
require trackpy>0.6.1 due to bug with predictive tracking
freemansw1 Nov 1, 2024
4062b12
fixes to trackpy version requirements
freemansw1 Nov 1, 2024
5e61691
updates to CI to bring them to micromamba
freemansw1 Nov 1, 2024
348abc5
update to checkout v4.
freemansw1 Nov 1, 2024
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
19 changes: 5 additions & 14 deletions .github/workflows/check_notebooks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,12 @@ jobs:
- name: check out repository code
uses: actions/checkout@v3
- name: set up conda environment
uses: conda-incubator/setup-miniconda@v2
uses: mamba-org/setup-micromamba@v1
with:
miniforge-version: latest
miniforge-variant: mambaforge
channel-priority: strict
channels: conda-forge
show-channel-urls: true
use-only-tar-bz2: true
auto-update-conda: true
auto-activate-base: false
activate-environment: notebook-env
- name: Install tobac dependencies
run: |
mamba install -c conda-forge --yes ffmpeg gcc jupyter pytables
mamba install -c conda-forge --yes --file example_requirements.txt
environment-file: environment-examples.yml
generate-run-shell: true
cache-environment: true
cache-downloads: true
- name: Install tobac
run: |
pip install .
Expand Down
20 changes: 8 additions & 12 deletions .github/workflows/codecov-CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,24 +7,20 @@ jobs:
runs-on: ubuntu-latest
env:
OS: ubuntu-latest
PYTHON: "3.9"
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4
# Similar to MetPy install-conda action
- name: Set up conda
uses: conda-incubator/setup-miniconda@v2
uses: mamba-org/setup-micromamba@v1
with:
miniforge-version: latest
miniforge-variant: mambaforge
channel-priority: strict
channels: conda-forge
show-channel-urls: true
use-only-tar-bz2: true
environment-file: environment-ci.yml
generate-run-shell: true
cache-environment: true
cache-downloads: true

- name: Install dependencies and generate report
shell: bash -l {0}
- name: Generate report
shell: micromamba-shell {0}
run:
mamba install --quiet --yes --file requirements.txt coverage pytest-cov &&
python -m coverage run -m pytest --cov=./ --cov-report=xml
- name: Upload Coverage to Codecov
uses: codecov/codecov-action@v4
Expand Down
23 changes: 10 additions & 13 deletions .github/workflows/pylint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,21 +14,18 @@ jobs:
shell: bash -l {0}
steps:
- name: Check out Git repository
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Set up conda
uses: conda-incubator/setup-miniconda@v2
- name: Set up mamba
uses: mamba-org/setup-micromamba@v1
with:
miniforge-version: latest
miniforge-variant: mambaforge
channel-priority: strict
channels: conda-forge
show-channel-urls: true
use-only-tar-bz2: true
environment-file: environment-ci.yml
generate-run-shell: true
cache-environment: true
cache-downloads: true

- name: Install tobac and pylint
- name: Install tobac
run: |
mamba install --yes pylint
pip install .

- name: Store the PR branch
Expand All @@ -37,7 +34,7 @@ jobs:
id: git

- name: Checkout RC branch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: ${{ github.base_ref }}

Expand All @@ -47,7 +44,7 @@ jobs:
id: main_score

- name: Checkout PR branch
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
ref: "${{ steps.git.outputs.SHA }}"

Expand Down
5 changes: 4 additions & 1 deletion environment-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@ dependencies:
- iris
- xarray
- cartopy
- trackpy
- trackpy>=0.6.1
- pytest
- typing_extensions
- black
- coverage
- pytest-cov
- pylint
29 changes: 29 additions & 0 deletions environment-examples.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: tobac-dev
channels:
- conda-forge
dependencies:
- numpy
- scipy
- scikit-image
- scikit-learn
- pandas
- matplotlib
- iris
- xarray
- cartopy
- trackpy>=0.6.1
- pytest
- typing_extensions
- black
- jupyter
- notebook
- pytables
- s3fs
- arm_pyart
- seaborn
- h5netcdf
- typing_extensions
- rioxarray
- numba
- dask
-
145 changes: 107 additions & 38 deletions tobac/testing.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import pandas as pd
from collections import Counter
from .utils import periodic_boundaries as pbc_utils
from typing import Union, Optional, Literal, Iterable


def make_simple_sample_data_2D(data_type="iris"):
Expand Down Expand Up @@ -815,37 +816,42 @@


def generate_single_feature(
start_h1,
start_h2,
start_v=None,
spd_h1=1,
spd_h2=1,
spd_v=1,
min_h1=0,
max_h1=None,
min_h2=0,
max_h2=None,
num_frames=1,
dt=datetime.timedelta(minutes=5),
start_date=datetime.datetime(2022, 1, 1, 0),
PBC_flag="none",
frame_start=0,
feature_num=1,
feature_size=None,
threshold_val=None,
start_h1: Union[float, Iterable[float]],
start_h2: Union[float, Iterable[float]],
start_v: Optional[Union[float, Iterable[float]]] = None,
spd_h1: float = 1,
spd_h2: float = 1,
spd_v: float = 1,
min_h1: float = 0,
max_h1: Optional[float] = None,
min_h2: float = 0,
max_h2: Optional[float] = None,
num_frames: int = 1,
dt: datetime.timedelta = datetime.timedelta(minutes=5),
start_date: datetime.datetime = datetime.datetime(2022, 1, 1, 0),
PBC_flag: Literal["none", "hdim_1", "hdim_2", "both"] = "none",
frame_start: int = 0,
feature_num: int = 1,
feature_size: Optional[int] = None,
threshold_val: Optional[float] = None,
):
"""Function to generate a dummy feature dataframe to test the tracking functionality

Parameters
----------
start_h1: float
Starting point of the feature in hdim_1 space
start_h1: float or iterable of floats
Starting point of the feature in hdim_1 space if float
or all h1 points if iterable. If iterable is passed,
all other parameters are ignored.

start_h2: float
Starting point of the feature in hdim_2 space
start_h2: float or iterable of floats
Starting point of the feature in hdim_2 space if float
or all h2 points if iterable

start_v: float, optional
Starting point of the feature in vdim space (if 3D). For 2D, set to None.
Starting point of the feature in vdim space (if 3D) if float
or all vertical points if iterable.
For 2D, set to None.
Default is None

spd_h1: float, optional
Expand Down Expand Up @@ -914,38 +920,101 @@
if max_h1 is None or max_h2 is None:
raise ValueError("Max coords must be specified.")

out_list_of_dicts = list()
curr_h1 = start_h1
curr_h2 = start_h2
curr_v = start_v
h1_list = []
h2_list = []
v_list = []

# check if start_h1, start_h2, and start_v are all arrays
if not np.isscalar(start_h1) and not np.isscalar(start_h2):
if start_v is not None and np.isscalar(start_h2):
raise ValueError(

Check warning on line 930 in tobac/testing.py

View check run for this annotation

Codecov / codecov/patch

tobac/testing.py#L930

Added line #L930 was not covered by tests
"Must specify all start_h1, start_h2, and start_v as arrays."
)
h1_list = start_h1
h2_list = start_h2
if start_v is not None:
v_list = start_v

Check warning on line 936 in tobac/testing.py

View check run for this annotation

Codecov / codecov/patch

tobac/testing.py#L936

Added line #L936 was not covered by tests
# we need to make the list of points.
else:
curr_h1 = start_h1
curr_h2 = start_h2
curr_v = start_v

for i in range(num_frames):
curr_h1, curr_h2 = get_single_pbc_coordinate(
min_h1, max_h1, min_h2, max_h2, curr_h1, curr_h2, PBC_flag
)

h1_list.append(curr_h1)
h2_list.append(curr_h2)
curr_h1 += spd_h1
curr_h2 += spd_h2

if start_v is not None:
v_list.append(curr_v)
curr_v += spd_v

out_list_of_dicts = []
curr_dt = start_date
is_3D = not (start_v is None)
for i in range(num_frames):
for i in range(len(h1_list)):
if h1_list[i] < 0 or h2_list[i] < 0:
curr_dt += dt
continue
if len(v_list) > 0:
if v_list[i] < 0:
curr_dt += dt
continue

Check warning on line 966 in tobac/testing.py

View check run for this annotation

Codecov / codecov/patch

tobac/testing.py#L965-L966

Added lines #L965 - L966 were not covered by tests
curr_dict = dict()
curr_h1, curr_h2 = get_single_pbc_coordinate(
min_h1, max_h1, min_h2, max_h2, curr_h1, curr_h2, PBC_flag
)
curr_dict["hdim_1"] = curr_h1
curr_dict["hdim_2"] = curr_h2
curr_dict["hdim_1"] = h1_list[i]
curr_dict["hdim_2"] = h2_list[i]
curr_dict["frame"] = frame_start + i
curr_dict["idx"] = 0
if curr_v is not None:
curr_dict["vdim"] = curr_v
if len(v_list) > 0:
curr_dict["vdim"] = v_list[i]
curr_v += spd_v
curr_dict["time"] = curr_dt
curr_dict["feature"] = feature_num + i
if feature_size is not None:
curr_dict["num"] = feature_size
if threshold_val is not None:
curr_dict["threshold_value"] = threshold_val
curr_h1 += spd_h1
curr_h2 += spd_h2
curr_dt += dt
out_list_of_dicts.append(curr_dict)

return pd.DataFrame.from_dict(out_list_of_dicts)


def combine_single_features(
feat_list: list[pd.DataFrame], begin_feat_num: int = 1
) -> pd.DataFrame:
"""Combines multiple generate_single_feature outputs into one
coherent output

Parameters
----------
feat_list

Returns
-------

"""

time_col_name: str = "time"

comb_output = pd.concat(feat_list)

all_times = comb_output[time_col_name].unique()
all_times = sorted(all_times)
frame_nums = {str(np.datetime64(x, "ns")): i for i, x in enumerate(all_times)}
vec_frame_func = np.vectorize(lambda x: frame_nums[str(np.datetime64(x, "ns"))])
comb_output["frame"] = vec_frame_func(comb_output[time_col_name])
comb_output["idx"] = comb_output.groupby("frame").transform("cumcount")
comb_output = comb_output.sort_values(["frame", "idx"], axis=0)
feat_col = np.arange(begin_feat_num, begin_feat_num + len(comb_output))
comb_output["feature"] = feat_col
return comb_output


def get_start_end_of_feat(center_point, size, axis_min, axis_max, is_pbc=False):
"""Gets the start and ending points for a feature given a size and PBC
conditions
Expand Down
Loading
Loading