tobac 1.6.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. tobac/__init__.py +112 -0
  2. tobac/analysis/__init__.py +31 -0
  3. tobac/analysis/cell_analysis.py +628 -0
  4. tobac/analysis/feature_analysis.py +212 -0
  5. tobac/analysis/spatial.py +619 -0
  6. tobac/centerofgravity.py +226 -0
  7. tobac/feature_detection.py +1758 -0
  8. tobac/merge_split.py +324 -0
  9. tobac/plotting.py +2321 -0
  10. tobac/segmentation/__init__.py +10 -0
  11. tobac/segmentation/watershed_segmentation.py +1316 -0
  12. tobac/testing.py +1179 -0
  13. tobac/tests/segmentation_tests/test_iris_xarray_segmentation.py +0 -0
  14. tobac/tests/segmentation_tests/test_segmentation.py +1183 -0
  15. tobac/tests/segmentation_tests/test_segmentation_time_pad.py +104 -0
  16. tobac/tests/test_analysis_spatial.py +1109 -0
  17. tobac/tests/test_convert.py +265 -0
  18. tobac/tests/test_datetime.py +216 -0
  19. tobac/tests/test_decorators.py +148 -0
  20. tobac/tests/test_feature_detection.py +1321 -0
  21. tobac/tests/test_generators.py +273 -0
  22. tobac/tests/test_import.py +24 -0
  23. tobac/tests/test_iris_xarray_match_utils.py +244 -0
  24. tobac/tests/test_merge_split.py +351 -0
  25. tobac/tests/test_pbc_utils.py +497 -0
  26. tobac/tests/test_sample_data.py +197 -0
  27. tobac/tests/test_testing.py +747 -0
  28. tobac/tests/test_tracking.py +714 -0
  29. tobac/tests/test_utils.py +650 -0
  30. tobac/tests/test_utils_bulk_statistics.py +789 -0
  31. tobac/tests/test_utils_coordinates.py +328 -0
  32. tobac/tests/test_utils_internal.py +97 -0
  33. tobac/tests/test_xarray_utils.py +232 -0
  34. tobac/tracking.py +613 -0
  35. tobac/utils/__init__.py +27 -0
  36. tobac/utils/bulk_statistics.py +360 -0
  37. tobac/utils/datetime.py +184 -0
  38. tobac/utils/decorators.py +540 -0
  39. tobac/utils/general.py +753 -0
  40. tobac/utils/generators.py +87 -0
  41. tobac/utils/internal/__init__.py +2 -0
  42. tobac/utils/internal/coordinates.py +430 -0
  43. tobac/utils/internal/iris_utils.py +462 -0
  44. tobac/utils/internal/label_props.py +82 -0
  45. tobac/utils/internal/xarray_utils.py +439 -0
  46. tobac/utils/mask.py +364 -0
  47. tobac/utils/periodic_boundaries.py +419 -0
  48. tobac/wrapper.py +244 -0
  49. tobac-1.6.2.dist-info/METADATA +154 -0
  50. tobac-1.6.2.dist-info/RECORD +53 -0
  51. tobac-1.6.2.dist-info/WHEEL +5 -0
  52. tobac-1.6.2.dist-info/licenses/LICENSE +29 -0
  53. tobac-1.6.2.dist-info/top_level.txt +1 -0
