# Path: pyroSAR/_dev_config.py
# __LOCAL__ = ['sensor', 'projection', 'orbit', 'polarizations', 'acquisition_mode',
#              'start', 'stop', 'product', 'spacing', 'samples', 'lines']
# LOOKUP = Storage(attributes={'sensor': 'TEXT',
#                              'orbit': 'TEXT',
#                              'acquisition_mode': 'TEXT',
#                              'start': 'TEXT',
#                              'stop': 'TEXT',
#                              'product': 'TEXT',
#                              'samples': 'INTEGER',
#                              'lines': 'INTEGER',
#                              'outname_base': 'TEXT PRIMARY KEY',
#                              'scene': 'TEXT',
#                              'hh': 'INTEGER',
#                              'vv': 'INTEGER',
#                              'hv': 'INTEGER',
#                              'vh': 'INTEGER'})
# URL = Storage(dem=dem,
#               orbit=orbit,
#               auxcal=auxcal)
# STORAGE = Storage(URL=URL,
#                   LOOKUP=LOOKUP)
# class Storage(dict):
# class Singleton(type):
# class ConfigHandler(metaclass=Singleton):
#     def __getattr__(self, name):
#     def __repr__(self):
#     def __dir__(self):
#     def __init__(cls, name, bases, attrs, **kwargs):
#     def __call__(cls, *args, **kwargs):
#     def __init__(self):
#     def __create_config(self):
#     def __str__(self):
#     def __getitem__(self, section):
#     def sections(self):
#     def keys(self, section):
#     def open(self):
#     def add_section(self, section):
#     def file(self):
#     def set(self, section, key, value, overwrite=False):
#     def remove_option(self, section, key):
#     def remove_section(self, section):
#     def write(self):


import os
import re
import inspect
from math import sin, radians
from datetime import datetime
from ._dev_config import product_pattern
from spatialist.ancillary import finder
# license terms in the LICENSE.txt file found in the top-level
# directory of this distribution and at
# https://github.com/johntruckenbrodt/pyroSAR/blob/master/LICENSE.txt.
# No part of the pyroSAR project, including this file, may be
# copied, modified, propagated, or distributed except according
# to the terms contained in the LICENSE.txt file.
###############################################################################
"""
This module gathers central functions and classes for general pyroSAR applications.
"""



def groupby(images, attribute):
    """
    group a list of images by a metadata attribute
    
    Parameters
    ----------
    images: list of str
        the names of the images to be sorted
    attribute: str
        the name of the attribute used for sorting;
        see :func:`parse_datasetname` for options
    
    Returns
    -------
    list of lists
        a list containing a list with image names ofr each group
    """

# Path: pyroSAR/_dev_config.py
# __LOCAL__ = ['sensor', 'projection', 'orbit', 'polarizations', 'acquisition_mode',
#              'start', 'stop', 'product', 'spacing', 'samples', 'lines']
# LOOKUP = Storage(attributes={'sensor': 'TEXT',
#                              'orbit': 'TEXT',
#                              'acquisition_mode': 'TEXT',
#                              'start': 'TEXT',
#                              'stop': 'TEXT',
#                              'product': 'TEXT',
#                              'samples': 'INTEGER',
#                              'lines': 'INTEGER',
#                              'outname_base': 'TEXT PRIMARY KEY',
#                              'scene': 'TEXT',
#                              'hh': 'INTEGER',
#                              'vv': 'INTEGER',
#                              'hv': 'INTEGER',
#                              'vh': 'INTEGER'})
# URL = Storage(dem=dem,
#               orbit=orbit,
#               auxcal=auxcal)
# STORAGE = Storage(URL=URL,
#                   LOOKUP=LOOKUP)
# class Storage(dict):
# class Singleton(type):
# class ConfigHandler(metaclass=Singleton):
#     def __getattr__(self, name):
#     def __repr__(self):
#     def __dir__(self):
#     def __init__(cls, name, bases, attrs, **kwargs):
#     def __call__(cls, *args, **kwargs):
#     def __init__(self):
#     def __create_config(self):
#     def __str__(self):
#     def __getitem__(self, section):
#     def sections(self):
#     def keys(self, section):
#     def open(self):
#     def add_section(self, section):
#     def file(self):
#     def set(self, section, key, value, overwrite=False):
#     def remove_option(self, section, key):
#     def remove_section(self, section):
#     def write(self):


# Path: pyroSAR/ancillary.py
import os
import re
import inspect
from math import sin, radians
from datetime import datetime
from ._dev_config import product_pattern
from spatialist.ancillary import finder

# license terms in the LICENSE.txt file found in the top-level
# directory of this distribution and at
# https://github.com/johntruckenbrodt/pyroSAR/blob/master/LICENSE.txt.
# No part of the pyroSAR project, including this file, may be
# copied, modified, propagated, or distributed except according
# to the terms contained in the LICENSE.txt file.
###############################################################################
"""
This module gathers central functions and classes for general pyroSAR applications.
"""



def groupby(images, attribute):
    """
    group a list of images by a metadata attribute
    
    Parameters
    ----------
    images: list of str
        the names of the images to be sorted
    attribute: str
        the name of the attribute used for sorting;
        see :func:`parse_datasetname` for options
    
    Returns
    -------
    list of lists
        a list containing a list with image names ofr each group
    """

    images_sort = sorted(images, key=lambda x: re.search(product_pattern, x).group(attribute))