utils
Helper functions used by other package modules.
extract_archive(file_path)
Extracts a ZIP archive into a directory with the same name as the file's base name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the ZIP file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
list[str]
|
A list of extracted file paths. |
Source code in rastertoolkit/utils.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
read_json(json_path)
Reads a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
json_path
|
str
|
Path to the JSON file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
dict[str, Any]
|
A dictionary representing the JSON structure. |
Source code in rastertoolkit/utils.py
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |
save_json(data, json_path, sort_keys=False, indent=4)
Saves a JSON object to a file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
dict
|
JSON object to be saved. |
required |
json_path
|
str
|
Path to the JSON file. |
required |
sort_keys
|
bool
|
Whether to sort the JSON keys. Defaults to False. |
False
|
indent
|
int
|
Indentation level for pretty-formatting the JSON file. Defaults to None. |
4
|
Returns:
| Type | Description |
|---|---|
None
|
None |
Source code in rastertoolkit/utils.py
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 | |
sha256(file_path)
Calculates the SHA-256 hash of a file.
Reference
https://www.quickprogrammingtips.com/python/how-to-calculate-sha256-hash-of-a-file-in-python.html
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
Path to the file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
A string representing the SHA-256 hash hex digest. |
Source code in rastertoolkit/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 | |