:py:mod:`curviriver.smoothing`
==============================

.. py:module:: curviriver.smoothing

.. autoapi-nested-parse::

   Smoothing functions for LineString objects or a set of coordinates.

   This module is taken from the `pygeoutils` package, which is available at
   `HyRiver <https://docs.hyriver.io/>`__.

   ..
       !! processed by numpydoc !!


Module Contents
---------------

.. py:function:: interpolate_na(x, y, z, fill_value)

   
   Interpolate NaN values in ``z`` using B-spline interpolation.

   .. rubric:: Notes

   The input ``x``, ``y``, and ``z`` must be 1D arrays of the same size.

   :Parameters: * **x** (:class:`numpy.ndarray`) -- 1D arrays representing the X-coordinates of the points.
                * **y** (:class:`numpy.ndarray`) -- 1D arrays representing the Y-coordinates of the points.
                * **z** (:class:`numpy.ndarray`) -- 1D arrays representing the Z-coordinates of the points.
                * **fill_value** (:class:`float`) -- Value to use to fill NaNs at the beginning and end of the array.

   :returns: :class:`numpy.ndarray` -- The input array ``z`` with NaN values interpolated or filled.

   :raises ValueError:















   ..
       !! processed by numpydoc !!

.. py:function:: make_bspline(x, y, n_pts, k = 3)

   
   Create a B-spline curve from a set of points.

   :Parameters: * **x** (:class:`numpy.ndarray`) -- x-coordinates of the points.
                * **y** (:class:`numpy.ndarray`) -- y-coordinates of the points.
                * **n_pts** (:class:`int`) -- Number of points in the output spline curve.
                * **k** (:class:`int`, *optional*) -- Degree of the spline. Should be an odd number less than the number of
                  points and greater than 1. Default is 3.

   :returns: :class:`Spline` -- A Spline object with ``x``, ``y``, ``phi``, ``radius``, ``distance``,
             and ``line`` attributes. The ``line`` attribute returns the B-spline
             as a ``shapely.LineString``.















   ..
       !! processed by numpydoc !!

.. py:function:: smooth_linestring(line, crs, n_pts, degree = 3)

   
   Smooth a line using B-spline interpolation.

   :Parameters: * **line** (:class:`shapely.LineString`, :class:`shapely.MultiLineString`) -- Line to smooth. Note that if ``line`` is ``MultiLineString``
                  it will be merged into a single ``LineString``. If the merge
                  fails, an exception will be raised.
                * **crs** (:class:`int`, :class:`str`, or :class:`pyproj.CRS`) -- CRS of the input line. It must be a projected CRS.
                * **n_pts** (:class:`int`) -- Number of points in the output spline curve.
                * **degree** (:class:`int`, *optional*) -- Degree of the spline. Should be less than the number of points and
                  greater than 1. Default is 3.

   :returns: :class:`Spline` -- A :class:`Spline` object with ``x``, ``y``, ``phi``, ``radius``,
             ``distance``, and ``line`` attributes. The ``line`` attribute
             returns the B-spline as a shapely.LineString.

   .. rubric:: Examples

   >>> import geopandas as gpd
   >>> import shapely
   >>> line = shapely.LineString(
   ...     [
   ...         (-97.06138, 32.837),
   ...         (-97.06133, 32.836),
   ...         (-97.06124, 32.834),
   ...         (-97.06127, 32.832),
   ...     ]
   ... )
   >>> sp = smooth_linestring(line, 4326, 5)
   >>> list(zip(*sp.line.xy))
   [(-97.06138, 32.837),
   (-97.06132, 32.83575),
   (-97.06126, 32.83450),
   (-97.06123, 32.83325),
   (-97.06127, 32.83200)]















   ..
       !! processed by numpydoc !!

