""" Custom transforms for Patsy formulas

TODO:
    - Add vegetation indices

"""
import numpy as np
from patsy import stateful_transform


class Harmonic(object):
    """ Transform `x` into seasonal harmonics with a given frequency

    Args:
      x (np.ndarray): array of ordinal dates
      freq (int or float): frequency of harmonics

    """
    def __init__(self):
        self.w = 2 * np.pi / 365.25

    def memorize_chunk(self, x, freq):
        pass

    def memorize_finish(self):
        pass

    def transform(self, x, freq):
        return np.array([
            np.cos(freq * self.w * x),
            np.sin(freq * self.w * x)
        ]).T


harm = stateful_transform(Harmonic)

@@ -526,32 +526,115 @@
 self, x, freq):%0A
+        x = np.asarray(x)%0A        if x.shape == ():%0A            x = x%5Bnp.newaxis%5D%0A%0A
         return n

Modify Patsy harmonic transform to deal with 1D x input #25