<commit_before># -*- coding: utf-8 -*-
"""Rewrite part of test.py in pyproj in the form of unittests."""
from __future__ import with_statement

import math
from distutils.version import LooseVersion
from sys import version_info as sys_version_info

import pyproj
from pyproj import Geod, Proj, pj_ellps, pj_list, proj_version_str, transform
from pyproj.crs import CRSError

if sys_version_info[:2] < (2, 7):
    # for Python 2.4 - 2.6 use the backport of unittest from Python 2.7 and onwards
    import unittest2 as unittest
    from unittest2 import skipIf
else:
    import unittest
    from unittest import skipIf

try:
    import nose2
    import nose2.tools

    HAS_NOSE2 = True
except ImportError:
    HAS_NOSE2 = False


class BasicTest(unittest.TestCase):
    def testProj4Version(self):
        awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107)
        # self.assertEqual(awips221.proj_version, 4.9)

    def testInitWithBackupString4(self):
        # this fails unless backup of to_string(4) is used
        pj = Proj(
            "+proj=merc +a=6378137.0 +b=6378137.0 +nadgrids=@null +lon_0=0.0 +x_0=0.0 +y_0=0.0 +units=m +no_defs"
        )
        assert pj.crs.is_valid

    def testProjAwips221(self):
        # AWIPS is Advanced Weather Interactive Processing System
        params = {"proj": "lcc", "R": 6371200, "lat_1": 50, "lat_2": 50, "lon_0": -107}
        nx = 349
        ny = 277
        awips221 = Proj(
            proj=params["proj"],
            R=params["R"],
            lat_1=params["lat_1"],
            lat_2=params["lat_2"],
            lon_0=params["lon_0"],
            preserve_units=False,
        )
        awips221_from_dict = Proj(params, preserve_units=False)

        items = sorted([val for val in awips221.crs.srs.split() if val])
        items_dict = sorted([val for val in awips221_from_dict.crs.srs.split() if val])
        self.assertEqual(items, items_dict)

        expected = sorted(
            (
                "+R=6371200",
                "+lat_0=0",
                "+lat_1=50",
                "+lat_2=50",
                "+lon_0=-107",
                "+no_defs",
                "+proj=lcc",
                "+type=crs",
                "+units=m",
                "+x_0=0",
                "+y_0=0",
            )
        )
        self.assertEqual(items, expected)

        point = awips221(-145.5, 1.0)
        x, y = -5632642.22547495, 1636571.4883145525
        self.assertAlmostEqual(point[0], x)
        self.assertAlmostEqual(point[1], y)

        pairs = [
            [(-45, 45), (4351601.20766915, 7606948.029327129)],
            [(45, 45), (5285389.07739382, 14223336.17467613)],
            [(45, -45), (20394982.466924712, 21736546.456803113)],
            [(-45, -45), (16791730.756976362, -3794425.4816524936)],
        ]
        for point_geog, expected in pairs:
            point = awips221(*point_geog)
            self.assertAlmostEqual(point[0], expected[0])
            self.assertAlmostEqual(point[1], expected[1])
            point_geog2 = awips221(*point, inverse=True)
            self.assertAlmostEqual(point_geog[0], point_geog2[0])
            self.assertAlmostEqual(point_geog[1], point_geog2[1])


class InverseHammerTest(unittest.TestCase):
    # This is a unit test of the inverse of the hammer projection, which
    # was added to the PROJ.4 repository on 2015-12-13.
    # PROJ.4 versions 4.9.2 and below do not contain this feature but future
    # releases of PROJ.4 should support the inverse of the hammer projection.
    # Therefore, different tests are to test the expected behavior on versions.
    @classmethod
    def setUpClass(self):
        self.p = Proj(proj="hammer")  # hammer proj
        self.x, self.y = self.p(-30, 40)
<commit_msg>add test for issue #183<commit_after># -*- coding: utf-8 -*-
"""Rewrite part of test.py in pyproj in the form of unittests."""
from __future__ import with_statement

import math
from distutils.version import LooseVersion
from sys import version_info as sys_version_info

import pyproj
from pyproj import Geod, Proj, pj_ellps, pj_list, proj_version_str, transform
from pyproj.crs import CRSError

if sys_version_info[:2] < (2, 7):
    # for Python 2.4 - 2.6 use the backport of unittest from Python 2.7 and onwards
    import unittest2 as unittest
    from unittest2 import skipIf
