<commit_before># Copyright (c) 2008-2015 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause

import numpy as np
from metpy.calc.thermo import *  # noqa
from metpy.units import units
from metpy.testing import assert_almost_equal, assert_array_almost_equal


class TestPotentialTemperature(object):
    def test_basic(self):
        temp = np.array([278., 283., 291., 298.]) * units.kelvin
        pres = np.array([900., 500., 300., 100.]) * units.mbar
        real_th = np.array([286.493, 344.961, 410.4335, 575.236]) * units.kelvin
        assert_array_almost_equal(potential_temperature(pres, temp), real_th, 3)

    def test_scalar(self):
        assert_almost_equal(potential_temperature(1000. * units.mbar, 293. * units.kelvin),
                            293. * units.kelvin, 4)
        assert_almost_equal(potential_temperature(800. * units.mbar, 293. * units.kelvin),
                            312.2828 * units.kelvin, 4)

    def test_farenheit(self):
        assert_almost_equal(potential_temperature(800. * units.mbar, 68. * units.degF),
                            (312.444 * units.kelvin).to(units.degF), 2)


class TestDryLapse(object):
    def test_array(self):
        levels = np.array([1000, 900, 864.89]) * units.mbar
        temps = dry_lapse(levels, 303.15 * units.kelvin)
        assert_array_almost_equal(temps,
                                  np.array([303.15, 294.16, 290.83]) * units.kelvin, 2)

    def test_2_levels(self):
        temps = dry_lapse(np.array([1000., 500.]) * units.mbar, 293. * units.kelvin)
        assert_array_almost_equal(temps, [293., 240.3723] * units.kelvin, 4)


class TestMoistLapse(object):
    def test_array(self):
        temp = moist_lapse(np.array([1000., 800., 600., 500., 400.]) * units.mbar,
                           293. * units.kelvin)
        true_temp = np.array([293, 284.64, 272.81, 264.42, 252.91]) * units.kelvin
        assert_array_almost_equal(temp, true_temp, 2)

    def test_degc(self):
        'Test moist lapse with Celsius'
        temp = moist_lapse(np.array([1000., 800., 600., 500., 400.]) * units.mbar,
                           19.85 * units.degC)
        true_temp = np.array([293, 284.64, 272.81, 264.42, 252.91]) * units.kelvin
        assert_array_almost_equal(temp, true_temp, 2)


class TestParcelProfile(object):
    def test_basic(self):
        levels = np.array([1000., 900., 800., 700., 600., 500., 400.]) * units.mbar
        true_prof = np.array([303.15, 294.16, 288.026, 283.073, 277.058, 269.402,
                              258.966]) * units.kelvin

        prof = parcel_profile(levels, 30. * units.degC, 20. * units.degC)
        assert_array_almost_equal(prof, true_prof, 2)


class TestSatVaporPressure(object):
    def test_basic(self):
        temp = np.array([5., 10., 18., 25.]) * units.degC
        real_es = np.array([8.72, 12.27, 20.63, 31.67]) * units.mbar
        assert_array_almost_equal(saturation_vapor_pressure(temp), real_es, 2)

    def test_scalar(self):
        es = saturation_vapor_pressure(0 * units.degC)
        assert_almost_equal(es, 6.112 * units.mbar, 3)

    def test_farenheit(self):
        temp = np.array([50., 68.]) * units.degF
        real_es = np.array([12.2717, 23.3695]) * units.mbar
        assert_array_almost_equal(saturation_vapor_pressure(temp), real_es, 4)


class TestDewpointRH(object):
    def test_basic(self):
        temp = np.array([30., 25., 10., 20., 25.]) * units.degC
        rh = np.array([30., 45., 55., 80., 85.]) / 100.

        real_td = np.array([11, 12, 1, 16, 22]) * units.degC
        assert_array_almost_equal(real_td, dewpoint_rh(temp, rh), 0)

    def test_scalar(self):
        td = dewpoint_rh(10.6 * units.degC, 0.37)
        assert_almost_equal(td, 26. * units.degF, 0)


