<commit_before>#!/usr/bin/env python

# Lat Long - UTM, UTM - Lat Long conversions

# Adjusted for use with NumPy by <NAME> <pica {at} pml.ac.uk>

import inspect

import numpy as np

from warnings import warn

# LatLong- UTM conversion..h
# definitions for lat/long to UTM and UTM to lat/lng conversions
# include <string.h>

_EquatorialRadius = 2
_eccentricitySquared = 3

_ellipsoid = [
    # id, Ellipsoid name, Equatorial Radius, square of eccentricity first once
    # is a placeholder only, To allow array indices to match id numbers
    [-1, "Placeholder", 0, 0],
    [1, "Airy", 6377563, 0.00667054],
    [2, "Australian National", 6378160, 0.006694542],
    [3, "Bessel 1841", 6377397, 0.006674372],
    [4, "Bessel 1841 (Nambia] ", 6377484, 0.006674372],
    [5, "Clarke 1866", 6378206, 0.006768658],
    [6, "Clarke 1880", 6378249, 0.006803511],
    [7, "Everest", 6377276, 0.006637847],
    [8, "Fischer 1960 (Mercury] ", 6378166, 0.006693422],
    [9, "Fischer 1968", 6378150, 0.006693422],
    [10, "GRS 1967", 6378160, 0.006694605],
    [11, "GRS 1980", 6378137, 0.00669438],
    [12, "Helmert 1906", 6378200, 0.006693422],
    [13, "Hough", 6378270, 0.00672267],
    [14, "International", 6378388, 0.00672267],
    [15, "Krassovsky", 6378245, 0.006693422],
    [16, "Modified Airy", 6377340, 0.00667054],
    [17, "Modified Everest", 6377304, 0.006637847],
    [18, "Modified Fischer 1960", 6378155, 0.006693422],
    [19, "South American 1969", 6378160, 0.006694542],
    [20, "WGS 60", 6378165, 0.006693422],
    [21, "WGS 66", 6378145, 0.006694542],
    [22, "WGS-72", 6378135, 0.006694318],
    [23, "WGS-84", 6378137, 0.00669438]
]

# Reference ellipsoids derived from <NAME>'s website:
# http://www.utexas.edu/depts/grg/gcraft/notes/datum/elist.html
# Department of Geography,
# University of Texas at Austin
# Email: <EMAIL>
# 3/22/95

# Source:
# Defense Mapping Agency. 1987b. DMA Technical Report: Supplement to Department
# of Defense World Geodetic System 1984 Technical Report. Part I and II.
# Washington, DC: Defense Mapping Agency


def _test(inLat, inLong, inZone=False):
    """ Simple test of the functions with a given lat/long pair.

    Parameters
    ----------
    inLat, inLong : float
        Input latitude and longitude pair.

    """

    z, e, n = LL_to_UTM(23, inLat, inLong, ZoneNumber=inZone)
    outLat, outLong = UTM_to_LL(23, n, e, z)

    return z, e, n, outLat, outLong


def _UTM_letter_designator(Lat):
    # This routine determines the correct UTM letter designator for the given
    # latitude. Returns 'Z' if latitude is outside the UTM limits of 84N to 80S
    # Written by <NAME>: <EMAIL>

    if 84 >= Lat >= 72:
        return 'X'
    elif 72 > Lat >= 64:
        return 'W'
    elif 64 > Lat >= 56:
        return 'V'
    elif 56 > Lat >= 48:
        return 'U'
    elif 48 > Lat >= 40:
        return 'T'
    elif 40 > Lat >= 32:
        return 'S'
    elif 32 > Lat >= 24:
        return 'R'
    elif 24 > Lat >= 16:
        return 'Q'
    elif 16 > Lat >= 8:
        return 'P'
    elif 8 > Lat >= 0:
        return 'N'
    elif 0 > Lat >= -8:
        return 'M'
    elif -8 > Lat >= -16:
        return 'L'
    elif -16 > Lat >= -24:
        return 'K'
    elif -24 > Lat >= -32:
        return 'J'
    elif -32 > Lat >= -40:
        return 'H'
    elif -40 > Lat >= -48:
        return 'G'
    elif -48 > Lat >= -56:
        return 'F'
    elif -56 > Lat >= -64:
        return 'E'
    elif -64 > Lat >= -72:
        return 'D'
    elif -72 > Lat >= -80:
        return 'C'
    else:
        return 'Z'    # if the Latitude is outside the UTM limits

    # void UTM_to_LL(int ReferenceEllipsoid, const double UTMNorthing,
    #             const double UTMEasting, const char* UTMZone,
    #             double& Lat,  double& Long )


