Repository: andersonreisoares/stmetrics (language: python)

Issue:
Dev
Preparing 0.1.7


Discussion / hints:

Fix patch:
diff --git a/docs/source/about.rst b/docs/source/about.rst
index bf6a5dd..c62f7a3 100644
--- a/docs/source/about.rst
+++ b/docs/source/about.rst
@@ -1,8 +1,8 @@
 About
 ======
 
-The stmetrics, is a python package that provides the extraction of state-of-the-art time-series features. These features can be used for remote sensing time-series image classification and analysis. 
+The **stmetrics** is a python package that provides the extraction of state-of-the-art time-series features. These features can be used for remote sensing time-series image classification and analysis. 
 
-Produce reliable land use and land cover maps to support the deployment and operation of public policies is a necessity, especially when environmental management and economic development are considered. To increase the accuracy of these maps, satellite image time-series have been used, as they allow the understanding of land cover dynamics through the time.
+Producing reliable land use and land cover maps to support the deployment and operation of public policies is a necessity, especially when environmental management and economic development are considered. To increase the accuracy of these maps, satellite image time-series (provided as Analysis Ready Data - ARD) have been used, as they allow the understanding of land cover dynamics through the time.
 
-This package is developed under the Brazil Data Cube project that is part of the “Environmental Monitoring of Brazilian Biomes project“, funded by the Amazon Fund through the financial collaboration of the Brazilian Development Bank (BNDES) and the Foundation for Science, Technology and Space Applications (FUNCATE) no. 17.2.0536.1. Brazil Data Cube is the successor of the research project e-sensing, funded by FAPESP (Fapesp 2014/08398-6). 
\ No newline at end of file
+This package is developed under the Brazil Data Cube project that is part of the “Environmental Monitoring of Brazilian Biomes project“, funded by the Amazon Fund through the financial collaboration of the Brazilian Development Bank (BNDES) and the Foundation for Science, Technology and Space Applications (FUNCATE) no. 17.2.0536.1. Brazil Data Cube is the successor of the research project e-sensing, funded by FAPESP (Fapesp 2014/08398-6). 
diff --git a/docs/source/basics.rst b/docs/source/basics.rst
index 3ebe628..5390d5d 100644
--- a/docs/source/basics.rst
+++ b/docs/source/basics.rst
@@ -1,7 +1,7 @@
 Basic metrics
 =============
 
-Module for computing basic metrics
+Module for computing basic metrics, including sum of values, average value, amplitude (max - min), and so on. We provide a function to compute all metrics in a single call (``ts_basics``).
 
 .. automodule:: stmetrics.basics
-	:members:
\ No newline at end of file
+	:members:
diff --git a/docs/source/dependencies.rst b/docs/source/dependencies.rst
index 21a51dd..7899c82 100644
--- a/docs/source/dependencies.rst
+++ b/docs/source/dependencies.rst
@@ -1,4 +1,4 @@
-.. _depend-opt:
+.. _depend-ref:
 
 Dependencies
 =============
