forked from fwitmer/CoastlineExtraction
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload_config.py
More file actions
71 lines (56 loc) · 3.01 KB
/
Copy pathload_config.py
File metadata and controls
71 lines (56 loc) · 3.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
"""
This script helps you load file paths from a config file for easy access in your project.
Steps to use:
1. Edit 'config_template.json' (or copy to 'config.json') in this folder. List your TIFF and SHP files.
2. In your script, import:
from load_config import load_config, get_image_path, get_shapefile_path
3. Load the config:
config = load_config()
4. Get the full path to a TIFF or SHP file by index:
image_path = get_image_path(config, 0) # First TIFF file
shapefile_path = get_shapefile_path(config, 0) # First SHP file
5. Change the index to select other files.
Example:
python load_config.py
# Prints the first image and shapefile path from the config.
"""
import json
import os
CONFIG_PATH = os.path.join(os.path.dirname(__file__), 'config_template.json')
def load_config(config_path=CONFIG_PATH):
"""Load the configuration JSON file."""
with open(config_path, 'r') as f:
return json.load(f)
def get_image_path(config, index=0):
"""Get the full path to an image file by index."""
return os.path.join(os.path.dirname(__file__), config['image_folder'], config['image_files'][index])
def get_raw_data_path(config, index=0):
"""Get the full path to a raw data file by index."""
return os.path.join(os.path.dirname(__file__), config['raw_data_folder'], config['raw_data_files'][index])
def get_shapefile_path(config, index=0):
"""Get the full path to a shapefile by index."""
return os.path.join(os.path.dirname(__file__), config['shapefile_folder'], config['shapefiles'][index])
def get_ground_truth_path(config, index=0):
"""Get the full path to a ground truth file by index."""
return os.path.join(os.path.dirname(__file__), config['ground_truth_folder'], config['ground_truth_files'][index])
def get_aligned_data_path(config, index=0):
"""Get the full path to an aligned data file by index."""
return os.path.join(os.path.dirname(__file__), config['aligned_data_folder'], config['aligned_data_files'][index])
def get_aligned_data_folder(config):
"""Get the full path to the aligned data folder."""
return os.path.join(os.path.dirname(__file__), config['aligned_data_folder'])
def get_georeference_output_folder(config):
"""Get the full path to the georeference output folder."""
return os.path.join(os.path.dirname(__file__), config['georeference_output_folder'])
def get_tile_images_output_folder(config):
"""Get the full path to the tile images output folder."""
return os.path.join(os.path.dirname(__file__), config['tile_images_output_folder'])
# Example:
if __name__ == "__main__":
config = load_config()
print("First image path:", get_image_path(config, 0))
print("First shapefile path:", get_shapefile_path(config, 0))
print("First aligned data path:", get_aligned_data_path(config, 0))
print("Aligned data folder:", get_aligned_data_folder(config))
print("Georeference output folder:", get_georeference_output_folder(config))
print("Tile images output folder:", get_tile_images_output_folder(config))