@@ -0,0 +1,104 @@
1
+ """Tests for time padding of segmentation"""
2
+
3
+ import datetime
4
+ import pytest
5
+ from typing import Optional
6
+ import numpy as np
7
+ import tobac.testing as tb_test
8
+ import tobac.segmentation.watershed_segmentation as watershed_segmentation
9
+ import tobac.feature_detection as feature_detection
10
+
11
+
12
+ @pytest.mark.parametrize(
13
+ "time_pad_setting, time_offset, expect_output,",
14
+ [
15
+ (datetime.timedelta(seconds=1), datetime.timedelta(seconds=0), True),
16
+ (datetime.timedelta(seconds=1), datetime.timedelta(seconds=2), False),
17
+ (datetime.timedelta(seconds=0), datetime.timedelta(seconds=2), False),
18
+ (datetime.timedelta(seconds=3), datetime.timedelta(seconds=2), True),
19
+ (datetime.timedelta(seconds=2), datetime.timedelta(seconds=1), True),
20
+ (datetime.timedelta(seconds=0), datetime.timedelta(seconds=0), True),
21
+ (None, datetime.timedelta(seconds=0), True),
22
+ (None, datetime.timedelta(seconds=1), False),
23
+ ],
24
+ )
25
+ def test_watershed_segmentation_time_pad(
26
+ time_pad_setting: Optional[datetime.timedelta],
27
+ time_offset: datetime.timedelta,
28
+ expect_output: bool,
29
+ ):
30
+ """Tests tobac.watershed_segmentation for time padding working correctly."""
31
+ test_dset_size = (50, 50)
32
+ test_hdim_1_pt = 20.0
33
+ test_hdim_2_pt = 20.0
34
+ test_hdim_1_sz = 5
35
+ test_hdim_2_sz = 5
36
+ size_feature1 = test_hdim_1_sz * test_hdim_2_sz
37
+ test_amp = 2
38
+ test_min_num = 2
39
+
40
+ test_data = np.zeros(test_dset_size)
41
+ test_data = tb_test.make_feature_blob(
42
+ test_data,
43
+ test_hdim_1_pt,
44
+ test_hdim_2_pt,
45
+ h1_size=test_hdim_1_sz,
46
+ h2_size=test_hdim_2_sz,
47
+ amplitude=test_amp,
48
+ )
49
+
50
+ # add feature of different size
51
+ test_hdim_1_pt = 40.0
52
+ test_hdim_2_pt = 40.0
53
+ test_hdim_1_sz = 10
54
+ test_hdim_2_sz = 10
55
+ size_feature2 = test_hdim_1_sz * test_hdim_2_sz
56
+ test_amp = 10
57
+ test_dxy = 1
58
+
59
+ test_data = tb_test.make_feature_blob(
60
+ test_data,
61
+ test_hdim_1_pt,
62
+ test_hdim_2_pt,
63
+ h1_size=test_hdim_1_sz,
64
+ h2_size=test_hdim_2_sz,
65
+ amplitude=test_amp,
66
+ )
67
+
68
+ test_data_xarray = tb_test.make_dataset_from_arr(test_data, data_type="xarray")
69
+ test_data_xarray = test_data_xarray.assign_coords(
70
+ time=datetime.datetime(2020, 1, 1)
71
+ )
72
+
73
+ test_data_xarray = test_data_xarray.expand_dims("time")
74
+ # detect both features
75
+ fd_output = feature_detection.feature_detection_multithreshold(
76
+ test_data_xarray,
77
+ i_time=0,
78
+ dxy=1,
79
+ threshold=[1, 2, 3],
80
+ n_min_threshold=test_min_num,
81
+ target="maximum",
82
+ statistic={"features_mean": np.mean},
83
+ )
84
+
85
+ # add feature IDs to data frame for one time step
86
+ fd_output["feature"] = [1, 2]
87
+ fd_output.loc[:, "time"] += time_offset
88
+
89
+ # perform segmentation
90
+ out_seg_mask, out_df = watershed_segmentation.segmentation(
91
+ field=test_data_xarray,
92
+ features=fd_output,
93
+ dxy=test_dxy,
94
+ threshold=1.5,
95
+ time_padding=time_pad_setting,
96
+ )
97
+ out_seg_mask_arr = out_seg_mask
98
+ if expect_output:
99
+ # assure that the number of grid cells belonging to each feature (ncells) are consistent with segmentation mask
100
+ assert np.sum(out_seg_mask_arr == 1) == size_feature1
101
+ assert np.sum(out_seg_mask_arr == 2) == size_feature2
102
+ else:
103
+ assert np.sum(out_seg_mask_arr == 1) == 0
104
+ assert np.sum(out_seg_mask_arr == 2) == 0