Rasters.jl icon indicating copy to clipboard operation
Rasters.jl copied to clipboard

Using `~` for homedir does not work on MacOS

Open asinghvi17 opened this issue 7 months ago • 5 comments

                             ⊼                                ⊽
julia> r1 = Raster("~/Downloads/N320_weights.nc")
ERROR: ArgumentError: file "~/Downloads/N320_weights.nc" not found
Stacktrace:
 [1] _filenotfound_error(filename::String)
   @ Rasters ~/.julia/dev/geo/Rasters.jl/src/utils.jl:531
 [2] checkfilename(::Rasters.NCDsource, filename::String)
   @ RastersNCDatasetsExt ~/.julia/dev/geo/Rasters.jl/ext/RastersNCDatasetsExt/ncdatasets_source.jl:4
 [3] #_open#1
   @ ~/.julia/dev/geo/Rasters.jl/ext/RastersNCDatasetsExt/ncdatasets_source.jl:10 [inlined]
 [4] _open
   @ ~/.julia/dev/geo/Rasters.jl/ext/RastersNCDatasetsExt/ncdatasets_source.jl:9 [inlined]
 [5] #_open#26
   @ ~/.julia/dev/geo/Rasters.jl/src/sources/sources.jl:110 [inlined]
 [6] Raster(filename::String; source::Rasters.NoKW, kw::@Kwargs{})
   @ Rasters ~/.julia/dev/geo/Rasters.jl/src/array.jl:327
 [7] Raster(filename::String)
   @ Rasters ~/.julia/dev/geo/Rasters.jl/src/array.jl:325
 [8] top-level scope
   @ REPL[3]:1
julia> r1 = Raster("/Users/anshul/Downloads/N320_weights.nc")
# runs

I think we need a abspath(expanduser(path)) somewhere, at least for local files...

asinghvi17 avatar May 10 '25 19:05 asinghvi17

Is this the same also for other file types?

felixcremer avatar May 11 '25 02:05 felixcremer

Same for GDALsource on that file

julia> Raster("~/Downloads/N320_weights.nc"; source = Rasters.GDALsource())
ERROR: ArgumentError: file "~/Downloads/N320_weights.nc" not found
Stacktrace:
 [1] _filenotfound_error(filename::String)
   @ Rasters ~/.julia/dev/geo/Rasters.jl/src/utils.jl:531
 [2] _open(f::Rasters.var"#78#79"{Rasters.GDALsource, @Kwargs{}, String}, ::Rasters.GDALsource, filename::String; write::Bool, mod::Nothing, kw::@Kwargs{})
   @ RastersArchGDALExt ~/.julia/dev/geo/Rasters.jl/ext/RastersArchGDALExt/gdal_source.jl:114
 [3] _open
   @ ~/.julia/dev/geo/Rasters.jl/ext/RastersArchGDALExt/gdal_source.jl:98 [inlined]
 [4] #_open#26
   @ ~/.julia/dev/geo/Rasters.jl/src/sources/sources.jl:110 [inlined]
 [5] _open
   @ ~/.julia/dev/geo/Rasters.jl/src/sources/sources.jl:109 [inlined]
 [6] #Raster#77
   @ ~/.julia/dev/geo/Rasters.jl/src/array.jl:327 [inlined]
 [7] top-level scope
   @ REPL[10]:1

If I call expanduser on the string first, it works in both cases.

asinghvi17 avatar May 11 '25 02:05 asinghvi17

Lets add abspath(expanduser(path)) then. Probably we need a better path handler function

rafaqz avatar May 11 '25 12:05 rafaqz

Well we have to handle urls, http, etc too

asinghvi17 avatar May 11 '25 13:05 asinghvi17

Yeah, probably why it doesn't work yet!

rafaqz avatar May 11 '25 13:05 rafaqz