gher-uliege / DIVAnd.jl

DIVAnd performs an n-dimensional variational analysis of arbitrarily located observations
GNU General Public License v2.0
70 stars 11 forks source link

[Help needed]How to create and use my bathymetry file? #131

Closed yfzhao-iocas closed 1 year ago

yfzhao-iocas commented 1 year ago

hi, When using my bathymetry file, the following error occurred: bx,by,b = load_bath(bathname,false,lonr,latr);

ArgumentError: range must be non-empty Stacktrace: [1] minimum(r::UnitRange{Int64}) @ Base .\range.jl:617 [2] (::DIVAnd.var"#405#406"{String, Bool, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, Float64, Float64})(nc::NCDataset{Nothing}) @ DIVAnd C:\Users\Admin.julia\packages\DIVAnd\MV3j9\src\load_mask.jl:98 [3] NCDataset(f::DIVAnd.var"#405#406"{String, Bool, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, Float64, Float64}, args::String; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}}) @ NCDatasets C:\Users\Admin.julia\packages\NCDatasets\fy34h\src\dataset.jl:255 [4] NCDataset @ C:\Users\Admin.julia\packages\NCDatasets\fy34h\src\dataset.jl:253 [inlined] [5] extract_bath @ C:\Users\Admin.julia\packages\DIVAnd\MV3j9\src\load_mask.jl:58 [inlined] [6] load_bath(bath_name::String, isglobal::Bool, xi::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, yi::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}) @ DIVAnd C:\Users\Admin.julia\packages\DIVAnd\MV3j9\src\load_mask.jl:120 [7] top-level scope @ .\timing.jl:210 [inlined] [8] top-level scope @ .\In[72]:0

I created my bathymetry file using the ArcGIS tool 'Raster to NetCDF'. How can I solve this problem? What should be noted when I creat bathymetry NetCDF files?

ctroupin commented 1 year ago

hello, here is the link to a bathymetry in netCDF which works with DIVAnd, so you know how the netCDF should look like. https://dox.ulg.ac.be/index.php/s/U0pqyXhcQrXjEUX/download

Also in the code there is an example of the output of ncdump -h:

netcdf gebco_30sec_8 {
dimensions:
     lat = 2702 ;
     lon = 5400 ;
variables:
     double lat(lat) ;
          lat:long_name = "Latitude" ;
          lat:standard_name = "latitude" ;
          lat:units = "degrees_north" ;
     double lon(lon) ;
          lon:long_name = "Longitude" ;
          lon:standard_name = "longitude" ;
          lon:units = "degrees_east" ;
     float bat(lat, lon) ;
          bat:long_name = "elevation above sea level" ;
          bat:standard_name = "height" ;
          bat:units = "meters" ;

// global attributes:
          :title = "GEBCO" ;
}
yfzhao-iocas commented 1 year ago

HI@ctroupin thanks for your information. According to file "gebco_30sec_16.nc", I edited my file with python NetCDF package, a new error occurred:

DimensionMismatch("tried to assign 1556×1371 array to 1586×1371 destination")

Stacktrace:
  [1] throw_setindex_mismatch(X::Matrix{Float32}, I::Tuple{Int64, Int64})
    @ Base .\indices.jl:193
  [2] setindex_shape_check
    @ .\indices.jl:253 [inlined]
  [3] _unsafe_setindex!(::IndexLinear, ::Matrix{Float64}, ::Matrix{Float32}, ::Base.Slice{Base.OneTo{Int64}}, ::Base.Slice{Base.OneTo{Int64}})
    @ Base .\multidimensional.jl:902
  [4] _setindex!
    @ .\multidimensional.jl:893 [inlined]
  [5] setindex!(::Matrix{Float64}, ::Matrix{Float32}, ::Function, ::Function)
    @ Base .\abstractarray.jl:1267
  [6] (::DIVAnd.var"#405#406"{String, Bool, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, Float64, Float64})(nc::NCDataset{Nothing})
    @ DIVAnd C:\Users\Admin\.julia\packages\DIVAnd\MV3j9\src\load_mask.jl:99
  [7] NCDataset(f::DIVAnd.var"#405#406"{String, Bool, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, Float64, Float64}, args::String; kwargs::Base.Iterators.Pairs{Union{}, Union{}, Tuple{}, NamedTuple{(), Tuple{}}})
    @ NCDatasets C:\Users\Admin\.julia\packages\NCDatasets\fy34h\src\dataset.jl:255
  [8] NCDataset
    @ C:\Users\Admin\.julia\packages\NCDatasets\fy34h\src\dataset.jl:253 [inlined]
  [9] extract_bath
    @ C:\Users\Admin\.julia\packages\DIVAnd\MV3j9\src\load_mask.jl:58 [inlined]
 [10] load_bath(bath_name::String, isglobal::Bool, xi::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}}, yi::StepRangeLen{Float64, Base.TwicePrecision{Float64}, Base.TwicePrecision{Float64}})
    @ DIVAnd C:\Users\Admin\.julia\packages\DIVAnd\MV3j9\src\load_mask.jl:120
 [11] top-level scope
    @ .\timing.jl:210 [inlined]
 [12] top-level scope
    @ .\In[15]:0

I upload my bathymetry file, Can you take a look? gebco_2023new.zip netcdf gebco_2023new { dimensions: 0: lat = 1371 ; 1: lon = 1556 ; variables: 0: double lat(lat) ; lat:long_name = "Latitude" ; lat:standard_name = "latitude" ; lat:units = "degrees_north" ; 1: double lon(lon) ; lon:long_name = "Longitude" ; lon:standard_name = "longitude" ; lon:units = "degrees_east" ; 2: double bat(lat, lon) ; bat:long_name = "elevation above sea level" ; bat:standard_name = "height" ; bat:units = "meters" ; }

ctroupin commented 1 year ago

thanks, sure I will check with your file.

ctroupin commented 1 year ago

I've run this code with your bathymetry:

dx = dy = 0.125
lonr = 120:dx:125.
latr = 31.:dy:36.2
bx,by,b = DIVAnd.load_bath(datafile,false,lonr,latr)

and it works without error, hence my question:

what values do you use for lonr and latr?

yfzhao-iocas commented 1 year ago

I don't know why, but it works with any dx value. thanks again for all your help.

yfzhao-iocas commented 1 year ago

My Python code for editing a bathymetry file. netCDF_edit_bathymetry.zip

ctroupin commented 1 year ago

Thanks, glad to know it now works. And thanks for the code.