-
Notifications
You must be signed in to change notification settings - Fork 0
/
create_cloudless.py
executable file
·634 lines (493 loc) · 27.3 KB
/
create_cloudless.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
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
#!/usr/bin/env python
#
#------------------------------------------------------------------------------
# -*- coding: utf-8 -*-
#-------------------------------------------------------------------------------
#
#
# Tool to generate cloudless products over a period of chosen time
# e.g. 10-days from the existing products
#
#
# Project: DeltaDREAM
# Name: create_cloudless.py
# Authors: Christian Schiller <christian dot schiller at eox dot at>
#
#-------------------------------------------------------------------------------
# Copyright (C) 2014 EOX IT Services GmbH
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies of this Software or works derived from this Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
#-------------------------------------------------------------------------------
#
#
import sys
import os
import time
import getopt
import wcs_client
# specific imports
from get_config import get_config
import tempfile
import shutil
from osgeo import gdal
from util import handle_error, set_logging, print_log, parse_xml
# check for OS Platform and set the Directory-Separator to be used
global dsep
dsep = os.sep
# the default config file (use full path here) - all other config parameters
# e.g. logging, dataset locations, etc. should be provided there
default_config_file = os.path.abspath('.')+dsep+"conf"+dsep+"cloudless_config.cfg"
# XML search tags for the request responses
xml_ID_tag = ['wcseo:DatasetSeriesId', 'wcs:CoverageId' ]
xml_date_tag = ['gml:beginPosition', 'gml:endPosition']
xml_bbox_tag = ['ows:LowerCorner', 'ows:UpperCorner']
# create a wcsClient instance to be used
global wcs
wcs = wcs_client.wcsClient()
# indicator that: output_format and/or output_datatype has been set at the cmd-line
# and a conversion of the results is needed
change_output = False
# ----------
# for performance testing/evaluation
startTime1 = time.time()
#/************************************************************************/
#/* usage() */
#/************************************************************************/
def usage():
"""
Print out the Usage information
"""
print ""
print "Usage: create_cloudless.py [-d|--dataset] <dataset> [-a|--aoi] <'minx,maxx,miny,maxy'> [-t|--time] <startdate> "
print " ([-s|--scenario] <T|M|B>) ([-p|--period] <num_days>) (-b|--bands <list_of_bands>) "
print " (-o|--output_dir <target_path>) (-k|--keep_temporary) "
print " "
print " Tool to generate cloudless products over a period of X-days from the existing products. The processing ends after X-days"
print " or when no more clouds are present."
print " REQUIRED parameters: "
print " -d|--dataset <dataset> -- Dataset to be used e.g. SPOT4Take5 "
print " -a|--aoi <'maxx,minx,maxy,miny'> -- the Area of Interest (AOI), with the coordinates of the BoundingBox, provided as"
print " the corner coordinates in Degrees (WGS84, Lat/Lon)"
print " -t|--time <startdate> -- Starttime - Date of the image to start with in ISO-Format e.g. '20120423' "
print " -o|--output_dir -- location to store the output/results "
print " OPTIONAL parameters: "
print " -h|--help -- This help information"
print " -i|--info -- Information about available DatasetSeries (result of GetCapability-DatasetSeriesSummary requests)"
print " -s|--scenario <T|M|B> -- Scenario type: a) input Dataset is topmost-layer (T), filling in clouded areas with pixels"
print " from older images [=default]"
print " b) input Dataset is middle (M), alternating newer and older images"
print " c) input Dataset acts as bottom-layer (B), filling in clouded areas with pixels"
print " from newer images"
print " [default=SUB]"
print " -p|--period <num days/img> -- time period (number of days(wcs)/images(local)) to run the cloudless processing [optional, default=7]"
print " a period of 10 days/images will usually be sufficient to achieve a good result."
print " -b|--bands <'b1,b2,..bn'> -- list of bands to be processed e.g. '3,2,1' [default = use all bands] "
print " -k|--keep_temporary -- do not delete the input files used for Cloudfree Product generation, but copy them "
print " to the output_dir"
print " -c|--output_crs -- the EPSG code (epsg:number) of the desired output [default='epsg:4326'] "
print " -f|--output_format -- output fileformat for the cloud-free product [default=GeoTiFF] "
print " - possible output formats: all formats supported by gdal as writable) "
print " - for listing use: ./create_cloudless.py --help_formats "
print " -y|--output_datatype -- the datatype of the desired output [default = same as input]; Valids are: Byte/Int16/ "
print " UInt16/UInt32/Int32/Float32/Float64/CInt16/CInt32/CFloat32/CFloat64 "
print " -e|--extract <SUB|FULL> -- work on an extracted subset (AOI) or use datsets as full files [default=SUB]"
print " "
print " "
print "Example: ./create_cloudless.py -d landsat5_2a -a 3.5,3.6,43.3,43.4 -t 20110513 -s T -b 3,2,1 -p 90 -o ./out "
print " "
sys.exit()
#/************************************************************************/
#/* help_formats() */
#/************************************************************************/
def help_formats():
os.system('gdal_translate --formats |grep "(rw"')
sys.exit()
#/************************************************************************/
#/* now() */
#/************************************************************************/
def now():
"""
get the current time stamp eg. for error messages
"""
return time.strftime('[%Y%m%dT%H%M%S] - ')
#/************************************************************************/
#/* check_toiinput() */
#/************************************************************************/
def check_toiinput(settings, period_in):
"""
check that the limit for TOI is considered, test for def_maxtoi
"""
if int(period_in) > int(settings['general.def_maxtoi']):
print '[Error] -- The chosen period is larger then the configured "def_maxtoi" of: ', settings['general.def_maxtoi']
sys.exit()
#/************************************************************************/
#/* check_aoiinput() */
#/************************************************************************/
def check_aoiinput(settings, aoi_in):
"""
check that the limit for AOI is considered, test for def_maxaoi
the def_maxaoi represents one-side of a square (in degree)
"""
def_aoi = float(settings['general.def_maxaoi'])**2
aoi = (float(aoi_in[1])-float(aoi_in[0])) * (float(aoi_in[3])-float(aoi_in[2]))
#print aoi, '-- ', def_aoi
if aoi > def_aoi:
print '[Error] -- The chosen AOI is larger then the configured "def_maxaoi" of: ', settings['general.def_maxaoi'], '*', settings['general.def_maxaoi'], ' degrees.'
sys.exit()
#/************************************************************************/
#/* dss_info() */
#/************************************************************************/
def dss_info(settings):
"""
provide listings of available DatasetSeries from all configured servers
(from the configuration file)
"""
# get all uniq servers defined in the config-file
serv_list = []
# just grab the server info - strip off the rest
for vv in settings.itervalues():
if vv.__class__ is str and vv.startswith('http'):
ss = vv.split('?')
serv_list.append(ss[0]+'?')
# get the uniqu server listing
serv_list = sorted(set(serv_list))
# call each server and ask for a GetCapabilities-DatasetSeriesSummary
for target_server in serv_list:
# result_list = list_available_dss(target_server, True)
list_available_dss(target_server, True)
print '-----------'
sys.exit()
#/************************************************************************/
#/* get_available_dss() */
#/************************************************************************/
def list_available_dss(target_server, printit):
"""
provides a listing of all DatasetSeries and and their respective
Coverage-Time-Ranges (Start-Stop) for all configured WCS servers
"""
#print target_server
global wcs
request = {'request': 'GetCapabilities',
'sections': 'DatasetSeriesSummary,ServiceIdentification',
'server_url': target_server }
getcap_xml = wcs.GetCapabilities(request, settings)
if getcap_xml is not None:
dss_ids = parse_xml(getcap_xml, xml_ID_tag[0])
dss_date1 = parse_xml(getcap_xml, xml_date_tag[0])
dss_date2 = parse_xml(getcap_xml, xml_date_tag[1])
dss_ll = parse_xml(getcap_xml, xml_bbox_tag[0])
dss_ur = parse_xml(getcap_xml, xml_bbox_tag[1])
else:
err_msg = 'Server not responding -- Skipping...'
print err_msg
return
if printit is True:
# prints the available DatasetSeriesIds and theri Coverage time-ranges to the screen
print "The following DatasetSeries [Name: From-To / LL-UR BBox] are available from: \t", request['server_url']
for i in range(len(dss_ids)):
#print " - ", dss_ids[i] , ": \t", dss_date1[i], " - ", dss_date2[i], '\n \t \t \t', dss_ll[i], " - ", dss_ur[i]
print " - ", dss_ids[i] , ': \n \t \t \t', dss_date1[i], " - ", dss_date2[i], '\n \t \t \t', dss_ll[i], " - ", dss_ur[i]
#/************************************************************************/
#/* do_cleanup() */
#/************************************************************************/
def do_cleanup_tmp(temp_storage, cf_result, input_params, settings):
"""
clean up the temporary storagespace used during download and processing
"""
if input_params['keep_temporary'] is False:
lmsg = 'Cleaning up temporary space...'
print_log(settings, lmsg)
if type(cf_result) is list:
for elem in cf_result:
elem = os.path.basename(elem)
shutil.copy2(temp_storage+dsep+elem, input_params['output_dir'])
elif type(cf_result) is unicode or type(cf_result) is str:
shutil.copy2(temp_storage+dsep+elem, input_params['output_dir'])
if os.path.exists(input_params['output_dir']+os.path.basename(cf_result[0])):
lmsg = '[Info] -- The Cloudfree dataset has been generated and is available at: '
print_log(settings, lmsg)
for elem in cf_result:
if os.path.exists(input_params['output_dir']+os.path.basename(elem)):
lmsg = input_params['output_dir']+os.path.basename(elem)
print_log(settings, lmsg)
# remove all the temporay storage area
shutil.rmtree(temp_storage, ignore_errors=True)
else:
lmsg = '[Error] -- The generated Cloudfree output-file could not be written to: ', input_params['output_dir']+os.path.basename(cf_result)
print_log(settings, lmsg)
sys.exit(7)
else:
lmsg = temp_storage[:-1]
print_log(settings, lmsg)
out_location = input_params['output_dir']+os.path.basename(temp_storage[:-1])
lmsg = '[Info] -- The Cloudfree dataset and the input files are available at: ', out_location
print_log(settings, lmsg)
shutil.move(temp_storage, input_params['output_dir'])
#/************************************************************************/
#/* do_print_flist() */
#/************************************************************************/
def do_print_flist(name, a_list):
"""
prints a listing of the supplied filenames (eg. BaseImage, GapFillingProducts,
and their respective Cloud-Mask filenames which are available/used)
"""
f_cnt = 1
for elem in a_list:
lmsg = name, f_cnt,': ', elem
print_log(settings, lmsg)
f_cnt += 1
#/************************************************************************/
#/* get_cmdline() */
#/************************************************************************/
def get_cmdline():
"""
get_cmdline() function - processing of the command-line inputs
Outputs the dictionary: input[ 'in_dataset':, 'in_aoi':, 'in_toi': 'in_scenario':,
'in_extract':, 'in_period':, 'in_output_crs':, 'in_bands':, 'in_output_datatype':, 'in_output_dir':,
'output_format': ]
"""
global change_output
try:
opts, args = getopt.getopt(sys.argv[1:], "hika:d:t:s:e:p:c:b:y:o:f:", ["help", "info", "aoi",
"time", "dataset", "scenario", "extract", "period", "crs", "bands", "datatype",
"output_dir", "output_format", "keep_temporary", "help_formats"])
except getopt.GetoptError, err:
# print help information and exit - will print something like "option -x not recognized"
print '[Error] -- ', now(), str(err)
usage()
input_params = {
'dataset' : None,
'aoi' : None,
'toi' : None,
'scenario' : None,
'extract' : None,
'period' : None,
'output_crs' : None,
'bands': None,
'output_datatype' : None,
'output_dir' : None,
'output_format' : None,
'keep_temporary' : False
}
if (len(sys.argv[1:]) == 0):
usage()
for opt, arg in opts:
if opt in ("-h", "--help", "-help", "help"):
usage()
elif opt in ("--help_formats"):
help_formats()
elif opt in ("-i", "--info", "-info", "info"):
print '==== You requested DatasetSeries information from all configured Servers ===='
dss_info(settings)
elif opt in ("-d", "--dataset"):
if arg is None or arg.startswith('-'):
print "[Error] -- 'dataset' is a required input parameter"
usage()
else:
input_params['dataset'] = arg
elif opt in ("-a", "--aoi"):
if arg is None:
print "[Error] -- 'aoi' is a required input parameter"
usage()
else:
input_params['aoi'] = arg.split(',') # as minx, maxx, miny, maxy
if len(input_params['aoi']) != 4:
print "[Error] -- the aoi requires 4 parameters 'minx, maxx, miny, maxy'"
usage()
elif opt in ("-t", "--time"):
if arg is None or arg.startswith('-'):
print "[Error] -- the 'time' is a required input parameter"
usage()
else:
input_params['toi'] = arg
elif opt in ("-s", "--scenario"):
input_params['scenario'] = str.upper(arg)
elif opt in ("-e","--extract"):
input_params['extract'] = str.upper(arg)
elif opt in ("-p","--period"):
input_params['period'] = int(arg)
elif opt in ("-o","--output_dir"):
if arg is None:
print "[Error] -- '-o <output_directory>' is a required input parameter"
usage()
else:
input_params['output_dir'] = arg
if input_params['output_dir'][-1] != dsep:
input_params['output_dir'] = input_params['output_dir']+dsep
elif opt in ("-b","--bands"):
if arg.count(',') > 0 or len(arg) == 1:
input_params['bands'] = arg.split(',')
else:
err_msg = '[Error] -- supplied Band parameters cannot be handled: ', opt, arg
handle_error(err_msg, 2, settings)
elif opt in ("-c","--crs"):
input_params['output_crs'] = arg
elif opt in ("-y","--datatype"):
input_params['output_datatype'] = str.lower(arg)
change_output = True
elif opt in ("-f", "--output_format"):
input_params['output_format'] = str.lower(arg)
change_output = True
input_params['output_format'] = str.upper(arg)
change_output = True
elif opt in ("-k","--keep_temporary"):
input_params['keep_temporary'] = True
else:
print '[Error] -- ', now(), ' unknown option(s): ', opts
# set the default values if optional parameters have not been supplied at the cmd-line
if input_params['bands'] is None: input_params['bands'] = settings['general.def_bands']
if input_params['period'] is None: input_params['period'] = int(settings['general.def_period'])
if input_params['scenario'] is None: input_params['scenario'] = str.upper(settings['general.def_scenario'])
if input_params['output_crs'] is None: input_params['output_crs'] = settings['general.def_output_crs']
if input_params['output_datatype'] is None: input_params['output_datatype'] = str.lower(settings['general.def_output_datatype'])
if input_params['output_format'] is None: input_params['output_format'] = str.upper(settings['general.def_output_format'])
if input_params['extract'] is None: input_params['extract'] = str.upper(settings['general.def_extract'])
# check that all required parameters are supplied
if input_params['dataset'] is None:
print "\n[Error] -- '-d <dataset>' is a required input parameter"
usage()
if input_params['aoi'] is None:
print "\n[Error] -- '-a <aoi>' is a required input parameter"
usage()
if input_params['toi'] is None:
print "\n[Error] -- '-t <time>' is a required input parameter"
usage()
if input_params['output_dir'] is None:
print "\n[Error] -- '-o <output_directory>' is a required input parameter"
usage()
# check the limits for AOI and TOI are considered
# test for def_maxtoi
check_toiinput(settings, input_params['period'])
# test for def_maxaoi
check_aoiinput(settings, input_params['aoi'])
return input_params
#/************************************************************************/
#/* cnv_output() */
#/************************************************************************/
def cnv_output(cf_result, input_params, settings):
"""
convert the resulting CF_image and CF_Mask accoring to the user requested
output_crs, output_format, output_datatype
"""
# @@
supported_ext = {'VRT': '.vrt', 'GTIFF': '.tif', 'NITF': '.nitf', 'HFA': '.img', 'ELAS': '.ELAS', 'AAIGRID': '.grd', 'DTED': '.DTED', 'PNG': '.png', 'JPEG': '.jpg', 'MEM': '.mem', 'GIF': '.gif', 'XPM': '.xpm', 'BMP': '.bmp', 'PCIDSK': '.PCIDSK', 'PCRASTER': '.PCRaster', 'ILWIS': '.ilw', 'SGI': '.sgi', 'SRTMHGT': '.SRTMHGT', 'LEVELLER': '.Leveller', 'TERRAGEN': '.Terragen', 'GMT': '.gmt', 'NETCDF': '.nc', 'HDF4IMAGE': '.hdf', 'ISIS2': '.ISIS2', 'ERS': '.ers', 'FIT': '.fit', 'JPEG2000': '.jp2', 'RMF': '.rmf', 'WMS ':'.WMS', 'RST': '.rst', 'INGR': '.INGR', 'GSAG': '.grd', 'GSBG': '.grd', 'GS7BG': '.grd', 'R': '.r', 'PNM': '.pnm', 'ENVI': '.img', 'EHDR': '.hdr', 'PAUX': '.aux', 'MFF': '.mff', 'MFF2': '.mff2', 'BT': '.bt', 'LAN': '.lan', 'IDA': '.ida', 'LCP': '.lcp', 'GTX': '.GTX', 'NTV2': '.NTv2', 'CTABLE2': '.CTable2', 'KRO': '.KRO', 'ARG': '.ARG', 'USGSDEM': '.USGDEM', 'ADRG': '.img', 'BLX': '.blx', 'RASTERLITE': '.Rasterlite', 'EPSILON': '.Epsilon', 'POSTGISRASTER': '.PostGISRaster', 'SAGA': '.sdat', 'KMLSUPEROVERLAY': '.kmlovl', 'XYZ': '.xyz', 'HF2': '.HF2', 'PDF': '.pdf', 'WEBP': '.webp', 'ZMAP': '.ZMap'}
if supported_ext.has_key(input_params['output_format']):
out_ext = supported_ext.get(input_params['output_format'])
lmsg = 'Converting -- CF_image and CF_mask to: ' + input_params['output_format'] + ' [ *' + out_ext + ']'
print_log(settings, lmsg)
if input_params['output_format'] == 'GTIFF':
tr_params1 = ""
else: tr_params1 = " -of " + str(input_params['output_format'])
if input_params['output_datatype'] == 'input':
tr_params2 = ""
else: tr_params2 = " -ot " + str(input_params['output_datatype'])
tr_params = tr_params1 + tr_params2
#print tr_params + " " + input_params['output_dir'] + cf_result[0] + " " + input_params['output_dir'] + cf_result[0][:-4]+out_ext
res = os.system("gdal_translate -q" + tr_params + " " + input_params['output_dir'] + cf_result[0] + " " + input_params['output_dir'] + cf_result[0][:-4]+out_ext )
if res is 0:
os.remove(input_params['output_dir'] + cf_result[0])
else:
err_msg = '[Error] - CF_image could not be converted'
handle_error(err_msg, res, settings)
res = os.system("gdal_translate -q" + tr_params + " " + input_params['output_dir'] + cf_result[1] + " " + input_params['output_dir'] + cf_result[1][:-4]+out_ext )
if res is 0:
os.remove(input_params['output_dir'] + cf_result[1])
else:
err_msg = '[Error] - CF_mask could not be converted'
handle_error(err_msg, res, settings)
#/************************************************************************/
#/* main() */
#/************************************************************************/
def main():
"""
Main function:
calls the subfunction according to user input
"""
# read in the default settings from the configuration file
global settings
settings = get_config(default_config_file)
# set the logging output i.e. to a File or the screen
set_logging(settings)
# get all parameters provided via cmd-line
global input_params
input_params = get_cmdline()
# now that we know what dataset we need and where to find them, select the
# correct reader for the requested dataset
# first test if requested dataset does exist
if settings.has_key('dataset.'+input_params['dataset']):
reader = 'CF_' + input_params['dataset'] + '_Reader'
else:
err_msg = '[Error] -- ', now(), ' the requested dataset does not exist (is not configured)', input_params['dataset']
err_code = 3
handle_error(err_msg, err_code, settings)
# call the reader module for the resepective dataset and process the data
import dataset_reader
attribute = getattr(dataset_reader, reader)
f_read = attribute()
#print 'READER: ', f_read #@@
# gets a listing of available DatasetSeries and their corresponding time-range
base_flist, base_mask_flist, gfp_flist, gfpmask_flist = f_read.get_filelist(input_params, settings)
# @@@@
## processing-limits (max. filenumber to be used) here # @@@
if gfp_flist.__len__() > int(settings['general.def_maxfiles']):
err_msg = '[Error] -- ', now(), ' the number of GFP products availabel (=', str(gfp_flist.__len__()).strip(),') for the selected time period is larger then the configured "def_maxfiles" of: ', settings['general.def_maxfiles'], '\n', 'Please select a shorter time-period.'
err_code = 4
handle_error(err_msg, err_code, settings)
# print the available input datasets: eg. during testing
do_print_flist('BASE', base_flist)
do_print_flist('BASE_Mask', base_mask_flist)
do_print_flist('GFP', gfp_flist)
do_print_flist('GFP_Mask', gfpmask_flist)
lmsg = 'Dataset_listing - RUNTIME in sec: ', time.time() - startTime1
print_log(settings, lmsg)
# create a temporarylocation under the provided settings['general.def_temp_dir'] to be used
# for the temporary storage during processing
temp_storage = tempfile.mkdtemp(prefix='cloudfree_',dir=settings['general.def_temp_dir'])
if temp_storage[-1] != dsep:
temp_storage = temp_storage+dsep
if len(base_flist) >= 1:
f_read.base_getcover(base_flist, input_params, settings, temp_storage, mask=False)
if len(base_mask_flist) >= 1:
f_read.base_getcover(base_mask_flist, input_params, settings, temp_storage, mask=True)
lmsg = 'BASE dataset_download - RUNTIME in sec: ', time.time() - startTime1 #, '\n'
print_log(settings, lmsg)
# call the Processor module for the resepective dataset and process the data
import dataset_processor
cfprocessor = 'CF_' + input_params['dataset'] + '_Processor'
attribute = getattr(dataset_processor, cfprocessor)
f_proc = attribute()
#print 'PROCESSOR: ', f_proc #@@
cf_result = f_proc.process_clouds_1(base_flist, base_mask_flist, gfp_flist, gfpmask_flist, input_params, settings, temp_storage, f_read)
# copy results to output location and clean-up the temporary storage area
do_cleanup_tmp(temp_storage, cf_result, input_params, settings)
# if output_format and/or output_datatype has been set by the user -> translate resulting image(s)
# using gdal_translate
if change_output is True:
cnv_output(cf_result, input_params, settings)
# ----------
# for performance testing
msg = 'Full Processing Runtime in sec: ', time.time() - startTime1, '\n'
print_log(settings, msg)
settings['logging.log_fsock'].close()
# print '**** D O N E ****', '\n'
#/************************************************************************/
#/* main() */
#/************************************************************************/
if __name__ == "__main__":
main()