|
28 | 28 |
|
29 | 29 | from .. import VAR_DESCR_inv
|
30 | 30 | from ..generic import build_index, cumsum_by_track, distance, split_line, wrap_longitude
|
31 |
| -from ..poly import create_vertice_from_2darray, polygon_overlap |
| 31 | +from ..poly import create_vertice_from_2darray, merge, polygon_overlap |
32 | 32 | from .observation import EddiesObservations
|
33 | 33 |
|
34 | 34 | logger = logging.getLogger("pet")
|
@@ -489,6 +489,43 @@ def extract_with_mask(
|
489 | 489 | new.track = id_translate[new.track]
|
490 | 490 | return new
|
491 | 491 |
|
| 492 | + def shape_polygon(self, intern=False): |
| 493 | + """ |
| 494 | + Get polygons which enclosed each track |
| 495 | +
|
| 496 | + :param bool intern: If True use speed contour instead of effective contour |
| 497 | + :rtype: list(array, array) |
| 498 | + """ |
| 499 | + xname, yname = self.intern(intern) |
| 500 | + return [merge(track[xname], track[yname]) for track in self.iter_track()] |
| 501 | + |
| 502 | + def display_shape(self, ax, ref=None, intern=False, **kwargs): |
| 503 | + """ |
| 504 | + This function will draw shape of each track |
| 505 | +
|
| 506 | + :param matplotlib.axes.Axes ax: ax where drawed |
| 507 | + :param float,int ref: if defined all coordinates will be wrapped with ref like west boundary |
| 508 | + :param bool intern: If True use speed contour instead of effective contour |
| 509 | + :param dict kwargs: keyword arguments for Axes.plot |
| 510 | + :return: matplotlib mappable |
| 511 | + """ |
| 512 | + if "label" in kwargs: |
| 513 | + kwargs["label"] = self.format_label(kwargs["label"]) |
| 514 | + if len(self) == 0: |
| 515 | + x, y = [], [] |
| 516 | + else: |
| 517 | + polygons = self.shape_polygon(intern) |
| 518 | + x, y = list(), list() |
| 519 | + for p_ in polygons: |
| 520 | + x.append((nan,)) |
| 521 | + y.append((nan,)) |
| 522 | + x.append(p_[0]) |
| 523 | + y.append(p_[1]) |
| 524 | + x, y = concatenate(x), concatenate(y) |
| 525 | + if ref is not None: |
| 526 | + x, y = wrap_longitude(x, y, ref, cut=True) |
| 527 | + return ax.plot(x, y, **kwargs) |
| 528 | + |
492 | 529 | def plot(self, ax, ref=None, **kwargs):
|
493 | 530 | """
|
494 | 531 | This function will draw path of each track
|
|
0 commit comments