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.
- tobac/__init__.py +112 -0
- tobac/analysis/__init__.py +31 -0
- tobac/analysis/cell_analysis.py +628 -0
- tobac/analysis/feature_analysis.py +212 -0
- tobac/analysis/spatial.py +619 -0
- tobac/centerofgravity.py +226 -0
- tobac/feature_detection.py +1758 -0
- tobac/merge_split.py +324 -0
- tobac/plotting.py +2321 -0
- tobac/segmentation/__init__.py +10 -0
- tobac/segmentation/watershed_segmentation.py +1316 -0
- tobac/testing.py +1179 -0
- tobac/tests/segmentation_tests/test_iris_xarray_segmentation.py +0 -0
- tobac/tests/segmentation_tests/test_segmentation.py +1183 -0
- tobac/tests/segmentation_tests/test_segmentation_time_pad.py +104 -0
- tobac/tests/test_analysis_spatial.py +1109 -0
- tobac/tests/test_convert.py +265 -0
- tobac/tests/test_datetime.py +216 -0
- tobac/tests/test_decorators.py +148 -0
- tobac/tests/test_feature_detection.py +1321 -0
- tobac/tests/test_generators.py +273 -0
- tobac/tests/test_import.py +24 -0
- tobac/tests/test_iris_xarray_match_utils.py +244 -0
- tobac/tests/test_merge_split.py +351 -0
- tobac/tests/test_pbc_utils.py +497 -0
- tobac/tests/test_sample_data.py +197 -0
- tobac/tests/test_testing.py +747 -0
- tobac/tests/test_tracking.py +714 -0
- tobac/tests/test_utils.py +650 -0
- tobac/tests/test_utils_bulk_statistics.py +789 -0
- tobac/tests/test_utils_coordinates.py +328 -0
- tobac/tests/test_utils_internal.py +97 -0
- tobac/tests/test_xarray_utils.py +232 -0
- tobac/tracking.py +613 -0
- tobac/utils/__init__.py +27 -0
- tobac/utils/bulk_statistics.py +360 -0
- tobac/utils/datetime.py +184 -0
- tobac/utils/decorators.py +540 -0
- tobac/utils/general.py +753 -0
- tobac/utils/generators.py +87 -0
- tobac/utils/internal/__init__.py +2 -0
- tobac/utils/internal/coordinates.py +430 -0
- tobac/utils/internal/iris_utils.py +462 -0
- tobac/utils/internal/label_props.py +82 -0
- tobac/utils/internal/xarray_utils.py +439 -0
- tobac/utils/mask.py +364 -0
- tobac/utils/periodic_boundaries.py +419 -0
- tobac/wrapper.py +244 -0
- tobac-1.6.2.dist-info/METADATA +154 -0
- tobac-1.6.2.dist-info/RECORD +53 -0
- tobac-1.6.2.dist-info/WHEEL +5 -0
- tobac-1.6.2.dist-info/licenses/LICENSE +29 -0
- tobac-1.6.2.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Perform analysis on the properties of detected features
|
|
3
|
+
"""
|
|
4
|
+
|
|
5
|
+
import logging
|
|
6
|
+
import numpy as np
|
|
7
|
+
|
|
8
|
+
from tobac.analysis.spatial import (
|
|
9
|
+
calculate_nearestneighbordistance,
|
|
10
|
+
calculate_area,
|
|
11
|
+
)
|
|
12
|
+
|
|
13
|
+
__all__ = (
|
|
14
|
+
"nearestneighbordistance_histogram",
|
|
15
|
+
"area_histogram",
|
|
16
|
+
"histogram_featurewise",
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
def nearestneighbordistance_histogram(
|
|
21
|
+
features,
|
|
22
|
+
bin_edges=np.arange(0, 30000, 500),
|
|
23
|
+
density=False,
|
|
24
|
+
method_distance=None,
|
|
25
|
+
return_values=False,
|
|
26
|
+
):
|
|
27
|
+
"""Create an nearest neighbor distance histogram of the features.
|
|
28
|
+
If the DataFrame does not contain a 'min_distance' column, the
|
|
29
|
+
distances are calculated.
|
|
30
|
+
|
|
31
|
+
----------
|
|
32
|
+
features
|
|
33
|
+
|
|
34
|
+
bin_edges : int or ndarray, optional
|
|
35
|
+
If bin_edges is an int, it defines the number of equal-width
|
|
36
|
+
bins in the given range. If bins is a ndarray, it defines a
|
|
37
|
+
monotonically increasing array of bin edges, including the
|
|
38
|
+
rightmost edge. Default is np.arange(0, 30000, 500).
|
|
39
|
+
|
|
40
|
+
density : bool, optional
|
|
41
|
+
If False, the result will contain the number of samples in
|
|
42
|
+
each bin. If True, the result is the value of the probability
|
|
43
|
+
density function at the bin, normalized such that the integral
|
|
44
|
+
over the range is 1. Default is False.
|
|
45
|
+
|
|
46
|
+
method_distance : {None, 'xy', 'latlon'}, optional
|
|
47
|
+
Method of distance calculation. 'xy' uses the length of the
|
|
48
|
+
vector between the two features, 'latlon' uses the haversine
|
|
49
|
+
distance. None checks wether the required coordinates are
|
|
50
|
+
present and starts with 'xy'. Default is None.
|
|
51
|
+
|
|
52
|
+
return_values : bool, optional
|
|
53
|
+
Bool determining wether the nearest neighbor distance of the
|
|
54
|
+
features are returned from this function. Default is False.
|
|
55
|
+
|
|
56
|
+
Returns
|
|
57
|
+
-------
|
|
58
|
+
hist : ndarray
|
|
59
|
+
The values of the histogram.
|
|
60
|
+
|
|
61
|
+
bin_edges : ndarray
|
|
62
|
+
The edges of the histogram.
|
|
63
|
+
|
|
64
|
+
distances, optional : ndarray
|
|
65
|
+
A numpy array with the nearest neighbor distances of each
|
|
66
|
+
feature.
|
|
67
|
+
|
|
68
|
+
"""
|
|
69
|
+
|
|
70
|
+
if "min_distance" not in features.columns:
|
|
71
|
+
logging.debug("calculate nearest neighbor distances")
|
|
72
|
+
features = calculate_nearestneighbordistance(
|
|
73
|
+
features, method_distance=method_distance
|
|
74
|
+
)
|
|
75
|
+
distances = features["min_distance"].values
|
|
76
|
+
hist, bin_edges = np.histogram(
|
|
77
|
+
distances[~np.isnan(distances)], bin_edges, density=density
|
|
78
|
+
)
|
|
79
|
+
if return_values:
|
|
80
|
+
return hist, bin_edges, distances
|
|
81
|
+
else:
|
|
82
|
+
return hist, bin_edges
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def area_histogram(
|
|
86
|
+
features,
|
|
87
|
+
mask,
|
|
88
|
+
bin_edges=np.arange(0, 30000, 500),
|
|
89
|
+
density=False,
|
|
90
|
+
method_area=None,
|
|
91
|
+
return_values=False,
|
|
92
|
+
representative_area=False,
|
|
93
|
+
):
|
|
94
|
+
"""Create an area histogram of the features. If the DataFrame
|
|
95
|
+
does not contain an area column, the areas are calculated.
|
|
96
|
+
|
|
97
|
+
Parameters
|
|
98
|
+
----------
|
|
99
|
+
features : pandas.DataFrame
|
|
100
|
+
DataFrame of the features.
|
|
101
|
+
|
|
102
|
+
mask : iris.cube.Cube
|
|
103
|
+
Cube containing mask (int for tracked volumes 0
|
|
104
|
+
everywhere else). Needs to contain either
|
|
105
|
+
projection_x_coordinate and projection_y_coordinate or
|
|
106
|
+
latitude and longitude coordinates. The output of a
|
|
107
|
+
segmentation should be used here.
|
|
108
|
+
|
|
109
|
+
bin_edges : int or ndarray, optional
|
|
110
|
+
If bin_edges is an int, it defines the number of
|
|
111
|
+
equal-width bins in the given range. If bins is a ndarray,
|
|
112
|
+
it defines a monotonically increasing array of bin edges,
|
|
113
|
+
including the rightmost edge.
|
|
114
|
+
Default is np.arange(0, 30000, 500).
|
|
115
|
+
|
|
116
|
+
density : bool, optional
|
|
117
|
+
If False, the result will contain the number of samples
|
|
118
|
+
in each bin. If True, the result is the value of the
|
|
119
|
+
probability density function at the bin, normalized such
|
|
120
|
+
that the integral over the range is 1. Default is False.
|
|
121
|
+
|
|
122
|
+
return_values : bool, optional
|
|
123
|
+
Bool determining wether the areas of the features are
|
|
124
|
+
returned from this function. Default is False.
|
|
125
|
+
|
|
126
|
+
representive_area: bool, optional
|
|
127
|
+
If False, no weights will associated to the values.
|
|
128
|
+
If True, the weights for each area will be the areas
|
|
129
|
+
itself, i.e. each bin count will have the value of
|
|
130
|
+
the sum of all areas within the edges of the bin.
|
|
131
|
+
Default is False.
|
|
132
|
+
|
|
133
|
+
Returns
|
|
134
|
+
-------
|
|
135
|
+
hist : ndarray
|
|
136
|
+
The values of the histogram.
|
|
137
|
+
|
|
138
|
+
bin_edges : ndarray
|
|
139
|
+
The edges of the histogram.
|
|
140
|
+
|
|
141
|
+
bin_centers : ndarray
|
|
142
|
+
The centers of the histogram intervalls.
|
|
143
|
+
|
|
144
|
+
areas : ndarray, optional
|
|
145
|
+
A numpy array approximating the area of each feature.
|
|
146
|
+
|
|
147
|
+
"""
|
|
148
|
+
|
|
149
|
+
if "area" not in features.columns:
|
|
150
|
+
logging.info("calculate area")
|
|
151
|
+
features = calculate_area(features, mask, method_area)
|
|
152
|
+
areas = features["area"].values
|
|
153
|
+
# restrict to non NaN values:
|
|
154
|
+
areas = areas[~np.isnan(areas)]
|
|
155
|
+
if representative_area:
|
|
156
|
+
weights = areas
|
|
157
|
+
else:
|
|
158
|
+
weights = None
|
|
159
|
+
hist, bin_edges = np.histogram(areas, bin_edges, density=density, weights=weights)
|
|
160
|
+
bin_centers = bin_edges[:-1] + 0.5 * np.diff(bin_edges)
|
|
161
|
+
|
|
162
|
+
if return_values:
|
|
163
|
+
return hist, bin_edges, bin_centers, areas
|
|
164
|
+
else:
|
|
165
|
+
return hist, bin_edges, bin_centers
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
def histogram_featurewise(Track, variable=None, bin_edges=None, density=False):
|
|
169
|
+
"""Create a histogram of a variable from the features
|
|
170
|
+
(detected objects at a single time step) of a track.
|
|
171
|
+
Essentially a wrapper of the numpy.histogram() method.
|
|
172
|
+
|
|
173
|
+
Parameters
|
|
174
|
+
----------
|
|
175
|
+
Track : pandas.DataFrame
|
|
176
|
+
The track containing the variable to create the
|
|
177
|
+
histogram from.
|
|
178
|
+
|
|
179
|
+
variable : string, optional
|
|
180
|
+
Column of the DataFrame with the variable on which the
|
|
181
|
+
histogram is to be based on. Default is None.
|
|
182
|
+
|
|
183
|
+
bin_edges : int or ndarray, optional
|
|
184
|
+
If bin_edges is an int, it defines the number of
|
|
185
|
+
equal-width bins in the given range. If bins is
|
|
186
|
+
a sequence, it defines a monotonically increasing
|
|
187
|
+
array of bin edges, including the rightmost edge.
|
|
188
|
+
|
|
189
|
+
density : bool, optional
|
|
190
|
+
If False, the result will contain the number of
|
|
191
|
+
samples in each bin. If True, the result is the
|
|
192
|
+
value of the probability density function at the
|
|
193
|
+
bin, normalized such that the integral over the
|
|
194
|
+
range is 1. Default is False.
|
|
195
|
+
|
|
196
|
+
Returns
|
|
197
|
+
-------
|
|
198
|
+
hist : ndarray
|
|
199
|
+
The values of the histogram
|
|
200
|
+
|
|
201
|
+
bin_edges : ndarray
|
|
202
|
+
The edges of the histogram
|
|
203
|
+
|
|
204
|
+
bin_centers : ndarray
|
|
205
|
+
The centers of the histogram intervalls
|
|
206
|
+
|
|
207
|
+
"""
|
|
208
|
+
|
|
209
|
+
hist, bin_edges = np.histogram(Track[variable].values, bin_edges, density=density)
|
|
210
|
+
bin_centers = bin_edges[:-1] + 0.5 * np.diff(bin_edges)
|
|
211
|
+
|
|
212
|
+
return hist, bin_edges, bin_centers
|