class TestDewpoint(object):
    def test_scalar(self):
        assert_almost_equal(dewpoint(6.112 * units.mbar), 0. * units.degC, 2)

    def test_weird_units(self):
        # This was revealed by a having odd dimensionless units and ending up using
        # numpy.ma math functions instead of numpy ones.
        assert_almost_equal(dewpoint(15825.6 * units('g * mbar / kg')),
                            13.8564 * units.degC, 4)


class TestMixingRatio(object):
    def test_scalar(self):
        p = 998. * units.mbar
        e = 73.75 * units.mbar
        assert_almost_equal(mixing_ratio(e, p), 0.04963, 2)


class TestVaporPressure(object):
    def test_scalar(self):
        assert_almost_equal(vapor_pressure(998. * units.mbar, 0.04963),
                            73.74925 * units.mbar, 5)


class TestLCL(object):
    def test_basic(self):
        'Simple test of LCL calculation.'
        l = lcl(1000. * units.mbar, 30. * units.degC, 20. * units.degC)
        assert_almost_equal(l, 864.761 * units.mbar, 2)


def test_saturation_mixing_ratio():
    'Simple test of saturation mixing ratio calculation.'
    p = 999. * units.mbar
    t = 288. * units.kelvin
    assert_almost_equal(saturation_mixing_ratio(p, t), .01068, 3)


def test_equivalent_potential_temperature():
    'Simple test of equivalent potential temperature calculation.'
    p = 999. * units.mbar
    t = 288. * units.kelvin
    ept = equivalent_potential_temperature(p, t)
    assert_almost_equal(ept, 315.46 * units.kelvin, 2)<commit_msg>Fixed test for equiv pot temp<commit_after># Copyright (c) 2008-2015 MetPy Developers.
# Distributed under the terms of the BSD 3-Clause License.
# SPDX-License-Identifier: BSD-3-Clause

import numpy as np
from metpy.calc.thermo import *  # noqa
from metpy.units import units
from metpy.testing import assert_almost_equal, assert_array_almost_equal


class TestPotentialTemperature(object):
    def test_basic(self):
        temp = np.array([278., 283., 291., 298.]) * units.kelvin
        pres = np.array([900., 500., 300., 100.]) * units.mbar
        real_th = np.array([286.493, 344.961, 410.4335, 575.236]) * units.kelvin
        assert_array_almost_equal(potential_temperature(pres, temp), real_th, 3)

    def test_scalar(self):
        assert_almost_equal(potential_temperature(1000. * units.mbar, 293. * units.kelvin),
                            293. * units.kelvin, 4)
        assert_almost_equal(potential_temperature(800. * units.mbar, 293. * units.kelvin),
                            312.2828 * units.kelvin, 4)

    def test_farenheit(self):
        assert_almost_equal(potential_temperature(800. * units.mbar, 68. * units.degF),
                            (312.444 * units.kelvin).to(units.degF), 2)


class TestDryLapse(object):
    def test_array(self):
        levels = np.array([1000, 900, 864.89]) * units.mbar
        temps = dry_lapse(levels, 303.15 * units.kelvin)
        assert_array_almost_equal(temps,
                                  np.array([303.15, 294.16, 290.83]) * units.kelvin, 2)

    def test_2_levels(self):
        temps = dry_lapse(np.array([1000., 500.]) * units.mbar, 293. * units.kelvin)
        assert_array_almost_equal(temps, [293., 240.3723] * units.kelvin, 4)


class TestMoistLapse(object):
    def test_array(self):
        temp = moist_lapse(np.array([1000., 800., 600., 500., 400.]) * units.mbar,
                           293. * units.kelvin)
        true_temp = np.array([293, 284.64, 272.81, 264.42, 252.91]) * units.kelvin
        assert_array_almost_equal(temp, true_temp, 2)

    def test_degc(self):
        'Test moist lapse with Celsius'
        temp = moist_lapse(np.array([1000., 800., 600., 500., 400.]) * units.mbar,
                           19.85 * units.degC)
        true_temp = np.array([293, 284.64, 272.81, 264.42, 252.91]) * units.kelvin
        assert_array_almost_equal(temp, true_temp, 2)