def LL_to_UTM(ReferenceEllipsoid, Lat, Long, ZoneNumber=False):
    """ Converts lat/long to UTM coords. Equations from USGS Bulletin 1532.

    East Longitudes are positive, west longitudes are negative. North latitudes
    are positive, south latitudes are negative. Lat and Long are in decimal
    degrees.

    Parameters
    ----------
    ReferenceEllipsoid : int
        Select from 23 reference ellipsoids:
            1. Airy
            2. Australian National
            3. Bessel 1841
            4. Bessel 1841 (Nambia)
            5. Clarke 1866
            6. Clarke 1880
            7. Everest
            8. Fischer 1960 (Mercury)
            9. Fischer 1968
            10. GRS 1967
            11. GRS 1980
            12. Helmert 1906
            13. Hough
            14. International
            15. Krassovsky
            16. Modified Airy
            17. Modified Everest
            18. Modified Fischer 1960
            19. South American 1969
            20. WGS 60
            21. WGS 66
            22. WGS-72
            23. WGS-84

    Lat, Long : float, ndarray
        Latitude and longitude values as floating point values. Negative
        coordinates are west and south for longitude and latitude respectively.

    ZoneNumber : str, optional
        UTM zone number in which the coordinates should be forced. This is
        useful if the spherical coordinates supplied in Lat and Long exceed
        a single UTM zone. Speficy both number and letter e.g. '30N'. If
        omitted, it is calculated automatically.


    Returns
    -------
    Zone : list
        UTM Zone for the coordinates supplied in Lat and Long.

    UTMEasting, UTMNorthing : ndarray
        Cartesian coordinates for the positions in Lat and Long.

    Notes
    -----
    Written by <NAME> - <EMAIL>
    Modified by <NAME> - pica {at} pml <dot> ac (dot) uk

    """

    if ~isinstance(Long, np.ndarray):
        Long = np.asarray(Long)
<commit_msg>Fix docstring for the UTM zone number type.<commit_after>#!/usr/bin/env python

# Lat Long - UTM, UTM - Lat Long conversions

# Adjusted for use with NumPy by <NAME> <pica {at} pml.ac.uk>

import inspect

import numpy as np

from warnings import warn

# LatLong- UTM conversion..h
# definitions for lat/long to UTM and UTM to lat/lng conversions
# include <string.h>

_EquatorialRadius = 2
_eccentricitySquared = 3

_ellipsoid = [
    # id, Ellipsoid name, Equatorial Radius, square of eccentricity first once
    # is a placeholder only, To allow array indices to match id numbers
    [-1, "Placeholder", 0, 0],
    [1, "Airy", 6377563, 0.00667054],
    [2, "Australian National", 6378160, 0.006694542],
    [3, "Bessel 1841", 6377397, 0.006674372],
    [4, "Bessel 1841 (Nambia] ", 6377484, 0.006674372],
    [5, "Clarke 1866", 6378206, 0.006768658],
    [6, "Clarke 1880", 6378249, 0.006803511],
    [7, "Everest", 6377276, 0.006637847],
    [8, "Fischer 1960 (Mercury] ", 6378166, 0.006693422],
    [9, "Fischer 1968", 6378150, 0.006693422],
    [10, "GRS 1967", 6378160, 0.006694605],
    [11, "GRS 1980", 6378137, 0.00669438],
    [12, "<NAME>", 6378200, 0.006693422],
    [13, "Hough", 6378270, 0.00672267],
    [14, "International", 6378388, 0.00672267],
    [15, "Krassovsky", 6378245, 0.006693422],
    [16, "Modified Airy", 6377340, 0.00667054],
    [17, "Modified Everest", 6377304, 0.006637847],
    [18, "Modified Fischer 1960", 6378155, 0.006693422],
    [19, "South American 1969", 6378160, 0.006694542],
    [20, "WGS 60", 6378165, 0.006693422],
    [21, "WGS 66", 6378145, 0.006694542],
    [22, "WGS-72", 6378135, 0.006694318],
    [23, "WGS-84", 6378137, 0.00669438]
]

# Reference ellipsoids derived from <NAME>'s website:
# http://www.utexas.edu/depts/grg/gcraft/notes/datum/elist.html
# Department of Geography,
# University of Texas at Austin
# Email: <EMAIL>
# 3/22/95

