CropHarvest
Collects data from a variety of agricultural land use datasets and remote sensing products.
https://github.com/nasaharvest/cropharvest
Category: Consumption
Sub Category: Agriculture and Nutrition
Last synced: about 1 hour ago
JSON representation
Repository metadata
Open source remote sensing dataset with benchmarks
- Host: GitHub
- URL: https://github.com/nasaharvest/cropharvest
- Owner: nasaharvest
- License: cc-by-sa-4.0
- Created: 2021-06-17T17:09:44.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-30T14:12:20.000Z (12 months ago)
- Last Synced: 2025-04-10T04:41:05.048Z (17 days ago)
- Language: Jupyter Notebook
- Homepage:
- Size: 100 MB
- Stars: 186
- Watchers: 7
- Forks: 48
- Open Issues: 35
- Releases: 9
-
Metadata Files:
- Readme: README.md
- Contributing: contributing.md
- License: LICENSE.txt
README.md
CropHarvest
CropHarvest is an open source remote sensing dataset for agriculture with benchmarks. It collects data from a variety of agricultural land use datasets and remote sensing products.
The dataset consists of 95,186 datapoints, of which 33,205 (35%) have multiclass labels. All other datapoints only have binary crop / non-crop labels.
70,213 (74%) of these labels are paired with remote sensing and climatology data, specifically Sentinel-2, Sentinel-1, the SRTM Digital Elevation Model and ERA 5 climatology data.
21 datasets are aggregated into CropHarvest - these are documented here.
More details about CropHarvest and the benchmarks are available in this paper.
Pipeline
The code in this repository
- combines the constituent datasets into a single geoJSON file,
- exports the associated satellite data from Earth Engine,
- combines both datasets to create
(X,y)
training tuples and - exposes those tuples via a
Dataset
object.
The pipeline through which this happens is shown below:
All blue boxes are associated with code in this repository. Anything green is data accessible via Zenodo. By default, the Zenodo data will get downloaded to the data folder - the data folder's Readme has more information about the exact structure of the data.
There are unique cases where you may need to use the EarthEngineExporter
directly, these use cases are demonstrated in the demo_exporting_data.ipynb
notebook.
Installation
Linux and MacOS users can install the latest version of CropHarvest with the following command:
pip install cropharvest
Windows users must install the CropHarvest within a conda environment to ensure all dependencies are installed correctly:
conda install 'fiona>=1.5' 'rasterio>=1.2.6'
pip install cropharvest
In addition, it may be necessary to install h5py
using conda as well (conda install 'h5py>3.7.0'
) prior to pip-installing cropharvest.
See the demo.ipynb
notebook for an example on how to download the data from Zenodo and train a random forest against this data.
For more examples of models trained against this dataset, see the benchmarks.
Contributing
If you would like to contribute a dataset, please see the contributing readme.
FAQ Questions asked at least once
All the data is accessible through the cropharvest.datasets.CropHarvest
object. The main parameters which you might be interested in manipulating are controllable through a cropharvest.datasets.Task
, which takes as input the following parameters:
- A bounding box, which defines the spatial boundaries of the labels retrieves
- A target label, which defines the class of the positive labels (if this is left to
None
, then the positive class will be crops and the negative class will be non-crops) - A boolean defining whether or not to balance the crops and non-crops in the negative class
- A test_identifier string, which tells the dataset whether or not to retrieve a file from the
test_features
folder and return it as the test data.
So if I wanted to use this to train a model to identify crop vs. non crop in France, I might do it like this:
from sklearn.ensemble import RandomForestClassifier
from cropharvest.datasets import Task, CropHarvest
from cropharvest.countries import get_country_bbox
# folder into which the data will be downloaded / already exists
data_dir = "data"
# get_country_bbox returns a list of bounding boxes.
# the one representing Metropolitan France is the 2nd box
metropolitan_france_bbox = get_country_bbox("France")[1]
task = Task(bounding_box=metropolitan_france_bbox, normalize=True)
my_dataset = CropHarvest(data_dir, task)
X, y = my_dataset.as_array(flatten_x=True)
model = RandomForestClassifier(random_state=0)
model.fit(X, y)
The specific use case here is to retrieve NDVI values for a specific row in the labels.geojson
. Here is how you might go about doing that:
Firstly, I will load the geosjon. I'll do it through a CropHarvestLabels
object, which is just a wrapper around the geojson but provides some nice utility functions.
>>> from cropharvest.datasets import CropHarvestLabels
>>>
>>> labels = CropHarvestLabels("cropharvest/data")
>>> labels_geojson = labels.as_geojson()
>>> labels_geojson.head()
harvest_date planting_date ... is_test geometry
0 None None ... False POLYGON ((37.08252 10.71274, 37.08348 10.71291...
1 None None ... False POLYGON ((37.08721 10.72398, 37.08714 10.72429...
2 None None ... False POLYGON ((37.08498 10.71371, 37.08481 10.71393...
3 None None ... False POLYGON ((37.09021 10.71320, 37.09014 10.71341...
4 None None ... False POLYGON ((37.08307 10.72160, 37.08281 10.72197...
[5 rows x 13 columns]
Now, I can use the labels
object to retrieve the filepath of the processed satellite data for each row in the labels geojson:
>>> path_to_file = labels._path_from_row(labels_geojson.iloc[0])
This processed satellite data is stored as h5py
files, so I can load it up as follows:
>>> import h5py
>>> h5py_file = h5py.File(path_to_file, "r")
>>> x = h5py_file.get("array")[:]
>>> x.shape
(12, 18)
The shape of x
represents 12 timesteps and 18 bands. To retrieve the band I am interested in:
>>> from cropharvest.bands import BANDS
>>> x[:, BANDS.index("NDVI")]
array([0.28992072, 0.28838343, 0.26833579, 0.22577633, 0.27138986,
0.06584114, 0.498998 , 0.50147203, 0.50437743, 0.44326343,
0.33735849, 0.28375967])
These are 12 NDVI values, corresponding to the 12 months captured in this timeseries. To find out exactly which month each timestep represents, I can do
>>> labels_geojson.iloc[0].export_end_date
'2021-02-01T00:00:00'
Wich tells me that the last timestep represents January 2021. I can work backwards from there.
License
CropHarvest has a Creative Commons Attribution-ShareAlike 4.0 International license.
Citation
If you use CropHarvest in your research, please use the following citation:
@inproceedings{
tseng2021cropharvest,
title={CropHarvest: A global dataset for crop-type classification},
author={Gabriel Tseng and Ivan Zvonkov and Catherine Lilian Nakalembe and Hannah Kerner},
booktitle={Thirty-fifth Conference on Neural Information Processing Systems Datasets and Benchmarks Track (Round 2)},
year={2021},
url={https://openreview.net/forum?id=JtjzUXPEaCu}
}
Owner metadata
- Name: nasaharvest
- Login: nasaharvest
- Email:
- Kind: organization
- Description:
- Website:
- Location:
- Twitter:
- Company:
- Icon url: https://avatars.githubusercontent.com/u/54071172?v=4
- Repositories: 12
- Last ynced at: 2023-03-03T23:14:40.431Z
- Profile URL: https://github.com/nasaharvest
GitHub Events
Total
- Issues event: 5
- Watch event: 24
- Issue comment event: 3
- Fork event: 8
Last Year
- Issues event: 5
- Watch event: 24
- Issue comment event: 3
- Fork event: 8
Committers metadata
Last synced: 5 days ago
Total Commits: 432
Total Committers: 5
Avg Commits per committer: 86.4
Development Distribution Score (DDS): 0.363
Commits in past year: 54
Committers in past year: 1
Avg Commits per committer in past year: 54.0
Development Distribution Score (DDS) in past year: 0.0
Name | Commits | |
---|---|---|
Gabriel Tseng | g****g@m****a | 275 |
ivanzvonkov | i****v@g****m | 136 |
Adebowale | d****7@g****m | 19 |
alexhernandezgarcia | a****a@g****m | 1 |
hannah-rae | h****r@g****m | 1 |
Committer domains:
Issue and Pull Request metadata
Last synced: 1 day ago
Total issues: 55
Total pull requests: 83
Average time to close issues: 2 months
Average time to close pull requests: 9 days
Total issue authors: 22
Total pull request authors: 7
Average comments per issue: 0.84
Average comments per pull request: 0.94
Merged pull request: 72
Bot issues: 0
Bot pull requests: 0
Past year issues: 3
Past year pull requests: 1
Past year average time to close issues: 7 days
Past year average time to close pull requests: about 4 hours
Past year issue authors: 3
Past year pull request authors: 1
Past year average comments per issue: 0.33
Past year average comments per pull request: 0.0
Past year merged pull request: 1
Past year bot issues: 0
Past year bot pull requests: 0
Top Issue Authors
- gabrieltseng (15)
- ivanzvonkov (9)
- cnakalembe (6)
- Joaquin-Gajardo (3)
- hannah-rae (3)
- jlpearso (2)
- ofcosar (2)
- yichiac (1)
- pavanthanay (1)
- ck-amrahd (1)
- LL0912 (1)
- EhrmannS (1)
- wllih (1)
- fmenat (1)
- dks4-hw (1)
Top Pull Request Authors
- gabrieltseng (52)
- ivanzvonkov (23)
- adebowaledaniel (4)
- hannah-rae (1)
- alexhernandezgarcia (1)
- rishisinhanj (1)
- TrellixVulnTeam (1)
Top Issue Labels
- new dataset (11)
- question (3)
- bug (1)
- enhancement (1)
Top Pull Request Labels
- new dataset (2)
Package metadata
- Total packages: 1
-
Total downloads:
- pypi: 885 last-month
- Total dependent packages: 1
- Total dependent repositories: 2
- Total versions: 10
- Total maintainers: 1
pypi.org: cropharvest
Open source remote sensing dataset with benchmarks
- Homepage: https://github.com/nasaharvest/cropharvest
- Documentation: https://cropharvest.readthedocs.io/
- Licenses: Other/Proprietary License
- Latest release: 0.7.0 (published 12 months ago)
- Last Synced: 2025-04-26T12:34:56.196Z (1 day ago)
- Versions: 10
- Dependent Packages: 1
- Dependent Repositories: 2
- Downloads: 885 Last month
-
Rankings:
- Dependent packages count: 3.24%
- Stargazers count: 6.347%
- Forks count: 6.852%
- Average: 8.478%
- Dependent repos count: 11.788%
- Downloads: 14.165%
- Maintainers (1)
Dependencies
- dill *
- learn2learn ==0.1.3
- pytorch-lightning ==0.7.1
- torch *
- black *
- earthengine-api >=0.1.271
- flake8 ==3.9.2
- jupyter *
- mypy *
- pytest-flake8 *
- pytest-mock *
- geopandas ==0.9.0
- h5py *
- h5py >=3.1.0,
- https *
- openpyxl >=2.5.9
- rasterio >=1.2.6
- scikit-learn >=0.22.2
- tqdm >=4.61.1
- xarray >=0.16.2
- actions/cache v2 composite
- actions/checkout v2 composite
- actions/checkout master composite
- actions/setup-python v2 composite
- actions/setup-python v1 composite
- conda-incubator/setup-miniconda v2 composite
- pypa/gh-action-pypi-publish master composite
- actions/checkout master composite
- actions/setup-python v1 composite
- pypa/gh-action-pypi-publish master composite
Score: 13.797697849465758