10
10
from processing .const import CustomMimeType
11
11
from openeoerrors import Internal
12
12
13
+ import json
14
+
13
15
# assume it's only 1 time and 1 bands dimension
14
16
def check_dimensions (time_dimensions , bands_dimensions ):
15
17
if len (time_dimensions ) == 0 :
16
- raise Internal ("No time dimensions exist. Only 1 time dimension is supported." )
18
+ print ("No time dimensions exist. Only 1 time dimension is supported." )
19
+ # raise Internal("No time dimensions exist. Only 1 time dimension is supported.")
17
20
18
21
if len (time_dimensions ) > 1 :
19
22
raise Internal ("More than 1 time dimension exist. Only 1 time dimension is supported." )
@@ -29,18 +32,52 @@ def get_timestamps_arrays(datacube_time_as_bands, time_dimensions, bands_dimensi
29
32
num_of_img_bands = len (datacube_time_as_bands ["band" ])
30
33
num_of_bands_dimension = len (bands_dimensions [0 ]["labels" ])
31
34
35
+ num_time_labels = 0
36
+ for time_dim in time_dimensions :
37
+ num_time_labels += len (time_dim ["labels" ])
38
+
39
+ num_band_labels = 0
40
+ for band_dim in bands_dimensions :
41
+ num_band_labels += len (band_dim ["labels" ])
42
+
43
+ num_actual_img_bands = (num_time_labels or 1 ) * (num_band_labels or 1 )
44
+
32
45
list_of_timestamps = []
33
46
list_of_timestamp_arrays = []
34
47
35
- for i in range (0 , num_of_img_bands , num_of_bands_dimension ):
36
- date = time_dimensions [0 ]["labels" ][int (i / num_of_bands_dimension )]
48
+ printdata = {
49
+ "data" : datacube_time_as_bands ,
50
+ "data_length" : len (datacube_time_as_bands ),
51
+ "data_len/num_of_bands_dimension" : len (datacube_time_as_bands ) / num_of_bands_dimension ,
52
+ "bands_dimensions" : bands_dimensions ,
53
+ "time_dimensions" : time_dimensions ,
54
+ "num_img_bands" : num_of_img_bands ,
55
+ "num_bands_dim" : num_of_bands_dimension ,
56
+ "range" : range (0 , num_actual_img_bands , num_of_bands_dimension ),
57
+ "num_actual_img_bands" : num_actual_img_bands ,
58
+ "num_band_labels" : num_band_labels ,
59
+ "num_time_labels" : num_time_labels ,
60
+ }
61
+
62
+ print ("get_timestamps_arrays" )
63
+ print (json .dumps (printdata , sort_keys = True , indent = 4 , default = str ))
64
+
65
+ for i in range (0 , num_actual_img_bands , num_of_bands_dimension ):
66
+
67
+ print ("for loop" , {
68
+ "time_dims" : time_dimensions ,
69
+ "time_dim_index" : int (i / num_of_bands_dimension )
70
+ })
71
+
72
+
73
+ date = time_dimensions [0 ]["labels" ][int (i / num_of_bands_dimension )] if num_time_labels > 0 else ""
37
74
timestamp_array = datacube_time_as_bands [i : i + num_of_bands_dimension ]
38
75
39
76
if output_format in [CustomMimeType .NETCDF , CustomMimeType .ZARR ]:
40
- pandas_time = pd .to_datetime (parser .parse (date ))
41
77
timestamp_array = timestamp_array .assign_coords (band = bands_dimensions [0 ]["labels" ])
42
- timestamp_array = timestamp_array .assign_coords (t = pandas_time )
43
- timestamp_array = timestamp_array .expand_dims (dim = "t" )
78
+ if num_time_labels > 0 :
79
+ timestamp_array = timestamp_array .assign_coords (t = pd .to_datetime (parser .parse (date )))
80
+ timestamp_array = timestamp_array .expand_dims (dim = "t" )
44
81
45
82
list_of_timestamps .append (date )
46
83
list_of_timestamp_arrays .append (timestamp_array )
@@ -51,7 +88,8 @@ def get_timestamps_arrays(datacube_time_as_bands, time_dimensions, bands_dimensi
51
88
def save_as_gtiff (list_of_timestamps , list_of_timestamp_arrays , output_dir , output_name ):
52
89
output_file_paths = []
53
90
for array , date in zip (list_of_timestamp_arrays , list_of_timestamps ):
54
- file_name = f"{ output_name ['name' ]} _{ date } { output_name ['ext' ]} "
91
+ date_string = "" if date == "" else f"_{ date } "
92
+ file_name = f"{ output_name ['name' ]} { date_string } { output_name ['ext' ]} "
55
93
file_path = os .path .join (output_dir , file_name )
56
94
output_file_paths .append (file_path )
57
95
@@ -92,6 +130,9 @@ def parse_multitemporal_gtiff_to_format(input_tiff, input_metadata, output_dir,
92
130
if len (bands_dimensions ) == 0 :
93
131
bands_dimensions = [{"name" : "bands" , "type" : "bands" , "labels" : ["results" ]}]
94
132
133
+ # if len(time_dimensions) == 0:
134
+ # time_dimensions = [{"name": "t", "type": "temporal", "labels": [""]}]
135
+
95
136
check_dimensions (time_dimensions , bands_dimensions )
96
137
97
138
list_of_timestamps , list_of_timestamp_arrays = get_timestamps_arrays (
0 commit comments