Data Handlers
create_paths(template_pattern, paths_or_bases, *, default_file_pattern=None, debug_logs=False, replace_symbol='$', create_folders=True)
¶
Create output paths using a filename template_pattern and a list of reference paths or names.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_pattern
|
(str, required)
|
Defines output files from a glob path or folder to match input paths or names. Specify like: "/input/files/\(.tif" or "/input/folder" (while passing default_file_pattern like: '\).tif') |
required |
paths_or_bases
|
List[str]
|
List of full paths or base names to derive the replace_symbol from. |
required |
default_file_pattern
|
str
|
Used if |
None
|
debug_logs
|
bool
|
Whether to print the created paths. |
False
|
replace_symbol
|
str
|
Placeholder symbol in the template to replace with base names. |
'$'
|
create_folders
|
bool
|
Whether to create output folders if they don't exist. |
True
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: List of constructed file paths. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in spectralmatch/handlers.py
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
match_paths(input_match_paths, reference_paths, match_regex, debug_logs=False)
¶
Match reference_paths to input_match_paths using a regex applied to the basenames of input_match_paths. The extracted key must be a substring of the reference filename.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_match_paths
|
List[str]
|
List of candidate paths to extract keys from. |
required |
reference_paths
|
List[str]
|
List of reference paths to align to. |
required |
match_regex
|
str
|
Regex applied to basenames of input_match_paths to extract a key to match via inclusion in reference_paths (e.g. "(.*)_LocalMatch.gpkg$" (without one of the backslashes)). |
required |
debug_logs
|
bool
|
If True, print matched and unmatched file basenames. |
False
|
Returns:
| Type | Description |
|---|---|
List[Optional[str]]
|
List[Optional[str]]: A list the same length as |
List[Optional[str]]
|
element is the matched path from |
Raises:
| Type | Description |
|---|---|
ValueError
|
If output list length does not match reference_paths length. |
Source code in spectralmatch/handlers.py
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 | |
search_paths(search_pattern, *, default_file_pattern=None, recursive=False, match_to_paths=None, debug_logs=False)
¶
Search for files using a glob pattern, or a folder with a default file pattern.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
search_pattern
|
(str, required)
|
Defines input files from a glob path or folder. Specify like: "/input/files/.tif" or "/input/folder" (while passing default_file_pattern like: '.tif') |
required |
default_file_pattern
|
str
|
Used when |
None
|
recursive
|
bool
|
Whether to search recursively. |
False
|
match_to_paths
|
Tuple[List[str], str]
|
Matches input files to a reference list using a regex. |
None
|
debug_logs
|
bool
|
Whether to print matched paths. |
False
|
Returns:
| Type | Description |
|---|---|
List[str]
|
List[str]: Sorted list of matched file paths. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in spectralmatch/handlers.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 | |