Troubles interpolating from nc files

4 vues (au cours des 30 derniers jours)
Mar
Mar le 13 Mai 2020
Commenté : Walter Roberson le 15 Mai 2020
Hello!
I am working with data from ERA-5, my nc file (uploaded in the link) contains information about 4 variables, i need this information in some specific coordinates, different of the available in the nc file, so i am trying to interpolate.
%%%coordinates of interest
lati = 21.44;
loni = -89.66;
%read the nc
Hs = ncread('OLEAJE-1979-1988.nc','swh');
lat = ncread('OLEAJE-1979-1988.nc','latitude');
lon = ncread('OLEAJE-1979-1988.nc','longitude');
[latgrid,longrid] = meshgrid(lat,lon);
interp2(latgrid,longrid,Hs,lati,loni)
with this i get an error message
Error using .'
Transpose on ND array is not defined. Use PERMUTE instead.
Error in interp2 (line 132)
V = V.';
I look to permute function but what i understand is that as squeeze when you rearrange you select only a portion of your data and i need it all.
When i sqeeze my variable before interp2 it works but this way I loose the dimension corresponding to time and i need it.
Any help is appreciated

Réponse acceptée

Walter Roberson
Walter Roberson le 13 Mai 2020
[G{1:3}] = ndgrid(double(lon),double(lat),1:size(Hs,3));
[P{1:3}] = ndgrid(loni,lati,1:size(Hs,3));
results = reshape(interpn(G{:},Hs,P{:}), 1, 1, []);
However you will find that the result is all nan.
Each of your layers has a shape like
0.751128593077692 0.654874720996251 0.545312003473382
0.712546384575774 0.545984167384565 0.376598861766387
0.695742286796193 0.459543888406399 NaN
0.699775270263292 0.420289515993297 NaN
0.71671380082511 0.413030145752519 NaN
0.742121596667837 0.333311505886186 NaN
0.781644834645412 0.362617852413774 NaN
0.835149081975598 0.379825248540066 NaN
0.90129001083603 0.577307005645704 NaN
and the query point is near and slightly to the right of the middle of the 4th row, so there is the NaN being blended in, giving a NaN result.
  2 commentaires
Mar
Mar le 15 Mai 2020
Hi Walter, thanks for your time and your answer, in fact i have nan values corresponding to land coordinates (and all my variables are oceanographic) so now, im discarding the coordinates that take place in land, but now my point is outside the domain of the previous defined grid, then what i really need is an extrapolation, i have read in the interpn documentation that extrapval only assign one scalar value to the querry points that are outside the domain and i need to calculate the values in that points, is there any other option?
Thank you so much!
Walter Roberson
Walter Roberson le 15 Mai 2020
What is the model for interpolation? As outsiders, we have no reason to know that the water does not end 2 inches to the right of the readings in the file, and we do not have enough domain knowledge to know whether the shores are shallow angle or steep in that area.
You can fillmissing() the area. In my tests, using 'linear' or 'spline' or 'makima' made a difference only at noise level (1e-16). But those are already doing interpolation and then you would be wanting to do more interpolation to get the values at particular points, and it is not clear that interpolation on top of interpolation is going to give you meaningful results.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by