Exemplo n.º 1
0
def get_weather_data(path):
    """Helper function to get weather data from S3 or locally

    Args:
      path (str): path (either local or s3 (s3://...)) to CSV to load weather data from

    Returns:
      dict: period => list(weather data)
    """

    if path.startswith('s3'):
        csvpath = get_from_s3(path)
    else:
        csvpath = path

    weather_dict = {}
    with open(csvpath, 'rb') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            date_str = row.pop('datetime')
            date, time = date_str.split('T')
            year, month, day = date.split('-')
            hour, _, _ = time.split(':')
            period = year + month + day + hour
            weather_dict[period] = row.values()
    return weather_dict
Exemplo n.º 2
0
def get_weather_data(path):
    """Helper function to get weather data from S3 or locally

    Args:
      path (str): path (either local or s3 (s3://...)) to CSV to load weather data from

    Returns:
      dict: period => list(weather data)
    """

    if path.startswith('s3'):
        csvpath = get_from_s3(path)
    else:
        csvpath = path

    weather_dict = {}
    with open(csvpath, 'rb') as csvfile:
        reader = csv.DictReader(csvfile)
        for row in reader:
            date_str = row.pop('datetime')
            date, time = date_str.split('T')
            year, month, day = date.split('-')
            hour, _, _ = time.split(':')
            period = year + month + day + hour
            weather_dict[period] = row.values()
    return weather_dict
Exemplo n.º 3
0
def tiff_to_array(path):
    """Function that loads a geotiff into a numpy array

    Args:
      path (str): s3 or local path to load tiff from

    Returns:
      numpy array
    """

    if path.startswith('s3'):
        local_raster_path = get_from_s3(path)
    else:
        local_raster_path = path

    return raster_to_array(local_raster_path)