# Path: PyFVCOM/utilities/time.py
# def date_range(start_date, end_date, inc=1):
#     """
#     Make a list of datetimes from start_date to end_date (inclusive).
# 
#     Parameters
#     ----------
#     start_date, end_date : datetime
#         Start and end time as datetime objects. `end_date' is inclusive.
#     inc : float, optional
#         Specify a time increment for the list of dates in days. If omitted,
#         defaults to 1 day.
# 
#     Returns
#     -------
#     dates : list
#         List of datetimes.
# 
#     """
# 
#     start_seconds = int(start_date.replace(tzinfo=pytz.UTC).strftime('%s'))
#     end_seconds = int(end_date.replace(tzinfo=pytz.UTC).strftime('%s'))
# 
#     inc *= 86400  # seconds
#     dates = np.arange(start_seconds, end_seconds, inc)
#     dates = [datetime.utcfromtimestamp(d) for d in dates]
#     if dates[-1] != end_date:
#         dates += [end_date]
#     dates = np.array(dates)
# 
#     return dates
# 
# def make_signal(time, amplitude=1, phase=0, period=1):
#     """
#     Make an arbitrary sinusoidal signal with given amplitude, phase and period over a specific time interval.
# 
#     Parameters
#     ----------
#     time : np.ndarray
#         Time series in number of days.
#     amplitude : float, optional
#         A specific amplitude (defaults to 1).
#     phase : float, optional
#         A given phase offset in degrees (defaults to 0).
#     period : float, optional
#         A period for the sine wave (defaults to 1).
# 
#     Returns
#     -------
#     signal : np.ndarray
#         The time series with the given parameters.
# 
#     """
# 
#     signal = (amplitude * np.sin((2 * np.pi * 1 / period * (time - np.min(time)) + np.deg2rad(phase))))
# 
#     return signal


import numpy.testing as test
import numpy as np
from unittest import TestCase
from datetime import datetime
from PyFVCOM.tide import *
from PyFVCOM.utilities.time import date_range, make_signal
from matplotlib.pyplot import *




class TideTest(TestCase):

    def setUp(self):
        """ Make a set of data for the various tide functions """
        self.start = datetime.strptime('2010-01-01 00:00:00', '%Y-%m-%d %H:%M:%S')
        self.end = datetime.strptime('2010-01-10 00:00:01', '%Y-%m-%d %H:%M:%S')
        self.interval = 2 / 24  # 2-hourly interval in days
        self.amplitude = 2  # base signal amplitude
        self.phase = 90  # base signal phase (degrees)
        self.period = (1 / (12 + (25 / 60))) * 24  # base signal period in days (~M2 tide)

        self.time = date_range(self.start, self.end, inc=self.interval)
        self.num_time = [int(d.strftime('%s')) / 60 / 60 / 24 for d in self.time]  # float days
        # Make a somewhat complicated time series to filter. It's characteristics are a strong sub-daily signal with
        # lower amplitude signals with longer periods added.
        self.signal = make_signal(self.num_time, self.amplitude, self.phase * 2, self.period / 2)

# Path: PyFVCOM/utilities/time.py
# def date_range(start_date, end_date, inc=1):
#     """
#     Make a list of datetimes from start_date to end_date (inclusive).
# 
#     Parameters
#     ----------
#     start_date, end_date : datetime
#         Start and end time as datetime objects. `end_date' is inclusive.
#     inc : float, optional
#         Specify a time increment for the list of dates in days. If omitted,
#         defaults to 1 day.
# 
#     Returns
#     -------
#     dates : list
#         List of datetimes.
# 
#     """
# 
#     start_seconds = int(start_date.replace(tzinfo=pytz.UTC).strftime('%s'))
#     end_seconds = int(end_date.replace(tzinfo=pytz.UTC).strftime('%s'))
# 
#     inc *= 86400  # seconds
#     dates = np.arange(start_seconds, end_seconds, inc)
#     dates = [datetime.utcfromtimestamp(d) for d in dates]
#     if dates[-1] != end_date:
#         dates += [end_date]
#     dates = np.array(dates)
# 
#     return dates
# 
# def make_signal(time, amplitude=1, phase=0, period=1):
#     """
#     Make an arbitrary sinusoidal signal with given amplitude, phase and period over a specific time interval.
# 
#     Parameters
#     ----------
#     time : np.ndarray
#         Time series in number of days.
#     amplitude : float, optional
#         A specific amplitude (defaults to 1).
#     phase : float, optional
#         A given phase offset in degrees (defaults to 0).
#     period : float, optional
#         A period for the sine wave (defaults to 1).
# 
#     Returns
#     -------
#     signal : np.ndarray
#         The time series with the given parameters.
# 
#     """
# 
#     signal = (amplitude * np.sin((2 * np.pi * 1 / period * (time - np.min(time)) + np.deg2rad(phase))))
# 
#     return signal


# Path: tests/tide.py
import numpy.testing as test
import numpy as np
from unittest import TestCase
from datetime import datetime
from PyFVCOM.tide import *
from PyFVCOM.utilities.time import date_range, make_signal
from matplotlib.pyplot import *





class TideTest(TestCase):

    def setUp(self):
        """ Make a set of data for the various tide functions """
        self.start = datetime.strptime('2010-01-01 00:00:00', '%Y-%m-%d %H:%M:%S')
        self.end = datetime.strptime('2010-01-10 00:00:01', '%Y-%m-%d %H:%M:%S')
        self.interval = 2 / 24  # 2-hourly interval in days
        self.amplitude = 2  # base signal amplitude
        self.phase = 90  # base signal phase (degrees)
        self.period = (1 / (12 + (25 / 60))) * 24  # base signal period in days (~M2 tide)

        self.time = date_range(self.start, self.end, inc=self.interval)
        self.num_time = [int(d.strftime('%s')) / 60 / 60 / 24 for d in self.time]  # float days
        # Make a somewhat complicated time series to filter. It's characteristics are a strong sub-daily signal with
        # lower amplitude signals with longer periods added.
        self.signal = make_signal(self.num_time, self.amplitude, self.phase * 2, self.period / 2)

        self.signal += make_signal(self.num_time, self.amplitude, self.phase, self.period)