nc2tif fails: terra/Mac OS issue?
Closed this issue · 1 comments
I am attempting to query netCDF subset data for NW Wyoming and convert nc files to tif for manipulation and analysis. Here is a reproducible example:
download_daymet_ncss(location = c(44.49073, -111.0388, 42.9683, -109.7625),
start = 2020, end = 2020,
param = c("tmin", "tmax"),
frequency = "monthly",
path = tempdir())
nc2tif(path = tempdir(), overwrite = TRUE)
When I run this code on my personal machine (Mac OS 12.6.2), I get the following error message:
Error : [rast] cannot open this file as a SpatRaster: /private/var/folders/75/5_f2nf9136d7jlc_4jx157xm0000gn/T/RtmplE3WQJ/tmax_monavg_2020_ncss.nc
In addition: Warning message:
/private/var/folders/75/5_f2nf9136d7jlc_4jx157xm0000gn/T/RtmplE3WQJ/tmax_monavg_2020_ncss.nc' not recognized as a supported file format. (GDAL error 4)
Conversion error...corrupt file?
Error : [rast] cannot open this file as a SpatRaster: /private/var/folders/75/5_f2nf9136d7jlc_4jx157xm0000gn/T/RtmplE3WQJ/tmin_monavg_2020_ncss.nc
In addition: Warning message:
/private/var/folders/75/5_f2nf9136d7jlc_4jx157xm0000gn/T/RtmplE3WQJ/tmin_monavg_2020_ncss.nc' not recognized as a supported file format. (GDAL error 4)
Conversion error...corrupt file?
Terra has known compatibility issues with Mac OS, particularly with respect to netCDF, as documented here. Following the advice in the link, I installed the development version of terra, but still received the same error message when running the nc2tif() function. To see if I could work around this, I tried running the code on a Windows 10 machine. The code ran without error.
Is this an issue the Daymetr developers are aware of? Ideally, all my data processing would be done locally on my Mac OS machine. Is there any way to work around terra, within daymetr, without splitting my workflow across two separate machines?
Thank you and I greatly appreciate any advice.
Package and dependencies info (versions are identical across platforms): daymetr (1.7), sf (1.0-12), terra (1.7-35), ncdf4 (1.21), tidyr (1.3.0), tibble (3.2.0).
Hi,
(sorry for the late reply, summer and all)
First and foremost check if the files are ok. Use GDAL on the command line to check this out. If the files are corrupt this might be a cause for issues.
Furthermore, I test my code using CI and macOS tests seem to pass.
https://github.com/bluegreen-labs/daymetr/actions/runs/4907133735/job/13293696660
So this might be a very system specific thing! GDAL and terra by extension have always been fickle on mac. I'm afraid that providing custom support on this matters is difficult if no more information is provided. The problem with a lot of these issues is that I can't recreate them for debugging (given to their idiosyncratic nature).
Sorry that I can't provide much more help.
K