class TestParcelProfile(object):
    def test_basic(self):
        levels = np.array([1000., 900., 800., 700., 600., 500., 400.]) * units.mbar
        true_prof = np.array([303.15, 294.16, 288.026, 283.073, 277.058, 269.402,
                              258.966]) * units.kelvin

        prof = parcel_profile(levels, 30. * units.degC, 20. * units.degC)
        assert_array_almost_equal(prof, true_prof, 2)


class TestSatVaporPressure(object):
    def test_basic(self):
        temp = np.array([5., 10., 18., 25.]) * units.degC
        real_es = np.array([8.72, 12.27, 20.63, 31.67]) * units.mbar
        assert_array_almost_equal(saturation_vapor_pressure(temp), real_es, 2)

    def test_scalar(self):
        es = saturation_vapor_pressure(0 * units.degC)
        assert_almost_equal(es, 6.112 * units.mbar, 3)

    def test_farenheit(self):
        temp = np.array([50., 68.]) * units.degF
        real_es = np.array([12.2717, 23.3695]) * units.mbar
        assert_array_almost_equal(saturation_vapor_pressure(temp), real_es, 4)


class TestDewpointRH(object):
    def test_basic(self):
        temp = np.array([30., 25., 10., 20., 25.]) * units.degC
        rh = np.array([30., 45., 55., 80., 85.]) / 100.

        real_td = np.array([11, 12, 1, 16, 22]) * units.degC
        assert_array_almost_equal(real_td, dewpoint_rh(temp, rh), 0)

    def test_scalar(self):
        td = dewpoint_rh(10.6 * units.degC, 0.37)
        assert_almost_equal(td, 26. * units.degF, 0)


class TestDewpoint(object):
    def test_scalar(self):
        assert_almost_equal(dewpoint(6.112 * units.mbar), 0. * units.degC, 2)

    def test_weird_units(self):
        # This was revealed by a having odd dimensionless units and ending up using
        # numpy.ma math functions instead of numpy ones.
        assert_almost_equal(dewpoint(15825.6 * units('g * mbar / kg')),
                            13.8564 * units.degC, 4)


class TestMixingRatio(object):
    def test_scalar(self):
        p = 998. * units.mbar
        e = 73.75 * units.mbar
        assert_almost_equal(mixing_ratio(e, p), 0.04963, 2)


class TestVaporPressure(object):
    def test_scalar(self):
        assert_almost_equal(vapor_pressure(998. * units.mbar, 0.04963),
                            73.74925 * units.mbar, 5)


class TestLCL(object):
    def test_basic(self):
        'Simple test of LCL calculation.'
        l = lcl(1000. * units.mbar, 30. * units.degC, 20. * units.degC)
        assert_almost_equal(l, 864.761 * units.mbar, 2)


def test_saturation_mixing_ratio():
    'Simple test of saturation mixing ratio calculation.'
    p = 999. * units.mbar
    t = 288. * units.kelvin
    assert_almost_equal(saturation_mixing_ratio(p, t), .01068, 3)


def test_equivalent_potential_temperature():
    'Simple test of equivalent potential temperature calculation.'
    p = 999. * units.mbar
    t = 288. * units.kelvin
    ept = equivalent_potential_temperature(p, t)
    assert_almost_equal(ept, 315.9548 * units.kelvin, 3)
{'fraction_non_alphanumeric': 0.13060538116591927, 'fraction_numerical': 0.09043348281016443, 'mean_word_length': 2.5922818791946307, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4915384', 'n_tokens_mistral': 4525, 'n_tokens_neox': 3617, 'n_words': 804}