|
14 | 14 | from pyinterpolate.semivariogram.experimental.functions.semivariance import \ |
15 | 15 | semivariance_fn |
16 | 16 | from pyinterpolate.semivariogram.lags.lags import get_lags |
| 17 | +from semivariogram.experimental.functions.directional import \ |
| 18 | + from_ellipse_weighted_cloud |
| 19 | +from semivariogram.experimental.functions.general import \ |
| 20 | + omnidirectional_weighted_semivariogram_cloud |
17 | 21 |
|
18 | 22 |
|
19 | 23 | def calculate_semivariance(ds: Union[np.ndarray, VariogramPoints], |
@@ -296,6 +300,77 @@ def directional_semivariance_cloud(points: np.ndarray, |
296 | 300 | return output_semivariances |
297 | 301 |
|
298 | 302 |
|
| 303 | +def directional_weighted_semivariance_cloud(points: np.ndarray, |
| 304 | + lags: Union[List, np.ndarray], |
| 305 | + custom_weights: np.ndarray, |
| 306 | + direction: float, |
| 307 | + tolerance: float, |
| 308 | + method: str) -> Dict: |
| 309 | + """ |
| 310 | + Function calculates directional semivariances. |
| 311 | +
|
| 312 | + Parameters |
| 313 | + ---------- |
| 314 | + points : numpy array |
| 315 | + ``[x, y, value]`` |
| 316 | +
|
| 317 | + lags : numpy array |
| 318 | +
|
| 319 | + custom_weights : numpy array |
| 320 | +
|
| 321 | + direction : float, optional |
| 322 | + Direction of semivariogram, values from 0 to 360 degrees: |
| 323 | +
|
| 324 | + - 0 or 180: is E-W, |
| 325 | + - 90 or 270 is N-S, |
| 326 | + - 45 or 225 is NE-SW, |
| 327 | + - 135 or 315 is NW-SE. |
| 328 | +
|
| 329 | + tolerance : float, optional |
| 330 | + If ``tolerance`` is 0 then points must be placed at a single line with |
| 331 | + the beginning in the origin of the coordinate system and the |
| 332 | + direction given by y axis and direction parameter. |
| 333 | + If ``tolerance`` is ``> 0`` then the bin is selected as an elliptical |
| 334 | + area with major axis pointed in the same direction as the line for |
| 335 | + ``0`` tolerance. |
| 336 | +
|
| 337 | + * The major axis size == ``step_size``. |
| 338 | + * The minor axis size is ``tolerance * step_size`` |
| 339 | + * The baseline point is at a center of the ellipse. |
| 340 | + * The ``tolerance == 1`` creates an omnidirectional semivariogram. |
| 341 | +
|
| 342 | + method : str |
| 343 | + Neighbors selection in a given direction. Available methods: |
| 344 | +
|
| 345 | + * "triangle" or "t", default method where point neighbors are |
| 346 | + selected from a triangular area, |
| 347 | + * "ellipse" or "e", more accurate method but also slower. |
| 348 | +
|
| 349 | + Returns |
| 350 | + ------- |
| 351 | + : Dict |
| 352 | + ``{lag: [semivariances]}`` |
| 353 | + """ |
| 354 | + output_semivariances = dict() |
| 355 | + |
| 356 | + if method == "e" or method == "ellipse": |
| 357 | + output_semivariances = from_ellipse_weighted_cloud( |
| 358 | + points, |
| 359 | + lags, |
| 360 | + custom_weights, |
| 361 | + direction, |
| 362 | + tolerance) |
| 363 | + elif method == "t" or method == "triangle": |
| 364 | + output_semivariances = from_triangle_cloud( |
| 365 | + points=points, |
| 366 | + lags=lags, |
| 367 | + direction=direction, |
| 368 | + tolerance=tolerance |
| 369 | + ) |
| 370 | + |
| 371 | + return output_semivariances |
| 372 | + |
| 373 | + |
299 | 374 | def directional_semivariance(points: np.ndarray, |
300 | 375 | lags: Union[List, np.ndarray], |
301 | 376 | direction: float, |
@@ -352,7 +427,7 @@ def directional_semivariance(points: np.ndarray, |
352 | 427 |
|
353 | 428 | if custom_weights is None: |
354 | 429 | if (dir_neighbor_selection_method == "e" or |
355 | | - dir_neighbor_selection_method == "ellipse"): |
| 430 | + dir_neighbor_selection_method == "ellipse"): |
356 | 431 | output_semivariances = from_ellipse( |
357 | 432 | semivariance_fn, |
358 | 433 | points, |
@@ -408,13 +483,16 @@ def omnidirectional_semivariance(points: np.ndarray, |
408 | 483 | else: |
409 | 484 |
|
410 | 485 | if custom_weights is not None: |
411 | | - # todo warning message - custom_weights not included |
412 | | - pass |
413 | | - |
414 | | - sorted_semivariances = omnidirectional_semivariogram_cloud( |
415 | | - points=points, |
416 | | - lags=lags |
417 | | - ) |
| 486 | + sorted_semivariances = omnidirectional_weighted_semivariogram_cloud( |
| 487 | + points=points, |
| 488 | + lags=lags, |
| 489 | + custom_weights=custom_weights |
| 490 | + ) |
| 491 | + else: |
| 492 | + sorted_semivariances = omnidirectional_semivariogram_cloud( |
| 493 | + points=points, |
| 494 | + lags=lags |
| 495 | + ) |
418 | 496 |
|
419 | 497 | return sorted_semivariances |
420 | 498 |
|
@@ -592,16 +670,22 @@ def point_cloud_semivariance(ds: Union[np.ndarray, VariogramPoints], |
592 | 670 | if direction is not None and tolerance is not None: |
593 | 671 |
|
594 | 672 | if custom_weights is not None: |
595 | | - # todo warning message - custom_weights not included |
596 | | - pass |
597 | | - |
598 | | - experimental_semivariances = directional_semivariance_cloud( |
599 | | - ds.points, |
600 | | - lags, |
601 | | - direction, |
602 | | - tolerance, |
603 | | - dir_neighbors_selection_method |
604 | | - ) |
| 673 | + experimental_semivariances = directional_weighted_semivariance_cloud( |
| 674 | + ds.points, |
| 675 | + lags, |
| 676 | + custom_weights, |
| 677 | + direction, |
| 678 | + tolerance, |
| 679 | + dir_neighbors_selection_method |
| 680 | + ) |
| 681 | + else: |
| 682 | + experimental_semivariances = directional_semivariance_cloud( |
| 683 | + ds.points, |
| 684 | + lags, |
| 685 | + direction, |
| 686 | + tolerance, |
| 687 | + dir_neighbors_selection_method |
| 688 | + ) |
605 | 689 | else: |
606 | 690 | experimental_semivariances = omnidirectional_semivariance( |
607 | 691 | ds.points, lags, custom_weights, as_point_cloud=True |
|
0 commit comments