Skip to content

Commit

Permalink
Add cropland ingestion
Browse files Browse the repository at this point in the history
  • Loading branch information
BielStela authored and alexeh committed Dec 17, 2024
1 parent a753dd5 commit d973d0a
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions data/h3_data_importer/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ WORKDIR_LIVESTOCK_GHG=data/livestock_ghg
WORKDIR_DEFAULT_COMMODITY=data/default_commodity
WORKDIR_EARTHSTAT=data/earthstat
WORKDIR_CROPGRIDS=data/cropgrids
WORKDIR_CROPLAND=data/cropland


CHECKSUMS_PATH=data_checksums
Expand Down Expand Up @@ -105,6 +106,35 @@ convert-cropgrids: download-cropgrids
python raster_folder_to_h3_table.py $(WORKDIR_CROPGRIDS)/crop-grids-production h3_grid_cropgrids_global_prod production cropgrids 2020 --h3-res=6 --thread-count=$(PARALLELIZATION_FACTOR)
python raster_folder_to_h3_table.py $(WORKDIR_CROPGRIDS)/crop-grids-harvest h3_grid_cropgrids_global_ha harvest_area cropgrids 2020 --h3-res=6 --thread-count=$(PARALLELIZATION_FACTOR)



# ---------------------------------------------
# CROP LAND
# ---------------------------------------------

download-cropland:
mkdir -p $(WORKDIR_CROPLAND)
aws s3 cp s3://landgriffon-raw-data/raw/CroplandPastureArea2000_Geotiff.zip $(WORKDIR_CROPLAND)/CroplandPastureArea2000_Geotiff.zip

extract-cropland: download-cropland
unzip -q -j -o -u $(WORKDIR_CROPLAND)/CroplandPastureArea2000_Geotiff.zip CroplandPastureArea2000_Geotiff/Cropland2000_5m.tif -d $(WORKDIR_CROPLAND)/
mkdir -p $(WORKDIR_CROPLAND)/production
mkdir -p $(WORKDIR_CROPLAND)/harvest
mv $(WORKDIR_CROPLAND)/Cropland2000_5m.tif $(WORKDIR_CROPLAND)/harvest/es_Cropland2000_ha.tif
# global yield value of cropland from faostat
gdal_calc.py --quiet --calc "A * 9.127829341" --format GTiff --type Float32 \
-A $(WORKDIR_CROPLAND)/harvest/es_Cropland2000_ha.tif --A_band 1 \
--outfile $(WORKDIR_CROPLAND)/production/es_Cropland2000_prod.tif;

rm -f $(WORKDIR_CROPLAND)/CroplandPastureArea2000_Geotiff.zip

convert-cropland: extract-cropland
python raster_folder_to_h3_table.py $(WORKDIR_CROPLAND)/production h3_grid_cropland_global_prod production cropland 2000 --h3-res=6
python raster_folder_to_h3_table.py $(WORKDIR_CROPLAND)/harvest h3_grid_cropland_global_ha harvest_area cropland 2000 --h3-res=6




###############################################################
# Gridded Livestock of the World (GLW3) - pasture production #
###############################################################
Expand Down
1 change: 1 addition & 0 deletions data/h3_data_importer/raster_folder_to_h3_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ def update_for_material_indicator(cursor: psycopg.Cursor, dataset: str, column_n
spam_id = f"spam_{column_name.split('PerTProduction')[0].lower()}" # something like 'spam_ocerwhea'
cursor.execute('select id from material where "datasetId" = %s', (spam_id,))
material_ids = cursor.fetchall()
breakpoint()
if not material_ids:
log.warning(f"Material with 'datasetId' {spam_id} does not exists")
raise ValueError(f"Material with 'datasetId' {spam_id} does not exists")
Expand Down
Empty file.

0 comments on commit d973d0a

Please sign in to comment.