s2
darts_acquisition.s2
¶
Sentinel 2 related data loading. Should be used temporary and maybe moved to the acquisition package.
convert_masks
¶
Convert the Sentinel 2 scl mask into our own mask format inplace.
Invalid: S2 SCL → 0,1 Low Quality S2: S2 SCL != 0,1 → 3,8,9,11 High Quality: S2 SCL != 0,1,3,8,9,11 → Alles andere
Parameters:
Returns:
Source code in darts-acquisition/src/darts_acquisition/s2.py
get_s2ids_from_shape_ee
¶
get_s2ids_from_shape_ee(
aoi_shapefile: pathlib.Path,
start_date: str,
end_date: str,
max_cloud_cover: int = 100,
) -> set[str]
Search for Sentinel 2 tiles via Earth Engine based on an aoi shapefile.
Parameters:
-
aoi_shapefile
(pathlib.Path
) –AOI shapefile path. Can be anything readable by geopandas.
-
start_date
(str
) –Starting date in a format readable by ee.
-
end_date
(str
) –Ending date in a format readable by ee.
-
max_cloud_cover
(int
, default:100
) –Maximum percentage of cloud cover. Defaults to 100.
Returns:
Source code in darts-acquisition/src/darts_acquisition/s2.py
get_s2ids_from_shape_stac
¶
get_s2ids_from_shape_stac(
aoi_shapefile: pathlib.Path,
start_date: str,
end_date: str,
max_cloud_cover: int = 100,
) -> set[str]
Search for Sentinel 2 tiles via Earth Engine based on an aoi shapefile.
Note
start_date
and end_date
will be concatted with a /
to form a date range.
Read more about the date format here: https://pystac-client.readthedocs.io/en/stable/api.html#pystac_client.Client.search
Parameters:
-
aoi_shapefile
(pathlib.Path
) –AOI shapefile path. Can be anything readable by geopandas.
-
start_date
(str
) –Starting date in a format readable by pystac_client.
-
end_date
(str
) –Ending date in a format readable by pystac_client.
-
max_cloud_cover
(int
, default:100
) –Maximum percentage of cloud cover. Defaults to 100.
Returns:
Source code in darts-acquisition/src/darts_acquisition/s2.py
load_s2_from_gee
¶
load_s2_from_gee(
img: str | ee.Image,
bands_mapping: dict = {
"B2": "blue",
"B3": "green",
"B4": "red",
"B8": "nir",
},
scale_and_offset: bool | tuple[float, float] = True,
cache: pathlib.Path | None = None,
) -> xarray.Dataset
Load a Sentinel 2 scene from Google Earth Engine and return it as an xarray dataset.
Parameters:
-
img
(str | ee.Image
) –The Sentinel 2 image ID or the ee image object.
-
bands_mapping
(dict[str, str]
, default:{'B2': 'blue', 'B3': 'green', 'B4': 'red', 'B8': 'nir'}
) –A mapping from bands to obtain. Will be renamed to the corresponding band names. Defaults to {"B2": "blue", "B3": "green", "B4": "red", "B8": "nir"}.
-
scale_and_offset
(bool | tuple[float, float]
, default:True
) –Whether to apply the scale and offset to the bands. If a tuple is provided, it will be used as the (
scale
,offset
) values withband * scale + offset
. If True, use the default values ofscale
= 0.0001 andoffset
= 0, taken from ee_extra. Defaults to True. -
cache
(pathlib.Path | None
, default:None
) –The path to the cache directory. If None, no caching will be done. Defaults to None.
Returns:
Source code in darts-acquisition/src/darts_acquisition/s2.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 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 |
|
load_s2_from_stac
¶
load_s2_from_stac(
s2id: str,
bands_mapping: dict = {
"B02_10m": "blue",
"B03_10m": "green",
"B04_10m": "red",
"B08_10m": "nir",
},
scale_and_offset: bool | tuple[float, float] = True,
cache: pathlib.Path | None = None,
) -> xarray.Dataset
Load a Sentinel 2 scene from the Copernicus STAC API and return it as an xarray dataset.
Parameters:
-
s2id
(str
) –The Sentinel 2 image ID.
-
bands_mapping
(dict[str, str]
, default:{'B02_10m': 'blue', 'B03_10m': 'green', 'B04_10m': 'red', 'B08_10m': 'nir'}
) –A mapping from bands to obtain. Will be renamed to the corresponding band names. Defaults to {"B2": "blue", "B3": "green", "B4": "red", "B8": "nir"}.
-
scale_and_offset
(bool | tuple[float, float]
, default:True
) –Whether to apply the scale and offset to the bands. If a tuple is provided, it will be used as the (
scale
,offset
) values withband * scale + offset
. If True, use the default values ofscale
= 0.0001 andoffset
= 0, taken from ee_extra. Defaults to True. -
cache
(pathlib.Path | None
, default:None
) –The path to the cache directory. If None, no caching will be done. Defaults to None.
Returns:
Source code in darts-acquisition/src/darts_acquisition/s2.py
load_s2_masks
¶
load_s2_masks(
fpath: str | pathlib.Path,
reference_geobox: odc.geo.geobox.GeoBox,
) -> xarray.Dataset
Load the valid and quality data masks from a Sentinel 2 scene.
Parameters:
-
fpath
(str | pathlib.Path
) –The path to the directory containing the TIFF files.
-
reference_geobox
(odc.geo.geobox.GeoBox
) –The reference geobox to reproject, resample and crop the masks data to.
Returns:
-
xarray.Dataset
–xr.Dataset: A merged xarray Dataset containing two data masks: - 'valid_data_mask': A mask indicating valid (1) and no data (0). - 'quality_data_mask': A mask indicating high quality (1) and low quality (0).
Source code in darts-acquisition/src/darts_acquisition/s2.py
load_s2_scene
¶
Load a Sentinel 2 satellite GeoTIFF file and return it as an xarray datset.
Parameters:
Returns:
Raises:
-
FileNotFoundError
–If no matching TIFF file is found in the specified path.
Source code in darts-acquisition/src/darts_acquisition/s2.py
parse_s2_tile_id
¶
Parse the Sentinel 2 tile ID from a file path.
Parameters:
Returns:
-
tuple[str, str, str]
–tuple[str, str, str]: A tuple containing the Planet crop ID, the Sentinel 2 tile ID and the combined tile ID.
Raises:
-
FileNotFoundError
–If no matching TIFF file is found in the specified path.