<commit_before># -*- coding: utf-8 -*-
from pyquery import PyQuery
from lc8_download import lc8

from os.path import join, expanduser
from datetime import date, timedelta


def three_digit(number):
    """ Add 0s to inputs that their length is less than 3.
    For example: 1 --> 001 | 02 --> 020 | st --> 0st
    """
    number = str(number)
    if len(number) == 1:
        return '00%s' % number
    elif len(number) == 2:
        return '0%s' % number
    else:
        return number


def calendar_date(year, day):
    """Receive a year and the number of the day in the year and return the
    calendar date.
    """
    return date(int(year), 1, 1) + timedelta(int(day) - 1)


def download(scene_name, bands, path=None):
    """Call the lc8_download library to download Landsat 8 imagery."""
    scene = lc8.Downloader(scene_name)
    if path is None:
        return scene.download(bands, metadata=True)
    else:
        return scene.download(bands, path, metadata=True)


def get_cloud_rate(scene_name):
    """Read the MTL file of the scene and return the cloud_rate of the scene
    """

    mtl_path = join(expanduser('~'), 'landsat', scene_name, scene_name + '_MTL.txt')
    with open(mtl_path, 'r') as f:
        lines = f.readlines()
        cloud_rate = [float(line.split(' = ')[-1]) for line in lines if 'CLOUD_COVER' in line][0]
        return cloud_rate


def get_bounds(scene_name):
    """Use the Earth Explorer metadata to get bounds of the Scene"""
    metadata = PyQuery('http://earthexplorer.usgs.gov/fgdc/4923/%s/' % scene_name)
    metadata = metadata.text()[
        metadata.text().find('G-Ring_Latitude:'):
        metadata.text().find('\n  Keywords:')]
    coords = metadata.replace(' ', '') \
                .replace('G-Ring_Latitude:', '') \
                .replace('G-Ring_Longitude:', '')\
                .split('\n')
    coords = [float(coord) for coord in coords if coord != '']
    coords = [coords[i:i + 2] for i in range(0, len(coords), 2)]
    [coord.reverse() for coord in coords]
    coords.append(coords[0])
    return coords<commit_msg>more documentation on get_bounds function<commit_after># -*- coding: utf-8 -*-
from pyquery import PyQuery
from lc8_download import lc8

from os.path import join, expanduser
from datetime import date, timedelta


def three_digit(number):
    """ Add 0s to inputs that their length is less than 3.
    For example: 1 --> 001 | 02 --> 020 | st --> 0st
    """
    number = str(number)
    if len(number) == 1:
        return '00%s' % number
    elif len(number) == 2:
        return '0%s' % number
    else:
        return number


def calendar_date(year, day):
    """Receive a year and the number of the day in the year and return the
    calendar date.
    """
    return date(int(year), 1, 1) + timedelta(int(day) - 1)


def download(scene_name, bands, path=None):
    """Call the lc8_download library to download Landsat 8 imagery."""
    scene = lc8.Downloader(scene_name)
    if path is None:
        return scene.download(bands, metadata=True)
    else:
        return scene.download(bands, path, metadata=True)


def get_cloud_rate(scene_name):
    """Read the MTL file of the scene and return the cloud_rate of the scene
    """
    mtl_path = join(expanduser('~'), 'landsat', scene_name, scene_name + '_MTL.txt')
    with open(mtl_path, 'r') as f:
        lines = f.readlines()
        cloud_rate = [float(line.split(' = ')[-1]) for line in lines if 'CLOUD_COVER' in line][0]
        return cloud_rate


def get_bounds(scene_name):
    """Use Earth Explorer metadata to get bounds of a Scene"""
    metadata = PyQuery('http://earthexplorer.usgs.gov/fgdc/4923/%s/' % scene_name)
    metadata = metadata.text()[
        metadata.text().find('G-Ring_Latitude:'):
        metadata.text().find('\n  Keywords:')]
    coords = metadata.replace(' ', '') \
                .replace('G-Ring_Latitude:', '') \
                .replace('G-Ring_Longitude:', '')\
                .split('\n')
    coords = [float(coord) for coord in coords if coord != '']
    # create a list of lists with the coordinates
    coords = [coords[i:i + 2] for i in range(0, len(coords), 2)]
    # use reverse() to change [lat, lon] to [lon, lat]
    [coord.reverse() for coord in coords]
    # repeat the first coordinate on the end of the list
    coords.append(coords[0])
    return coords
{'fraction_non_alphanumeric': 0.13497355713957232, 'fraction_numerical': 0.016555530006898137, 'mean_word_length': 2.825857519788918, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2688244', 'n_tokens_mistral': 1460, 'n_tokens_neox': 1384, 'n_words': 439}