Exemple #1
0
def get_months_years(path, alert):
    """ From a given path of images, the function will return a list 
    of the months/years present in the folder
    
    """

    tifs = glob(f'{path}/*.tif')

    if tifs:
        try:
            years = list(
                set([ps.parse_other_files(image)[4].year for image in tifs]))
            months = list(
                set([ps.parse_other_files(image)[4].month for image in tifs]))
            years.sort()
            months.sort()

            return years, months

        except Exception as e:
            alert.add_msg("ERROR: Check the folder and make sure that \
                all the images follow the format: 'YYYY_mm_dd'",
                          type_='error')

            return None
    else:
        alert.add_msg("ERROR: The folder is empty. Please make sure that you \
            have run the closing filter before run the statistics.",
                      type_='error')
Exemple #2
0
def filter_dates(tifs, months=None, years=None, ini_date=None, end_date=None):
    """ Return a list of images filtered by months and 
        years.
    """
    # Get a list of tuples (date, image_name)

    list_ = [(pd.Timestamp(ps.parse_other_files(image)[4]), image)
             for image in tifs]
    x = pd.DataFrame(list_, columns=['date', 'image_name'])
    x = x.sort_values(['date'])

    # Create a indexdate
    x = x.reset_index(drop=True).set_index('date')

    # If months is empty

    if years and not months:
        months = list(range(1, 13))

    elif months and not years:
        years = list(set(x.index.year))

    if ini_date:
        df2 = x[ini_date:end_date]

    else:
        # Filter by months and years
        df2 = x[x.index.month.isin(months) & (x.index.year.isin(years))]

    filtered = list(df2['image_name'])

    return filtered
Exemple #3
0
def images_summary(tifs):
    
    list_ = [(pd.Timestamp(ps.parse_other_files(image)[4]), image) for image in tifs]
    x = pd.DataFrame(list_, columns=['date','Image name'])
    x = x.sort_values(['date'])
    x = x.reset_index(drop=True).set_index('date')

    # Transform the index in string, because json can't decode 
    # de datetimeindex
    x.index = x.index.strftime("%Y-%m-%d")
    
    return x