Skip to content

Commit 038c04d

Browse files
authored
Merge pull request #285 from rtburns-jpl/python39
Remove use of deprecated XML ElementTree getchildren method
2 parents ef29fec + f20e8d3 commit 038c04d

File tree

14 files changed

+215
-213
lines changed

14 files changed

+215
-213
lines changed

.circleci/config.yml

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ jobs:
5353
topsApp.py --help --steps
5454
stripmapApp.py --help --steps
5555
python3 -c "import isce"
56+
# Create dummy ref/secondary configs for topsApp
57+
ln -s ../examples/input_files/reference_TOPS_SENTINEL1.xml reference.xml
58+
ln -s reference.xml secondary.xml
59+
topsApp.py --steps --end=preprocess ../examples/input_files/topsApp.xml
5660
5761
test:
5862
docker:

components/isceobj/Catalog/Catalog.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def renderXml(self, file=None, nodeTag=None, elementTag=None):
246246
def dict_to_xml(adict,file,nodeTag=None,elementTag=None):
247247
a = ET.Element(nodeTag) # something to hang nodes on
248248
a = dict_to_et(a,adict,nodeTag,elementTag)
249-
et = a.getchildren()[0]
249+
et = list(a)[0]
250250
indent(et)
251251
tree = ET.ElementTree(et)
252252
tree.write(file)

components/isceobj/Sensor/CEOS.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def __init__(self, xml=None, dataFile=None):
4444
self.metadata = {}
4545
if not xml == None:
4646
self.xmlFP = open(self.xml, 'r')
47-
self.rootChildren = ET(file=self.xmlFP).getroot().getchildren()
47+
self.rootChildren = list(ET(file=self.xmlFP).getroot())
4848
else:
4949
self.xmlFP = None
5050
self.rootChildren = []
@@ -81,7 +81,7 @@ def parseFast(self):
8181
self.metadata[key] = [None]*loopCount
8282
for i in range(loopCount):
8383
struct = {}
84-
for node in z.getchildren():
84+
for node in z:
8585
(subkey,data) = self.decodeNode(node)
8686
struct[subkey] = data
8787
self.metadata[key][i] = struct
@@ -98,7 +98,7 @@ def parse(self):
9898
xmlFP = open(self.xml, 'r')
9999

100100
self.root = ET(file=xmlFP).getroot()
101-
for z in self.root.getchildren():
101+
for z in self.root:
102102
# If the tag name is 'rec', this is a plain old record
103103
if z.tag == 'rec':
104104
(key,data) = self.decodeNode(z)
@@ -116,7 +116,7 @@ def parse(self):
116116
self.metadata[key] = [None]*loopCount
117117
for i in range(loopCount):
118118
struct = {}
119-
for node in z.getchildren():
119+
for node in z:
120120
(subkey,data) = self.decodeNode(node)
121121
struct[subkey] = data
122122
self.metadata[key][i] = struct

components/isceobj/Sensor/GRD/Radarsat2.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ def populateBbox(self, margin=0.1):
276276
glist = (self.getxmlelement('imageAttributes/geographicInformation/geolocationGrid'))
277277
lat = []
278278
lon = []
279-
for child in glist.getchildren():
280-
for grandchild in child.getchildren():
279+
for child in glist:
280+
for grandchild in child:
281281
string = ElementTree.tostring(grandchild, encoding = 'unicode', method = 'xml')
282282
string = string.split("<")[1]
283283
string = string.split(">")[0]
@@ -303,7 +303,7 @@ def getOrbitFromXML(self):
303303
if node.tag == 'stateVector':
304304
sv = StateVector()
305305
sv.configure()
306-
for z in node.getchildren():
306+
for z in node:
307307
if z.tag == 'timeStamp':
308308
timeStamp = self.convertToDateTime(z.text)
309309
elif z.tag == 'xPosition':
@@ -346,16 +346,16 @@ def readGCPsFromXML(self):
346346
if not node.tag == 'imageTiePoint':
347347
continue
348348

349-
for z in node.getchildren():
349+
for z in node:
350350
if z.tag == 'imageCoordinate':
351-
for zz in z.getchildren():
351+
for zz in z:
352352
if zz.tag == 'line':
353353
line = float(zz.text)
354354
elif zz.tag == 'pixel':
355355
pixel = float(zz.text)
356356

357357
if z.tag == 'geodeticCoordinate':
358-
for zz in z.getchildren():
358+
for zz in z:
359359
if zz.tag == 'latitude':
360360
lat = float(zz.text)
361361
elif zz.tag == 'longitude':
@@ -424,8 +424,8 @@ def extractgr2sr(self):
424424
lines = []
425425
data = []
426426

427-
for child in node.getchildren():
428-
for child in node.getchildren():
427+
for child in node:
428+
for child in node:
429429
string = ElementTree.tostring(child, encoding = 'unicode', method = 'xml')
430430
string = string.split("<")[1]
431431
string = string.split(">")[0]

