You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When passing images to spectral_recovery.io.read_and_stack_tifs, each image must be named after the year the image was captured/derived, e.g "2022.tif", "2023.tif". This is true whether the user passes a list or a directory to the path_to_tifs= parameter. If a user's image names do not match the convention they are forced to rename all of their images before using the tool.
Context
This convention was used because there needed to be a way to definitively map an image to it's year/time coordinate in the DataArray structure that read_and_stack_tifs produces. See the involved code below:
image_dict = {}
if isinstance(path_to_tifs, str):
# check if path is a directory
if Path(path_to_tifs).is_dir():
path_to_tifs = list(Path(path_to_tifs).glob("*.tif"))
for file in path_to_tifs:
with rioxarray.open_rasterio(Path(file), chunks="auto") as data:
image_dict[Path(file).stem] = data
time_keys = []
for filename in image_dict.keys():
if _str_is_year(filename):
time_keys.append(pd.to_datetime(filename))
else:
raise ValueError(
f"TIF filenames must be in format 'YYYY' but received: '{filename}'"
) from None
stacked_data = _stack_bands(image_dict.values(), time_keys, dim_name="time")
The current workflow of mapping files to time, generally is:
Find all TIF files in a directory or read all files passed in the list
Parse years from filenames
For each image, convert year filenames to datetime objects and assign as image's time coordinate
Proposed Solution
Some more thought/discussion is needed on how/if this naming convention should be loosened.
The text was updated successfully, but these errors were encountered:
In the current version (0.4.1), I think the easiest way to finally address this is to allow users to to pass a dictionary mapping years to filenames. This should be in addition to being able to pass a path to a dir so to maintain backwards compatibility.
szwiep
changed the title
Allow less restrictive file naming
ENH: Allow dict of TIF files
Apr 18, 2024
Issue
When passing images to
spectral_recovery.io.read_and_stack_tifs
, each image must be named after the year the image was captured/derived, e.g "2022.tif", "2023.tif". This is true whether the user passes a list or a directory to thepath_to_tifs=
parameter. If a user's image names do not match the convention they are forced to rename all of their images before using the tool.Context
This convention was used because there needed to be a way to definitively map an image to it's year/time coordinate in the DataArray structure that
read_and_stack_tifs
produces. See the involved code below:The current workflow of mapping files to time, generally is:
Proposed Solution
Some more thought/discussion is needed on how/if this naming convention should be loosened.
The text was updated successfully, but these errors were encountered: