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

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

Closed
yfzhao-iocas opened this issue May 31, 2023 · 7 comments
Closed

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

yfzhao-iocas opened this issue May 31, 2023 · 7 comments

Comments

@yfzhao-iocas
Copy link

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
Copy link
Member

ctroupin commented May 31, 2023

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
Copy link
Author

yfzhao-iocas commented Jun 1, 2023

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
Copy link
Member

ctroupin commented Jun 1, 2023

thanks, sure I will check with your file.

@ctroupin
Copy link
Member

ctroupin commented Jun 1, 2023

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
Copy link
Author

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

@yfzhao-iocas
Copy link
Author

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

@ctroupin
Copy link
Member

ctroupin commented Jun 2, 2023

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

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