components/isceobj/Sensor/GRD/Sentinel1.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ def populateBbox(self, margin=0.1):
406406
lat = []
407407
lon = []
408408

409-
for child in glist.getchildren():
409+
for child in glist:
410410
lat.append( float(child.find('latitude').text))
411411
lon.append( float(child.find('longitude').text))
412412

@@ -502,7 +502,7 @@ def extractOrbit(self):
502502
frameOrbit = Orbit()
503503
frameOrbit.configure()
504504

505-
for child in node.getchildren():
505+
for child in node:
506506
timestamp = self.convertToDateTime(child.find('time').text)
507507
pos = []
508508
vel = []
@@ -543,7 +543,7 @@ def extractPreciseOrbit(self):
543543
tstart = self.product.sensingStart - margin
544544
tend = self.product.sensingStop + margin
545545

546-
for child in node.getchildren():
546+
for child in node:
547547
timestamp = self.convertToDateTime(child.find('UTC').text[4:])
548548

549549
if (timestamp >= tstart) and (timestamp < tend):
@@ -606,7 +606,7 @@ def extractBetaLUT(self):
606606
pixels = []
607607
data = None
608608

609-
for ii, child in enumerate(node.getchildren()):
609+
for ii, child in enumerate(node):
610610
pixnode = child.find('pixel')
611611
nump = int(pixnode.attrib['count'])
612612

@@ -685,7 +685,7 @@ def extractNoiseLUT(self):
685685
noise_range_lut_indices = np.zeros((num_vectors,))
686686
noise_range_lut_values = np.zeros((num_vectors, self.product.numberOfSamples))
687687

688-
for ii, child in enumerate(node.getchildren()):
688+
for ii, child in enumerate(node):
689689
print("Processing range noise vector {}/{}".format(ii + 1, num_vectors))
690690
pixnode = child.find('pixel')
691691

@@ -711,7 +711,7 @@ def extractNoiseLUT(self):
711711
noise_azimuth_lut_indices = defaultdict(list)
712712
noise_azimuth_lut_values = defaultdict(list)
713713

714-
for block_i, child in enumerate(node.getchildren()):
714+
for block_i, child in enumerate(node):
715715
print("Processing azimuth noise vector {}/{}".format(block_i + 1, num_vectors))
716716
linenode = child.find('line')
717717
signode = child.find("noiseAzimuthLut")
@@ -861,7 +861,7 @@ def extractSlantRange(self, full=True):
861861
data = []
862862

863863

864-
for ii, child in enumerate(node.getchildren()):
864+
for ii, child in enumerate(node):
865865
t0 = self.convertToDateTime(child.find('azimuthTime').text)
866866

867867
lines.append( (t0-self.product.sensingStart).total_seconds()/self.product.azimuthTimeInterval)

components/isceobj/Sensor/GRD/Terrasarx.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -325,8 +325,8 @@ def populateBbox(self, margin=0.1):
325325
glist = (self.getxmlelement(self._xml2_root, 'geolocationGrid'))
326326
lat = []
327327
lon = []
328-
for child in glist.getchildren():
329-
for grandchild in child.getchildren():
328+
for child in glist:
329+
for grandchild in child:
330330
string = ElementTree.tostring(child, encoding = 'unicode', method = 'xml')
331331
string = string.split("<")[1]
332332
string = string.split(">")[0]
@@ -352,7 +352,7 @@ def getOrbitFromXML(self):
352352
if node.tag == 'stateVec':
353353
sv = StateVector()
354354
sv.configure()
355-
for z in node.getchildren():
355+
for z in node:
356356
if z.tag == 'timeUTC':
357357
timeStamp = self.convertToDateTime2(z.text)
358358
elif z.tag == 'posX':
@@ -396,7 +396,7 @@ def readGCPsFromXML(self):
396396
if not node.tag == 'gridPoint':
397397
continue
398398

399-
for zz in node.getchildren():
399+
for zz in node:
400400
if zz.tag == 't':
401401
az_time = float(zz.text)
402402
elif zz.tag == 'tau':
@@ -429,9 +429,9 @@ def extractlutSigma(self):
429429
if not node.tag == 'antennaPattern':
430430
continue
431431

432-
for z in node.getchildren():
432+
for z in node:
433433
if z.tag == 'elevationPattern':
434-
for zz in z.getchildren():
434+
for zz in z:
435435
if zz.tag == 'gainExt':
436436
node = float(zz.text)
437437
node2.append(node)
@@ -467,9 +467,9 @@ def extractgr2sr(self):
467467
for node in self._xml_root.find('productSpecific'):
468468
if not node.tag == 'projectedImageInfo':
469469
continue
470-
for z in node.getchildren():
470+
for z in node:
471471
if z.tag == 'slantToGroundRangeProjection':
472-
for zz in z.getchildren():
472+
for zz in z:
473473
if zz.tag == 'coefficient':
474474
p = float(zz.text)*(SPEED_OF_LIGHT)
475475
pp.append(p)

0 commit comments

Comments
 (0)