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

prepInputs error : [mask] too many values for writing #415

Open
achubaty opened this issue Jan 8, 2025 · 0 comments
Open

prepInputs error : [mask] too many values for writing #415

achubaty opened this issue Jan 8, 2025 · 0 comments

Comments

@achubaty
Copy link
Collaborator

achubaty commented Jan 8, 2025

using latest development version:

devtools::load_all("~/GitHub/PredictiveEcology/reproducible")
#> ℹ Loading reproducible

cacheDir <- file.path(tempdir(), "reprex_maskTo", "cache")
inputDir <- file.path(tempdir(), "reprex_maskTo", "inputs")
outputDir <- file.path(tempdir(), "reprex_maskTo", "outputs")

targetCRS <- paste("+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95",
                   "+x_0=0 +y_0=0 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0")

## get studyArea (Ontario forest management units)
studyArea <- {
  prepInputs(
    url = "https://www.gisapplication.lrc.gov.on.ca/fmedatadownload/Packages/FORMGMT.zip",
    destinationPath = asPath(inputDir),
    targetFile = "FOREST_MANAGEMENT_UNIT.shp",
    alsoExtract = "similar",
    fun = "sf::st_read"
  ) |>
    sf::st_transform(crs = targetCRS) |>
    sf::st_union()
} |>
  Cache()
#> No cachePath supplied and getOption('reproducible.cachePath') is inside a temporary directory;
#>   this will not persist across R sessions.
#> Running `prepInputs`
#> Running `preProcess`
#> Preparing: FOREST_MANAGEMENT_UNIT.shp
#> ...downloading...
#>    Downloading
#>      https://www.gisapplication.lrc.gov.on.ca/fmedatadownload/Packages/FORMGMT.zip
#>      ...
#> Hardlinked version of file(s) created:
#> ... no copy/copies made.
#> User supplied files don't correctly specify the files in the archive (likely because of sub-folders); 
#> using items in archive with same basenames. Renaming to these: 
#> LIO-2023-08-19/FOREST_MANAGEMENT_UNIT.shp
#> From:
#> /tmp/RtmpKGaOHk/reprex_maskTo/inputs/FORMGMT.zip  
#> Extracting
#> files
#>                                        <char>
#>  1: LIO-2023-08-19/FOREST_MANAGEMENT_UNIT.dbf
#>  2: LIO-2023-08-19/FOREST_MANAGEMENT_UNIT.prj
#>  3: LIO-2023-08-19/FOREST_MANAGEMENT_UNIT.shp
#>  4: LIO-2023-08-19/FOREST_MANAGEMENT_UNIT.shx
#> ... Done extracting 6 files
#>    Appending checksums to CHECKSUMS.txt. If you see this message repeatedly,
#>      you can specify targetFile (and optionally alsoExtract) so it knows what
#>      to look for.
#> `preProcess` done; took 43.41183 secs
#> Running `process` (i.e., loading file into R)
#> targetFile located at:
#> /tmp/RtmpKGaOHk/reprex_maskTo/inputs/LIO-2023-08-19/FOREST_MANAGEMENT_UNIT.shp
#> Loading object into R
#> Reading layer `FOREST_MANAGEMENT_UNIT' from data source 
#>   `/tmp/RtmpKGaOHk/reprex_maskTo/inputs/LIO-2023-08-19/FOREST_MANAGEMENT_UNIT.shp' 
#>   using driver `ESRI Shapefile'
#> Simple feature collection with 39 features and 14 fields
#> Geometry type: MULTIPOLYGON
#> Dimension:     XY
#> Bounding box:  xmin: -95.15363 ymin: 44.31563 xmax: -75.81624 ymax: 52.39881
#> Geodetic CRS:  NAD83
#>    Saving large object (fn: sf::st_read , cacheId: 677ef02367f902c4 ) to Cache
#>      : 73.9 Mb
#> � Done!
#> Saved! Cache file: 677ef02367f902c4.rds; fn: sf::st_read
#> `prepInputs` done; took 51.21939 secs
#> Saving large object (fn: sf::st_union , cacheId: f85b7d2a0cd7dd6b ) to Cache :
#>   23.4 Mb
#> � Done!
#> Saved! Cache file: f85b7d2a0cd7dd6b.rds; fn: sf::st_union

## prep LCC for studyArea and write to outputDir
LCC <- Cache(
  prepInputs,
  url = paste0(
    "https://ftp.maps.canada.ca/pub/nrcan_rncan/",
    "Land-cover_Couverture-du-sol/canada-landcover_canada-couverture-du-sol/",
    "CanadaLandcover2010.zip"
  ),
  destinationPath = asPath(inputDir),
  to = studyArea,
  method = "near",
  datatype = "INT2U",
  fun = "terra::rast",
  targetFile = asPath("CAN_LC_2010_CAL.tif"),
  writeTo = asPath(file.path(outputDir, "LCC_ON_FMU.tif"))
)
#> No cachePath supplied and getOption('reproducible.cachePath') is inside a temporary directory;
#>   this will not persist across R sessions.
#> Running `prepInputs`
#> Running `preProcess`
#> Preparing: CAN_LC_2010_CAL.tif
#> alsoExtract is unspecified; assuming that all files must be extracted
#> Checksumming all files in archive
#> ...downloading...
#>    Downloading
#>      https://ftp.maps.canada.ca/pub/nrcan_rncan/Land-cover_Couverture-du-sol/canada-landcover_canada-couverture-du-sol/CanadaLandcover2010.zip
#>      ...
#> Hardlinked version of file(s) created:
#> ... no copy/copies made.
#> From:
#> /tmp/RtmpKGaOHk/reprex_maskTo/inputs/CanadaLandcover2010.zip  
#> Extracting
#> files
#>                  <char>
#>  1: CAN_LC_2010_CAL.tif
#> ... Done extracting 2 files
#>    Appending checksums to CHECKSUMS.txt. If you see this message repeatedly,
#>      you can specify targetFile (and optionally alsoExtract) so it knows what
#>      to look for.
#> `preProcess` done; took 42.43514 secs
#> Running `process` (i.e., loading file into R)
#> targetFile located at:
#> /tmp/RtmpKGaOHk/reprex_maskTo/inputs/CAN_LC_2010_CAL.tif
#> Loading object into R
#> Running `postProcessTo`
#> cropping...
#> |---------|---------|---------|---------|=========================================                                          
#> �done! took:  23.1 secs
#> projecting...
#> 
#> projectTo is a Vector dataset, which does not define all metadata required.
#> Using original resolution (30x30m)
#>    Using the origin and extent from `ext(from)` in the projection from
#>      `crs(projectTo)`.
#>    If this is not correct, create a template gridded object and pass that to
#>      `projectTo`...
#> |---------|---------|---------|---------|=========================================                                          |---------|---------|---------|---------|=========================================                                          
#> �done! took:  9.25 mins
#> masking...
#> |---------|---------|---------|---------|
#> maskTo resulted in following error: 
#>     - [mask] too many values for writing: 1214009477 > 151528274
#>     --> attempting to fix
#> |---------|---------|---------|---------|
#> Error in maskTo(from, maskTo, ..., overwrite = overwrite): Error : [mask] too many values for writing: 1214009477 > 246297134

try(unlink(file.path(tempdir(), "reprex_maskTo"), recursive = TRUE))

Created on 2025-01-08 with reprex v2.1.1

achubaty added a commit that referenced this issue Jan 8, 2025
TODO: `prepInputs` is failing when masking (#415)
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

1 participant