<commit_before># Coordinate reference systems and functions.
#
# PROJ.4 is the law of this land: http://proj.osgeo.org/. But whereas PROJ.4
# coordinate reference systems are described by strings of parameters such as
#
#   +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
#
# here we use mappings:
#
#   {'proj': 'longlat', 'ellps': 'WGS84', 'datum': 'WGS84', 'no_defs': True}
#

from six import string_types

def to_string(crs):
    """Turn a parameter mapping into a more conventional PROJ.4 string.

    Mapping keys are tested against the ``all_proj_keys`` list. Values of
    ``True`` are omitted, leaving the key bare: {'no_defs': True} -> "+no_defs"
    and items where the value is otherwise not a str, int, or float are
    omitted.
    """
    items = []
    for k, v in sorted(filter(
            lambda x: x[0] in all_proj_keys and x[1] is not False and (type
                (x[1]) in (bool, int, float) or isinstance(x[1],string_types)),
            crs.items() )):
        items.append(
            "+" + "=".join(
                map(str, filter(lambda y: y and y is not True, (k, v)))) )
    return " ".join(items)

def from_string(prjs):
    """Turn a PROJ.4 string into a mapping of parameters.
<commit_msg>Follow up to #83. All tests passing.<commit_after># Coordinate reference systems and functions.
#
# PROJ.4 is the law of this land: http://proj.osgeo.org/. But whereas PROJ.4
# coordinate reference systems are described by strings of parameters such as
#
#   +proj=longlat +ellps=WGS84 +datum=WGS84 +no_defs
#
# here we use mappings:
#
#   {'proj': 'longlat', 'ellps': 'WGS84', 'datum': 'WGS84', 'no_defs': True}
#

from six import string_types

def to_string(crs):
    """Turn a parameter mapping into a more conventional PROJ.4 string.

    Mapping keys are tested against the ``all_proj_keys`` list. Values of
    ``True`` are omitted, leaving the key bare: {'no_defs': True} -> "+no_defs"
    and items where the value is otherwise not a str, int, or float are
    omitted.
    """
    items = []
    for k, v in sorted(filter(
            lambda x: x[0] in all_proj_keys and x[1] is not False and (
                isinstance(x[1], (bool, int, float)) or 
                isinstance(x[1], string_types)),
            crs.items() )):
        items.append(
            "+" + "=".join(
                map(str, filter(lambda y: y and y is not True, (k, v)))) )
    return " ".join(items)

def from_string(prjs):
    """Turn a PROJ.4 string into a mapping of parameters.

{'fraction_non_alphanumeric': 0.12965186074429771, 'fraction_numerical': 0.013605442176870748, 'mean_word_length': 2.869969040247678, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '7173510', 'n_tokens_mistral': 841, 'n_tokens_neox': 805, 'n_words': 299}