pycontrails.datalib.leo_utils.sentinel_metadata¶
Download and parse Sentinel metadata.
Functions
| 
 | Extrapolate NaN values in a 2D azimuth array using linear interpolation/extrapolation. | 
| 
 | Return the detector ID that captured a given pixel in a Sentinel-2 image. | 
| 
 | Return the time delay for a given detector. | 
| 
 | Convert GPS time (datetime object) to UTC time. | 
| 
 | Return the ephemeris data from the DATASTRIP xml file. | 
| 
 | Load in the detector mask from either JP2 or GML file. | 
| Parse high-resolution viewing incidence angles (zenith and azimuth). | |
| 
 | Parse the sensing_time in the granule metadata. | 
| 
 | Parse the CRS in the granule metadata. | 
| Read sensor incidence angles from metadata. | |
| 
 | Read sensor incidence angles from metadata. | 
| 
 | Map a pixel value and location to an azimuth value. | 
| 
 | Read image x and y coordinates. | 
- pycontrails.datalib.leo_utils.sentinel_metadata.extrapolate_array(array)¶
- Extrapolate NaN values in a 2D azimuth array using linear interpolation/extrapolation. 
- pycontrails.datalib.leo_utils.sentinel_metadata.get_detector_id(detector_band_metadata_path, tile_metadata_path, x, y, band='B03')¶
- Return the detector ID that captured a given pixel in a Sentinel-2 image. - Parameters:
- detector_band_metadata_path ( - str) – Path to the MSK_DETFOO_Bxx.jp2 detector band mask file.
- tile_metadata_path ( - str) – Path to the tile metadata XML file (MTD_TL.xml) containing image geometry.
- x ( - npt.NDArray[np.floating]) – X coordinate (in UTM coordinate system) of the target pixel.
- y ( - npt.NDArray[np.floating]) – Y coordinate (in UTM coordinate system) of the target pixel.
- band ( - str, optional) – Spectral band to use for geometry parsing. Default is “B03”.
 
- Returns:
- npt.NDArray[np.integer]– The detector ID (in the range 1 to 12) that captured the pixel. Returns 0 if the pixel is outside the image bounds or not covered by any detector.
 
- pycontrails.datalib.leo_utils.sentinel_metadata.get_time_delay_detectors(datastrip_metadata_path, band='B03')¶
- Return the time delay for a given detector. - Detector id’s are positioned in alternating viewing angle. - Even detectors capture earlier, odd detectors later. Check page 41: https://sentiwiki.copernicus.eu/__attachments/1692737/S2-PDGS-CS-DI-PSD%20-%20S2%20Product%20Specification%20Document%202024%20-%2015.0.pdf?inst-v=e48c493c-f3ee-4a19-8673-f60058308b2a. - This function checks the DATASTRIP xml to find the reference times used for intializing the offset. Currently it calculates the average time for a certain band_id, and then returns the offset between the detector_id time and the average time. (Unsure whether average is actually correct usage) 
- pycontrails.datalib.leo_utils.sentinel_metadata.gps_to_utc(gps_time)¶
- Convert GPS time (datetime object) to UTC time. - https://gssc.esa.int/navipedia/index.php/Transformations_between_Time_Systems 
- pycontrails.datalib.leo_utils.sentinel_metadata.parse_ephemeris_sentinel(datatsrip_metadata_path)¶
- Return the ephemeris data from the DATASTRIP xml file. - Parameters:
- datatsrip_metadata_path ( - str) – The location of the DATASTRIP xml file
- Returns:
- pandas.DataFrame– A- pandas.DataFramecontaining the ephemeris track with columns: - EPHEMERIS_TIME: Timestamps of the ephemeris data. - EPHEMERIS_ECEF_X: ECEF X coordinates. - EPHEMERIS_ECEF_Y: ECEF Y coordinates. - EPHEMERIS_ECEF_Z: ECEF Z coordinates.
 
- pycontrails.datalib.leo_utils.sentinel_metadata.parse_high_res_detector_mask(metadata_path, scale=10)¶
- Load in the detector mask from either JP2 or GML file. - JP2: Reads pixel-level mask indicating which detector [1-12] captured each pixel. 
- GML: Converts detector polygons to raster mask, where each pixel corresponds to a detector ID. 
 - Lower the resolution with ‘scale’ to speed up processing. Scale 1 -> 10m resolution. Scale 10 -> 100m resolution. 
- pycontrails.datalib.leo_utils.sentinel_metadata.parse_high_res_viewing_incidence_angles(tile_metadata_path, detector_band_metadata_path, scale=10)¶
- Parse high-resolution viewing incidence angles (zenith and azimuth). - Parameters:
- Returns:
- xarray.Dataset– Dataset with coordinates (‘y’, ‘x’) containing: - VZA: View Zenith Angle - VAA: View Azimuth Angle
- Raises:
- ValueError – If required data (zenith or azimuth) cannot be parsed. 
 
- pycontrails.datalib.leo_utils.sentinel_metadata.parse_sensing_time(granule_metadata_path)¶
- Parse the sensing_time in the granule metadata. 
- pycontrails.datalib.leo_utils.sentinel_metadata.parse_sentinel_crs(granule_metadata_path)¶
- Parse the CRS in the granule metadata. 
- pycontrails.datalib.leo_utils.sentinel_metadata.parse_viewing_incidence_angle_by_detector(metadata_path, target_detector_id, target_band_id='2')¶
- Read sensor incidence angles from metadata. 
- pycontrails.datalib.leo_utils.sentinel_metadata.parse_viewing_incidence_angles(metadata_path, target_band_id='2')¶
- Read sensor incidence angles from metadata. Returns the total of all detectors. 
- pycontrails.datalib.leo_utils.sentinel_metadata.process_pixel(pixel_val, pixel_location, image_shape, azimuth_dict)¶
- Map a pixel value and location to an azimuth value. 
- pycontrails.datalib.leo_utils.sentinel_metadata.read_image_coordinates(meta, band)¶
- Read image x and y coordinates.