dartobsgen.polygon_from_netcdf_mask#

dartobsgen.polygon_from_netcdf_mask(nc_file, mask_var, lat_var, lon_var)[source]#

Extract the boundary of a 2D 0/1 mask and return a shapely Polygon.

Contours the mask at level 0.5 using skimage.measure.find_contours. If multiple contours are found the one with the most vertices is used (i.e. the largest boundary).

Parameters:
  • nc_file (str) – Path to the NetCDF file.

  • mask_var (str) – Name of the 2D mask variable (0 = outside, 1 = inside).

  • lat_var (str) – Name of the latitude coordinate variable (1D or 2D).

  • lon_var (str) – Name of the longitude coordinate variable (1D or 2D).

Return type:

shapely.geometry.Polygon

Raises:

ValueError – If no contour is found in the mask.