# Source:
# Defense Mapping Agency. 1987b. DMA Technical Report: Supplement to Department
# of Defense World Geodetic System 1984 Technical Report. Part I and II.
# Washington, DC: Defense Mapping Agency


def _test(inLat, inLong, inZone=False):
    """ Simple test of the functions with a given lat/long pair.

    Parameters
    ----------
    inLat, inLong : float
        Input latitude and longitude pair.

    """

    z, e, n = LL_to_UTM(23, inLat, inLong, ZoneNumber=inZone)
    outLat, outLong = UTM_to_LL(23, n, e, z)

    return z, e, n, outLat, outLong


def _UTM_letter_designator(Lat):
    # This routine determines the correct UTM letter designator for the given
    # latitude. Returns 'Z' if latitude is outside the UTM limits of 84N to 80S
    # Written by <NAME>: <EMAIL>star.com

    if 84 >= Lat >= 72:
        return 'X'
    elif 72 > Lat >= 64:
        return 'W'
    elif 64 > Lat >= 56:
        return 'V'
    elif 56 > Lat >= 48:
        return 'U'
    elif 48 > Lat >= 40:
        return 'T'
    elif 40 > Lat >= 32:
        return 'S'
    elif 32 > Lat >= 24:
        return 'R'
    elif 24 > Lat >= 16:
        return 'Q'
    elif 16 > Lat >= 8:
        return 'P'
    elif 8 > Lat >= 0:
        return 'N'
    elif 0 > Lat >= -8:
        return 'M'
    elif -8 > Lat >= -16:
        return 'L'
    elif -16 > Lat >= -24:
        return 'K'
    elif -24 > Lat >= -32:
        return 'J'
    elif -32 > Lat >= -40:
        return 'H'
    elif -40 > Lat >= -48:
        return 'G'
    elif -48 > Lat >= -56:
        return 'F'
    elif -56 > Lat >= -64:
        return 'E'
    elif -64 > Lat >= -72:
        return 'D'
    elif -72 > Lat >= -80:
        return 'C'
    else:
        return 'Z'    # if the Latitude is outside the UTM limits

    # void UTM_to_LL(int ReferenceEllipsoid, const double UTMNorthing,
    #             const double UTMEasting, const char* UTMZone,
    #             double& Lat,  double& Long )


def LL_to_UTM(ReferenceEllipsoid, Lat, Long, ZoneNumber=False):
    """ Converts lat/long to UTM coords. Equations from USGS Bulletin 1532.

    East Longitudes are positive, west longitudes are negative. North latitudes
    are positive, south latitudes are negative. Lat and Long are in decimal
    degrees.

    Parameters
    ----------
    ReferenceEllipsoid : int
        Select from 23 reference ellipsoids:
            1. Airy
            2. Australian National
            3. Bessel 1841
            4. Bessel 1841 (Nambia)
            5. Clarke 1866
            6. Clarke 1880
            7. Everest
            8. Fischer 1960 (Mercury)
            9. Fischer 1968
            10. GRS 1967
            11. GRS 1980
            12. Helmert 1906
            13. Hough
            14. International
            15. Krassovsky
            16. Modified Airy
            17. Modified Everest
            18. Modified Fischer 1960
            19. South American 1969
            20. WGS 60
            21. WGS 66
            22. WGS-72
            23. WGS-84

    Lat, Long : float, ndarray
        Latitude and longitude values as floating point values. Negative
        coordinates are west and south for longitude and latitude respectively.

    ZoneNumber : int, optional
        UTM zone number in which the coordinates should be forced. This is
        useful if the spherical coordinates supplied in Lat and Long exceed
        a single UTM zone. If omitted, it is calculated automatically.


    Returns
    -------
    Zone : list
        UTM Zone for the coordinates supplied in Lat and Long.

    UTMEasting, UTMNorthing : ndarray
        Cartesian coordinates for the positions in Lat and Long.

    Notes
    -----
    Written by <NAME> - <EMAIL>
    Modified by <NAME> - pica {at} pml <dot> ac (dot) uk

    """

    if ~isinstance(Long, np.ndarray):
        Long = np.asarray(Long)

{'fraction_non_alphanumeric': 0.11122688200052097, 'fraction_numerical': 0.1160024311886776, 'mean_word_length': 2.142701227830832, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 106, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '3576499', 'n_tokens_mistral': 4830, 'n_tokens_neox': 3789, 'n_words': 1351}