diff --git a/docs/source/examples/Benchmark.ipynb b/docs/source/examples/Benchmark.ipynb
index 650ba0f..6ff4d09 100644
--- a/docs/source/examples/Benchmark.ipynb
+++ b/docs/source/examples/Benchmark.ipynb
@@ -20,7 +20,7 @@
    "source": [
     "Install stmetrics\n",
     "-----------------------\n",
-    "pip install git+https://github.com/andersonreisoares/stmetrics.git"
+    "!pip install git+https://github.com/brazil-data-cube/stmetrics.git"
    ]
   },
   {
diff --git a/docs/source/examples/TimeMetrics.ipynb b/docs/source/examples/TimeMetrics.ipynb
index a28d127..c7dc788 100644
--- a/docs/source/examples/TimeMetrics.ipynb
+++ b/docs/source/examples/TimeMetrics.ipynb
@@ -45,7 +45,7 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "!pip install E:\\dados_dos_usuarios_deste_servidor\\Anderson\\DataCube\\Python\\stmetrics --upgrade"
+    "!pip install git+https://github.com/brazil-data-cube/stmetrics.git"
    ]
   },
   {
diff --git a/docs/source/index.rst b/docs/source/index.rst
index 752cb70..add5883 100644
--- a/docs/source/index.rst
+++ b/docs/source/index.rst
@@ -15,7 +15,7 @@ Welcome to stmetrics's documentation!
    about.rst
    license.rst
    contributors.rst
-   citation.rst
+   publications.rst
 
 
 .. toctree::
@@ -52,4 +52,17 @@ Welcome to stmetrics's documentation!
 
 .. Note::
    This documentation is not finished. Parts of the description are \
-   incomplete and/or incorrect. Please, come back later for the definitive documentation.
\ No newline at end of file
+   incomplete and may need corrections. Please, come back later for \
+   the definitive documentation.
+
+**stmetrics** is a python package that aims at making the process of feature \
+extraction of state-of-the-art time-series as simple as possible.
+
+It provides functions to support time-series analyzes that includes not only \
+the feature extraction but also spatio-temporal analysis through a \
+spatio-temporal segmentation and filtering approaches that are a first step \
+to the full exploitation of the spatio-temporal information.
+
+The documentation presented here summarize the technical aspects of the \
+package. The methodoogical application of the package and it's methods are \
+available at the :ref:`publications-ref` section.
\ No newline at end of file
diff --git a/docs/source/installation.rst b/docs/source/installation.rst
index 86cf723..34b682c 100644
--- a/docs/source/installation.rst
+++ b/docs/source/installation.rst
@@ -1,7 +1,7 @@
 Installation
 ==============
 
-**stmetrics** is mostly written in python, however, due to the spatial-temporal segmentation algorithm available it requires C++ compiler. Please, prior to install, check the required dependecies at :ref:`depend-opt`. Configuring this compiler is the critical step in getting the spatial-temporal algorithm running. 
+**stmetrics** is mostly written in python, however, due to the spatial-temporal segmentation algorithm available it requires C++ compiler. Please, prior to install, check the required dependecies at :ref:`depend-ref`. Configuring this compiler is the critical step in getting the spatial-temporal algorithm running. 
 
 ---------------------
  stmetrics on Windows
diff --git a/docs/source/metrics.rst b/docs/source/metrics.rst
index c91f3a6..333d796 100644
--- a/docs/source/metrics.rst
+++ b/docs/source/metrics.rst
@@ -1,7 +1,7 @@
-Metric module
-=============
+Metrics module
+==============
 
 Module for computing metrics
 
 .. automodule:: stmetrics.metrics
-	:members:
\ No newline at end of file
+	:members:
diff --git a/docs/source/polar.rst b/docs/source/polar.rst
index 19d695d..1658e0e 100644
--- a/docs/source/polar.rst
+++ b/docs/source/polar.rst
@@ -1,7 +1,7 @@
 Polar metrics
 =============
 
-Module for computing polar metrics
+Module for computing polar metrics, that are derived from a time wheel legend, projecting the values of a timeseries to angles in the interval ``[0, 2pi]``. 
 
 .. automodule:: stmetrics.polar
-	:members:
\ No newline at end of file
+	:members:
diff --git a/docs/source/citation.rst b/docs/source/publications.rst
similarity index 95%
rename from docs/source/citation.rst
rename to docs/source/publications.rst
index 998a288..1eab7ec 100644
--- a/docs/source/citation.rst
+++ b/docs/source/publications.rst
@@ -1,5 +1,7 @@
-Citation and References
-=======================
+.. _publications-ref:
+
+Publications
+============
 
 Soares, A. R., Bendini, H. N., Vaz, D. V., Uehara, T. D., Neves, A. K., Lechler, S., Körting, T. S., Fonseca, L. M. G. `STMETRICS: A PYTHON PACKAGE FOR SATELLITE IMAGE TIME-SERIES FEATURE EXTRACTION. <http://brazildatacube.org/wp-content/uploads/2020/06/202008_IGARSS-2020_STMETRICS_Soares-etal.pdf>`_ Conference: 2020 IEEE International Geoscience and Remote Sensing Symposium (IGARSS 2020).
 
diff --git a/docs/source/spatial.rst b/docs/source/spatial.rst
index 5553ac8..8da8672 100644
--- a/docs/source/spatial.rst
+++ b/docs/source/spatial.rst
@@ -1,7 +1,7 @@
 Spatial Module
 ===============
 
-Module for spatial functions
+Module for spatial functions, considering a set of polygons obtained by image segmentation.
 
 .. automodule:: stmetrics.spatial
-	:members:
\ No newline at end of file
+	:members:
diff --git a/docs/source/utils.rst b/docs/source/utils.rst
index 6454e49..087fea1 100644
--- a/docs/source/utils.rst
+++ b/docs/source/utils.rst
@@ -1,7 +1,7 @@
 Utility functions
 =================
 
-Utility module for tsmetrics
+Utility module for stmetrics
 
 .. automodule:: stmetrics.utils
-	:members:
\ No newline at end of file
+	:members:
diff --git a/stmetrics/basics.py b/stmetrics/basics.py
index cf0f018..6c6ddde 100644
--- a/stmetrics/basics.py
+++ b/stmetrics/basics.py
@@ -3,23 +3,37 @@
 
 
 def ts_basics(timeseries, funcs=["all"], nodata=-9999):
-    """This function compute 7 basic metrics:
+    """This function compute all basic metrics in a single call, returning a dictionary:
         - "Max" - Maximum value of the time series.
+
         - "Min" - Minimum value of the time series.
+
         - "Mean" - Average value of the time series.
+
         - "Std" - Standard deviation of the time series.
+
         - "Sum" - Sum of values over a cycle. Usually is an indicator of the \
             annual production of vegetation.
+
         - "Amplitude" - The difference between the time series’s maximum and \
             minimum values.
+
         - "MSE" - Mean Spectral Energy.
+
         - "First_slope" - Maximum value of the first slope of the cycle.
+
         - "Skew" - Measures the asymmetry of the time series.
+
         - "AMD" - Absolute mean derivative (AMD).
+
         - "AbsSum" - Absolute Sum of values over of the time series.
+
         - "IQR" - Interquaritle range (IQR) of the time series.
+
         - "FQR" - First quartile of the time series.
+        
         - "SQR" - Second quartile of the time series.
+
         - "TQR" - Third quaritle of the time series.
 
     :param timeseries: Time series.
@@ -64,7 +78,8 @@ def ts_basics(timeseries, funcs=["all"], nodata=-9999):
 
 
 def mean_ts(timeseries, nodata=-9999):
-    """Average value of the time series.
+    """Average value (mean) of the time series, considering only valid \
+    values. When nodata is found, it is not included in N value (for all functions). 
 
     :param timeseries: Time series.
     :type timeseries: numpy.ndarray
@@ -131,7 +146,8 @@ def std_ts(timeseries, nodata=-9999):
 def sum_ts(timeseries, nodata=-9999):
     """Sum of values of the time series.
 
-    Usually is an indicator of the annual production of vegetation.
+    When dealing with vegetation analysis, this value \
+    can be a proxy of the annual production of vegetation.
 
     :param timeseries: Time series.
     :type timeseries: numpy.ndarray
@@ -183,7 +199,8 @@ def fslope_ts(timeseries, nodata=-9999):
 
 
 def abs_sum_ts(timeseries, nodata=-9999):
-    """Absolute Sum of values of the time series.
+    """Sum of absolute values of the time series. All values are \
+    converted to absolute (positive) values, and are summed.
 
     :param timeseries: Time series.
     :type timeseries: numpy.ndarray
@@ -191,7 +208,7 @@ def abs_sum_ts(timeseries, nodata=-9999):
     :param nodata: nodata of the time series. Default is -9999.
     :type nodata: int
 
-    :returns: Sum of absolute values of time series.
+    :returns: Sum of absolute values of the time series.
     """
 
     ts = fixseries(timeseries, nodata)
@@ -229,7 +246,7 @@ def amd_ts(timeseries, nodata=-9999):
     :param nodata: nodata of the time series. Default is -9999.
     :type nodata: int
 
-    :returns: The absolute mean derivative of time series.
+    :returns: The mean of the absolute derivative of time series.
     """
     ts = fixseries(timeseries, nodata)
 
@@ -239,8 +256,8 @@ def amd_ts(timeseries, nodata=-9999):
 def mse_ts(timeseries, nodata=-9999):
     """Computes mean spectral energy of a time series.
 
-    Mean Energy spectral density computesthe energy of the time series that \
-    is distributed with frequency. High frequencies time series usually \
+    Mean spectral energy density computes the energy of the time series that \
+    is distributed with frequency. High frequency time series usually \
     have lower spectral energy.
 
     :param timeseries: Time series.
@@ -249,7 +266,7 @@ def mse_ts(timeseries, nodata=-9999):
     :param nodata: nodata of the time series. Default is -9999.
     :type nodata: int
 
-    :returns: The absolute mean derivative of time series.
+    :returns: The mean spectral energy of the time series.
     """
 
     ts = fixseries(timeseries, nodata)
@@ -266,7 +283,7 @@ def fqr_ts(timeseries, nodata=-9999):
     :param nodata: nodata of the time series. Default is -9999.
     :type nodata: int
 
-    :returns: The absolute mean derivative of time series.
+    :returns: The first quartile of the time series.
     """
 
     ts = fixseries(timeseries, nodata)
@@ -275,7 +292,7 @@ def fqr_ts(timeseries, nodata=-9999):
 
 
 def tqr_ts(timeseries, nodata=-9999):
-    """Computes the third quartileof a time series.
+    """Computes the third quartile of a time series.
 
     :param timeseries: Time series.
     :type timeseries: numpy.ndarray
@@ -283,7 +300,7 @@ def tqr_ts(timeseries, nodata=-9999):
     :param nodata: nodata of the time series. Default is -9999.
     :type nodata: int
 
-    :returns: The absolute mean derivative of time series.
+    :returns: The third quartile of the time series.
     """
 
     ts = fixseries(timeseries, nodata)
@@ -292,7 +309,7 @@ def tqr_ts(timeseries, nodata=-9999):
 
 
 def sqr_ts(timeseries, nodata=-9999):
-    """Computes the second quartile the time series.
+    """Computes the second quartile of the time series.
 
     :param timeseries: Time series.
     :type timeseries: numpy.ndarray
@@ -300,7 +317,7 @@ def sqr_ts(timeseries, nodata=-9999):
     :param nodata: nodata of the time series. Default is -9999.
     :type nodata: int
 
-    :returns: The interquaritle range of the time series.
+    :returns: The second quartile of the time series.
 
     """
     ts = fixseries(timeseries, nodata)
diff --git a/stmetrics/fractal.py b/stmetrics/fractal.py
index caab345..05fc350 100644
--- a/stmetrics/fractal.py
+++ b/stmetrics/fractal.py
@@ -3,12 +3,14 @@
 
 
 def ts_fractal(timeseries, funcs=['all'], nodata=-9999):
-    """This function compute 4 fractal dimensions and the hurst exponential.
+    """This function computes 4 fractal dimensions and the hurst exponential.
 
         - DFA: measures the Hurst parameter H, which is similar to the \
         Hurst exponent.
+
         - HE: self-similarity measure that assess long-range dependence in a \
         time series.
+        
         - KFD: This algorirhm computes the FD using Katz algorithm.
 
     :param timeseries: Time series.
@@ -39,7 +41,7 @@ def ts_fractal(timeseries, funcs=['all'], nodata=-9999):
 
 def dfa_fd(timeseries, nvals=None,  overlap=True, order=1, nodata=-9999):
     """Detrended Fluctuation Analysis (DFA) measures the Hurst \
-    parameter H, which is very similar to the Hurst exponent.
+    parameter H, which is very similar to the Hurst Exponent (HE).
     The main difference is that DFA can be used for non-stationary \
     time series.
 
@@ -49,7 +51,7 @@ def dfa_fd(timeseries, nvals=None,  overlap=True, order=1, nodata=-9999):
     :param nvals: Sizes of subseries to use.
     :type nvals: int
 
-    :param overlap: if True, there will be a 50% overlap on windows\
+    :param overlap: if True, there will be a 50% overlap on windows \
     otherwise non-overlapping windows will be used.
     :type overlap: Boolean
 
@@ -63,10 +65,11 @@ def dfa_fd(timeseries, nvals=None,  overlap=True, order=1, nodata=-9999):
 
     .. Note::
 
-        This functions uses the dfa implementation from the Nolds package.
-        Due to time series carachteristcs we use by default the 'RANSAC' \
+        This function uses the Detrended Fluctuation Analysis (DFA) \
+        implementation from the Nolds package. Due to time series \
+        characteristcs we use by default the 'RANSAC' \
         fitting method as it is more robust to outliers.
-        For more details regarding the hurst implementation, check nolds \
+        For more details regarding the hurst implementation, check Nolds \
         documentation page.
 
     """
@@ -78,28 +81,31 @@ def dfa_fd(timeseries, nvals=None,  overlap=True, order=1, nodata=-9999):
 
 
 def hurst_exp(timeseries, nvals=None, nodata=-9999):
-    """Computes the H exponent by a standard \
+    """Computes the Hurst Exponent (HE) by a standard \
     rescaled range (R/S) approach.
-    Hurst exponent is a self-similarity measure that assess long-range \
+    HE is a self-similarity measure that assesses long-range \
     dependence in a time series. It can be used to determine whether the \
     time series is more, less, or equally likely to increase if it has \
     increased in previous steps.
 
     :param timeseries: Time series.
     :type timeseries: numpy.ndarray
+    
     :param nvals: Sizes of subseries to use.
     :type nvals: int
+    
     :param nodata: nodata of the time series. Default is -9999.
     :type nodata: int
 
-    :return hurst: Hurst expoent.
+    :return hurst: The Hurst Expoent (HE).
 
     .. Note::
 
-        This function was adapted from the package Nolds.
-        Due to time series carachteristcs we use by default the 'RANSAC' \
+        This function was adapted from the package Nolds. Due to time series \
+        characteristcs we use by default the 'RANSAC' \
         fitting method as it is more robust to outliers.
-        For more details regarding the hurst implementation.
+        For more details regarding the hurst implementation, check Nolds \
+        documentation page.
     """
     import nolds
     ts = fixseries(timeseries, nodata)
@@ -113,12 +119,13 @@ def katz_fd(timeseries, nodata=-9999):
     It is defined by:
     .. math:: K = \\frac{\\log_{10}(n)}{\\log_{10}(d/L)+\\log_{10}(n)}
     where :math:`L` is the total length of the time series and :math:`d` \
-    is the Euclidean distancebetween the first point in the series and \
+    is the Euclidean distance between the first point in the series and \
     the point that provides the furthest distance with respect to \
     the first point.
 
     :param timeseries: Time series.
     :type timeseries: numpy.ndarray
+    
     :param nodata: nodata of the time series. Default is -9999.
     :type nodata: int
 
diff --git a/stmetrics/metrics.py b/stmetrics/metrics.py
index 07e158d..38fb841 100644
--- a/stmetrics/metrics.py
+++ b/stmetrics/metrics.py
@@ -8,7 +8,7 @@
 
 
 def get_metrics(series, metrics_dict=METRICS_DICT, nodata=-9999, show=False):
-    """This function perform the computation of the \
+    """This function performs the computation of the \
     basic, polar and fractal metrics available in the stmetrics package.
 
     :param timeseries: Time series.
diff --git a/stmetrics/spatial.py b/stmetrics/spatial.py
index d8438e4..512437f 100644
--- a/stmetrics/spatial.py
+++ b/stmetrics/spatial.py
@@ -4,8 +4,9 @@
 from numba import njit, prange
 
 
-def snitc(dataset, ki, m, scale=10000, iter=10, pattern="hexagonal",
-          output="shp"):
+def snitc(dataset, ki, m, nodata=0, scale=10000, iter=10, pattern="hexagonal",
+          output="shp", window=None, max_dist=None, max_step=None, 
+          max_diff=None, penalty=None, psi=None, pruning=False):
     """This function create spatial-temporal superpixels using a Satellite \
     Image Time Series (SITS). Version 1.4
 
@@ -15,6 +16,14 @@ def snitc(dataset, ki, m, scale=10000, iter=10, pattern="hexagonal",
     :param k: Number or desired superpixels.
     :type k: int
 
+    :param m: Compactness value. Bigger values led to regular superpixels.
+    :type m: int
+
+    :param nodata: If you dataset contain nodata, it will be replace by \
+    this value. This value is necessary to be possible the use the \
+    DTW distance. Ideally your dataset must not contain nodata.
+    :type nodata: float
+
     :param scale: Adjust the time series, to 0-1. Necessary to distance \
     calculation.
     :type scale: int
@@ -29,6 +38,22 @@ def snitc(dataset, ki, m, scale=10000, iter=10, pattern="hexagonal",
     :param output: Type of output to be produced. Default is shp (Shapefile).
     :type output: string
 
+    :param window: Only allow for maximal shifts from the two diagonals \
+    smaller than this number. It includes the diagonal, meaning that an \
+    Euclidean distance is obtained by setting window=1.
+
+    :param max_dist: Stop if the returned values will be larger than \
+    this value.
+
+    :param max_step: Do not allow steps larger than this value.
+
+    :param max_diff: Return infinity if length of two series is larger.
+
+    :param penalty: Penalty to add if compression or expansion is applied.
+
+    :param psi: Psi relaxation parameter (ignore start and end of matching). \
+    Useful for cyclical series.
+
     :returns segmentation: Shapefile containing superpixels produced.
 
     ..Note::
@@ -54,7 +79,7 @@ def snitc(dataset, ki, m, scale=10000, iter=10, pattern="hexagonal",
             # READ FILE
             transform = dataset.transform
             crs = dataset.crs
-            img = numpy.squeeze(dataset.values).astype(float)
+            img = numpy.squeeze(dataset.values)
         except:
             Exception('Sorry we could not read your dataset.')
     else:
@@ -63,7 +88,7 @@ def snitc(dataset, ki, m, scale=10000, iter=10, pattern="hexagonal",
 
     # Normalize data
     for band in range(img.shape[0]):
-        img[numpy.isnan(img)] = 0
+        img[numpy.isnan(img)] = nodata
         img[band, :, :] = (img[band, :, :])/scale
 
     # Get image dimensions
@@ -102,10 +127,17 @@ def snitc(dataset, ki, m, scale=10000, iter=10, pattern="hexagonal",
 
             # Calculate Spatio-temporal distance
             try:
-                D = distance_fast(c_series, ic, jc, subim, S, m, rmin, cmin)
+                D = distance_fast(c_series, ic, jc, subim, S, m, rmin, cmin, 
+                                  window=window, max_dist=max_dist,
+                                  max_step=max_step, 
+                                  max_diff=max_diff,
+                                  penalty=penalty, psi=psi)
             except:
                 print('dtaidistance package is not properly installed.')
-                D = distance(C[kk, :], subim, S, m, rmin, cmin)  # DTW regular
+                D = distance(C[kk, :], subim, S, m, rmin, cmin,
+                             window=window, max_dist=max_dist,
+                             max_step=max_step, max_diff=max_diff,
+                             penalty=penalty, psi=psi)  # DTW regular
 
             subd = d[rmin:rmax, cmin:cmax]
             subl = l[rmin:rmax, cmin:cmax]
@@ -132,26 +164,28 @@ def snitc(dataset, ki, m, scale=10000, iter=10, pattern="hexagonal",
         return labelled
 
 
-def distance_fast(c_series, ic, jc, subim, S, m, rmin, cmin):
+def distance_fast(c_series, ic, jc, subim, S, m, rmin, cmin,  
+                  window=None, max_dist=None, max_step=None, 
+                  max_diff=None, penalty=None, psi=None):
     """This function computes the spatial-temporal distance between \
     two pixels using the dtw distance with C implementation.
 
-    :param c_series: average time series of cluster
+    :param c_series: average time series of cluster.
     :type c_series: numpy.ndarray
 
-    :param ic: X coordinate of cluster center
+    :param ic: X coordinate of cluster center.
     :type ic: int
 
-    :param jc: Y coordinate of cluster center
+    :param jc: Y coordinate of cluster center.
     :type jc: int
 
-    :param subim: Block of image from the cluster under analysis .
+    :param subim: Block of image from the cluster under analysis.
     :type subim: int
 
     :param S: Pattern spacing value.
     :type S: int
 
-    :param m: Compactness value
+    :param m: Compactness value.
     :type m: float
 
     :param rmin: Minimum row.
@@ -160,6 +194,22 @@ def distance_fast(c_series, ic, jc, subim, S, m, rmin, cmin):
     :param cmin: Minimum column.
     :type cmin: int
 
+    :param window: Only allow for maximal shifts from the two diagonals \
+    smaller than this number. It includes the diagonal, meaning that an \
+    Euclidean distance is obtained by setting window=1.
+
+    :param max_dist: Stop if the returned values will be larger than \
+    this value.
+
+    :param max_step: Do not allow steps larger than this value.
+
+    :param max_diff: Return infinity if length of two series is larger.
+
+    :param penalty: Penalty to add if compression or expansion is applied.
+
+    :param psi: Psi relaxation parameter (ignore start and end of matching).
+        Useful for cyclical series.
+
     :returns D:  numpy.ndarray distance.
     """
     from dtaidistance import dtw
@@ -173,12 +223,15 @@ def distance_fast(c_series, ic, jc, subim, S, m, rmin, cmin):
     # Tranpose matrix to allow dtw fast computation with dtaidistance
     linear = subim.transpose(1, 2, 0).reshape(subim.shape[1]*subim.shape[2],
                                               subim.shape[0])
-    merge = numpy.vstack((linear, c_series))
+    merge = numpy.vstack((linear, c_series)).astype(numpy.double)
 
     # Compute dtw distances
     c = dtw.distance_matrix_fast(merge, block=((0, merge.shape[0]),
                                  (merge.shape[0] - 1, merge.shape[0])),
-                                 compact=True, parallel=True)
+                                 compact=True, parallel=True, window=window, 
+                                 max_dist=max_dist, max_step=max_step,
+                                 max_length_diff=max_diff, penalty=penalty,
+                                 psi=psi)
     c1 = numpy.frombuffer(c)
     dc = c1.reshape(subim.shape[1], subim.shape[2])
 
@@ -194,26 +247,28 @@ def distance_fast(c_series, ic, jc, subim, S, m, rmin, cmin):
     return D
 
 
-def distance(c_series, ic, jc, subim, S, m, rmin, cmin):
+def distance(c_series, ic, jc, subim, S, m, rmin, cmin,
+             window=None, max_dist=None, max_step=None, 
+             max_diff=None, penalty=None, psi=None, pruning=False):
     """This function computes the spatial-temporal distance between \
     two pixels using the DTW distance.
 
-    :param c_series: average time series of cluster
+    :param c_series: average time series of cluster.
     :type c_series: numpy.ndarray
 
-    :param ic: X coordinate of cluster center
+    :param ic: X coordinate of cluster center.
     :type ic: int
 
-    :param jc: Y coordinate of cluster center
+    :param jc: Y coordinate of cluster center.
     :type jc: int
 
-    :param subim: Block of image from the cluster under analysis .
+    :param subim: Block of image from the cluster under analysis.
     :type subim: int
 
     :param S: Pattern spacing value.
     :type S: int
 
-    :param m: Compactness value
+    :param m: Compactness value.
     :type m: float
 
     :param rmin: Minimum row.
@@ -222,6 +277,24 @@ def distance(c_series, ic, jc, subim, S, m, rmin, cmin):
     :param cmin: Minimum column.
     :type cmin: int
 
+    :param window: Only allow for maximal shifts from the two diagonals \
+    smaller than this number. It includes the diagonal, meaning that an \
+    Euclidean distance is obtained by setting window=1.
+
+    :param max_dist: Stop if the returned values will be larger than \
+    this value.
+
+    :param max_step: Do not allow steps larger than this value.
+
+    :param max_diff: Return infinity if length of two series is larger.
+
+    :param penalty: Penalty to add if compression or expansion is applied.
+
+    :param psi: Psi relaxation parameter (ignore start and end of matching).
+        Useful for cyclical series.
+
+    :param use_pruning: Prune values based on Euclidean distance.
+
     :returns D: numpy.ndarray distance.
     """
     from dtaidistance import dtw
@@ -268,7 +341,7 @@ def update_cluster(img, la, rows, columns, bands, k):
     :param columns: Number of columns of image.
     :type columns: int
 
-    :param bands: Number of bands (lenght of time series)
+    :param bands: Number of bands (lenght of time series).
     :type bands: int
 
     :param k: Number of superpixel.
@@ -298,7 +371,7 @@ def update_cluster(img, la, rows, columns, bands, k):
 
 
 def postprocessing(raster, S):
-    """Post processing function to enforce conectivity.
+    """Post processing function to enforce connectivity.
 
     :param raster: Labelled image.
     :type raster: numpy.ndarray
@@ -333,7 +406,7 @@ def postprocessing(raster, S):
 
 
 def write_pandas(segmentation, transform, crs):
-    """This function creates a geopandas DataFrame \
+    """This function creates a GeoPandas DataFrame \
     of the segmentation.
 
     :param segmentation: Segmentation numpy array.
@@ -384,7 +457,7 @@ def init_cluster_hex(rows, columns, ki, img, bands):
     :param img: Input image.
     :type img: numpy.ndarray
 
-    :param bands: Number of bands (lenght of time series)
+    :param bands: Number of bands (lenght of time series).
     :type bands: int
 
     :returns C: ND-array containing cluster centres information.
@@ -469,7 +542,7 @@ def init_cluster_regular(rows, columns, ki, img, bands):
     :param img: Input image.
     :type img: numpy.ndarray
 
-    :param bands: Number of bands (lenght of time series)
+    :param bands: Number of bands (lenght of time series).
     :type bands: int
 
     :returns C: ND-array containing cluster centres information.
@@ -641,7 +714,7 @@ def extract_features(dataset, segmentation,
     for each polygon: Area, Perimeter, Width, Length, Aspect Ratio ratio, \
     Symmetry, Compactness and Rectangular fit.
 
-    :param dataset: Images or path were images that compose time series are.
+    :param dataset: Images or path to images that compose time series.
     :type dataset: Rasterio, Xarray.Dataset or string
 
     :param segmentation: Spatio-temporal Segmentation.
@@ -653,7 +726,7 @@ def extract_features(dataset, segmentation,
     :param nodata: Nodata value
     :type nodata: int
 
-    :returns segmentation: Geopandas dataframe with the features.
+    :returns segmentation: GeoPandas DataFrame with the features.
     """
     import os
     import pandas
@@ -901,9 +974,9 @@ def aspect_ratio(geom):
 def symmetry(geom):
     """This function computes the symmetry of a given geometry.
 
-    Symmetry is calculated by dividing the overlapping area AO, between \
+    Symmetry is calculated by dividing the overlapping area (AO), between \
     a polygon P and its reflection across the horizontal axis by the area of \
-    the polygon P. The range of this score falls between [0,1] and a \
+    the polygon P (A_p). The range of this score falls between [0,1] and a \
     score closer to 1 indicates a more compact and regular geometry.
 
     .. math:: Symmetry = AO/A_p
@@ -932,7 +1005,7 @@ def reock_compactness(geom):
 
     .. math:: Reock = A_p/A_{MBC}
 
-    :param geom: Polygon geometry
+    :param geom: Polygon geometry.
     :type geom: shapely.geometry.Polygon
 
     :returns reock: Polygon reock compactness.
@@ -954,7 +1027,7 @@ def reock_compactness(geom):
 
 
 def rectangular_fit(geom):
-    """This functions computes the rectangular_fit of a geometry. \
+    """This function computes the rectangular fit of a geometry. \
     The rectangular fit is defined as:
 
     .. math:: RectFit = (AR - AD) / AO
@@ -983,9 +1056,9 @@ def rectangular_fit(geom):
 
 
 def width(geom):
-    """This functions computes the width of a geometry.
+    """This function computes the width of a geometry.
 
-    :param geom: Polygon geometry
+    :param geom: Polygon geometry.
     :type geom: shapely.geometry.Polygon
 
     :returns width: Polygon width.
@@ -997,9 +1070,9 @@ def width(geom):
 
 
 def length(geom):
-    """This functions computes the lenght of a geometry.
+    """This function computes the lenght of a geometry.
 
-    :param geom: Polygon geometry
+    :param geom: Polygon geometry.
     :type geom: shapely.geometry.Polygon
 
     :returns length: Polygon length.
@@ -1031,7 +1104,7 @@ def dtw_filter(dataset, kernel_size=3, window=None, max_dist=None,
 
     :param max_step: Do not allow steps larger than this value.
 
-    :param max_length_diff: Return infinity if length of two series is larger.
+    :param max_diff: Return infinity if length of two series is larger.
 
     :param penalty: Penalty to add if compression or expansion is applied.
 
@@ -1069,7 +1142,7 @@ def dtw_filter(dataset, kernel_size=3, window=None, max_dist=None,
                                            subim[:, rs, cs].astype(float),
                                            window=window, max_dist=max_dist,
                                            max_step=max_step,
-                                           max_length_diff=max_length_diff,
+                                           max_length_diff=max_diff,
                                            penalty=penalty, psi=psi,
                                            use_pruning=pruning)
                     tmp = dc + tmp
diff --git a/stmetrics/utils.py b/stmetrics/utils.py
index 49a66ee..3dc3d9a 100644
--- a/stmetrics/utils.py
+++ b/stmetrics/utils.py
@@ -2,11 +2,11 @@
 
 
 def fixseries(timeseries, nodata=-9999):
-    """This function ajust the time series to polar transformation.
+    """This function ajusts the time series to polar transformation.
 
-    As some time series may have very significant noises, when coverted to \
+    As some time series may have very significant noises (such as spikes), when coverted to \
     polar space it may produce an inconsistent geometry. To avoid this issue, \
-    this function remove this spikes.
+    this function removes this spikes.
 
     :param timeseries: Your time series.
     :type timeseries: numpy.ndarray
@@ -50,7 +50,7 @@ def create_polygon(timeseries):
     """This function converts a time series to the polar space.
 
     If the time series has lenght smaller than 3, it can not be properly \
-    converted to polar space.
+    converted to the polar space.
 
     :param timeseries: Your time series.
     :type timeseries: numpy.ndarray
@@ -112,7 +112,7 @@ def get_list_of_points(timeseries):
 
 
 def check_input(timeseries):
-    """This function check the input and raise exception if it is too short \
+    """This function checks the input and raises one exception if it is too short \
     or has the wrong type.
 
     :param timeseries: Your time series.
@@ -182,13 +182,13 @@ def img2xarray(path, band):
 
 
 def bdc2xarray(cube_path, list_bands):
-    """This function read a path with BDC ARD data and create a xarray \
-    dataset.
+    """This function reads a path with BDC ARD (Brazil Data Cube Analysis Ready Data) \
+    and creates an xarray dataset.
 
     :param cube_path: Path of folder with images.
     :type cube_path: string
 
-    :param list_bands: List of bands that will be available on xarray.
+    :param list_bands: List of bands that will be available as xarray.
     :type list_bands: list
 
     :return cube_dataset: Xarray dataset.
@@ -249,7 +249,7 @@ def error_fractal():
 
 
 def list_metrics():
-    """This function list the available metrics in stmetrics.
+    """This function lists the available metrics in stmetrics.
     """
     import stmetrics
     metrics = [*error_basics().keys(),


Test patch:
diff --git a/tests/test_gmetrics.py b/tests/test_gmetrics.py
index a326970..a427013 100644
--- a/tests/test_gmetrics.py
+++ b/tests/test_gmetrics.py
@@ -229,8 +229,9 @@ def test_getmetrics_sits():
     out = numpy.array([  1.      ,   1.      ,   1.      ,   0.      , 360.      ,
 				         0.      , 360.      ,   0.      ,   0.      ,   0.      ,
 				       360.      ,   0.      ,   1.      ,   1.      ,   1.      ,
-				         1.      ,   1.      ,   3.141433,   0.      ,   0.      ,
-				         0.785358,   0.785358,   0.785358,   0.785358,   1.000025])
+				         3.141433,   0.      ,   0.785358,   0.785358,   0.785358,   
+				         0.785358,   0.      ,   1.      ,   1.      ,
+				         1.000025])
 
     res = metrics._getmetrics(numpy.ones((360)))
     res = res[~numpy.isnan(res)]
@@ -239,6 +240,7 @@ def test_getmetrics_sits():
 
 def test_list_metrics():
 	from stmetrics import utils
+
 	out = ['max_ts',
 		 'min_ts',
 		 'mean_ts',
@@ -252,17 +254,17 @@ def test_list_metrics():
 		 'abs_sum_ts',
 		 'iqr_ts',
 		 'fqr_ts',
-		 'tqr_ts',
 		 'sqr_ts',
-		 'ecc_metric',
-		 'gyration_radius',
+		 'tqr_ts',
 		 'area_ts',
-		 'polar_balance',
 		 'angle',
 		 'area_q1',
 		 'area_q2',
 		 'area_q3',
 		 'area_q4',
+		 'polar_balance',
+		 'ecc_metric',
+		 'gyration_radius',
 		 'csi',
 		 'dfa_fd',
 		 'hurst_exp',
@@ -332,88 +334,88 @@ def test_sits2metrics():
 				        [0.9029195 , 0.99803176]]])
 
 	output = numpy.array([[[ 9.750800e-01,  9.298420e-01],
-					        [ 9.501170e-01,  9.983260e-01]],
+					       [ 9.501170e-01,  9.983260e-01]],
 
-					       [[ 1.181400e-02,  5.176300e-02],
-					        [ 6.319800e-02,  3.722370e-01]],
+					      [[ 1.181400e-02,  5.176300e-02],
+					       [ 6.319800e-02,  3.722370e-01]],
 
-					       [[ 5.087680e-01,  5.520260e-01],
-					        [ 5.138130e-01,  7.830350e-01]],
+					      [[ 5.087680e-01,  5.520260e-01],
+					       [ 5.138130e-01,  7.830350e-01]],
 
-					       [[ 3.312370e-01,  2.702780e-01],
-					        [ 2.762990e-01,  2.297330e-01]],
+					      [[ 3.312370e-01,  2.702780e-01],
+					       [ 2.762990e-01,  2.297330e-01]],
 
-					       [[ 5.087687e+00,  5.520261e+00],
-					        [ 5.138136e+00,  7.830350e+00]],
+					      [[ 5.087687e+00,  5.520261e+00],
+					       [ 5.138136e+00,  7.830350e+00]],
 
-					       [[ 9.632650e-01,  8.780780e-01],
-					        [ 8.869190e-01,  6.260890e-01]],
+					      [[ 9.632650e-01,  8.780780e-01],
+					       [ 8.869190e-01,  6.260890e-01]],
 
-					       [[ 3.685641e+00,  3.777832e+00],
-					        [ 3.403455e+00,  6.659211e+00]],
+					      [[ 3.685641e+00,  3.777832e+00],
+					       [ 3.403455e+00,  6.659211e+00]],
 
-					       [[ 8.844000e-01,  7.386330e-01],
-					        [ 8.397200e-01,  5.784910e-01]],
+					      [[ 8.844000e-01,  7.386330e-01],
+					       [ 8.397200e-01,  5.784910e-01]],
 
-					       [[-4.801000e-02, -2.996340e-01],
-					        [ 1.285020e-01, -8.078330e-01]],
+					      [[-4.801000e-02, -2.996340e-01],
+					       [ 1.285020e-01, -8.078330e-01]],
 
-					       [[ 4.132970e-01,  2.622960e-01],
-					        [ 3.397510e-01,  2.659790e-01]],
+					      [[ 4.132970e-01,  2.622960e-01],
+					       [ 3.397510e-01,  2.659790e-01]],
 
-					       [[ 5.087687e+00,  5.520261e+00],
-					        [ 5.138136e+00,  7.830350e+00]],
+					      [[ 5.087687e+00,  5.520261e+00],
+					       [ 5.138136e+00,  7.830350e+00]],
 
-					       [[ 5.974480e-01,  4.437080e-01],
-					        [ 4.179080e-01,  3.368950e-01]],
+					      [[ 5.974480e-01,  4.437080e-01],
+					       [ 4.179080e-01,  3.368950e-01]],
 
-					       [[ 2.700580e-01,  3.401940e-01],
-					        [ 3.427010e-01,  6.921580e-01]],
+					      [[ 2.700580e-01,  3.401940e-01],
+					       [ 3.427010e-01,  6.921580e-01]],
 
-					       [[ 7.783240e-01,  7.466950e-01],
-					        [ 6.662430e-01,  9.536500e-01]],
+					      [[ 5.128380e-01,  5.990310e-01],
+					       [ 4.824760e-01,  8.751500e-01]],
 
-					       [[ 5.128380e-01,  5.990310e-01],
-					        [ 4.824760e-01,  8.751500e-01]],
+					      [[ 7.783240e-01,  7.466950e-01],
+					       [ 6.662430e-01,  9.536500e-01]],
 
-					       [[ 9.558100e-01,  7.489210e-01],
-					        [ 7.805490e-01,  9.796340e-01]],
+					      [[ 7.090790e-01,  9.537960e-01],
+					       [ 7.414750e-01,  1.785940e+00]],
 
-					       [[ 1.767650e-01,  8.556510e-01],
-					        [ 6.298040e-01,  6.739810e-01]],
+					      [[ 1.396263e+00,  3.490658e+00],
+					       [ 3.490658e+00,  5.585053e+00]],
 
-					       [[ 7.090790e-01,  9.537960e-01],
-					        [ 7.414750e-01,  1.785940e+00]],
+					      [[ 1.183530e-01,  2.287100e-01],
+					       [ 3.691700e-01,  3.263750e-01]],
 
-					       [[ 1.068700e-01,  1.322950e-01],
-					        [ 1.072770e-01,  1.576630e-01]],
+					      [[ 3.475680e-01,  8.975300e-02],
+					       [ 1.130390e-01,  5.781790e-01]],
 
-					       [[ 1.396263e+00,  3.490658e+00],
-					        [ 3.490658e+00,  5.585053e+00]],
+					      [[ 6.238000e-02,  4.504290e-01],
+					       [ 1.095530e-01,  2.568520e-01]],
 
-					       [[ 1.183530e-01,  2.287100e-01],
-					        [ 3.691700e-01,  3.263750e-01]],
+					      [[ 1.807770e-01,  1.849030e-01],
+					       [ 1.497120e-01,  6.245320e-01]],
 
-					       [[ 3.475680e-01,  8.975300e-02],
-					        [ 1.130390e-01,  5.781790e-01]],
+					      [[ 1.068700e-01,  1.322950e-01],
+					       [ 1.072770e-01,  1.576630e-01]],
 
-					       [[ 6.238000e-02,  4.504290e-01],
-					        [ 1.095530e-01,  2.568520e-01]],
+					      [[ 9.558100e-01,  7.489210e-01],
+					       [ 7.805490e-01,  9.796340e-01]],
 
-					       [[ 1.807770e-01,  1.849030e-01],
-					        [ 1.497120e-01,  6.245320e-01]],
+					      [[ 1.767650e-01,  8.556510e-01],
+					       [ 6.298040e-01,  6.739810e-01]],
 
-					       [[ 3.372378e+00,  1.761302e+00],
-					        [ 2.543674e+00,  1.508493e+00]],
+					      [[ 3.372378e+00,  1.761302e+00],
+					       [ 2.543674e+00,  1.508493e+00]],
 
-					       [[-4.280310e-01, -7.486000e-03],
-					        [ 1.888369e+00, -4.988190e-01]],
+					      [[-4.280310e-01, -7.486000e-03],
+					       [ 1.888369e+00, -4.988190e-01]],
 
-					       [[ 4.724270e-01,  4.724270e-01],
-					        [ 6.548670e-01,  6.492550e-01]],
+					      [[ 4.724270e-01,  4.724270e-01],
+					       [ 6.548670e-01,  6.492550e-01]],
 
-					       [[ 2.596693e+00,  1.818503e+00],
-					        [ 2.289875e+00,  2.566626e+00]]])
+					      [[ 2.596693e+00,  1.818503e+00],
+					       [ 2.289875e+00,  2.566626e+00]]])
 
 	res = stmetrics.metrics.sits2metrics(sits)