:py:mod:`opendrift.readers.basereader.unstructured` =================================================== .. py:module:: opendrift.readers.basereader.unstructured Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: opendrift.readers.basereader.unstructured.UnstructuredReader Attributes ~~~~~~~~~~ .. autoapisummary:: opendrift.readers.basereader.unstructured.logger .. py:data:: logger .. py:class:: UnstructuredReader Bases: :py:obj:`opendrift.readers.basereader.variables.Variables` An unstructured reader. Data is gridded irregularily. The initial type of grid that this class supports are `triangular prisms `_. Unstructured in xy-coordinates, x and y is constant in z. z might be non-cartesian (e.g. sigma-levels). .. seealso:: :py:mod:`opendrift.readers` :class:`.structured.StructuredReader` .. py:attribute:: PARALLEL_WORKERS .. py:attribute:: boundary .. py:attribute:: x .. py:attribute:: y .. py:attribute:: node_variables .. py:attribute:: nodes_idx .. py:attribute:: xc .. py:attribute:: yc .. py:attribute:: face_variables .. py:attribute:: faces_idx .. py:method:: get_variables(variables, time=None, x=None, y=None, z=None) :abstractmethod: Obtain and return values of the requested variables at all positions (x, y, z) closest to given time. Returns: Dictionary with arrays of length len(time) with values at exact positions x, y and z. .. py:method:: _get_variables_interpolated_(variables, profiles, profiles_depth, time, reader_x, reader_y, z) This method _must_ be implemented by every reader. Usually by subclassing one of the reader types (e.g. :class:`structured.StructuredReader`). Arguments are in _native projection_ of reader. .. seealso: * :meth:`get_variables_interpolated_xy`. * :meth:`get_variables_interpolated`. .. py:method:: _build_boundary_polygon_(x, y) Build a polygon of the boundary of the mesh. Arguments: :param x: Array of node x position, lenght N :param y: Array of node y position, length N Returns: A `shapely.prepareped.prep` `shapely.Polygon`. The boundary of the mesh, ideally including holes in the mesh. Algorithms: .. note:: Try this alogrithm: https://stackoverflow.com/a/14109211/377927 Boundary edges (line between two nodes) are only referenced by a single triangle. 1. Find a starting edge segment: [v_start, v_next] (v is vertex or node) 2. Find another _unvisited_ edge segment [v_i, v_j] that has either v_i = v_next or v_j = v_next and add the one not equal to v_next to the polygon. 3. Reset v_next to the newly added point. Mark edge as visited. 4. Continue untill we reach v_start. The polygon has a rotation, but this should not matter for our purpose of checking the bounds. Note: In order to find holes in the polygon all points must be scanned. Approximate using the convex hull: An alternative simple approximation is to use the convex hull of the points, but this will miss points along the boundary which form a wedge in the boundary (as well as holes in the mesh). Holes in the mesh will often be covered by the landmask anyway, so they will usually not be a problem. .. py:method:: covers_positions(x, y, z=0) Check which points are within boundary of mesh. .. py:method:: _build_rtree_(x, y) Builds an R-tree of x, y .. py:method:: _build_ckdtree_(x, y) .. py:method:: __nearest_ckdtree__(idx, x, y) Return index of nearest point in cKDTree .. py:method:: __nearest_rtree__(idx, x, y) :staticmethod: Take array of points and get nearest point in rtree index. .. py:method:: _nearest_node_(x, y) Return nearest node (id) for x and y .. py:method:: _nearest_face_(xc, yc) Return nearest element or face (id) for xc and yc