Post Processing
Post-processing module.
Module containing some functions used in post-processing of the results.
is_regularly_spaced(array, tolerance=0.01, return_delta=True)
Determines whether an input array is regularly spaced, within some (absolute) tolerance.
Gets the large differences (defined by tolerance) in the array, and sees whether all of them are within 5% of one another.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
array
|
ndarray
|
Input array to be analysed. |
required |
tolerance
|
float
|
Absolute value above which the difference between values is considered significant. Defaults to 0.01. |
0.01
|
return_delta
|
bool
|
Whether to return the value of the regular grid spacing. Defaults to True. |
True
|
Returns:
| Type | Description |
|---|---|
bool
|
Whether the grid is regularly spaced. |
float
|
The value of the regular grid spacing. |
Source code in src/pyelq/support_functions/post_processing.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
calculate_rectangular_statistics(emission_rates, source_locations, bin_size_x=1, bin_size_y=1, burn_in=0, normalized_count_limit=0.005)
Function which aggregates the pyELQ results into rectangular bins and outputs the related summary statistics.
The function creates a pixel grid (binning) in East-North coordinates based on the bin_size_x and bin_size_y parameters. For each bin both a count as well as a weighted sum of the emission rate estimates is calculated. The count is normalized by the number of iterations used in the MCMC and a boolean array is created which indicates if the count is above a certain threshold. Connected pixels where the count is above this threshold are considered to be a single blob/source and emission estimates per blob are summed over all pixels in the blob. The function then calculates the summary statistics for each blob of estimates which are connected pixels. The summary statistics include the median and IQR of the emission rate estimates, the mean location of the blob and the likelihood of the blob.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
emission_rates
|
ndarray
|
and array of shape (number_of_sources, number_of_iterations) |
required |
source_locations
|
ENU
|
An object containing the east, north, and up coordinates of source locations, |
required |
bin_size_x
|
float
|
Size of the bins in the x-direction. Defaults to 1. |
1
|
bin_size_y
|
float
|
Size of the bins in the y-direction. Defaults to 1. |
1
|
burn_in
|
int
|
Number of burn-in iterations used in the MCMC. Defaults to 0. |
0
|
normalized_count_limit
|
float
|
Threshold for the normalized count to be considered a blob. |
0.005
|
Returns:
| Name | Type | Description |
|---|---|---|
result_weighted |
ndarray
|
Weighted sum of the emission rate estimates in each bin. |
overall_count |
ndarray
|
Count of the number of estimates in each bin. |
normalized_count |
ndarray
|
Normalized count of the number of estimates in each bin. |
count_boolean |
ndarray
|
Boolean array which indicates if likelihood of pixel is over threshold. |
edges_result |
list
|
Centers of the pixels in the x and y direction. |
summary_result |
DataFrame
|
Summary statistics for each blob of estimates. |
Source code in src/pyelq/support_functions/post_processing.py
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
create_lla_polygons_from_xy_points(points_array, ref_latitude, ref_longitude, ref_altitude, boolean_mask=None)
Function to create polygons in LLA coordinates from a grid of points in ENU coordinates.
This function takes a grid of East-North points, these points are used as center points for a pixel grid. The pixel grid is then converted to LLA coordinates and these center points are used to create a polygon in LLA coordinates. A polygon is only created if the boolean mask for that pixel is True. In case one unique East-North point is available, a predefined grid size of 1e-6 (equaling to 0.0036 seconds) is assumed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
points_array
|
list[ndarray]
|
List of arrays of grid of points in ENU coordinates. |
required |
ref_latitude
|
float
|
Reference latitude in degrees of ENU coordinate system. |
required |
ref_longitude
|
float
|
Reference longitude in degrees of ENU coordinate system. |
required |
ref_altitude
|
float
|
Reference altitude in meters of ENU coordinate system. |
required |
boolean_mask
|
ndarray
|
Boolean mask to indicate which pixels to create polygons for. Defaults to None which means all pixels are used. |
None
|
Returns:
| Type | Description |
|---|---|
list[Polygon]
|
list[geometry.Polygon]: List of polygons in LLA coordinates |
Source code in src/pyelq/support_functions/post_processing.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 | |
create_aggregation(result_x_vals, result_y_vals, result_z_vals, results_estimates, result_iteration_vals, count_boolean, x_edges, y_edges, nof_iterations, burn_in, ref_latitude, ref_longitude, ref_altitude)
Function to create the aggregated information for the blobs of estimates.
We identify all blobs of estimates which appear close together on the map by looking at connected pixels in the count_boolean array. Next we find the summary statistics for all estimates in that blob like overall median and IQR estimate, mean location and the likelihood of that blob.
When multiple sources are present in the same blob at the same iteration we first sum those emission rate estimates before taking the median.
If no blobs are found a dataframe with nan values is return to avoid breaking plotting code which calls this function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result_x_vals
|
ndarray
|
X-coordinate of estimates, flattened array of (n_sources_max * nof_iterations,). |
required |
result_y_vals
|
ndarray
|
Y-coordinate of estimates, flattened array of (n_sources_max * nof_iterations,). |
required |
result_z_vals
|
ndarray
|
Z-coordinate of estimates, flattened array of (n_sources_max * nof_iterations,). |
required |
results_estimates
|
ndarray
|
Emission rate estimates, flattened array of (n_sources_max * nof_iterations,). |
required |
result_iteration_vals
|
ndarray
|
Iteration number corresponding each estimated value, flattened array of (n_sources_max * nof_iterations,). |
required |
count_boolean
|
ndarray
|
Boolean array which indicates if likelihood of pixel is over threshold. |
required |
x_edges
|
ndarray
|
Pixel edges x-coordinates. |
required |
y_edges
|
ndarray
|
Pixel edges y-coordinates. |
required |
nof_iterations
|
int
|
Number of iterations used in MCMC. |
required |
burn_in
|
int
|
Burn-in used in MCMC. |
required |
ref_latitude
|
float
|
Reference latitude in degrees of ENU coordinate system. |
required |
ref_longitude
|
float
|
Reference longitude in degrees of ENU coordinate system. |
required |
ref_altitude
|
float
|
Reference altitude in meters of ENU coordinate system. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
summary_result |
DataFrame
|
Summary statistics for each blob of estimates. |
Source code in src/pyelq/support_functions/post_processing.py
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 | |
return_empty_summary_dataframe()
Helper function to create and return an empty summary dataframe with predifined columns.
Source code in src/pyelq/support_functions/post_processing.py
353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 | |