Closed Balinus closed 1 year ago
When you specify your outdims as longitude and latitude it takes the axes from the input cube. You would have to constrict new lat and Lon axes with the values from coords.
Oh, I see! Not sure how I should constrict the new lat and lon axes with this mapCube approach? Is there a way to pass the second cube and to link the lat-lon axes from this second cube? (the cube named dest
in this case).
Cheers!
If you do
outdims = OutDims(axlist)
with the axlist that you use to define the dest cube than this should work.
Great! I will test later today. Cheers!
It worked, thanks! Here's the code in case it interest someone. Lots of reverse
, but Interpolations only accept ascending index order.
function regrid_cube(xout, xin; xg1, yg1, coords)
# Interpolation struct
itp = interpolate((xg1,yg1), reverse(xin, dims=1), Gridded(Linear()))
etpf = extrapolate(itp, Flat())
return xout .= reverse((c->etpf(c...)).(coords), dims=1)
end
"""
regrid_cube(cube::YAXArray, dest::YAXArray)
Regrid des données de cube (prévisions saisonnières) vers grille dest (ERA5)
"""
function regrid_cube(source::YAXArray, dest::YAXArray)
# subset "hardcodé" pour éviter effet de bords
source_spatial = source[longitude = minimum(dest.longitude)..maximum(dest.longitude), latitude=minimum(dest.latitude)..maximum(dest.latitude)]
dest_spatial = dest[longitude = minimum(source_spatial.longitude)..maximum(source_spatial.longitude), latitude=minimum(source_spatial.latitude)..maximum(source_spatial.latitude)]
# Grille source
xg1,yg1 = collect(source_spatial.longitude), reverse(collect(source_spatial.latitude))
# Grille destination
xg2,yg2 = collect(dest_spatial.longitude), reverse(collect(dest_spatial.latitude))
coords = Iterators.product(xg2,yg2)
# Dimensions
indims = InDims("longitude","latitude")
outdims = OutDims(RangeAxis("longitude", xg2), RangeAxis("latitude", reverse(yg2)))
mapCube(regrid_cube, source_spatial; xg1=xg1, yg1=yg1, coords=coords, indims=indims, outdims=outdims)
end
Hello!
I am trying to understand the following behaviour. I am regridding a Cube onto new coordinates (coords taken from another Cube). When I developed the code outside of the mapCube feature, the resulting dimensions are coherent with the expected sizes. When I transfered the code to use it as mapCube approach, I do not get the same dimensions sizes. I'm sure it's trivial and possibly made an error somewhere, but I can't see it!
Here's a MWE mimicking an interpolation for a single raster.
Now, here's the example using Cubes
Functions
Cubes
Regrid