Skip to content

Commit

Permalink
Fix print statements and update method calls in s3-olci-composites.py
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelmathot committed Mar 26, 2024
1 parent 60cd4e7 commit 00376e6
Show file tree
Hide file tree
Showing 2 changed files with 747 additions and 28 deletions.
56 changes: 28 additions & 28 deletions src/cdab-remote-client/libexec/ts-scripts/s3-olci-composites.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def view_graph(self):
Raises:
None.
"""
print(etree.tostring(self.root , pretty_print=True))
print((etree.tostring(self.root , pretty_print=True)))

def add_node(self, node_id, operator, parameters, source):
"""This method adds or overwrites a node to the SNAP Graph
Expand All @@ -80,7 +80,7 @@ def add_node(self, node_id, operator, parameters, source):
sources_elem = self.root.xpath(xpath_expr + '/sources')[0]
parameters_elem = self.root.xpath(xpath_expr + '/parameters')

for key, value in parameters.iteritems():
for key, value in list(parameters.items()):

if key == 'targetBandDescriptors':

Expand Down Expand Up @@ -114,7 +114,7 @@ def add_node(self, node_id, operator, parameters, source):

elif isinstance(source, dict):

for key, value in source.iteritems():
for key, value in list(source.items()):

source_product_elem = etree.SubElement(sources_elem, key)
source_product_elem.text = value
Expand All @@ -126,7 +126,7 @@ def add_node(self, node_id, operator, parameters, source):
parameters_elem = etree.SubElement(node_elem, 'parameters')
parameters_elem.attrib['class'] = 'com.bc.ceres.binding.dom.XppDomElement'

for key, value in parameters.iteritems():
for key, value in list(parameters.items()):

if key == 'targetBandDescriptors':

Expand Down Expand Up @@ -207,9 +207,9 @@ def run(self):
p = subprocess.Popen(options,
stdout=subprocess.PIPE, stdin=subprocess.PIPE, stderr=subprocess.PIPE)

print('Process PID: %s' % p.pid)
print(('Process PID: %s' % p.pid))
res, err = p.communicate()
print (res, err)
print((res, err))
finally:
os.remove(path)

Expand Down Expand Up @@ -269,18 +269,18 @@ def get_operator_help(operator):
"""
op_spi = GPF.getDefaultInstance().getOperatorSpiRegistry().getOperatorSpi(operator)

print('Operator name: {}'.format(op_spi.getOperatorDescriptor().getName()))
print(('Operator name: {}'.format(op_spi.getOperatorDescriptor().getName())))

print('Operator alias: {}\n'.format(op_spi.getOperatorDescriptor().getAlias()))
print(('Operator alias: {}\n'.format(op_spi.getOperatorDescriptor().getAlias())))
print('Parameters:\n')
param_Desc = op_spi.getOperatorDescriptor().getParameterDescriptors()

for param in param_Desc:
print('{}: {}\nDefault Value: {}\n'.format(param.getName(),
print(('{}: {}\nDefault Value: {}\n'.format(param.getName(),
param.getDescription(),
param.getDefaultValue()))
param.getDefaultValue())))

print('Possible values: {}\n').format(list(param.getValueSet()))
print(('Possible values: {}\n').format(list(param.getValueSet())))


def op_help(op):
Expand All @@ -297,18 +297,18 @@ def op_help(op):
"""
op_spi = snappy.GPF.getDefaultInstance().getOperatorSpiRegistry().getOperatorSpi(op)

print('Operator name: {}'.format(op_spi.getOperatorDescriptor().getName()))
print(('Operator name: {}'.format(op_spi.getOperatorDescriptor().getName())))

print('Operator alias: {}\n'.format(op_spi.getOperatorDescriptor().getAlias()))
print(('Operator alias: {}\n'.format(op_spi.getOperatorDescriptor().getAlias())))
print('Parameters:\n')
param_Desc = op_spi.getOperatorDescriptor().getParameterDescriptors()

for param in param_Desc:
print('{}: {}\nDefault Value: {}\n'.format(param.getName(),
print(('{}: {}\nDefault Value: {}\n'.format(param.getName(),
param.getDescription(),
param.getDefaultValue()))
param.getDefaultValue())))

print('Possible values: {}\n').format(list(param.getValueSet()))
print(('Possible values: {}\n').format(list(param.getValueSet())))

def get_operators():
"""This function provides a Python dictionary with all SNAP operators.
Expand All @@ -330,7 +330,7 @@ def get_operators():

while op_spi_it.hasNext():

op_spi = op_spi_it.next()
op_spi = next(op_spi_it)

op_class = op_spi.getOperatorDescriptor().getName()

Expand Down Expand Up @@ -373,8 +373,8 @@ def get_write_formats():
write_plugins = ProductIOPlugInManager.getInstance().getAllWriterPlugIns()

while write_plugins.hasNext():
plugin = write_plugins.next()
print ('{} ({})'.format(plugin.getFormatNames()[0], plugin.getDefaultFileExtensions()[0]))
plugin = next(write_plugins)
print(('{} ({})'.format(plugin.getFormatNames()[0], plugin.getDefaultFileExtensions()[0])))

def get_mask(idepix, classif_flags):

Expand Down Expand Up @@ -470,25 +470,25 @@ def s3_olci_import(idepix, **kwargs):
]

for operator in operators:
print('Getting default values for Operator {}'.format(operator))
print(('Getting default values for Operator {}'.format(operator)))
parameters = get_operator_default_parameters(operator)

options[operator] = parameters

for key, value in kwargs.items():
print('Updating Operator {}'.format(key))
for key, value in list(kwargs.items()):
print(('Updating Operator {}'.format(key)))
options[key.replace('_', '-')].update(value)

mygraph = GraphProcessor()

for index, operator in enumerate(operators):
print ('Adding Operator {} to graph').format(operator)
print(('Adding Operator {} to graph'.format(operator)))
if index == 0:
source_node_id = ''
else:
source_node_id = operators[index - 1]

if operator == 'Idepix.Sentinel3.Olci':
if operator == 'Idepix.Olci':
mygraph.add_node(operator, operator, idepix, source_node_id)
else:
mygraph.add_node(operator, operator, options[operator], source_node_id)
Expand Down Expand Up @@ -610,7 +610,7 @@ def extract_info(search_result_file):

s3_olci_bands = []

for key, value in composites.items():
for key, value in list(composites.items()):
if value['create']:
for band in value['bands'].split(','):
s3_olci_bands.append(band)
Expand Down Expand Up @@ -652,13 +652,13 @@ def extract_info(search_result_file):
output_stopdate = input_metadata.iloc[0]['enddate']


for k, v in composites.items():
for k, v in list(composites.items()):

print("k = {0}".format(k))
print(("k = {0}".format(k)))

bands = [os.path.join(write['file'] + '.data', '{}.img'.format(band)) for band in (composites[k]['bands'].split(',') + ['pixel_classif_flags'])]

print("BANDS = {0}".format(bands))
print(("BANDS = {0}".format(bands)))

ds = gdal.Open(bands[0])

Expand Down
Loading

0 comments on commit 00376e6

Please sign in to comment.