The USDA NASS Cropland Data Layers (CDLs) include Cropland, Confidence, Cultivated, and Frequency products. The Cropland product is a crop-specific land cover data layer created annually for the contiguous United States (CONUS). A corresponding Confidence product represents the predicted confidence that is associated with an output pixel. A value of zero indicates low confidence, while a value of 100 indicates high confidence. The Cultivated product identifies cultivated and non-cultivated land cover for CONUS and is based on land cover information derived from the 2017 through 2021 Cropland products. The Frequency product identifies crop specific planting frequency and are based on land cover information derived from the 2008 through 2021 Cropland products. There are currently four individual crop frequency data layers that represent four major crops: corn, cotton, soybeans, and wheat. All products have a 30 meter resolution.
Documentation for this dataset is available at the Planetary Computer Data Catalog.
This notebook works with or without an API key, but you will be given more permissive access to the data with an API key. The Planetary Computer Hub sets the environment variable "PC_SDK_SUBSCRIPTION_KEY" when your server is started. The API key may be manually set via the following code:
pc.settings.set_subscription_key(<YOUR API Key>)
The datasets hosted by the Planetary Computer are available in Azure Blob Storage. We'll use pystac-client to search the Planetary Computer's STAC API for the subset of the data that we care about, and then we'll load the data directly from Azure Blob Storage. We'll specify a modifier
so that we can access the data stored in the Planetary Computer's private Blob Storage Containers. See Reading from the STAC API and Using tokens for data access for more.
import planetary_computer
import pystac_client
# Open the Planetary Computer STAC API
catalog = pystac_client.Client.open(
"https://planetarycomputer.microsoft.com/api/stac/v1/",
modifier=planetary_computer.sign_inplace,
)
collection = catalog.get_collection("usda-cdl")
collection
ID: usda-cdl |
Title: USDA Cropland Data Layers (CDLs) |
Description: The Cropland Data Layer (CDL) is a product of the USDA National Agricultural Statistics Service (NASS) with the mission "to provide timely, accurate and useful statistics in service to U.S. agriculture" (Johnson and Mueller, 2010, p. 1204). The CDL is a crop-specific land cover classification product of more than 100 crop categories grown in the United States. CDLs are derived using a supervised land cover classification of satellite imagery. The supervised classification relies on first manually identifying pixels within certain images, often called training sites, which represent the same crop or land cover type. Using these training sites, a spectral signature is developed for each crop type that is then used by the analysis software to identify all other pixels in the satellite image representing the same crop. Using this method, a new CDL is compiled annually and released to the public a few months after the end of the growing season. This collection includes Cropland, Confidence, Cultivated, and Frequency products. - Cropland: Crop-specific land cover data created annually. There are currently four individual crop frequency data layers that represent four major crops: corn, cotton, soybeans, and wheat. - Confidence: The predicted confidence associated with an output pixel. A value of zero indicates low confidence, while a value of 100 indicates high confidence. - Cultivated: cultivated and non-cultivated land cover for CONUS based on land cover information derived from the 2017 through 2021 Cropland products. - Frequency: crop specific planting frequency based on land cover information derived from the 2008 through 2021 Cropland products. For more, visit the [Cropland Data Layer homepage](https://www.nass.usda.gov/Research_and_Science/Cropland/SARS1a.php). |
Providers:
|
type: Collection |
title: USDA Cropland Data Layers (CDLs) |
assets: {'thumbnail': {'href': 'https://ai4edatasetspublicassets.blob.core.windows.net/assets/pc_thumbnails/usda-cdl-thumb.png', 'type': 'image/png', 'roles': ['thumbnail'], 'title': 'USDA Cropland Data Layer (CDL) thumbnail'}} |
keywords: ['USDA', 'United States', 'Land Cover', 'Land Use', 'Agriculture'] |
providers: [{'url': 'https://www.nass.usda.gov/', 'name': 'United States Department of Agriculture - National Agricultural Statistics Service', 'roles': ['producer', 'licensor']}, {'url': 'https://planetarycomputer.microsoft.com', 'name': 'Microsoft', 'roles': ['host']}] |
summaries: {'usda_cdl:type': ['cropland', 'frequency', 'cultivated']} |
item_assets: {'corn': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'raster:bands': [{'nodata': 255, 'data_type': 'uint8', 'spatial_resolution': 30}]}, 'wheat': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'raster:bands': [{'nodata': 255, 'data_type': 'uint8', 'spatial_resolution': 30}]}, 'cotton': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'raster:bands': [{'nodata': 255, 'data_type': 'uint8', 'spatial_resolution': 30}]}, 'cropland': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'raster:bands': [{'nodata': 0, 'data_type': 'uint8', 'spatial_resolution': 30}], 'classification:classes': [{'value': 1, 'color_hint': 'FFD200', 'description': 'Corn'}, {'value': 2, 'color_hint': 'FF2525', 'description': 'Cotton'}, {'value': 3, 'color_hint': '00A8E3', 'description': 'Rice'}, {'value': 4, 'color_hint': 'FF9E0A', 'description': 'Sorghum'}, {'value': 5, 'color_hint': '256F00', 'description': 'Soybeans'}, {'value': 6, 'color_hint': 'FFFF00', 'description': 'Sunflower'}, {'value': 10, 'color_hint': '6FA400', 'description': 'Peanuts'}, {'value': 11, 'color_hint': '00AE4A', 'description': 'Tobacco'}, {'value': 12, 'color_hint': 'DDA40A', 'description': 'Sweet Corn'}, {'value': 13, 'color_hint': 'DDA40A', 'description': 'Pop or Orn Corn'}, {'value': 14, 'color_hint': '7DD2FF', 'description': 'Mint'}, {'value': 21, 'color_hint': 'E1007B', 'description': 'Barley'}, {'value': 22, 'color_hint': '886153', 'description': 'Durum Wheat'}, {'value': 23, 'color_hint': 'D7B56B', 'description': 'Spring Wheat'}, {'value': 24, 'color_hint': 'A46F00', 'description': 'Winter Wheat'}, {'value': 25, 'color_hint': 'D59EBB', 'description': 'Other Small Grains'}, {'value': 26, 'color_hint': '6F6F00', 'description': 'Winter Wheat/Soybeans'}, {'value': 27, 'color_hint': 'AC007B', 'description': 'Rye'}, {'value': 28, 'color_hint': '9F5888', 'description': 'Oats'}, {'value': 29, 'color_hint': '6F0048', 'description': 'Millet'}, {'value': 30, 'color_hint': 'D59EBB', 'description': 'Speltz'}, {'value': 31, 'color_hint': 'D1FF00', 'description': 'Canola'}, {'value': 32, 'color_hint': '7D99FF', 'description': 'Flaxseed'}, {'value': 33, 'color_hint': 'D5D500', 'description': 'Safflower'}, {'value': 34, 'color_hint': 'D1FF00', 'description': 'Rape Seed'}, {'value': 35, 'color_hint': '00AE4A', 'description': 'Mustard'}, {'value': 36, 'color_hint': 'FFA4E1', 'description': 'Alfalfa'}, {'value': 37, 'color_hint': 'A4F18B', 'description': 'Other Hay/Non Alfalfa'}, {'value': 38, 'color_hint': '00AE4A', 'description': 'Camelina'}, {'value': 39, 'color_hint': 'D59EBB', 'description': 'Buckwheat'}, {'value': 41, 'color_hint': 'A800E3', 'description': 'Sugarbeets'}, {'value': 42, 'color_hint': 'A40000', 'description': 'Dry Beans'}, {'value': 43, 'color_hint': '6F2500', 'description': 'Potatoes'}, {'value': 44, 'color_hint': '00AE4A', 'description': 'Other Crops'}, {'value': 45, 'color_hint': 'B07DFF', 'description': 'Sugarcane'}, {'value': 46, 'color_hint': '6F2500', 'description': 'Sweet Potatoes'}, {'value': 47, 'color_hint': 'FF6666', 'description': 'Misc. Vegs & Fruits'}, {'value': 48, 'color_hint': 'FF6666', 'description': 'Watermelons'}, {'value': 49, 'color_hint': 'FFCC66', 'description': 'Onions'}, {'value': 50, 'color_hint': 'FF6666', 'description': 'Cucumbers'}, {'value': 51, 'color_hint': '00AE4A', 'description': 'Chick Peas'}, {'value': 52, 'color_hint': '00DDAE', 'description': 'Lentils'}, {'value': 53, 'color_hint': '53FF00', 'description': 'Peas'}, {'value': 54, 'color_hint': 'F1A277', 'description': 'Tomatoes'}, {'value': 55, 'color_hint': 'FF6666', 'description': 'Caneberries'}, {'value': 56, 'color_hint': '00AE4A', 'description': 'Hops'}, {'value': 57, 'color_hint': '7DD2FF', 'description': 'Herbs'}, {'value': 58, 'color_hint': 'E8BEFF', 'description': 'Clover/Wildflowers'}, {'value': 59, 'color_hint': 'AEFFDD', 'description': 'Sod/Grass Seed'}, {'value': 60, 'color_hint': '00AE4A', 'description': 'Switchgrass'}, {'value': 61, 'color_hint': 'BEBE77', 'description': 'Fallow/Idle Cropland'}, {'value': 63, 'color_hint': '92CC92', 'description': 'Forest'}, {'value': 64, 'color_hint': 'C5D59E', 'description': 'Shrubland'}, {'value': 65, 'color_hint': 'CCBEA2', 'description': 'Barren'}, {'value': 66, 'color_hint': 'FF00FF', 'description': 'Cherries'}, {'value': 67, 'color_hint': 'FF8EAA', 'description': 'Peaches'}, {'value': 68, 'color_hint': 'B9004F', 'description': 'Apples'}, {'value': 69, 'color_hint': '6F4488', 'description': 'Grapes'}, {'value': 70, 'color_hint': '007777', 'description': 'Christmas Trees'}, {'value': 71, 'color_hint': 'B09A6F', 'description': 'Other Tree Crops'}, {'value': 72, 'color_hint': 'FFFF7D', 'description': 'Citrus'}, {'value': 74, 'color_hint': 'B56F5B', 'description': 'Pecans'}, {'value': 75, 'color_hint': '00A482', 'description': 'Almonds'}, {'value': 76, 'color_hint': 'E9D5AE', 'description': 'Walnuts'}, {'value': 77, 'color_hint': 'B09A6F', 'description': 'Pears'}, {'value': 81, 'color_hint': 'F1F1F1', 'description': 'Clouds/No Data'}, {'value': 82, 'color_hint': '9A9A9A', 'description': 'Developed'}, {'value': 83, 'color_hint': '4A6fA2', 'description': 'Water'}, {'value': 87, 'color_hint': '7DB0B0', 'description': 'Wetlands'}, {'value': 88, 'color_hint': 'E8FFBE', 'description': 'Nonag/Undefined'}, {'value': 92, 'color_hint': '00FFFF', 'description': 'Aquaculture'}, {'value': 111, 'color_hint': '4A6FA2', 'description': 'Open Water'}, {'value': 112, 'color_hint': 'D2E1F8', 'description': 'Perennial Ice/Snow'}, {'value': 121, 'color_hint': '9A9A9A', 'description': 'Developed/Open Space'}, {'value': 122, 'color_hint': '9A9A9A', 'description': 'Developed/Low Intensity'}, {'value': 123, 'color_hint': '9A9A9A', 'description': 'Developed/Med Intensity'}, {'value': 124, 'color_hint': '9A9A9A', 'description': 'Developed/High Intensity'}, {'value': 131, 'color_hint': 'CCBEA2', 'description': 'Barren'}, {'value': 141, 'color_hint': '92CC92', 'description': 'Deciduous Forest'}, {'value': 142, 'color_hint': '92CC92', 'description': 'Evergreen Forest'}, {'value': 143, 'color_hint': '92CC92', 'description': 'Mixed Forest'}, {'value': 152, 'color_hint': 'C5D59E', 'description': 'Shrubland'}, {'value': 176, 'color_hint': 'E8FFBE', 'description': 'Grassland/Pasture'}, {'value': 190, 'color_hint': '7DB0B0', 'description': 'Woody Wetlands'}, {'value': 195, 'color_hint': '7DB0B0', 'description': 'Herbaceous Wetlands'}, {'value': 204, 'color_hint': '00FF8B', 'description': 'Pistachios'}, {'value': 205, 'color_hint': 'D59EBB', 'description': 'Triticale'}, {'value': 206, 'color_hint': 'FF6666', 'description': 'Carrots'}, {'value': 207, 'color_hint': 'FF6666', 'description': 'Asparagus'}, {'value': 208, 'color_hint': 'FF6666', 'description': 'Garlic'}, {'value': 209, 'color_hint': 'FF6666', 'description': 'Cantaloupes'}, {'value': 210, 'color_hint': 'FF8EAA', 'description': 'Prunes'}, {'value': 211, 'color_hint': '334833', 'description': 'Olives'}, {'value': 212, 'color_hint': 'E36F25', 'description': 'Oranges'}, {'value': 213, 'color_hint': 'FF6666', 'description': 'Honeydew Melons'}, {'value': 214, 'color_hint': 'FF6666', 'description': 'Broccoli'}, {'value': 215, 'color_hint': '66994B', 'description': 'Avocados'}, {'value': 216, 'color_hint': 'FF6666', 'description': 'Peppers'}, {'value': 217, 'color_hint': 'B09A6F', 'description': 'Pomegranates'}, {'value': 218, 'color_hint': 'FF8EAA', 'description': 'Nectarines'}, {'value': 219, 'color_hint': 'FF6666', 'description': 'Greens'}, {'value': 220, 'color_hint': 'FF8EAA', 'description': 'Plums'}, {'value': 221, 'color_hint': 'FF6666', 'description': 'Strawberreis'}, {'value': 222, 'color_hint': 'FF6666', 'description': 'Squash'}, {'value': 223, 'color_hint': 'FF8EAA', 'description': 'Apricots'}, {'value': 224, 'color_hint': '00AE4A', 'description': 'Vetch'}, {'value': 225, 'color_hint': 'FFD200', 'description': 'Winter Wheat/Corn'}, {'value': 226, 'color_hint': 'FFD200', 'description': 'Oats/Corn'}, {'value': 227, 'color_hint': 'FF6666', 'description': 'Lettuce'}, {'value': 228, 'color_hint': 'FF6666', 'description': 'Triticale/Corn'}, {'value': 229, 'color_hint': 'FF6666', 'description': 'Pumpkins'}, {'value': 230, 'color_hint': '886153', 'description': 'Lettuce/Durum Wheat'}, {'value': 231, 'color_hint': 'FF6666', 'description': 'Lettuce/Cataloupe'}, {'value': 232, 'color_hint': 'FF2525', 'description': 'Lettuce/Cotton'}, {'value': 233, 'color_hint': 'A1007B', 'description': 'Lettuce/Barley'}, {'value': 234, 'color_hint': 'FF9E0A', 'description': 'Durum Wheat/Sorghum'}, {'value': 235, 'color_hint': 'FF9E0A', 'description': 'Barley/Sorghum'}, {'value': 236, 'color_hint': 'A46F00', 'description': 'Winter Wheat/Sorghum'}, {'value': 237, 'color_hint': 'FFD200', 'description': 'Barley/Corn'}, {'value': 238, 'color_hint': 'A46F00', 'description': 'Winter Wheat/Cotton'}, {'value': 239, 'color_hint': '256F00', 'description': 'Soybeans/Cotton'}, {'value': 240, 'color_hint': '256F00', 'description': 'Soybeans/Oats '}, {'value': 241, 'color_hint': 'FFD200', 'description': 'Corn/Soybeans'}, {'value': 242, 'color_hint': '000099', 'description': 'Blueberries'}, {'value': 243, 'color_hint': 'FF6666', 'description': 'Cabbage'}, {'value': 244, 'color_hint': 'FF6666', 'description': 'Cauliflower'}, {'value': 245, 'color_hint': 'FF6666', 'description': 'Celery'}, {'value': 246, 'color_hint': 'FF6666', 'description': 'Radishes'}, {'value': 247, 'color_hint': 'FF6666', 'description': 'Turnips'}, {'value': 248, 'color_hint': 'FF6666', 'description': 'Eggplants'}, {'value': 249, 'color_hint': 'FF6666', 'description': 'Gourds'}, {'value': 250, 'color_hint': 'FF6666', 'description': 'Cranberries'}, {'value': 254, 'color_hint': '256F00', 'description': 'Barley/Soybeans'}]}, 'soybeans': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'raster:bands': [{'nodata': 255, 'data_type': 'uint8', 'spatial_resolution': 30}]}, 'confidence': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'raster:bands': [{'nodata': 0, 'data_type': 'uint8', 'spatial_resolution': 30}]}, 'cultivated': {'type': 'image/tiff; application=geotiff; profile=cloud-optimized', 'roles': ['data'], 'raster:bands': [{'nodata': 0, 'data_type': 'uint8', 'spatial_resolution': 30}], 'classification:classes': [{'value': 1, 'color_hint': '000000', 'description': 'Non-Cultivated'}, {'value': 2, 'color_hint': '006300', 'description': 'Cultivated'}]}} |
msft:container: usda-cdl |
stac_extensions: ['https://stac-extensions.github.io/item-assets/v1.0.0/schema.json', 'https://stac-extensions.github.io/raster/v1.1.0/schema.json', 'https://stac-extensions.github.io/classification/v1.1.0/schema.json'] |
msft:storage_account: landcoverdata |
msft:short_description: The UDA Cropland Data Layer is an annual raster, geo-referenced, crop-specific land cover data layer produced using satellite imagery and extensive agricultural ground truth collected during the current growing season. |
https://stac-extensions.github.io/item-assets/v1.0.0/schema.json |
https://stac-extensions.github.io/raster/v1.1.0/schema.json |
https://stac-extensions.github.io/classification/v1.1.0/schema.json |
ID: cultivated_2021_973905_922575_90000 |
Bounding Box: [-85.863818, 30.011035, -84.82565, 30.906785] |
datetime: None |
proj:epsg: 5070 |
proj:shape: [3000, 3000] |
end_datetime: 2021-12-31T23:59:59Z |
usda_cdl:type: cultivated |
proj:transform: [30.0, 0.0, 973905.0, 0.0, -30.0, 922605.0] |
start_datetime: 2021-01-01T00:00:00Z |
stac_extensions: ['https://stac-extensions.github.io/projection/v1.0.0/schema.json', 'https://stac-extensions.github.io/classification/v1.1.0/schema.json', 'https://stac-extensions.github.io/raster/v1.1.0/schema.json'] |
https://stac-extensions.github.io/projection/v1.0.0/schema.json |
https://stac-extensions.github.io/classification/v1.1.0/schema.json |
https://stac-extensions.github.io/raster/v1.1.0/schema.json |
href: https://landcoverdata.blob.core.windows.net/usda-cdl/tiles/973905/2021_cultivated_layer_973905_922575_90000.tif?st=2023-01-12T15%3A32%3A46Z&se=2023-01-20T15%3A32%3A46Z&sp=rl&sv=2021-06-08&sr=c&skoid=c85c15d6-d1ae-42d4-af60-e2ca0f81359b&sktid=72f988bf-86f1-41af-91ab-2d7cd011db47&skt=2023-01-13T15%3A32%3A45Z&ske=2023-01-20T15%3A32%3A45Z&sks=b&skv=2021-06-08&sig=wWgx06KJ3m2Dof1XnPNBRTc961kCI198AmyRF7hmogs%3D |
Title: Cultivated 2021 |
Media type: image/tiff; application=geotiff; profile=cloud-optimized |
Roles: ['data'] |
Owner: |
raster:bands: [{'nodata': 0, 'data_type': 'uint8', 'spatial_resolution': 30}] |
classification:classes: [{'value': 1, 'color_hint': '000000', 'description': 'Non-Cultivated'}, {'value': 2, 'color_hint': '006300', 'description': 'Cultivated'}] |
href: https://planetarycomputer.microsoft.com/api/data/v1/item/tilejson.json?collection=usda-cdl&item=cultivated_2021_973905_922575_90000&assets=cropland&tile_format=png&colormap_name=usda-cdl&format=png |
Title: TileJSON with default rendering |
Media type: application/json |
Roles: ['tiles'] |
Owner: |
href: https://planetarycomputer.microsoft.com/api/data/v1/item/preview.png?collection=usda-cdl&item=cultivated_2021_973905_922575_90000&assets=cropland&tile_format=png&colormap_name=usda-cdl&format=png |
Title: Rendered preview |
Media type: image/png |
Roles: ['overview'] |
Owner: |
rel: preview |
Rel: collection |
Target: https://planetarycomputer.microsoft.com/api/stac/v1/collections/usda-cdl |
Media Type: application/json |
Rel: parent |
Target: https://planetarycomputer.microsoft.com/api/stac/v1/collections/usda-cdl |
Media Type: application/json |
Rel: root |
Target: https://planetarycomputer.microsoft.com/api/stac/v1/ |
Media Type: application/json |
Rel: self |
Target: https://planetarycomputer.microsoft.com/api/stac/v1/collections/usda-cdl/items/cultivated_2021_973905_922575_90000 |
Media Type: application/geo+json |
2021 National Cultivated Layer
Rel: source |
Target: https://landcoverdata.blob.core.windows.net/usda-cdl-onboarding/2021_Cultivated_Layer.zip |
Media Type: application/zip |
Map of item
Rel: preview |
Target: https://planetarycomputer.microsoft.com/api/data/v1/item/map?collection=usda-cdl&item=cultivated_2021_973905_922575_90000 |
Media Type: text/html |
Rel: items |
Target: https://planetarycomputer.microsoft.com/api/stac/v1/collections/usda-cdl/items |
Media Type: application/geo+json |
Rel: parent |
Target: https://planetarycomputer.microsoft.com/api/stac/v1/ |
Media Type: application/json |
Microsoft Planetary Computer STAC API
Rel: root |
Target: |
Media Type: application/json |
Rel: self |
Target: https://planetarycomputer.microsoft.com/api/stac/v1/collections/usda-cdl |
Media Type: application/json |
Product Landing Page
Rel: about |
Target: https://www.nass.usda.gov/Research_and_Science/Cropland/SARS1a.php |
Human readable dataset overview and reference
Rel: describedby |
Target: https://planetarycomputer.microsoft.com/dataset/usda-cdl |
Media Type: text/html |
href: https://ai4edatasetspublicassets.blob.core.windows.net/assets/pc_thumbnails/usda-cdl-thumb.png |
Title: USDA Cropland Data Layer (CDL) thumbnail |
Media type: image/png |
Roles: ['thumbnail'] |
Owner: |
# Search the catalog and collection for desired items
latitude = 36.7378
longitude = -119.7871
Fresno = [longitude, latitude]
geometry = {
"type": "Point",
"coordinates": Fresno,
}
search = catalog.search(
collections=collection,
intersects=geometry,
datetime="2021",
)
items = list(search.get_items())
items
[<Item id=cultivated_2021_-2086095_1822575_90000>, <Item id=cropland_2021_-2086095_1822575_90000>, <Item id=frequency_2008-2021_-2086095_1822575_90000>]
Let's display the available assets and metadata.
import rich.table
# Assets
t_assets = rich.table.Table("Key", "Value")
for key, asset in items[1].assets.items():
t_assets.add_row(key, asset.title)
t_assets
┏━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Key ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ cropland │ Cropland Data Layer (CDL) 2021 │ │ confidence │ Confidence 2021 │ │ tilejson │ TileJSON with default rendering │ │ rendered_preview │ Rendered preview │ └──────────────────┴─────────────────────────────────┘
# Metadata
t_metadata = rich.table.Table("Key", "Value")
for k, v in sorted(items[0].properties.items()):
t_metadata.add_row(k, str(v))
t_metadata
┏━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┓ ┃ Key ┃ Value ┃ ┡━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┩ │ datetime │ None │ │ end_datetime │ 2021-12-31T23:59:59Z │ │ proj:epsg │ 5070 │ │ proj:shape │ [3000, 3000] │ │ proj:transform │ [30.0, 0.0, -2086095.0, 0.0, -30.0, 1822605.0] │ │ start_datetime │ 2021-01-01T00:00:00Z │ │ usda_cdl:type │ cultivated │ └────────────────┴────────────────────────────────────────────────┘
The cropland
items include a rendered_preview
asset which can be used to easily visualize the data using the Planetary Computer's data API.
from IPython.display import Image
(cropland,) = [item for item in items if item.properties["usda_cdl:type"] == "cropland"]
Image(url=cropland.assets["rendered_preview"].href)
import odc.stac
ds = odc.stac.load(items, groupby="end_datetime")
ds
<xarray.Dataset> Dimensions: (y: 3001, x: 3001, time: 1) Coordinates: * y (y) float64 1.823e+06 1.823e+06 ... 1.733e+06 1.733e+06 * x (x) float64 -2.086e+06 -2.086e+06 ... -1.996e+06 -1.996e+06 spatial_ref int32 5070 * time (time) datetime64[ns] 2008-01-01 Data variables: cultivated (time, y, x) uint8 1 1 1 1 1 1 1 1 1 1 ... 1 1 1 1 1 1 1 1 1 1 cropland (time, y, x) uint8 176 176 176 176 176 ... 142 142 142 142 142 confidence (time, y, x) uint8 92 69 83 83 92 88 ... 100 100 100 100 100 cotton (time, y, x) uint8 255 255 255 255 255 ... 255 255 255 255 255 corn (time, y, x) uint8 255 255 255 255 255 ... 255 255 255 255 255 wheat (time, y, x) uint8 255 255 255 255 255 ... 255 255 255 255 255 soybeans (time, y, x) uint8 255 255 255 255 255 ... 255 255 255 255 255
This dataset includes a preferred colormap mapping raster values to colors. The Collection's item_assets
field includes an overview of the class descriptions and values.
from pystac.extensions.item_assets import ItemAssetsExtension
ia = ItemAssetsExtension.ext(collection)
x = ia.item_assets["cropland"]
class_names = {
x["description"]: x["value"] for x in x.properties["classification:classes"]
}
class_values = {v: k for k, v in class_names.items()}
t = rich.table.Table("Description", "Value")
for k, v in class_names.items():
t.add_row(k, str(v))
t
┏━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━┓ ┃ Description ┃ Value ┃ ┡━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━┩ │ Corn │ 1 │ │ Cotton │ 2 │ │ Rice │ 3 │ │ Sorghum │ 4 │ │ Soybeans │ 5 │ │ Sunflower │ 6 │ │ Peanuts │ 10 │ │ Tobacco │ 11 │ │ Sweet Corn │ 12 │ │ Pop or Orn Corn │ 13 │ │ Mint │ 14 │ │ Barley │ 21 │ │ Durum Wheat │ 22 │ │ Spring Wheat │ 23 │ │ Winter Wheat │ 24 │ │ Other Small Grains │ 25 │ │ Winter Wheat/Soybeans │ 26 │ │ Rye │ 27 │ │ Oats │ 28 │ │ Millet │ 29 │ │ Speltz │ 30 │ │ Canola │ 31 │ │ Flaxseed │ 32 │ │ Safflower │ 33 │ │ Rape Seed │ 34 │ │ Mustard │ 35 │ │ Alfalfa │ 36 │ │ Other Hay/Non Alfalfa │ 37 │ │ Camelina │ 38 │ │ Buckwheat │ 39 │ │ Sugarbeets │ 41 │ │ Dry Beans │ 42 │ │ Potatoes │ 43 │ │ Other Crops │ 44 │ │ Sugarcane │ 45 │ │ Sweet Potatoes │ 46 │ │ Misc. Vegs & Fruits │ 47 │ │ Watermelons │ 48 │ │ Onions │ 49 │ │ Cucumbers │ 50 │ │ Chick Peas │ 51 │ │ Lentils │ 52 │ │ Peas │ 53 │ │ Tomatoes │ 54 │ │ Caneberries │ 55 │ │ Hops │ 56 │ │ Herbs │ 57 │ │ Clover/Wildflowers │ 58 │ │ Sod/Grass Seed │ 59 │ │ Switchgrass │ 60 │ │ Fallow/Idle Cropland │ 61 │ │ Forest │ 63 │ │ Shrubland │ 152 │ │ Barren │ 131 │ │ Cherries │ 66 │ │ Peaches │ 67 │ │ Apples │ 68 │ │ Grapes │ 69 │ │ Christmas Trees │ 70 │ │ Other Tree Crops │ 71 │ │ Citrus │ 72 │ │ Pecans │ 74 │ │ Almonds │ 75 │ │ Walnuts │ 76 │ │ Pears │ 77 │ │ Clouds/No Data │ 81 │ │ Developed │ 82 │ │ Water │ 83 │ │ Wetlands │ 87 │ │ Nonag/Undefined │ 88 │ │ Aquaculture │ 92 │ │ Open Water │ 111 │ │ Perennial Ice/Snow │ 112 │ │ Developed/Open Space │ 121 │ │ Developed/Low Intensity │ 122 │ │ Developed/Med Intensity │ 123 │ │ Developed/High Intensity │ 124 │ │ Deciduous Forest │ 141 │ │ Evergreen Forest │ 142 │ │ Mixed Forest │ 143 │ │ Grassland/Pasture │ 176 │ │ Woody Wetlands │ 190 │ │ Herbaceous Wetlands │ 195 │ │ Pistachios │ 204 │ │ Triticale │ 205 │ │ Carrots │ 206 │ │ Asparagus │ 207 │ │ Garlic │ 208 │ │ Cantaloupes │ 209 │ │ Prunes │ 210 │ │ Olives │ 211 │ │ Oranges │ 212 │ │ Honeydew Melons │ 213 │ │ Broccoli │ 214 │ │ Avocados │ 215 │ │ Peppers │ 216 │ │ Pomegranates │ 217 │ │ Nectarines │ 218 │ │ Greens │ 219 │ │ Plums │ 220 │ │ Strawberreis │ 221 │ │ Squash │ 222 │ │ Apricots │ 223 │ │ Vetch │ 224 │ │ Winter Wheat/Corn │ 225 │ │ Oats/Corn │ 226 │ │ Lettuce │ 227 │ │ Triticale/Corn │ 228 │ │ Pumpkins │ 229 │ │ Lettuce/Durum Wheat │ 230 │ │ Lettuce/Cataloupe │ 231 │ │ Lettuce/Cotton │ 232 │ │ Lettuce/Barley │ 233 │ │ Durum Wheat/Sorghum │ 234 │ │ Barley/Sorghum │ 235 │ │ Winter Wheat/Sorghum │ 236 │ │ Barley/Corn │ 237 │ │ Winter Wheat/Cotton │ 238 │ │ Soybeans/Cotton │ 239 │ │ Soybeans/Oats │ 240 │ │ Corn/Soybeans │ 241 │ │ Blueberries │ 242 │ │ Cabbage │ 243 │ │ Cauliflower │ 244 │ │ Celery │ 245 │ │ Radishes │ 246 │ │ Turnips │ 247 │ │ Eggplants │ 248 │ │ Gourds │ 249 │ │ Cranberries │ 250 │ │ Barley/Soybeans │ 254 │ └──────────────────────────┴───────┘
And the Planetary Computer's Data API includes the colormap.
import requests
classmap = requests.get(
"https://planetarycomputer.microsoft.com/api/data/v1/legend/classmap/usda-cdl"
).json()
We'll convert those values to a matplotlib Colormap for plotting.
import matplotlib.colors
import numpy as np
colors = [matplotlib.colors.to_rgba([x / 255 for x in c]) for c in classmap.values()]
cmap = matplotlib.colors.ListedColormap(colors, name="usda-cdl")
ticks = np.arange(cmap.N)
labels = [class_values.get(value, "nodata") for value in ticks]
Finally, we can read and plot the data.
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(16, 12))
p = (
ds["cropland"]
.isel(time=-1)
.plot(
ax=ax,
cmap=cmap,
norm=matplotlib.colors.NoNorm(),
)
)
ax.set_axis_off()
ax.set_title("USDA NASS CDLs - Cropland \n California Agriculture \n 2021 Fresno, CA")
colorbar = fig.axes[1]