Skip to content

read IFPRI and IIASA SPAM data at the scale of user defined shapefiles and crop groups

License

Notifications You must be signed in to change notification settings

RaphaelPB/SPAM_data_reader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SPAM_data_reader

Read IFPRI and IIASA SPAM global data at the scale of user defined shapefiles and crop groups. SPAM 2020 data is available at https://www.mapspam.info/. SPAM data contains global gridded data for area, yield and production for 46 crops and 2 production systems (irrigated, rainfed), previously also: rainfed high input, rainfed low input and rainfed subsitence.

Requierments

You need python with the following libraries: pandas, geopandas, rasterstats, and numpy

Usage

  • Download this repository
  • Download the SPAM data: https://mapspam.info/ (SPAM2020v1)
  • Place your desired shapefiles in the Shapefiles folder - the projection needs to be EPSG:4326 - WGS84 - default shapefiles of the Zambezi River Basin are in this repository for you to test the script
  • Open the excel file SPAM_metadata.xlsx - in the sheet SHAPEFILES insert your shapefiles' name and the id to be used (replace default 'catchments' and 'countries' shapefiles)
  • Run the SPAM_data_reader.py script
  • (Automatic downloading of Data currently NOT available) - the first time, the script needs to download SPAM data (see Options to avoid this), hence it might take some time depending on your connection
  • Go to the Ouptputs folder and look at the output files

Options

You can customize different options in the SPAM_metadata.xlsx file, a complete description of the options is available within the excel file:

  • SHAPEFILES: define which shapefiles should be used
  • SPAMvars: define which variables should be compiled, convert units, data source and download options
  • SPAMcrops: define which crops should be compiled
  • SPAMtechs: define which technologies (/production system) should be compiled
  • GROUPcrops: define your own crop groups to reframe SPAM data
  • EXPORT: define the outputs and csv files options
  • INFO: define an Info message to be attached in the output excel files

Outputs

All outputs are found in the Outputs folder (or user-defined folder):

  • SPAM_yourshapefile.csv: csv file with the raw SPAM data at the level of your shapefile
  • SPAM_yourshapefile_cropgroups.csv: same as previous for user defined crop groups instead of SPAM crops
  • SPAM_yourshapefile_summarized.xlsx: excel file with the SPAM data at the level of your shapefile as 2D Tables, area and production are summed, yield is as a weighted average (by harvested area)
  • SPAM_yourshapefile_cropgroups_summarized.xlsx: same as previous for user defined crop groups instead of SPAM crops

Common errors

  • If shapefiles do not have the correct projection WGS 84, EPSG 4326:

File "rasterio_io.pyx", line 323, in rasterio._io.DatasetReaderBase.read MemoryError

  • If all crops are not assigned a crop group !

return cropgroup[cropgroup.eq(crop).any(1)].index[0] File "C:\Programs\envs\Python36\lib\site-packages\pandas\core\indexes\base.py", line 4280, in getitem return getitem(key) IndexError: index 0 is out of bounds for axis 0 with size 0

Author

Raphael Payet-Burin ([email protected])

About

read IFPRI and IIASA SPAM data at the scale of user defined shapefiles and crop groups

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages