Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to make a table with >= 2^31 elements #6

Closed
lime-n opened this issue Mar 19, 2021 · 3 comments
Closed

attempt to make a table with >= 2^31 elements #6

lime-n opened this issue Mar 19, 2021 · 3 comments

Comments

@lime-n
Copy link

lime-n commented Mar 19, 2021

I keep getting the following error when using the contingencyTable function on my raster.

I'm using a MODIS MCD12q1 land-cover yearly dataset.

landcover
class      : RasterStack 
dimensions : 7149, 10258, 73334442, 10  (nrow, ncol, ncell, nlayers)
resolution : 463.3127, 463.3127  (x, y)
extent     : -9793968, -5041306, 2716866, 6029088  (xmin, xmax, ymin, ymax)
crs        : +proj=sinu +lon_0=0 +x_0=0 +y_0=0 +R=6371007.181 +units=m +no_defs 
names      : landcover_2010, landcover_2011, landcover_2012, landcover_2013, landcover_2014, landcover_2015, landcover_2016, landcover_2017, landcover_2018, landcover_2019 
min values :              0,              0,              0,              0,              0,              0,              0,              0,              0,              0 
max values :            255,            255,            255,            255,            255,            255,            255,            255,            255,            255 
land.cover<- contingencyTable(input_raster = landcover, pixelresolution = 5)

Error in (function (..., exclude = if (useNA == "no") c(NA, NaN), useNA = c("no", :
attempt to make a table with >= 2^31 elements

I thought it was a problem with pixelresolution, so I had it changed to 463.3127 and selected ontly the first two years:

land.cover<- contingencyTable(input_raster = landcover[[1:2]], pixelresolution = 463.3127)

Warning messages:
1: Expected 2 pieces. Missing pieces filled with NA in 176 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
2: Expected 2 pieces. Missing pieces filled with NA in 176 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
3: Expected 2 pieces. Missing pieces filled with NA in 176 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...].
4: Expected 2 pieces. Missing pieces filled with NA in 176 rows [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, ...]

Then I got:

land.cover
$lulc_Multistep
# A tibble: 532 x 8
   Period  From    To         km2  QtPixel Interval yearFrom yearTo
   <chr>  <int> <int>       <dbl>    <int>    <int>    <int>  <int>
 1 NA-NA      0     0 3790609.    17658776       NA       NA     NA
 2 NA-NA      0     1      29.6        138       NA       NA     NA
 3 NA-NA      0     4       0.215        1       NA       NA     NA
 4 NA-NA      0     5       7.94        37       NA       NA     NA
 5 NA-NA      0     8      98.3        458       NA       NA     NA
 6 NA-NA      0     9      15.7         73       NA       NA     NA
 7 NA-NA      0    10      31.8        148       NA       NA     NA
 8 NA-NA      0    11     310.        1445       NA       NA     NA
 9 NA-NA      0    15      77.9        363       NA       NA     NA
10 NA-NA      1     0       9.02        42       NA       NA     NA
# ... with 522 more rows

$lulc_Onestep
# A tibble: 190 x 8
   Period  From    To         km2  QtPixel Interval yearFrom yearTo
   <chr>  <int> <int>       <dbl>    <int>    <int>    <int>  <int>
 1 NA-NA      0     0 3789984.    17655864       NA       NA     NA
 2 NA-NA      0     1      55.4        258       NA       NA     NA
 3 NA-NA      0     4       0.644        3       NA       NA     NA
 4 NA-NA      0     5      11.4         53       NA       NA     NA
 5 NA-NA      0     7       1.29         6       NA       NA     NA
 6 NA-NA      0     8     158.         737       NA       NA     NA
 7 NA-NA      0     9      29.4        137       NA       NA     NA
 8 NA-NA      0    10     151.         705       NA       NA     NA
 9 NA-NA      0    11     548.        2552       NA       NA     NA
10 NA-NA      0    12       7.73        36       NA       NA     NA
# ... with 180 more rows

$tb_legend
# A tibble: 16 x 3
   categoryValue categoryName color  
           <int> <fct>        <chr>  
 1             0 PQL          #7F2A2B
 2             1 JCP          #5F1415
 3             2 RZW          #6F8DD2
 4             3 DLW          #BD5758
 5             4 HNU          #DD9191
 6             5 GSX          #C5CFF0
 7             6 SEK          #EFF1F8
 8             7 HZI          #F9DCDC
 9             8 MWH          #F9EFEF
10             9 YFN          #8EA4DE
11            10 SYW          #ABBBE8
12            11 QXN          #295EAE
13            12 QOB          #EAACAC
14            13 AOF          #002F70
15            14 BDX          #DCE2F6
16            15 NFA          #A13F3F

$totalArea
# A tibble: 1 x 2
   area_km2   QtPixel
      <dbl>     <int>
1 38406511. 178918995

$totalInterval
[1] NA

Everything filled with NA's

@qfviolin
Copy link

qfviolin commented Oct 3, 2022

Hello friend, I also encountered the same problem, please tell me how you solved it

@lime-n
Copy link
Author

lime-n commented Oct 15, 2022

@qfviolin it has been a while since I have last done this.

I might not have solved it at all but I cannot remember. Although, I can take another stab at it if you send me the file you’re working with.

it may be an issue with the data columns that you’re using and the pixel resolution.

@qfviolin
Copy link

Thanks to my friend, I changed the resolution and have solved the problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants