forked from luiscnr/aceasy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idepix_lois.py
67 lines (60 loc) · 2.51 KB
/
idepix_lois.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
import os
import configparser
import subprocess
class IDEPIX:
def __init__(self, fconfig, verbose):
self.verbose = verbose
if fconfig is None:
fconfig = 'aceasy_config.ini'
self.gpt_path = None
if os.path.exists(fconfig):
options = configparser.ConfigParser()
options.read(fconfig)
if options.has_section('IDEPIX'):
if options.has_option('IDEPIX', 'gpt_path'):
self.gpt_path = options['IDEPIX']['gpt_path']
def check_runac(self):
if self.gpt_path is None:
if self.verbose:
print('[ERROR]: IDEPIX class can no be started. GPT file path is not available')
return False
if not os.path.exists(self.gpt_path):
if self.verbose:
print('[ERROR]: IDEPIX class can no be started. GPT path does not exist')
return False
return True
def run_process(self, prod_path, output_dir):
prod_name = prod_path.split('/')[-1]
if prod_name.endswith('.SEN3') and os.path.isdir(prod_path):
output_name = prod_name[0:-5] + '_IDEPIX.nc'
output_path = os.path.join(output_dir, output_name)
else:
print(f'[ERROR] Product {prod_name} is not a correct *.SEN3 directory')
return False
if os.path.exists(output_path):
print(f'[INFO] Output file {output_path} already exists. Skiping...')
return True
if self.verbose:
print(f'[INFO] Input product: {prod_name}')
cmd = f'{self.gpt_path} Idepix.Olci {prod_path} -f NetCDF4-CF -t {output_path}'
if self.verbose:
print(f'[INFO] Starting IDEPIX processing...')
#print(cmd)
proc = subprocess.Popen(cmd, shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
outs, errs = proc.communicate()
if self.verbose:
if outs:
for l in outs.decode().split('\n'):
if l:
print(f'[INFO] GPT --> {l}')
if errs:
for l in errs.decode().split('\n'):
if l:
print(f'[WARNING] GPT --> {l}')
if proc.returncode == 0:
if self.verbose:
print(f'[INFO] IDEPIX-OLCI completed. Output file name: {output_name}')
return True
else:
print(f'[ERROR] IDEPIX-OLCI NOT completed for product: {prod_name}')
return False