Last active
March 26, 2026 06:57
-
-
Save robbibt/e1d74862272c6929d53f083c5fd58014 to your computer and use it in GitHub Desktop.
Stream DEA products in QGIS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from qgis.core import QgsRasterLayer, QgsProject, QgsLayerTreeGroup | |
| def stream_dea_products(product: str, version: str, year: str) -> None: | |
| """ | |
| Stream DEA Tidal Composites and DEA Intertidal COGs into QGIS via /vsicurl/. | |
| Parameters | |
| ---------- | |
| product : str | |
| Either 'ga_s2ls_intertidal_cyear_3' or 'ga_s2_tidal_composites_cyear_3'. | |
| version : str | |
| Product version (e.g., '2-5-0'). | |
| year : str | |
| Temporal period (e.g., '2022--P1Y'). | |
| """ | |
| # Mapping definitions | |
| config = { | |
| "ga_s2ls_intertidal_cyear_3": { | |
| "bands": [ | |
| "elevation", "elevation-uncertainty", "exposure", "extents", | |
| "qa-coastal-connectivity", "qa-count-clear", "qa-ndwi-corr", | |
| "qa-ndwi-freq", "ta-hat", "ta-hot", "ta-lat", "ta-lot", | |
| "ta-offset-high", "ta-offset-low", "ta-spread" | |
| ] | |
| }, | |
| "ga_s2_tidal_composites_cyear_3": { | |
| "bands": [ | |
| "qa-low-threshold", "qa-high-threshold", "qa-count-clear", | |
| "qa-count-clear-total", "low-coastal-aerosol", "low-blue", | |
| "low-green", "low-red", "low-red-edge-1", "low-red-edge-2", | |
| "low-red-edge-3", "low-nir-1", "low-nir-2", "low-swir-2", | |
| "low-swir-3", "high-coastal-aerosol", "high-blue", "high-green", | |
| "high-red", "high-red-edge-1", "high-red-edge-2", | |
| "high-red-edge-3", "high-nir-1", "high-nir-2", "high-swir-2", | |
| "high-swir-3" | |
| ] | |
| } | |
| } | |
| if product not in config: | |
| print(f"Product '{product}' not supported.") | |
| return | |
| # Create product URI | |
| prod = config[product] | |
| base_url = f"https://data.dev.dea.ga.gov.au/derivative/{product}/{version}/continental_mosaics/{year}" | |
| # Create QGIS group for outputs | |
| project = QgsProject.instance() | |
| root = project.layerTreeRoot() | |
| group_name = f"{product} ({year}, v{version})" | |
| group = root.findGroup(group_name) or root.addGroup(group_name) | |
| # Enable mutual exclusivity on folder | |
| group.setIsMutuallyExclusive(True) | |
| # Add each band to map | |
| for band in prod["bands"]: | |
| file_name = f"{product}_mosaic_{year}_{band}.tif" | |
| uri = f"/vsicurl/{base_url}/{file_name}" | |
| # Load layer | |
| layer = QgsRasterLayer(uri, f"{band}", "gdal") | |
| if layer.isValid(): | |
| # Apply simple 20-2500 stretch to spectral bands | |
| if band.startswith(("low-", "high-")): | |
| renderer = layer.renderer() | |
| ce = QgsContrastEnhancement(layer.dataProvider().dataType(1)) | |
| ce.setMinimumValue(20) | |
| ce.setMaximumValue(2500) | |
| ce.setContrastEnhancementAlgorithm(QgsContrastEnhancement.StretchToMinimumMaximum) | |
| renderer.setContrastEnhancement(ce) | |
| # Add to project and minimize item | |
| project.addMapLayer(layer, False) | |
| node = group.addLayer(layer) | |
| node.setExpanded(False) | |
| print(f"Streaming: {band}") | |
| else: | |
| print(f"Failed to resolve: {uri}") | |
| # Run | |
| VERSION = "2-5-2" | |
| YEAR = "2020--P1Y" | |
| PRODUCT = "ga_s2ls_intertidal_cyear_3" | |
| # stream_dea_products(PRODUCT, VERSION, YEAR) | |
| PRODUCT = "ga_s2_tidal_composites_cyear_3" | |
| stream_dea_products(PRODUCT, VERSION, YEAR) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment