-
Notifications
You must be signed in to change notification settings - Fork 0
/
ingredients.py
152 lines (106 loc) · 3.08 KB
/
ingredients.py
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
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
146
147
148
149
150
151
152
#!/usr/bin/env python
import os
import json
import fnmatch
from pprint import pprint
def initialize_template():
ingredients = {
"config": {
"service_url": "http://localhost:8080/rasdaman/ows",
"tmp_directory": "/tmp/",
"crs_resolver": "http://localhost:8080/def/",
"default_crs": "http://localhost:8080/def/crs/EPSG/0/__insert__", # Insert EPSG
"mock": False,
"automated": False,
"subset_correction": True
},
"input": {
"coverage_id": "S2_TILE_TYPE", # Insert TILE and TYPE
"paths": [] # Append paths.
},
"recipe": {
"name": "time_series_irregular",
"options": {
"time_parameter" :{
"filename": {
"regex": "(.*)_(\\d\\d\\d\\d\\d\\d\\d\\d)_(.*)",
"group": "2"
},
"datetime_format": "YYYYMMDD"
},
"time_crs": "http://localhost:8080/def/crs/OGC/0/AnsiDate",
"tiling": "ALIGNED [0:127480, 0:85900, 1]"
}
}
}
return ingredients
def get_crs():
#use gdal to get crs
def insert_crs():
## Do this once per type of tile.
jsonconfig = ingredients["config"]
print jsonconfig["default_crs"]
jsonconfig["default_crs"] = 'apple'
def insert_coverageID(tile_name, cube_type):
## Do this once for type of tile
coverageID = "S2_{}_{}".format(tile_name, cube_type)
jsoninput = ingredients["input"]
def insert_paths(linux_folder, tile_path):
## Do this for each matching tile.
something = ''
path = os.path.join(linux_folder, something)
jsoninput = ingredients["input"]
path_list = jsoninput["paths"]
# append new path to list
def get_folders(root_folder):
'''This function returns all of the directories (with full path) located
directly in the input folder (i.e. root_folder).'''
#
# Create list for tile folder paths with one or more stacks for import.
#
tile_folders = []
#
# Set depth of next()
#
dir_names = 1
#
# Return list of tile folder paths.
#
for name in next(os.walk(root_folder))[dir_names]:
tile_folders.append(os.path.join(root_folder, name))
return tile_folders
def get_layer_paths(root_folder, cube_type):
'''This function returns paths to all layers/stacks of a certain type
located within the directory tree of the defined root folder.
Currently, all such layers are created directly in each tile folder.'''
#
# Create list for layer/stack paths for import/load.
#
layer_paths = []
for dirpath, dirnames, filenames in os.walk(folder, topdown=True):
for filename in filenames:
def save_ingredients(root_folder, cube_type, tile_name, ingredients):
'''This function saves a completed ingredients file to the root_folder. '''
#
# Creates ingredients file name and file path
#
json_name = 'ingredients_{}_{}.json'.format(cube_type, tile_name)
file_path = os.path.join(root_folder, json_name)
#
# Writes and saves the file to disk.
#
with open(file_path, 'w') as file:
file.write(json.dumps(ingredients))
if __name__ == '__main__':
#
# Where the tile folders are located.
#
root_folder = 'C:/temps2'
#
# The folder where the data will be for loading to the database.
#
linux_folder = "/var/projects/iq4sen/"
#
# The type of coverage for the ID (e.g. CLS, MSK, IQ4SEN)
#
cube_type = 'IQ4SEN'