South Africa Crop Type#
- class torchgeo.datasets.SouthAfricaCropType(paths='data', crs=None, classes=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], bands=('B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09', 'B11', 'B12'), transforms=None, download=False, time_series=False)[source]#
Bases:
RasterDatasetSouth Africa Crop Type Challenge dataset.
The South Africa Crop Type Challenge dataset includes satellite imagery from Sentinel-1 and Sentinel-2 and labels for crop type that were collected by aerial and vehicle survey from May 2017 to March 2018. Data was provided by the Western Cape Department of Agriculture and is available via the Radiant Earth Foundation. For each field id the dataset contains time series imagery and a single label mask. Since TorchGeo does not yet support timeseries datasets, the first available imagery in July will be returned for each field. Note that the dates for S1 and S2 imagery for a given field are not guaranteed to be the same. Due to this date mismatch only S1 or S2 bands may be queried at a time, a mix of both is not supported. Each pixel in the label contains an integer field number and crop type class.
Dataset format:
images are 2-band Sentinel 1 and 12-band Sentinel-2 data with a cloud mask
masks are tiff images with unique values representing the class and field id.
Dataset classes:
No Data
Lucerne/Medics
Planted pastures (perennial)
Fallow
Wine grapes
Weeds
Small grain grazing
Wheat
Canola
Rooibos
If you use this dataset in your research, please cite the following dataset:
Western Cape Department of Agriculture, Radiant Earth Foundation (2021) “Crop Type Classification Dataset for Western Cape, South Africa”, Version 1.0, Radiant MLHub, https://doi.org/10.34911/rdnt.j0co8q
Note
This dataset requires the following additional library to be installed:
azcopy: to download the dataset from Source Cooperative.
Added in version 0.6.
- filename_regex = '\n ^(?P<field_id>\\d+)\n _(?P<date>\\d{4}_07_\\d{2})\n _(?P<band>[BHV\\d]+)\n _10m\n '#
Regular expression used to extract date from filename.
The expression should use named groups. The expression may contain any number of groups. The following groups are specifically searched for by the base class:
date: used to calculatemintandmaxtforindexinsertionstart: used to calculatemintforindexinsertionstop: used to calculatemaxtforindexinsertion
When
separate_filesis True, the following additional groups are searched for to find other files:band: replaced with requested band name
- date_format = '%Y_%m_%d'#
Date format string used to parse date from filename.
Not used if
filename_regexdoes not contain adategroup orstartandstopgroups.
- all_bands: tuple[str, ...] = ('VH', 'VV', 'B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09', 'B11', 'B12')#
Names of all available bands in the dataset
- __init__(paths='data', crs=None, classes=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9], bands=('B01', 'B02', 'B03', 'B04', 'B05', 'B06', 'B07', 'B08', 'B8A', 'B09', 'B11', 'B12'), transforms=None, download=False, time_series=False)[source]#
Initialize a new South Africa Crop Type dataset instance.
- Parameters:
paths (str | PathLike[str] | Iterable[str | PathLike[str]]) – paths directory where dataset can be found
crs (CRS | None) – coordinate reference system to be used
transforms (Callable[[dict[str, Any]], dict[str, Any]] | None) – a function/transform that takes input sample and its target as entry and returns a transformed version
download (bool) – if True, download dataset and store it in the root directory
time_series (bool) – if True, stack data along the time series dimension [T, C, H, W]. If False, merge data into a [C, H, W] mosaic.
- Raises:
DatasetNotFoundError – If dataset is not found and download is False.
Added in version 0.9: The time_series parameter.
- filename_glob = '*_07_*_{}_10m.*'#
Glob expression used to search for files.
This expression should be specific enough that it will not pick up files from other datasets. It should not include a file extension, as the dataset may be in a different file format than what it was originally downloaded as.
- __getitem__(index)[source]#
Retrieve input, target, and/or metadata indexed by spatiotemporal slice.
- Parameters:
index (slice | tuple[slice] | tuple[slice, slice] | tuple[slice, slice, slice]) – [xmin:xmax:xres, ymin:ymax:yres, tmin:tmax:tres] coordinates to index.
- Returns:
Sample of input, target, and/or metadata at that index.
- Raises:
IndexError – If index is not found in the dataset.
- Return type:
- plot(sample, show_titles=True, suptitle=None)[source]#
Plot a sample from the dataset.
- Parameters:
- Returns:
a matplotlib Figure with the rendered sample
- Raises:
RGBBandsMissingError – If bands does not include all RGB bands.
- Return type: