Найди меня sh точек внутри контура - PullRequest
0 голосов
/ 28 марта 2020

Я хочу знать, сколько точек сетки в каждом замкнутом контуре.

enter image description here

предположим, что я sh сетка. У меня есть список точек, которые образуют замкнутые (связанные) контуры.

Я хочу знать, сколько точек сетки в замкнутых контурах отдельно?

import numpy as np
import matplotlib.pyplot as plt
import xarray as xr
import math
#calculate area 
def area(vs):
    a = 0
    x0, y0 = vs[0]
    for [x1, y1] in vs[1:]:
        dx = (x1 - x0) * 119.19
        dy = (y1 - y0) * 103.09
        a += 0.5 * (y0 * dx - x0 * dy)
        x0 = x1
        y0 = y1
    return a
# Read data
ds1 = xr.open_dataset('2015.nc')
lons = ds1.variables['lon'][:]
lats = ds1.variables['lat'][:]
times = ds1.variables['time'][:]
surf_els = ds1.variables['surf_el'][:]
lon = np.asarray(lons)
lat = np.asarray(lats)
time = np.asarray(times)
surf_el = np.asarray(surf_els)
ds1.close()
surf_el_mean = np.nanmean(surf_el[0])
surf_el[0] = (surf_el[0]) - surf_el_mean
#contour level -35/1000
cs = plt.contour(lon, lat, surf_el[0], [-35/1000],colors='r')
#extract path or contours level -35/1000
p = cs.collections[0].get_paths()[0]
v = p.vertices
x = v[:, 0]
y = v[:, 1]
vs = p.vertices
print(p)
plt.show()
#All of p are not closed.Closed contour important for me. but i don't know #how many points inside a closed contour? this problem is similar Pick's #theorem in math.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...