else:
    import unittest
    from unittest import skipIf

try:
    import nose2
    import nose2.tools

    HAS_NOSE2 = True
except ImportError:
    HAS_NOSE2 = False


class BasicTest(unittest.TestCase):
    def testProj4Version(self):
        awips221 = Proj(proj="lcc", R=6371200, lat_1=50, lat_2=50, lon_0=-107)
        # self.assertEqual(awips221.proj_version, 4.9)

    def testInitWithBackupString4(self):
        # this fails unless backup of to_string(4) is used
        pj = Proj(
            "+proj=merc +a=6378137.0 +b=6378137.0 +nadgrids=@null +lon_0=0.0 +x_0=0.0 +y_0=0.0 +units=m +no_defs"
        )
        assert pj.crs.is_valid

    def testProjAwips221(self):
        # AWIPS is Advanced Weather Interactive Processing System
        params = {"proj": "lcc", "R": 6371200, "lat_1": 50, "lat_2": 50, "lon_0": -107}
        nx = 349
        ny = 277
        awips221 = Proj(
            proj=params["proj"],
            R=params["R"],
            lat_1=params["lat_1"],
            lat_2=params["lat_2"],
            lon_0=params["lon_0"],
            preserve_units=False,
        )
        awips221_from_dict = Proj(params, preserve_units=False)

        items = sorted([val for val in awips221.crs.srs.split() if val])
        items_dict = sorted([val for val in awips221_from_dict.crs.srs.split() if val])
        self.assertEqual(items, items_dict)

        expected = sorted(
            (
                "+R=6371200",
                "+lat_0=0",
                "+lat_1=50",
                "+lat_2=50",
                "+lon_0=-107",
                "+no_defs",
                "+proj=lcc",
                "+type=crs",
                "+units=m",
                "+x_0=0",
                "+y_0=0",
            )
        )
        self.assertEqual(items, expected)

        point = awips221(-145.5, 1.0)
        x, y = -5632642.22547495, 1636571.4883145525
        self.assertAlmostEqual(point[0], x)
        self.assertAlmostEqual(point[1], y)

        pairs = [
            [(-45, 45), (4351601.20766915, 7606948.029327129)],
            [(45, 45), (5285389.07739382, 14223336.17467613)],
            [(45, -45), (20394982.466924712, 21736546.456803113)],
            [(-45, -45), (16791730.756976362, -3794425.4816524936)],
        ]
        for point_geog, expected in pairs:
            point = awips221(*point_geog)
            self.assertAlmostEqual(point[0], expected[0])
            self.assertAlmostEqual(point[1], expected[1])
            point_geog2 = awips221(*point, inverse=True)
            self.assertAlmostEqual(point_geog[0], point_geog2[0])
            self.assertAlmostEqual(point_geog[1], point_geog2[1])

    def test_from_dict_with_bool(self):
        # issue #183
        p_d = {'proj': 'omerc',
               'lat_2': 80.27942,
               'lat_0': 62.87671,
               'lat_1': 42.751232,
               'ellps': 'WGS84',
               'no_rot': True,
               'lon_1': 33.793186,
               'lon_2': -18.374414}
        p=Proj(p_d)
        self.assertTrue('+no_rot' in p.srs.split())
        p_d = {'proj': 'omerc',
               'lat_2': 80.27942,
               'lat_0': 62.87671,
               'lat_1': 42.751232,
               'ellps': 'WGS84',
               'no_rot': False,
               'lon_1': 33.793186,
               'lon_2': -18.374414}
        p=Proj(p_d)
        self.assertFalse('+no_rot' in p.srs.split())



class InverseHammerTest(unittest.TestCase):
    # This is a unit test of the inverse of the hammer projection, which
    # was added to the PROJ.4 repository on 2015-12-13.
    # PROJ.4 versions 4.9.2 and below do not contain this feature but future
    # releases of PROJ.4 should support the inverse of the hammer projection.
    # Therefore, different tests are to test the expected behavior on versions.
    @classmethod
    def setUpClass(self):
        self.p = Proj(proj="hammer")  # hammer proj
        self.x, self.y = self.p(-30, 40)

{'fraction_non_alphanumeric': 0.11974460908324298, 'fraction_numerical': 0.0983014094687387, 'mean_word_length': 2.1566539923954373, 'pattern_counts': {'":': 10, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3778887', 'n_tokens_mistral': 3314, 'n_tokens_neox': 2764, 'n_words': 662}