darts_acquisition
darts_acquisition
¶
Acquisition of data from various sources for the DARTS dataset.
download_admin_files
¶
Download the admin files for the regions.
Files will be stored under [admin_dir]/adm1.shp and [admin_dir]/adm2.shp.
Parameters:
Source code in darts-acquisition/src/darts_acquisition/admin.py
load_arcticdem
¶
load_arcticdem(
geobox: odc.geo.geobox.GeoBox,
data_dir: pathlib.Path | str,
resolution: darts_acquisition.arcticdem.RESOLUTIONS,
buffer: int = 0,
persist: bool = True,
) -> xarray.Dataset
Load the ArcticDEM for the given geobox, fetch new data from the STAC server if necessary.
Parameters:
-
geobox
(odc.geo.geobox.GeoBox
) –The geobox for which the tile should be loaded.
-
data_dir
(pathlib.Path | str
) –The directory where the ArcticDEM data is stored.
-
resolution
(typing.Literal[2, 10, 32]
) –The resolution of the ArcticDEM data in m.
-
buffer
(int
, default:0
) –The buffer around the projected (epsg:3413) geobox in pixels. Defaults to 0.
-
persist
(bool
, default:True
) –If the data should be persisted in memory. If not, this will return a Dask backed Dataset. Defaults to True.
Returns:
-
xarray.Dataset
–xr.Dataset: The ArcticDEM tile, with a buffer applied. Note: The buffer is applied in the arcticdem dataset's CRS, hence the orientation might be different. Final dataset is NOT matched to the reference CRS and resolution.
Warning
Geobox must be in a meter based CRS.
Usage
Since the API of the load_arcticdem
is based on GeoBox, one can load a specific ROI based on an existing Xarray DataArray:
import xarray as xr
import odc.geo.xr
from darts_aquisition import load_arcticdem
# Assume "optical" is an already loaded s2 based dataarray
arcticdem = load_arcticdem(
optical.odc.geobox,
"/path/to/arcticdem-parent-directory",
resolution=2,
buffer=ceil(self.tpi_outer_radius / 2 * sqrt(2))
)
# Now we can for example match the resolution and extent of the optical data:
arcticdem = arcticdem.odc.reproject(optical.odc.geobox, resampling="cubic")
The buffer
parameter is used to extend the region of interest by a certain amount of pixels.
This comes handy when calculating e.g. the Topographic Position Index (TPI), which requires a buffer around the region of interest to remove edge effects.
Raises:
-
ValueError
–If the resolution is not supported.
Source code in darts-acquisition/src/darts_acquisition/arcticdem.py
load_planet_masks
¶
Load the valid and quality data masks from a Planet scene.
Parameters:
Raises:
-
FileNotFoundError
–If no matching UDM-2 TIFF file is found in the specified path.
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/planet.py
load_planet_scene
¶
Load a PlanetScope satellite GeoTIFF file and return it as an xarray datset.
Parameters:
-
fpath
(str | pathlib.Path
) –The path to the directory containing the TIFF files or a specific path to the TIFF file.
Returns:
Raises:
-
FileNotFoundError
–If no matching TIFF file is found in the specified path.
Source code in darts-acquisition/src/darts_acquisition/planet.py
load_tcvis
¶
load_tcvis(
geobox: odc.geo.geobox.GeoBox,
data_dir: pathlib.Path | str,
buffer: int = 0,
persist: bool = True,
) -> xarray.Dataset
Load the TCVIS for the given geobox, fetch new data from GEE if necessary.
Parameters:
-
geobox
(odc.geo.geobox.GeoBox
) –The geobox to load the data for.
-
data_dir
(pathlib.Path | str
) –The directory to store the downloaded data for faster access for consecutive calls.
-
buffer
(int
, default:0
) –The buffer around the geobox in pixels. Defaults to 0.
-
persist
(bool
, default:True
) –If the data should be persisted in memory. If not, this will return a Dask backed Dataset. Defaults to True.
Returns:
Usage
Since the API of the load_tcvis
is based on GeoBox, one can load a specific ROI based on an existing Xarray DataArray:
import xarray as xr
import odc.geo.xr
from darts_aquisition import load_tcvis
# Assume "optical" is an already loaded s2 based dataarray
tcvis = load_tcvis(
optical.odc.geobox,
"/path/to/tcvis-parent-directory",
)
# Now we can for example match the resolution and extent of the optical data:
tcvis = tcvis.odc.reproject(optical.odc.geobox, resampling="cubic")
Source code in darts-acquisition/src/darts_acquisition/tcvis.py
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.