diff --git a/src/dolphin/io.py b/src/dolphin/io.py index 8fc7a9f4..fbab21a5 100644 --- a/src/dolphin/io.py +++ b/src/dolphin/io.py @@ -329,6 +329,26 @@ def get_raster_bounds( return (left, bottom, right, top) +def get_raster_metadata(filename: Filename, domain: str = ""): + """Get metadata from a raster file. + + Parameters + ---------- + filename : Filename + Path to the file to load. + domain : str, optional + Domain to get metadata for. Default is "" (all domains). + + Returns + ------- + dict + Dictionary of metadata. + """ + ds = gdal.Open(fspath(filename)) + md = ds.GetMetadata(domain) + return md + + def rowcol_to_xy( row: int, col: int, diff --git a/src/dolphin/utils.py b/src/dolphin/utils.py index f4e81691..6f149b9a 100644 --- a/src/dolphin/utils.py +++ b/src/dolphin/utils.py @@ -242,11 +242,11 @@ def sort_key(file_date_tuple): except TypeError: return (-1, dates) - date_file_tuples = [(get_dates(f, fmt=file_date_fmt), f) for f in files] - date_files = sorted([fd_tuple for fd_tuple in date_file_tuples], key=sort_key) + file_date_tuples = [(f, get_dates(f, fmt=file_date_fmt)) for f in files] + file_dates = sorted([fd_tuple for fd_tuple in file_date_tuples], key=sort_key) # Unpack the sorted pairs with new sorted values - dates, file_list = zip(*date_files) # type: ignore + file_list, dates = zip(*file_dates) # type: ignore return list(file_list), list(dates)