mapme-initiative / mapme.biodiversity

Efficient analysis of spatial biodiversity datasets for global portfolios
https://mapme-initiative.github.io/mapme.biodiversity/dev
GNU General Public License v3.0
33 stars 7 forks source link

Column names of unnested indicator are not as expected #107

Closed goergen95 closed 11 months ago

goergen95 commented 2 years ago
    Thank you, it worked well (my portfolio has been initialized)!

I'm now trying to calculate some indicators such as mangroves area evolution with these codes :

----- Mangrove Area -----

download relevant data

afd_portfolio2<- get_resources(afd_portfolio, resources = c("gmw") )

calculate indicators

afd_portfolio2<- calc_indicators(x = afd_portfolio2, indicators = "mangroves_area", overwrite=T)

unnest results data for further analysis

colnames(afd_portfolio2) # check the columns at the end to derive the relevant column names afd_mangroves<-tidyr::unnest(afd_portfolio2, cols="mangroves_area")

view unnested data (only relevant columns are selected for the view and geometry is dropped)

colnames(afd_mangroves) # check the columns at the end to derive the relevant column names afd_mangroves %>% sf::st_drop_geometry() %>% dplyr::select(ID_pr,WDPAID,year,mangrove_extent) %>% View()

However, when I run "colnames(afd_mangroves) ", I get :

colnames(afdmangroves) [1] "WDPAID" "WDPA" "PADE" "NAME" "ORIG" "DESIG" "DESIG_E" "DESIGT" "IUCN" "INT_C"
[11] "MARIN" "REP_M" "GIS_M" "REP_A" "GIS_A" "NO_TA" "NOTK" "STATUS" "STATUS" "GOV_T"
[21] "OWN_T" "MANG_A" "MANG_P" "VERIF" "METAD" "SUBL" "PAREN" "ISO3" "SUPP" "CONS_"
[31] "ID_pr" "Nmd" "N__" "IDcn" "Lblldc" "Dsc" "Mntnt" "Mtglb" "E__" "mnt__"
[41] "Prodt" "Lbllp" "Dvsn
" "Lblldv" "Agenc" "Lbllg" "Ann_c" "Dt_ct" "D
1_" "D__"
[51] "DC" "DurdcncrsA" "DrdcncrsAn" "IdPys" "Pays" "Drct_" "Atrsp" "Ett" "Lbllt" "Bnfcr"
[61] "Rspns" "Dr__
" "Dt_
" "Cfn_1" "Cfn_2" "Cfn_3" "Cfn_4" "Cfn_5" "Cfn6" "KFW"
[71] "mtrs
" "Sprfc" "nAP" "détal" "projt" "cmmnt" "WDPAID_2" "WDPAID_3" "Nm_AP" "Cmmnt_1"
[81] "assetid" "value" "geometry"

WHERE you can see there is no "year" column, nor "mangrove_extent" column, so I'm getting an error message " Can't subset columns that don't exist".

Why don't the year and mangrove_extent appear ?

Thank you so much

Originally posted by @APAF13 in https://github.com/mapme-initiative/mapme.biodiversity/issues/102#issuecomment-1286186725

goergen95 commented 2 years ago

