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

Error: cow_data could not be filled correctly #2

Closed AdrienDams closed 4 months ago

AdrienDams commented 4 months ago

I am trying to simply run GADM with the default grid and the last GADM files (4.10).

While running 3_map_countries_to_grid_collection.R, I have this error:

id_collection.R
Linking to GEOS 3.12.1, GDAL 3.8.5, PROJ 9.4.0; sf_use_s2() is TRUE
Loading required package: sp
Linking to liblwgeom 3.0.0beta1 r16016, GEOS 3.12.1, PROJ 9.4.0

Attaching package: ‘lwgeom’

The following object is masked from ‘package:sf’:

    st_perimeter

Please note that rgdal will be retired during October 2023,
plan transition to sf/stars/terra functions using GDAL and PROJ
at your earliest convenience.
See https://r-spatial.org/r/2023/05/15/evolution4.html and https://github.com/r-spatial/evolution
rgdal: version: 1.6-7, (SVN revision 1203)
Geospatial Data Abstraction Library extensions to R successfully loaded
Loaded GDAL runtime: GDAL 3.8.5, released 2024/04/02
Path to GDAL shared files: 
 GDAL does not use iconv for recoding strings.
GDAL binary built with GEOS: TRUE 
Loaded PROJ runtime: Rel. 9.4.0, March 1st, 2024, [PJ_VERSION: 940]
Path to PROJ shared files: /app/spack/0.19.0/opt/spack/linux-almalinux9-x86_64/gcc-11.3.1/proj-8.2.1-54gqm4h7b6cpailljrmtbp63rxln6nc2/share/proj
PROJ CDN enabled: TRUE
Linking to sp version:2.1-4
To mute warnings of possible GDAL/OSR exportToProj4() degradation,
use options("rgdal_show_exportToProj4_warnings"="none") before loading sp or rgdal.
udunits database from /bg/home/damseaux-a/.conda/envs/LandInG/share/udunits/udunits2.xml
Warning message:
GDAL support is provided by the sf and terra packages among others 
Info: Removing 51 cells from grid because their cell area is below threshold_grid of 1000 m2.
/bg/home/damseaux-a/LandInG/gadm/grid_gadm_30arcmin.bin existed and was deleted to create a new one
/bg/home/damseaux-a/LandInG/gadm/landfrac_gadm_30arcmin.bin existed and was deleted to create a new one
Info: There are 17012 cells exceeding land fraction of 1 by a maximum of 305030 which will be cut to 1
Error: cow_data could not be filled correctly
Execution halted

I think the error comes much earlier, for example my array "level0" is nearly empty:

"x"
"No land"

I guess this is related to "Info: There are 17012 cells exceeding land fraction of 1 by a maximum of 305030 which will be cut to 1". I had a couple of warning messages in the previous steps but nothing serious.

Any help?

sostberg commented 4 months ago

The problem is that new versions of GADM have renamed the column "NAME_0" into "COUNTRY". I encountered this before. I think it works again if you replace "NAME_0" with "COUNTRY" in line 62 of 3_map_countries_to_grid_collection.R. You will also have to change 6_map_districts_to_grid_collection.R if you plan to run all scripts in the gadm directory.

AdrienDams commented 4 months ago

Thanks for the nearly instant answer! What a odd choice from them to decide to rename "NAME_0" into "COUNTRY", but keeps "NAME_1".

I changed what you told me but I think this is not the only change needed. In line 676 level0 <- unlist(country_list[sort_order]) is likely not working. I am not a R expert but country_list[sort_order] gives:

$ABW
character(0)

$AFG
character(0)

$AGO
character(0)

$AIA
character(0)

$ALA
character(0)

$ALB
character(0)

$AND
character(0)

...

and level0 gives:

character(0)
sostberg commented 4 months ago

Can you check if there is a "celllist_*:RData" file in the working directory? If so, please try to delete it and then run 3_map_countries_to_grid_collection.R again.

AdrienDams commented 4 months ago

It solved it! Thanks