Cropland Data Layer#
- class torchgeo.datasets.CDL(paths='data', crs=None, res=None, years=[2023], classes=[0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 81, 82, 83, 87, 88, 92, 111, 112, 121, 122, 123, 124, 131, 141, 142, 143, 152, 176, 190, 195, 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, 254], transforms=None, cache=True, download=False, checksum=False, time_series=False)[source]#
Bases:
RasterDatasetCropland Data Layer (CDL) dataset.
The Cropland Data Layer, hosted on CropScape, provides a raster, geo-referenced, crop-specific land cover map for the continental United States. The CDL also includes a crop mask layer and planting frequency layers, as well as boundary, water and road layers. The Boundary Layer options provided are County, Agricultural Statistics Districts (ASD), State, and Region. The data is created annually using moderate resolution satellite imagery and extensive agricultural ground truth.
The dataset contains 134 classes, for a description of the classes see the xls file at the top of this page.
If you use this dataset in your research, please cite it using the following format:
- filename_glob = '*_30m_cdls.tif'#
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.
- filename_regex = '\n ^(?P<date>\\d+)\n _30m_cdls\\..*$\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'#
Date format string used to parse date from filename.
Not used if
filename_regexdoes not contain adategroup orstartandstopgroups.
- is_image = False#
True if the dataset only contains model inputs (such as images). False if the dataset only contains ground truth model outputs (such as segmentation masks).
The sample returned by the dataset/data loader will use the “image” key if is_image is True, otherwise it will use the “mask” key.
For datasets with both model inputs and outputs, the recommended approach is to use 2 RasterDataset instances and combine them using an IntersectionDataset.
- cmap: ClassVar[dict[int, tuple[int, int, int, int]]] = {0: (0, 0, 0, 255), 1: (255, 211, 0, 255), 2: (255, 37, 37, 255), 3: (0, 168, 226, 255), 4: (255, 158, 9, 255), 5: (37, 111, 0, 255), 6: (255, 255, 0, 255), 10: (111, 166, 0, 255), 11: (0, 175, 73, 255), 12: (222, 166, 9, 255), 13: (222, 166, 9, 255), 14: (124, 211, 255, 255), 21: (226, 0, 124, 255), 22: (137, 96, 83, 255), 23: (217, 181, 107, 255), 24: (166, 111, 0, 255), 25: (213, 158, 188, 255), 26: (111, 111, 0, 255), 27: (171, 0, 124, 255), 28: (160, 88, 137, 255), 29: (111, 0, 73, 255), 30: (213, 158, 188, 255), 31: (209, 255, 0, 255), 32: (124, 153, 255, 255), 33: (213, 213, 0, 255), 34: (209, 255, 0, 255), 35: (0, 175, 73, 255), 36: (255, 166, 226, 255), 37: (166, 241, 139, 255), 38: (0, 175, 73, 255), 39: (213, 158, 188, 255), 41: (168, 0, 226, 255), 42: (166, 0, 0, 255), 43: (111, 37, 0, 255), 44: (0, 175, 73, 255), 45: (175, 124, 255, 255), 46: (111, 37, 0, 255), 47: (255, 102, 102, 255), 48: (255, 102, 102, 255), 49: (255, 204, 102, 255), 50: (255, 102, 102, 255), 51: (0, 175, 73, 255), 52: (0, 222, 175, 255), 53: (83, 255, 0, 255), 54: (241, 162, 120, 255), 55: (255, 102, 102, 255), 56: (0, 175, 73, 255), 57: (124, 211, 255, 255), 58: (232, 190, 255, 255), 59: (175, 255, 222, 255), 60: (0, 175, 73, 255), 61: (190, 190, 120, 255), 63: (147, 204, 147, 255), 64: (198, 213, 158, 255), 65: (204, 190, 162, 255), 66: (255, 0, 255, 255), 67: (255, 143, 171, 255), 68: (185, 0, 79, 255), 69: (111, 69, 137, 255), 70: (0, 120, 120, 255), 71: (175, 153, 111, 255), 72: (255, 255, 124, 255), 74: (181, 111, 92, 255), 75: (0, 166, 130, 255), 76: (232, 213, 175, 255), 77: (175, 153, 111, 255), 81: (241, 241, 241, 255), 82: (153, 153, 153, 255), 83: (73, 111, 162, 255), 87: (124, 175, 175, 255), 88: (232, 255, 190, 255), 92: (0, 255, 255, 255), 111: (73, 111, 162, 255), 112: (211, 226, 249, 255), 121: (153, 153, 153, 255), 122: (153, 153, 153, 255), 123: (153, 153, 153, 255), 124: (153, 153, 153, 255), 131: (204, 190, 162, 255), 141: (147, 204, 147, 255), 142: (147, 204, 147, 255), 143: (147, 204, 147, 255), 152: (198, 213, 158, 255), 176: (232, 255, 190, 255), 190: (124, 175, 175, 255), 195: (124, 175, 175, 255), 204: (0, 255, 139, 255), 205: (213, 158, 188, 255), 206: (255, 102, 102, 255), 207: (255, 102, 102, 255), 208: (255, 102, 102, 255), 209: (255, 102, 102, 255), 210: (255, 143, 171, 255), 211: (51, 73, 51, 255), 212: (226, 111, 37, 255), 213: (255, 102, 102, 255), 214: (255, 102, 102, 255), 215: (102, 153, 77, 255), 216: (255, 102, 102, 255), 217: (175, 153, 111, 255), 218: (255, 143, 171, 255), 219: (255, 102, 102, 255), 220: (255, 143, 171, 255), 221: (255, 102, 102, 255), 222: (255, 102, 102, 255), 223: (255, 143, 171, 255), 224: (0, 175, 73, 255), 225: (255, 211, 0, 255), 226: (255, 211, 0, 255), 227: (255, 102, 102, 255), 228: (255, 211, 0, 255), 229: (255, 102, 102, 255), 230: (137, 96, 83, 255), 231: (255, 102, 102, 255), 232: (255, 37, 37, 255), 233: (226, 0, 124, 255), 234: (255, 158, 9, 255), 235: (255, 158, 9, 255), 236: (166, 111, 0, 255), 237: (255, 211, 0, 255), 238: (166, 111, 0, 255), 239: (37, 111, 0, 255), 240: (37, 111, 0, 255), 241: (255, 211, 0, 255), 242: (0, 0, 153, 255), 243: (255, 102, 102, 255), 244: (255, 102, 102, 255), 245: (255, 102, 102, 255), 246: (255, 102, 102, 255), 247: (255, 102, 102, 255), 248: (255, 102, 102, 255), 249: (255, 102, 102, 255), 250: (255, 102, 102, 255), 254: (37, 111, 0, 255)}#
Color map for the dataset, used for plotting
- __init__(paths='data', crs=None, res=None, years=[2023], classes=[0, 1, 2, 3, 4, 5, 6, 10, 11, 12, 13, 14, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 74, 75, 76, 77, 81, 82, 83, 87, 88, 92, 111, 112, 121, 122, 123, 124, 131, 141, 142, 143, 152, 176, 190, 195, 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, 254], transforms=None, cache=True, download=False, checksum=False, time_series=False)[source]#
Initialize a new Dataset instance.
- Parameters:
paths (str | PathLike[str] | Iterable[str | PathLike[str]]) – one or more root directories to search or files to load
crs (CRS | None) – coordinate reference system (CRS) to warp to (defaults to the CRS of the first file found)
res (float | tuple[float, float] | None) – resolution of the dataset in units of CRS in (xres, yres) format. If a single float is provided, it is used for both the x and y resolution. (defaults to the resolution of the first file found)
years (list[int]) – list of years for which to use cdl layer
classes (list[int]) – list of classes to include, the rest will be mapped to 0 (defaults to all classes)
transforms (Callable[[dict[str, Any]], dict[str, Any]] | None) – a function/transform that takes an input sample and returns a transformed version
cache (bool) – if True, cache file handle to speed up repeated sampling
download (bool) – if True, download dataset and store it in the root directory
checksum (bool) – if True, check the MD5 of the downloaded files (may be slow)
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:
AssertionError – if
yearsorclassesare invalidDatasetNotFoundError – If dataset is not found and download is False.
Added in version 0.9: The time_series parameter.
Added in version 0.5: The years and classes parameters.
Changed in version 0.5: root was renamed to paths.
- __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
- Return type:
Changed in version 0.3: Method now takes a sample dict, not a Tensor. Additionally, possible to show subplot titles and/or use a custom suptitle.
- __annotate_func__()#
The type of the None singleton.