Please use Markdown Code blocks (use: ``) to wrap your code, or, even better, use the [{reprex}`](https://reprex.tidyverse.org/) package to provide a reproducible example in a very clear format. This is reall hard to read!

To me this looks like none of the assets in your portfolio intersects with the mangrove data layer thus in the value column you should find just NAs. Could you please confirm if this is the case?

ghost commented 2 years ago

Hello,

Alright, sorry about that.

Yes the value column is just NAs, whereas I know my protected areas contains mangroves ... And the gmw ressources have been well and fully downloaded.

Thanks again

goergen95 commented 2 years ago

Could you somehow share some of those geometries?

ghost commented 2 years ago

For instance, I have Moheli National Park (WDPAID = 313046) , Sao Tomé Natural Park (124355), Ankarea(555548848), Ankivonjy (555548847), Nanumea (555547863), Helen Reef Convervation Area (555645473)

goergen95 commented 2 years ago

Could you please Export them to Geopackage and Post theme here or somewhere else?

ghost commented 2 years ago

ecos_cot_shp.zip

ghost commented 2 years ago

Here is a sample of coastal PAs

ghost commented 1 year ago

Hello, Does this file work for you?

goergen95 commented 1 year ago

Yes, the following code works for me:

library(mapme.biodiversity)
library(sf)

st_read("ecos_cot_shp.shp") %>% 
  st_cast("POLYGON") %>%
  init_portfolio(years = 2010, 
                 outdir = "data", 
                 tmpdir = "data/tmp", 
                 cores = 4, 
                 aria_bin = "/usr/bin/aria2c",
                 add_resources = TRUE) %>%
  get_resources(resources = "gmw") %>%
  calc_indicators(indicators = "mangroves_area") %>% 
  dplyr::select(mangroves_area) %>% 
  tidyr::unnest(mangroves_area)

Do you get any more error/warning messages that could help us?

ghost commented 1 year ago

You mean you get some value of extent of mangroves (no NA) ?

goergen95 commented 1 year ago

Yes, for the polygons that do intersect with the mangrove layer. Could you please run the above code and also report the version of mapme.biodiversity you are using?

ghost commented 1 year ago

'Reading layer 'BDD_SHP_nodupl' from data source /Users/lea/Desktop/AP/base/BDD_SHP_nodupl.shp' using driverESRI Shapefile' Simple feature collection with 88 features and 80 fields Geometry type: MULTIPOLYGON Dimension: XY Bounding box: xmin: -171.9129 ymin: -24.17141 xmax: 179.0909 ymax: 33.80984 Geodetic CRS: WGS 84 Starting process to download resource 'gmw'........ Checking URLs for existence. This may take a while... |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=02m 05s Translating shapefiles to GeoPackages. This may take a while.... |++++++++++++++++++++++++++++++++++++++++++++++++++| 100% elapsed=21s
Simple feature collection with 152 features and 1 field Geometry type: POLYGON Dimension: XY Bounding box: xmin: -171.9129 ymin: -24.17141 xmax: 179.0909 ymax: 33.80984 Geodetic CRS: WGS 84 A tibble: 152 × 2 value geometry

1 NA ((1.69199 11.40924, 1.70254 11.40491, 1.70738 11.41325, 1.71178 11.42612, 1.71889 11.4240... 2 NA ((14.87231 8.461353, 14.88299 8.451499, 14.89752 8.443149, 14.9086 8.432232, 14.90871 8.4... 3 NA ((15.3454 0.6910242, 15.34064 0.688721, 15.33687 0.6834468, 15.33506 0.6803146, 15.33423 ... 4 NA ((-7.261752 7.131596, -7.260419 7.131294, -7.259589 7.131303, -7.258703 7.131339, -7.2579... 5 NA ((38.06962 2.531882, 38.06917 2.527018, 38.0686 2.524258, 38.06698 2.518548, 38.06612 2.5... 6 NA ((38.35806 -0.0720933, 38.35622 -0.07023748, 38.35289 -0.06823892, 38.35044 -0.0663831, 3... 7 NA ((-16.05677 20.02755, -16.0405 20.02648, -16.01518 20.02758, -15.99542 20.02417, -15.9738... 8 NA ((-16.52376 15.88408, -16.50925 15.88397, -16.5093 15.88227, -16.50907 15.8811, -16.50835... 9 NA ((12.6054 3.427483, 12.60694 3.423277, 12.61065 3.423669, 12.61379 3.423868, 12.61651 3.4... 10 NA ((12.74226 8.473881, 12.73558 8.460353, 12.73441 8.451167, 12.78067 8.423777, 12.78852 8.... … with 142 more rows Use print(n = ...) to see more rows Message d'avis : Dans st_cast.sf(., "POLYGON") : repeating attributes for all sub-geometries for which they may not be constant '
ghost commented 1 year ago

It seems there is still only NA ...

ghost commented 1 year ago

I use the mapme version 0.2.1 ...