0

I need to obtain the CLOUDY_PIXEL_PERCENTAGE for several Sentinel images. The metadata for the images is contained in an xml file:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<n1:Level-1C_Tile_ID xmlns:n1="https://psd-14.sentinel2.eo.esa.int/PSD/S2_PDI_Level-1C_Tile_Metadata.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="https://psd-14.sentinel2.eo.esa.int/PSD/S2_PDI_Level-1C_Tile_Metadata.xsd /dpc/app/s2ipf/FORMAT_METADATA_TILE_L1C/02.11.01/scripts/../../../schemas/02.13.01/PSD/S2_PDI_Level-1C_Tile_Metadata.xsd">

  <n1:General_Info>
    <TILE_ID metadataLevel="Brief">S2A_OPER_MSI_L1C_TL_EPAE_20180311T025733_A014184_T55HGV_N02.06</TILE_ID>
    <DATASTRIP_ID metadataLevel="Standard">S2A_OPER_MSI_L1C_DS_EPAE_20180311T025733_S20180311T000236_N02.06</DATASTRIP_ID>
    <DOWNLINK_PRIORITY metadataLevel="Standard">NOMINAL</DOWNLINK_PRIORITY>
    <SENSING_TIME metadataLevel="Standard">2018-03-11T00:02:36.456Z</SENSING_TIME>
    <Archiving_Info metadataLevel="Expertise">
      <ARCHIVING_CENTRE>EPA_</ARCHIVING_CENTRE>
      <ARCHIVING_TIME>2018-03-11T03:25:25.640875Z</ARCHIVING_TIME>
    </Archiving_Info>
  </n1:General_Info>
  <n1:Quality_Indicators_Info metadataLevel="Standard">
    <Image_Content_QI>
      <CLOUDY_PIXEL_PERCENTAGE>0</CLOUDY_PIXEL_PERCENTAGE>
      <DEGRADED_MSI_DATA_PERCENTAGE>0</DEGRADED_MSI_DATA_PERCENTAGE>
    </Image_Content_QI>
    </n1:Quality_Indicators_Info>
</n1:Level-1C_Tile_ID>

I've tried using the tools described on the Python xml.etree.ElementTree with no success. The return value is empty string.

import xml.etree.ElementTree as ET
xml_path = project_output+"sentinel_s2_l1c/55HGV_20180311/"
xml_file = 'metadata.xml'

tree = ET.parse(xml_path+xml_file)
root = tree.getroot()
cloud = tree.findall("CLOUDY_PIXEL_PERCENTAGE")

namespaces = {'n1': 'https://psd-14.sentinel2.eo.esa.int/PSD/S2_PDI_Level-1C_Tile_Metadata.xsd'}
root.findall('n1:Quality_Indicators_Info', namespaces)

As suggested to use namespaces, but I am still confused how to pass the name spaces here to extract the value for CLOUDY_PIXEL_PERCENTAGE

Karen Chen
  • 65
  • 1
  • 7
  • Do not repost the same question. Improve your existing question using the guidance provided. Follow-up there as needed. – kjhughes Nov 12 '21 at 04:54
  • I've added a second duplicate link. Between the two, everything you need to solve your problem can be found. Two hints: Use a full XPath to `findall()` and define your namespace before the call and use it in the call, not after (?!?). – kjhughes Nov 12 '21 at 04:59

0 Answers0