Skip to content

Commit 80624d2

Browse files
committed
Get obs in a list of polygons
1 parent 3b3d4b5 commit 80624d2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/py_eddy_tracker/observations/observation.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,26 @@ def set_global_attr_netcdf(self, h_nc):
16931693
for key, item in self.global_attr.items():
16941694
h_nc.setncattr(key, item)
16951695

1696+
def mask_from_polygons(self, polygons):
1697+
"""
1698+
Return mask for all observation in one of polygons list
1699+
1700+
:param list((array,array)) polygons: list of x/y array which be used to identify observations
1701+
"""
1702+
x, y = polygons[0]
1703+
m = insidepoly(
1704+
self.longitude, self.latitude, x.reshape((1, -1)), y.reshape((1, -1))
1705+
)
1706+
for x, y in polygons[1:]:
1707+
m_ = ~m
1708+
m[m_] = insidepoly(
1709+
self.longitude[m_],
1710+
self.latitude[m_],
1711+
x.reshape((1, -1)),
1712+
y.reshape((1, -1)),
1713+
)
1714+
return m
1715+
16961716
def extract_with_area(self, area, **kwargs):
16971717
"""
16981718
Extract geographically with a bounding box.

0 commit comments

Comments
 (0)