darts_acquisition.planet
¶
PLANET related data loading. Should be used temporary and maybe moved to the acquisition package.
_is_valid_date
¶
get_planet_geometry
¶
Get the geometry of a Planet scene.
Parameters:
Returns:
-
odc.geo.Geometry–odc.geo.Geometry: The geometry of the Planet scene.
Raises:
-
FileNotFoundError–If no matching TIFF file is found in the specified path.
Source code in darts-acquisition/src/darts_acquisition/planet.py
load_planet_masks
¶
Load quality and validity masks from a PlanetScope scene's UDM-2 data.
This function extracts data quality information from the PlanetScope Usable Data Mask (UDM-2) to create simplified quality masks for filtering and analysis.
Parameters:
-
fpath(str | pathlib.Path) –Path to the directory containing the PlanetScope scene data. Must contain _udm2.tif (or _udm2_clip.tif) file.
Returns:
-
xarray.Dataset–xr.Dataset: Dataset containing quality mask information with the following data variables: - quality_data_mask (uint8): Combined quality indicator * 0 = Invalid (no data) * 1 = Low quality (clouds, shadows, haze, snow, or other artifacts) * 2 = High quality (clear, usable data) Attributes: data_source="planet", long_name="Quality data mask", description="0 = Invalid, 1 = Low Quality, 2 = High Quality" - planet_udm (uint8): Raw UDM-2 bands (8 bands) Attributes: data_source="planet", long_name="Planet UDM", description="Usable Data Mask"
Raises:
-
FileNotFoundError–If the UDM-2 TIFF file is not found in the directory.
Note
Quality mask derivation logic: - Invalid: UDM band 8 (no data) is set - Low quality: Any of UDM bands 2-6 (clouds, shadows, haze, snow, or artifacts) is set - High quality: Neither invalid nor low quality
UDM-2 band definitions: 1. Clear - 2. Snow - 3. Shadow - 4. Light Haze - 5. Heavy Haze 6. Cloud - 7. Confidence - 8. No Data
Example
Load and apply quality masks:
from darts_acquisition import load_planet_scene, load_planet_masks
# Load scene and masks
scene = load_planet_scene("/data/planet/20230615_123045_1234")
masks = load_planet_masks("/data/planet/20230615_123045_1234")
# Filter to high quality pixels only
scene_filtered = scene.where(masks.quality_data_mask == 2)
# Count quality distribution
import numpy as np
unique, counts = np.unique(
masks.quality_data_mask.values,
return_counts=True
)
print(dict(zip(unique, counts)))
Source code in darts-acquisition/src/darts_acquisition/planet.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 | |
load_planet_scene
¶
Load a PlanetScope satellite scene from GeoTIFF files.
This function loads PlanetScope surface reflectance data (PSScene or PSOrthoTile) from a directory containing TIFF files and metadata. The scene type is automatically detected from the directory name format.
Parameters:
-
fpath(str | pathlib.Path) –Path to the directory containing the PlanetScope scene data. The directory must follow PlanetScope naming conventions: - Scene: YYYYMMDD_HHMMSS_NN_XXXX or YYYYMMDD_HHMMSS_XXXX - Orthotile: NNNNNNN_NNNNNNN_YYYY-MM-DD_XXXX Must contain _SR.tif (or _SR_clip.tif) and *_metadata.json files.
Returns:
-
xarray.Dataset–xr.Dataset: The loaded PlanetScope dataset with the following data variables: - blue (float32): Blue band surface reflectance [0-1] - green (float32): Green band surface reflectance [0-1] - red (float32): Red band surface reflectance [0-1] - nir (float32): Near-infrared band surface reflectance [0-1]
Each variable has attributes: - long_name: "PLANET {Band}" - units: "Reflectance" - data_source: "planet" - planet_type: "scene" or "orthotile"
Dataset-level attributes: - azimuth (float): Solar azimuth angle in degrees - elevation (float): Solar elevation angle in degrees - tile_id (str): Unique identifier for the scene - planet_scene_id (str): Scene identifier (for scenes) or scene portion (for orthotiles) - planet_orthotile_id (str): Orthotile identifier (only for orthotiles)
Raises:
-
FileNotFoundError–If required TIFF or metadata files are not found in the directory.
Note
- Input DN values are divided by 10000 to convert to reflectance [0-1].
- The scene type (PSScene vs PSOrthoTile) is automatically detected from the directory name.
- Solar geometry is extracted from the metadata JSON file.
Example
Load a PlanetScope scene:
from darts_acquisition import load_planet_scene
# Load scene data
planet_ds = load_planet_scene("/data/planet/20230615_123045_1234")
# Access bands
ndvi = (planet_ds.nir - planet_ds.red) / (planet_ds.nir + planet_ds.red)
# Check solar geometry
print(f"Solar azimuth: {planet_ds.azimuth}")
print(f"Solar elevation: {planet_ds.elevation}")
Source code in darts-acquisition/src/darts_acquisition/planet.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 | |
parse_planet_type
¶
Parse the type of Planet data from the directory path.
Parameters:
Returns:
Raises:
-
ValueError–If the Planet data type cannot be parsed from the file path.