PIK-LPJmL / LandInG

The Land Input Generator (LandInG) contains a collection of scripts to derive basic input datasets for terrestrial ecosystem models from diverse and partially conflicting data sources.
https://doi.org/10.5194/gmd-16-3375-2023
GNU Affero General Public License v3.0
7 stars 1 forks source link

cells have no GADM information in cell_list #6

Open Han-Su22 opened 1 month ago

Han-Su22 commented 1 month ago

I downloaded gadm36 both in shp and gpkg format. I ran the GADM from step 1 to step 6 at 0.5 degree spatial resolution. For steps 1-5, I can run the code without error reporting. However, when I ran step 6, it reported error as:

Error: 4183 cells in /home/han/lpjml/LandInG-main/gadm/grid_gadm_30arcmin.bin have no GADM information in cell_list. They are not associated to gadm_no_land in /home/han/lpjml/LandInG-main/gadm/cow_gadm_30arcmin.bin either.

All the cells should be assigned to a region in steps 1-3, and I didn't get error when running them. Does anyone have any idea how to solve it?

sostberg commented 1 month ago

Another user has recently encountered several problems when trying to run LandInG with the current GADM version 4.1 (see issue #2, #3 and #4) but was able to run the code for GADM version 3.6.

Do you use a prescribed grid (force_grid <- TRUE) or do you let the script determine the grid based on the GADM shapes?

Han-Su22 commented 1 month ago

Another user has recently encountered several problems when trying to run LandInG with the current GADM version 4.1 (see issue #2, #3 and #4) but was able to run the code for GADM version 3.6.

Do you use a prescribed grid (force_grid <- TRUE) or do you let the script determine the grid based on the GADM shapes?

No. I have force_grid as False. Any ideas on how I could provide you more information regarding the error, because I didn't change the code setting except file path

I got the data from: https://geodata.ucdavis.edu/gadm/gadm3.6/

sostberg commented 1 month ago

I can reproduce the error. The problem seems to occur in line 294 of file 5_map_districts_to_grid_intersection.R. It seems like st_crop does not work correctly here. As a result, lpjgrid_shape_country is missing a lot of polygons for grid cells, and many land areas get lost in the intersection between the grid cells and the land polygons. This does not show up as errors when running 5_map_districts_to_grid_intersection.R, but does show up in 6_map_districts_to_grid_collection.R, which compares its results to the results from steps 1-3.

From a quick test, it looks like st_crop works as expected if you switch off s2 functionality in the sf package. You can do that by uncommenting line 97 in file gadm_setup.R.

Note that running sf with or without s2 functionality can have some effect on the results of the polygon intersections. If you switch off s2 functionality I would suggest that you delete all (intermediate and final) results in the gadm directory and run all the scripts again.

As an alternative, you could try skipping line 284-305 in file 5_map_districts_to_grid_intersection.R. Change line 308 to use lpjgrid_shape instead of lpjgrid_shape_country. This should work without switching off s2 functionality. In this case, you only need to delete the directory "grid_intersection_30arcmin_districts" and the intermediate file "celllist_30arcmin_districts.RData" and then run 5_map_districts_to_grid_intersection.R and 6_map_districts_to_grid_collection.R again.

Han-Su22 commented 1 month ago

Thank you so much for your confirmation and suggestions! I uncommented line 97 in gadm_setup.R and can run steps 1-6 successfully so far. It works!