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

path with special character #223

Closed
kongdd opened this issue May 25, 2021 · 4 comments
Closed

path with special character #223

kongdd opened this issue May 25, 2021 · 4 comments

Comments

@kongdd
Copy link

kongdd commented May 25, 2021

Path with Chinese character is not recognised by Terra.

library(ncdf4)
library(terra)
#> terra version 1.2.10
file_pet = "F:/SciData/ET_products/已完成/GLEAM_3.5a_yearly/Ep_1980-2020_GLEAM_v3.5a_YR_fixed.nc"
# file_pet2 = "F:/SciData/ET_products/已完成/GLEAM_3.5a_yearly/Ep_1980-2020_GLEAM_v3.5a_YR_fixed_1deg.nc"

fid <- nc_open(file_pet)
fid
#> File F:/SciData/ET_products/已完成/GLEAM_3.5a_yearly/Ep_1980-2020_GLEAM_v3.5a_YR_fixed.nc (NC_FORMAT_CLASSIC):
#> 
#>      1 variables (excluding dimension variables):
#>         float Ep[lon,lat,time]   
#>             units: mm/year
#>             _FillValue: -9999
#> 
#>      3 dimensions:
#>         lon  Size:1440
#>             units: degrees_east
#>             long_name: lon
#>         lat  Size:720
#>             units: degrees_north
#>             long_name: lat
#>         time  Size:41   *** is unlimited ***
#>             units: days since 1970-01-01
#>             long_name: time
#>             calendar: proleptic_gregorian
#> 
#>     2 global attributes:
#>         history: Created by nctools, Tue May 25 00:25:59 2021
#>         Conventions: nctools version 0.0.0.9000

rast(file_pet)
#> Warning: F:/SciData/ET_products/已完成/GLEAM_3.5a_yearly/
#> Ep_1980-2020_GLEAM_v3.5a_YR_fixed.nc: No such file or directory (GDAL error 4)
#> Error: [rast] cannot read from F:/SciData/ET_products/已完成/GLEAM_3.5a_yearly/Ep_1980-2020_GLEAM_v3.5a_YR_fixed.nc

Created on 2021-05-25 by the reprex package (v2.0.0)

@rhijmans
Copy link
Member

rhijmans commented May 25, 2021

Thank you for reporting this. It is a problem on windows but not on other operating systems. I made some changes and now things appear to work for geotiff and some other formats --- but not quite for ncdf. Here is some test code

dir <- "已完成"
library(terra)
r <- rast(nrows=5, ncols=5, vals=1:25)
ftif <- file.path(dir, "test.tif")
fasc <- file.path(dir, "test.asc")
fncd <- file.path(dir, "test.nc")

writeRaster(r, ftif, overwrite=TRUE)
writeRaster(r, fasc, overwrite=TRUE)

### cannot write CDF via GDAL or via R/ncdf4
## GDAL
writeRaster(r, fncd, overwrite=TRUE)
#Error: [writeRaster] failed writing NETCDF file. Path does not exist
#In addition: Warning messages:
#1: [consider writeCDF to write ncdf files]  
#2: Unable to create netCDF file D:/gdrive/testdata/已完�/test.nc (Error code 2): No such file or directory . (GDAL error 4) 

## ncdf4
writeCDF(r, fncd, overwrite=TRUE)
#Error in R_nc4_create: Permission denied (creation mode was 4096)
#Error in ncdf4::nc_create(filename, ncvars, force_v4 = force_v4, verbose = verbose) : 
#  Error in nc_create!

# write and then copy
writeCDF(r, "test.nc", overwrite=TRUE)
file.copy("test.nc", dir, overwrite=TRUE)
#[1] TRUE

# read again (multiplying with 1 to see if it really works)
x <- rast(ftif) * 1
x <- rast(fasc) * 1

x <- rast(fncd) * 1
# Warning message:
# [rast] unknown extent

I need to poke a bit more, but given that it works for some file types (GDAL drivers) but not for NETCDF, it would seem that this is an issue with NETCDF (or the GDAL driver) on windows.

@kongdd
Copy link
Author

kongdd commented May 26, 2021

Thanks for your quick response. Waiting for your good news.

@kongdd kongdd closed this as completed May 26, 2021
@kongdd kongdd reopened this May 26, 2021
@rhijmans
Copy link
Member

It appears that this is indeed a NetCDF issue that has been fixed (Unidata/netcdf-c#1666) but may take a while to propagate to GDAL and NCDF4.

@kongdd
Copy link
Author

kongdd commented Nov 21, 2021

Got it. Thank u!

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

2 participants