From 889eb9164c1dc5cd916476ad3802b5a0d581c591 Mon Sep 17 00:00:00 2001 From: William Jones Date: Wed, 4 Oct 2023 14:35:06 +0100 Subject: [PATCH 1/6] Fix to weighted_circmean so that if the result equals the 'high' value it instead returns the 'low' value --- tobac/utils/periodic_boundaries.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tobac/utils/periodic_boundaries.py b/tobac/utils/periodic_boundaries.py index 18453465..9e4e7fdc 100644 --- a/tobac/utils/periodic_boundaries.py +++ b/tobac/utils/periodic_boundaries.py @@ -297,7 +297,10 @@ def weighted_circmean( angle_average = np.arctan2(sin_average, cos_average) % (2 * np.pi) rescaled_average = (angle_average * scaling_factor) + low # Round return value to try and supress rounding errors - return np.round(rescaled_average, 12) + rescaled_average = np.round(rescaled_average, 12) + if rescaled_average == high: + rescaled_average = low + return rescaled_average def transfm_pbc_point(in_dim, dim_min, dim_max): From 6e87312683c68f73f305950a509949acb863c626 Mon Sep 17 00:00:00 2001 From: William Jones Date: Wed, 4 Oct 2023 14:45:32 +0100 Subject: [PATCH 2/6] Update segmentation.add_markers to pick nearest pixel when 'column' seeding, and to take the modulo of the pixel location to prevent out of bounds errors --- tobac/segmentation.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tobac/segmentation.py b/tobac/segmentation.py index b173f48c..d635d8dd 100644 --- a/tobac/segmentation.py +++ b/tobac/segmentation.py @@ -104,8 +104,9 @@ def add_markers( marker_arr = marker_arr[np.newaxis, :, :] if seed_3D_flag == "column": - for index, row in features.iterrows(): - marker_arr[level, int(row["hdim_1"]), int(row["hdim_2"])] = row["feature"] + for _, row in features.iterrows(): + # Offset marker locations by 0.5 to find nearest pixel + marker_arr[level, int(row["hdim_1"]+0.5) % h1_len, int(row["hdim_2"]+0.5) % h2_len] = row["feature"] elif seed_3D_flag == "box": # Get the size of the seed box from the input parameter @@ -123,7 +124,7 @@ def add_markers( seed_h1 = seed_3D_size seed_h2 = seed_3D_size - for index, row in features.iterrows(): + for _, row in features.iterrows(): if is_3D: # If we have a 3D input and we need to do box seeding # we need to have 3D features. From ce6efa7b363d37d17537f006befd6977eedd9cc3 Mon Sep 17 00:00:00 2001 From: William Jones Date: Wed, 4 Oct 2023 14:51:25 +0100 Subject: [PATCH 3/6] Formatting --- tobac/segmentation.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tobac/segmentation.py b/tobac/segmentation.py index d635d8dd..ee4e71e5 100644 --- a/tobac/segmentation.py +++ b/tobac/segmentation.py @@ -106,7 +106,11 @@ def add_markers( if seed_3D_flag == "column": for _, row in features.iterrows(): # Offset marker locations by 0.5 to find nearest pixel - marker_arr[level, int(row["hdim_1"]+0.5) % h1_len, int(row["hdim_2"]+0.5) % h2_len] = row["feature"] + marker_arr[ + level, + int(row["hdim_1"] + 0.5) % h1_len, + int(row["hdim_2"] + 0.5) % h2_len, + ] = row["feature"] elif seed_3D_flag == "box": # Get the size of the seed box from the input parameter From b3be488a13cad7ac2990cde391b3e5c98b0b1b22 Mon Sep 17 00:00:00 2001 From: William Jones Date: Thu, 5 Oct 2023 09:39:00 +0100 Subject: [PATCH 4/6] Update .readthedocs.yml --- .readthedocs.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.readthedocs.yml b/.readthedocs.yml index 1fcc341c..d6e8bc48 100644 --- a/.readthedocs.yml +++ b/.readthedocs.yml @@ -1,6 +1,9 @@ version: 2 formats: all +build: + os: ubuntu-22.04 + tools: + python: "3.9" python: - version: 3 install: - - requirements: doc/requirements.txt \ No newline at end of file + - requirements: doc/requirements.txt From c985963806c3c9b89f08a0c81b28063a70e6d7e8 Mon Sep 17 00:00:00 2001 From: William Jones Date: Thu, 5 Oct 2023 09:50:00 +0100 Subject: [PATCH 5/6] Update requirements.txt --- doc/requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/doc/requirements.txt b/doc/requirements.txt index 6ba789a0..799f24f9 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -1,3 +1,4 @@ ipykernel nbsphinx numpy +sphinx_rtd_theme From 3fdbf6ec254733035c1937cf6250f6125313ed8b Mon Sep 17 00:00:00 2001 From: William Jones Date: Thu, 5 Oct 2023 13:10:41 +0100 Subject: [PATCH 6/6] Select first row in buddy_feat dataframe to prevent FutureWarning in segmentation due to calling int/float on a length 1 array --- tobac/segmentation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tobac/segmentation.py b/tobac/segmentation.py index ee4e71e5..2f346e42 100644 --- a/tobac/segmentation.py +++ b/tobac/segmentation.py @@ -786,7 +786,7 @@ def segmentation_timestep( if buddy == 0: continue # isolate feature from set of buddies - buddy_feat = features_in[features_in["feature"] == buddy] + buddy_feat = features_in[features_in["feature"] == buddy].iloc[0] # transform buddy feature position if needed for positioning in z2/y2/x2 space # MAY be redundant with what is done just below here