rcatool.utils.polygons.mask_region

rcatool.utils.polygons.mask_region(xp, yp, area, data=None, iter_3d=None, cut_data=False)[source]

Routine to mask grid points outside a specified polygon.

Parameters:
  • xp (numpy arrays) – eastward and northward grid points respectively, normally lon/lat arrays.

  • yp (numpy arrays) – eastward and northward grid points respectively, normally lon/lat arrays.

  • area (string or list with tuples) – Either name of predefined region to extract (see reg_dict function for more info.), or a list with tuples defining a polygon; e.g. [(lon1, lat1), (lon2, lat2),…,(lonN, latN), (lon1, lat1)]. NB! First and last tuple must be the same, closing the polygon.

  • data (2D/3D numpy array, optional) – data matrix

  • iter_3d (int, optional) – If set, masking is performed along the zeroth dimension of array. Thus array must be 3D and have shape [iter_3d, y, x].

  • cut_data (boolean, optional) – If True, the data will be cut to a box that covers the input area, leaving one extra (masked) grid point beyond each limiting north/south/east/west grid point. This option will return not only masked and cut data but also cut lon/lat data as well as the box edges (as indices) in the x,y plane.

Returns:

  • mask_out (boolean array) – A 2D mask with True inside region of interest, False outside. Returned if data is None.

  • masked_data (2D/3D numpy array) – If data is passed to function, this is the returned masked data.

  • xp_cut/yp_cut (numpy arrays) – If cut_data is True, these arrays are the cut xp/yp arrays

  • reg_x_edges, reg_y_edges (tuples) – If cut_data is True, the tuples contain index of the edges of cropped region in x and y directions respectively.