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

Problem with mat2grid #731

Closed
amarux opened this issue Oct 26, 2021 · 9 comments
Closed

Problem with mat2grid #731

amarux opened this issue Oct 26, 2021 · 9 comments

Comments

@amarux
Copy link

amarux commented Oct 26, 2021

Hi.

I am having some troubles to use mat2grid in GMT.jl 0.38.0.
My dataset is a cube read from a NetCDF with NCDatasets in the following way:

using GMT, NCDatasets

ifile = "SLA_AVISO_L4REP_PACIFIC_2014010120190513.nc"
ds = NCDataset(ifile)

sla = coalesce.(ds["sla"][:, :, 1], NaN)      # Dimensions (lon, lat, time). 
lat = ds["latitude"][:]
lon = ds["longitude"][:]

The sizes and type of the objects are:
sla => 681×132 Matrix{Float64}
lon => 681-element Vector{Float32}
lat => 132-element Vector{Float32}

I am trying to convert my data to a GMTgrid using:

grd = mat2grid(sla; x=lon, y=lat)

However I got the following error:

ERROR: size of x,y vectors incompatible with 2D array size
Stacktrace:
 [1] error(s::String)
   @ Base ./error.jl:33
 [2] grdimg_hdr_xy(mat::Matrix{Float64}, reg::Int64, hdr::Nothing, x::Vector{Float32}, y::Vector{Float32})
   @ GMT ~/.julia/packages/GMT/TPV4a/src/utils_types.jl:684
 [3] mat2grid(mat::Matrix{Float64}, xx::Vector{Float64}, yy::Vector{Float64}; reg::Nothing, x::Vector{Float32}, y::Vector{Float32}, v::Vector{Float64}, hdr::Nothing, proj4::String, wkt::String, epsg::Int64, tit::String, rem::String, cmd::String, names::Vector{String}, scale::Float32, offset::Float32)
   @ GMT ~/.julia/packages/GMT/TPV4a/src/utils_types.jl:611
 [4] top-level scope
   @ none:1

I also tried using the transpose of sla mat2grid(sla'; x=lon, y=lat) but it doesn't work
What I am doing wrong?

@joa-quim
Copy link
Member

OK, I need to improve the documentation of mat2grid. It requires that the x and y vectors are Float64 and not Float32 (this should be acceptable as well, another thing to change). Try converting them to Float64, thought the error seems to point into another direction.

But perhaps even better (though please try the above), just try

cube = gdaltranslate("SLA_AVISO_L4REP_PACIFIC_2014010120190513.nc");

@amarux
Copy link
Author

amarux commented Oct 27, 2021

Thank you for answering so fast!

I tried using the gdaltranslate function, but it doesn't work.
I got:

ERROR: UndefVarError: sds_name not defined
Stacktrace:
 [1] gd2gmt_helper(input::GMT.Gdal.IDataset, sds::Int64)
   @ GMT ~/.julia/packages/GMT/TPV4a/src/gdal_utils.jl:144
 [2] gd2gmt(_dataset::GMT.Gdal.IDataset; band::Int64, bands::Vector{Int64}, sds::Int64, pad::Int64, layout::String)
   @ GMT ~/.julia/packages/GMT/TPV4a/src/gdal_utils.jl:26
 [3] helper_run_GDAL_fun(::Function, ::String, ::String, ::Vector{String}, ::String)
   @ GMT.Gdal ~/.julia/packages/GMT/TPV4a/src/gdal_tools.jl:147
 [4] #gdaltranslate#106
   @ ~/.julia/packages/GMT/TPV4a/src/gdal_tools.jl:24 [inlined]
 [5] gdaltranslate (repeats 2 times)
   @ ~/.julia/packages/GMT/TPV4a/src/gdal_tools.jl:24 [inlined]
 [6] top-level scope
   @ none:1

I found an alternative to solve the issue. The first step was converting the vectors from Float32 to Float64,as you reccomended. Then, I used the transpose of the matrix using the following syntax:

mat2grid(sla'[:, :]; x=lon, y=lat)

Using mat2grid(sla'; x=lon, y=lat) doesn't work. I think it is realted to the data type used by Julia (v1.6.3) for the transpose. The data type of sla' is 132×681 adjoint(::Matrix{Float64}) with eltype Float64.

Maybe the problem is related to the compatibility with the Julia version.

Thank you so much @joa-quim !

@joa-quim
Copy link
Member

No, it's not a Julia version issue for sure but cubes are a bit harder to deal with. If you can make one those files available I can have a look into make the access easier.

And this is for sure a GMT.jl bug

ERROR: UndefVarError: sds_name not defined
Stacktrace:
 [1] gd2gmt_helper(input::GMT.Gdal.IDataset, sds::Int64)
   @ GMT ~/.julia/packages/GMT/TPV4a/src/gdal_utils.jl:144

@amarux
Copy link
Author

amarux commented Oct 27, 2021

Sure! I never had sent a file before. The files I have are .nc above 700 MB what is the best way to send them? email?

@joa-quim
Copy link
Member

Ups, 700 MB it's too big for mail. Any place where I can download one of them?

@amarux
Copy link
Author

amarux commented Oct 27, 2021

Yes! The data I used are Sea Surface Heights gathered from the Copernicus Marine Service.
You can find them here https://resources.marine.copernicus.eu/product-detail/SEALEVEL_GLO_PHY_L4_REP_OBSERVATIONS_008_047/INFORMATION

Thanks a lot!!

@joa-quim
Copy link
Member

Thanks, will try to look tomorrow.

@joa-quim
Copy link
Member

Sorry, tried but don't have the days that are needed to navigate in those horrible copernicus pages that only show dozens of links that point to other pages with dozens of links and no damn data.

But I was being particularly dumb yesterday, You can read any level with (level 11 in the example below)

G = gmtread("SLA_AVISO_L4REP_PACIFIC_2014010120190513.nc?[10]")

See
https://docs.generic-mapping-tools.org/dev/cookbook/features.html#modifiers-for-cf

@amarux
Copy link
Author

amarux commented Oct 29, 2021

Thank you! I used gmtread and it works smoothly

@joa-quim joa-quim closed this as completed Nov 6, 2021
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