I was coding in Google Earth Engine and one of the functions I run for cloud and shadow masking used the MEAN_SOLAR_AZIMUTH_ANGLE property.

shadow_azimuth = ee.Number(90).subtract(ee.Number(img.get('MEAN_SOLAR_AZIMUTH_ANGLE')))

I'm now trying to replicate what I did on GEE locally in python using the Sentinel-2 L2A product from Copernicus. I was trying to find this value in the .SAFE product but I just don't seem to find it. Is this a value that comes with the Sentinel product or is this value calculated by GEE? And if it is, is there a way I can calculate it myself?

1 Answer 1


I think I found the answer. In the metadata file inside Granule, named MTD_TL.xml using this function it returns the azimuth and zenith angle.

import xml.etree.ElementTree as ET

def get_mean_solar_angles(metadata):
    tree = ET.parse(metadata)
    root = tree.getroot()
    tile_angles_element = root.find('.//Tile_Angles')
    if tile_angles_element is not None:
        mean_sun_angle_element = tile_angles_element.find('.//Mean_Sun_Angle')
        if mean_sun_angle_element is not None:
            zenith_angle = mean_sun_angle_element.find('./ZENITH_ANGLE').text
            azimuth_angle = mean_sun_angle_element.find('./AZIMUTH_ANGLE').text
            print("No Mean Sun Angle was found")
        return float(zenith_angle), float(azimuth_angle)    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.