fudong03 commited on
Commit
2d86e7c
1 Parent(s): 6468b23

Creat readme file

Browse files
Files changed (1) hide show
  1. README.md +195 -0
README.md ADDED
@@ -0,0 +1,195 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # CropNet: An Open Large-Scale Dataset with Multiple Modalities for Climate Change-aware Crop Yield Predictions
2
+
3
+ ![Motivation](images/dataset-motivation.png)
4
+
5
+
6
+
7
+ The CropNet dataset is an open, large-scale, and deep learning-ready dataset, specifically targeting climate change-aware crop yield predictions for the contiguous United States (U.S.) continent at the county level. It is composed of three modalities of data, i.e., Sentinel-2 Imagery, WRF-HRRR Computed Dataset, and USDA Crop Dataset, aligned in both the spatial and temporal domains, for over 2200 U.S. counties spanning 6 years (2017-2022). It is expected to facilitate researchers in developing deep learning models for timely and precisely predicting crop yields at the county level, by accounting for the effects of both short-term growing season weather variations and long-term climate change on crop yields. Although our initial goal of crafting the CropNet dataset is for precise crop yield prediction, we believe its future applicability is broad and can benefit the deep learning, agriculture, and meteorology communities, for exploring more interesting, critical, and climate change-related applications, by using one or more modalities of data.
8
+
9
+
10
+
11
+ ## Contributions
12
+
13
+ #### The `CropNet` dataset
14
+
15
+ - The first *terabyte-sized*, publicly available, and multi-modal dataset for climate change-aware crop yield predictions
16
+ - The `CropNet` dataset is available at [Google Drive](https://drive.google.com/drive/folders/1Js98GAxf1LeAUTxP1JMZZIrKvyJStDgz)
17
+
18
+ #### The `CropNet` package
19
+
20
+ - A *deep learning-ready* Python package for facilitating researchers in downloading the CropNet data on the fly over the time and region of interest, and developing deep neural networks (DNNs) for climate change-aware crop yield predictions
21
+ - The `CropNet` package is available at [Python Package Index (PyPI)](https://pypi.org/project/cropnet/)
22
+
23
+
24
+
25
+ ## Tutorials
26
+
27
+ The tutorials for the CropNet dataset are available at Google Colab, with their links listed below
28
+
29
+ - [Sentinel-2 Imagery Tutorial](https://colab.research.google.com/drive/1Tj69JdhO7aX8ks-4UWYvHrFm9GB1PNCd?usp=sharing)
30
+ - [WRF-HRRR Computed Dataset Tutorial](https://colab.research.google.com/drive/14l-JSNHtelawNu3kVG_ukTd2WUJpaZEc?usp=sharing)
31
+
32
+ - [USDA Crop Dataset Tutorial](https://colab.research.google.com/drive/1U-vFoRyLSb2l2Q67LeGbkUKTeRaHDkkK?usp=sharing)
33
+
34
+
35
+
36
+ ## The CropNet Dataset
37
+
38
+ 0ur CropNet dataset is composed of three modalities of data, i.e., Sentinel-2 Imagery, WRF-HRRR Computed Dataset, and USDA Crop Dataset, spanning from 2017 to 2022 (i.e., 6 years) across 2291 U.S. counties, with its geographic distribution illustrated below. We also include the number of counties corresponding to each crop type in the USDA Crop Dataset (see the rightmost bar chart in the figure) since crop planting is highly geography-dependent.
39
+
40
+ ![Geographic Distribution](images/dataset-geo-overview-violet-pastel.png)
41
+
42
+
43
+
44
+ ### Sentinel-2 Imagery
45
+
46
+ The Sentinel-2 Imagery, obtained from the Sentinel-2 mission, provides high-resolution satellite images for monitoring crop growth on the ground. It contains two types of 224x224 RGB satellite images, agriculture imagery (AG) and normalized difference vegetation index (NDVI), both with a spatial resolution of 9x9 km, and a revisit frequency of 14 days. Examples of AG and NDVI images are depicted as follows.
47
+
48
+ - **Agriculture Imagery (AG)**
49
+
50
+ ![AG](images/dataset-Sentinel2-AG.png)
51
+
52
+ - **Normalized Difference Vegetation Index (NDVI)**
53
+
54
+ ![NDVI](images/dataset-Sentinel2-NDVI.png)
55
+
56
+
57
+
58
+ ### WRF-HRRR Computed Dataset
59
+
60
+ The WRF-HRRR Computed Dataset, sourced from the WRF-HRRR model, contains daily and monthly meteorological parameters, with the former and the latter designed for capturing direct effects of short-term growing season weather variations on crop growth, and for learning indirect impacts of long-term climate change on crop yields, respectively. It contains 9 meteorological parameters gridded at 9 km in a one-day (and one-month) interval. The figures show the temperature in the spring, the summer, the fall, and the winter, respectively.
61
+
62
+ ![HRRR Temperature](images/dataset-HRRR-temperature.png)
63
+
64
+
65
+
66
+ ### USDA Crop Dataset
67
+
68
+ The USDA Crop Dataset, collected from the USDA Quick Statistic website, offers valuable information, such as production, yield, etc., for crops grown at each available county. It offers crop information for four types of crops, i.e., corn, cotton, soybeans, and winter wheat, at a county-level basis, with a temporal resolution of one year. The figure illustrates the 2022 Corn Yield across the United States.
69
+
70
+ ![USDA Corn Yield](images/dataset-corn-yield.png)
71
+
72
+ ### The CropNet Package
73
+
74
+ Beyond the contribution of our CropNet dataset, we also release the CropNet package in the Python Package Index (PyPI) for facilitating researchers in downloading the CropNet data based on the time and region of interest, and flexibly building their deep learning models for accurate crop yield predictions. In particular, the CropNet package includes three types of APIs, listed as follows:
75
+
76
+ - **DataDownloader**: This API allows users to download the CropNet data over the time/region of interest on the fly.
77
+
78
+ - **DataRetriever**: With this API, users can conveniently obtain the CropNet data stored in the local machine (e.g., if you have downloaded our curated CropNet from Google Drive) over the time/region of interest.
79
+
80
+ - **DataLoader**: This API is designed to facilitate researchers in developing their DNNs for accurate crop yield predictions. Specifically, the code in this API ( 1) combines all three modalities of data to create $(\mathbf{x}, \mathbf{y_{s}}, \mathbf{y_{l}}, \mathbf{z})$ tuples, with $\mathbf{x}, \mathbf{y_{s}}, \mathbf{y_{l}}, \text{and}~ \mathbf{z}$, respectively representing satellite images, short-term daily whether parameters, long-term monthly meteorological parameters, and ground-truth crop yield (or production) information, and then (2) exposes those tuples via a `Dataset` object after appropriate data pre-processing techniques.
81
+
82
+
83
+
84
+ ### Installation
85
+
86
+ Researchers and practitioners can install the latest version of CropNet with the following commands:
87
+
88
+ ```python
89
+ # Create and activate a conda environment
90
+ conda create -n cropnet_api python=3.10
91
+ conda activate cropnet_api
92
+
93
+ # Install the latest version of CropNet
94
+ pip install cropnet
95
+
96
+ # Slove the ecCodes library dependency issue
97
+ pip install ecmwflibs
98
+ ```
99
+
100
+
101
+
102
+ ### CropNet API Examples
103
+
104
+ - **Example 1: A DataDownloader Example for Downloading the Up-to-date CropNet Data**
105
+
106
+ Given the time and region (i.e., the FIPS codes for two U.S. counties) of interest, the following code presents how to utilize the **DataDownloader** to download the up-to-date CropNet data:
107
+
108
+ ```python
109
+ from cropnet.data_downloader import DataDownloader
110
+
111
+ # Use the "target_dir" to specify where the data should be downloaded to
112
+ downloader = DataDownloader(target_dir="./data")
113
+
114
+ # Download 2022 USDA Soybean data
115
+ # Note that most of the 2023 USDA data are not yet available
116
+ downloader.download_USDA("Soybean", fips_codes=["10003", "22007"], years=["2022"])
117
+
118
+ # Download the 2023 (the 1st and 2nd quarters) Sentinel-2 Imagery
119
+ downloader.download_Sentinel2(fips_codes=["10003", "22007"], years=["2023"], image_type="AG")
120
+ downloader.download_Sentinel2(fips_codes=["10003", "22007"], years=["2023"], image_type="NDVI")
121
+
122
+ # Download the 2023 (January to July) WRF-HRRR data
123
+ downloader.download_HRRR(fips_codes=["10003", "22007"], years=["2023"])
124
+ ```
125
+
126
+
127
+
128
+ - **Example 2: A DataRetriever Example for Obtaining Our Curated CropNet Data**
129
+
130
+ Given the time and region of interest, the following code shows how to use the **DataRetriever** to obtain the CropNet data stored in the local machine in a user-friendly format:
131
+
132
+ ```python
133
+ # Use the "base_fir" to specify where the CropNet data is stored
134
+ retriever = DataRetriever(base_dir="/mnt/data/CropNet")
135
+
136
+ # Retrieve the 2022 USDA Soybean data
137
+ usda_data = retriever.retrieve_USDA(crop_type="Soybean", fips_codes=["10003", "22007"], years=["2022"])
138
+
139
+ # Retrieve the 2022 Sentinel-2 Imagery data
140
+ sentinel2_data = retriever.retrieve_Sentinel2(fips_codes=["10003", "22007"], years=["2022"], image_type="AG")
141
+ sentinel2_data = retriever.retrieve_Sentinel2(fips_codes=["10003", "22007"], years=["2022"], image_type="NDVI")
142
+
143
+ # Retrieve the 2022 WRF-HRRR data
144
+ hrrr_data = retriever.retrieve_HRRR(fips_codes=["10003","22007"], years=["2022"])
145
+ ```
146
+
147
+
148
+
149
+ - **Example 3: A PyTorch Example for Using the DataLoader API for Training DNNs**
150
+
151
+ The following code presents a PyTorch example of training a deep learning model (i.e., MMST-ViT) for climate change-aware crop yield predictions, by utilizing the DataLoader APIs:
152
+
153
+ ```python
154
+ import torch
155
+ from torch.utils.data import DataLoader
156
+ from models_mmst_vit import MMST_ViT
157
+ from cropnet.dataset.hrrr_computed_dataset import HRRRComputedDataset
158
+ from cropnet.dataset.sentinel2_imagery import Sentinel2Imagery
159
+ from cropnet.dataset.usda_crop_dataset import USDACropDataset
160
+
161
+ # The base directory for the CropNet dataset
162
+ base_dir = "/mnt/data/CropNet"
163
+ # The JSON configuration file
164
+ config_file = "data/soybeans_train.json"
165
+
166
+ # The dataloaders for each modality of data
167
+ sentinel2_loader = DataLoader(Sentinel2Imagery(base_dir, config_file), batch_size=1)
168
+ hrrr_loader = DataLoader(HRRRComputedDataset(base_dir, config_file), batch_size=1)
169
+ usda_loader = DataLoader(USDACropDataset(base_dir, config_file), batch_size=1)
170
+
171
+ # The model, the optimizer, and the loss function
172
+ model = MMST_ViT()
173
+ optimizer = torch.optim.AdamW(model.parameters(), lr=1e-3, betas=(0.9, 0.999))
174
+ criterion = torch.nn.MSELoss()
175
+
176
+ # Traning the model for one epoch
177
+ for s, h, u in zip(sentinel2_loader, hrrr_loader, usda_loader):
178
+ # x: satellite images
179
+ # ys (or yl): short-term daily (or long-term monthly) weather parameters
180
+ # z: ground-truth crop yield (or production) information
181
+ x, ys, yl, z, = s[0], h[0], h[1], u[0]
182
+
183
+ optimizer.zero_grad()
184
+ z_hat = model(x, ys, yl)
185
+ loss = criterion(z, z_hat)
186
+
187
+ loss.backward()
188
+ optimizer.step()
189
+ ```
190
+
191
+
192
+
193
+ ## License
194
+
195
+ CropNet has a [Creative Commons Attribution-NonCommercial 4.0 International (CC BY-NC 4.0)](https://creativecommons.org/licenses/by-nc/4.0/) license.