From c49846a4d149114ac44d163b677211b19b4be75d Mon Sep 17 00:00:00 2001 From: raphaelrpl Date: Thu, 27 May 2021 10:24:32 -0300 Subject: [PATCH] Add option to interpolate missing_values on plot (close #59) --- wtss/timeseries.py | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/wtss/timeseries.py b/wtss/timeseries.py index 810a0c4..551d0ad 100644 --- a/wtss/timeseries.py +++ b/wtss/timeseries.py @@ -57,10 +57,11 @@ def values(self, attr_name): return getattr(self, attr_name) - def plot(self, **options): + def plot(self, discard_nodata=False, **options): """Plot the time series on a chart. Keyword Args: + discard_nodata (bool): Discard the missing values in time series. Default is False. attributes (sequence): A sequence like ('red', 'nir') or ['red', 'nir'] . line_styles (sequence): Not implemented yet. markers (sequence): Not implemented yet. @@ -118,8 +119,27 @@ def plot(self, **options): attrs = options['attributes'] if 'attributes' in options else self.attributes for attr in attrs: + missing_value = None + for coverage_attribute in self._coverage.attributes: + print(coverage_attribute) + if coverage_attribute['name'] == attr: + missing_value = coverage_attribute['missing_value'] + break + y = self.values(attr) + if discard_nodata: + _y = [] + _x = [] + + for i, value in enumerate(y): + if value != missing_value: + _y.append(value) + _x.append(x[i]) + + y = _y + x = _x + ax.plot(x, y, ls='-', marker='o',