# Path: windpowerlib/temperature.py
# def linear_gradient(temperature, temperature_height, hub_height):
#     r"""
#     Calculates the temperature at hub height using a linear gradient.
# 
#     A linear temperature gradient of -6.5 K/km is assumed. This function is
#     carried out when the parameter `temperature_model` of an instance of
#     the :class:`~.modelchain.ModelChain` class is
#     'temperature_gradient'.
# 
#     Parameters
#     ----------
#     temperature : :pandas:`pandas.Series<series>` or numpy.array
#         Air temperature in K.
#     temperature_height : float
#         Height in m for which the parameter `temperature` applies.
#     hub_height : float
#         Hub height of wind turbine in m.
# 
#     Returns
#     -------
#     :pandas:`pandas.Series<series>` or numpy.array
#         Temperature at hub height in K.
# 
#     Notes
#     -----
# 
#     The following equation is used [1]_:
# 
#     .. math:: T_{hub}=T_{air}-0.0065\cdot\left(h_{hub}-h_{T,data}\right)
# 
#     with:
#         T: temperature [K], h: height [m]
# 
#     :math:`h_{T,data}` is the height in which the temperature :math:`T_{air}`
#     is measured and :math:`T_{hub}` is the temperature at hub height
#     :math:`h_{hub}` of the wind turbine.
# 
#     Assumptions:
# 
#     * Temperature gradient of -6.5 K/km (-0.0065 K/m)
# 
#     References
#     ----------
#     .. [1] ICAO-Standardatmosphäre (ISA).
#         http://www.dwd.de/DE/service/lexikon/begriffe/S/Standardatmosphaere_pdf.pdf?__blob=publicationFile&v=3
# 
#     """
#     return temperature - 0.0065 * (hub_height - temperature_height)


import pandas as pd
import numpy as np
from pandas.util.testing import assert_series_equal
from numpy.testing import assert_array_equal
from windpowerlib.temperature import linear_gradient
"""
SPDX-FileCopyrightText: 2019 oemof developer group <contact@oemof.org>
SPDX-License-Identifier: MIT
"""




class TestTemperature:
    def test_linear_gradient(self):
        """Test temperature as pd.Series"""
        parameters = {
            "temperature": pd.Series(data=[267, 268]),
            "temperature_height": 2,
            "hub_height": 100,
        }
        temp_hub_exp = pd.Series(data=[266.363, 267.36300])
        assert_series_equal(linear_gradient(**parameters), temp_hub_exp)

    def test_temperature_as_np_array(self):
        """Test temperature as np.array"""
        parameters = {
            "temperature": np.array([267, 268]),
            "temperature_height": 2,
            "hub_height": 100,
        }
        temp_hub_exp = np.array([266.363, 267.36300])
        assert_array_equal(linear_gradient(**parameters), temp_hub_exp)

# Path: windpowerlib/temperature.py
# def linear_gradient(temperature, temperature_height, hub_height):
#     r"""
#     Calculates the temperature at hub height using a linear gradient.
# 
#     A linear temperature gradient of -6.5 K/km is assumed. This function is
#     carried out when the parameter `temperature_model` of an instance of
#     the :class:`~.modelchain.ModelChain` class is
#     'temperature_gradient'.
# 
#     Parameters
#     ----------
#     temperature : :pandas:`pandas.Series<series>` or numpy.array
#         Air temperature in K.
#     temperature_height : float
#         Height in m for which the parameter `temperature` applies.
#     hub_height : float
#         Hub height of wind turbine in m.
# 
#     Returns
#     -------
#     :pandas:`pandas.Series<series>` or numpy.array
#         Temperature at hub height in K.
# 
#     Notes
#     -----
# 
#     The following equation is used [1]_:
# 
#     .. math:: T_{hub}=T_{air}-0.0065\cdot\left(h_{hub}-h_{T,data}\right)
# 
#     with:
#         T: temperature [K], h: height [m]
# 
#     :math:`h_{T,data}` is the height in which the temperature :math:`T_{air}`
#     is measured and :math:`T_{hub}` is the temperature at hub height
#     :math:`h_{hub}` of the wind turbine.
# 
#     Assumptions:
# 
#     * Temperature gradient of -6.5 K/km (-0.0065 K/m)
# 
#     References
#     ----------
#     .. [1] ICAO-Standardatmosphäre (ISA).
#         http://www.dwd.de/DE/service/lexikon/begriffe/S/Standardatmosphaere_pdf.pdf?__blob=publicationFile&v=3
# 
#     """
#     return temperature - 0.0065 * (hub_height - temperature_height)


# Path: tests/test_temperature.py
import pandas as pd
import numpy as np
from pandas.util.testing import assert_series_equal
from numpy.testing import assert_array_equal
from windpowerlib.temperature import linear_gradient

"""
SPDX-FileCopyrightText: 2019 oemof developer group <contact@oemof.org>
SPDX-License-Identifier: MIT
"""




class TestTemperature:
    def test_linear_gradient(self):
        """Test temperature as pd.Series"""
        parameters = {
            "temperature": pd.Series(data=[267, 268]),
            "temperature_height": 2,
            "hub_height": 100,
        }
        temp_hub_exp = pd.Series(data=[266.363, 267.36300])
        assert_series_equal(linear_gradient(**parameters), temp_hub_exp)

    def test_temperature_as_np_array(self):
        """Test temperature as np.array"""
        parameters = {
            "temperature": np.array([267, 268]),
            "temperature_height": 2,
            "hub_height": 100,
        }
        temp_hub_exp = np.array([266.363, 267.36300])
        assert_array_equal(linear_gradient(**parameters), temp_hub_exp)

        assert isinstance(linear_gradient(**parameters), np.ndarray)