フィルターのクリア

Speeding up interpolation with scattered interpolation

28 ビュー (過去 30 日間)
daniel
daniel 2023 年 12 月 9 日
コメント済み: daniel 2023 年 12 月 10 日
Hi,
I've been working on speeding up my code for a project and I've identified that I'm spending a lot of time interpolating my data. I have data for wind speeds, air temperature, pressure and a few other things that depend on position in the X,Y and Z directions. I've been using ScatteredInterpolation to interpolate across 1425 data points and then using the interpolant find the wind speeds, air temperature, pressure etc. at a specific position. I was wondering if there was a faster way to do this, either speeding up scatteredinterpolation or a different interpolating method. Am fairly new to MATLAB so help appreciated.
Thanks.
  4 件のコメント
daniel
daniel 2023 年 12 月 10 日
The whole code is very long, slighly messy and would be a pain to share on here. If its possible not to share the whole thing I'd rather do that if thats okay. Ive attached below the sections of code for the interpolation.
The Atmospheric data arrays contain data from the GFS weather model, more specifically they contain Temperature, Pressure, Air Density, Eastwards windspeed, northwards windspeed and vertical windspeed at a range of points.
The points are spaced every 0.25 lat and long and there is data for 57 different altitudes.
When I am interpolating I'm interpolating across a 5 latitudes and 5 longitudes and all altitudes.
AtmosphericDataPrevious = G.AtmosphericDataPrevious;
AtmosphericDataCurrent = G.AtmosphericDataCurrent;
AtmosphericDataNext = G.AtmosphericDataNext;
PreviousForecastTime = str2double(G.PreviousForecastTime);
CurrentForecastTime = str2double(G.CurrentForecastTime);
NextForecastTime = str2double(G.NextForecastTime);
AltitudeData = reshape(AtmosphericDataCurrent(LowerLatLocation:UpperLatLocation,LeftLonLocation:RightLonLocation,:,1),[1425,1]);
LatData0 = LowerLat:0.25:UpperLat;
LatData1 = repmat(LatData0,[5,1,57]);
LatData = reshape(LatData1,[1425,1]);
LonData0 = LeftLon:RightLon;
LonData1 = reshape(LonData0,[5,1]);
LonData2 = repmat(LonData1,[1,5,57]);
LonData = reshape(LonData2,[1425,1]);
%previous data
TemperatureArrayPrevious = reshape(AtmosphericDataPrevious(LowerLatLocation:UpperLatLocation,LeftLonLocation:RightLonLocation,:,4),[1425,1]);
TemperaturePrevious0 = scatteredInterpolant(LatData,LonData,AltitudeData,TemperatureArrayPrevious,"natural");
DensityArrayPrevious = reshape(AtmosphericDataPrevious(LowerLatLocation:UpperLatLocation,LeftLonLocation:RightLonLocation,:,3),[1425,1]);
DensityPrevious0 = scatteredInterpolant(LatData,LonData,AltitudeData,DensityArrayPrevious,"natural");
PressureArrayPrevious = reshape(AtmosphericDataPrevious(LowerLatLocation:UpperLatLocation,LeftLonLocation:RightLonLocation,:,2),[1425,1]);
PressurePrevious0 = scatteredInterpolant(LatData,LonData,AltitudeData,PressureArrayPrevious,"natural");
VerticalWindVelocityArrayPrevious = reshape(AtmosphericDataPrevious(LowerLatLocation:UpperLatLocation,LeftLonLocation:RightLonLocation,:,5),[1425,1]);
VerticalWindVelocityPrevious0 = scatteredInterpolant(LatData,LonData,AltitudeData,VerticalWindVelocityArrayPrevious,"natural");
EastwardsWindVelocityArrayPrevious = reshape(AtmosphericDataPrevious(LowerLatLocation:UpperLatLocation,LeftLonLocation:RightLonLocation,:,6),[1425,1]);
EastwardsWindVelocityPrevious0 = scatteredInterpolant(LatData,LonData,AltitudeData,EastwardsWindVelocityArrayPrevious,"natural");
NorthwardsWindVelocityArrayPrevious = reshape(AtmosphericDataPrevious(LowerLatLocation:UpperLatLocation,LeftLonLocation:RightLonLocation,:,7),[1425,1]);
NorthwardsWindVelocityPrevious0 = scatteredInterpolant(LatData,LonData,AltitudeData,NorthwardsWindVelocityArrayPrevious,"natural");
TemperaturePrevious = TemperaturePrevious0(CurrentLatitude,CurrentLongitude,CurrentAltitude);%Temperature at altitude (K)
DensityPrevious = DensityPrevious0(CurrentLatitude,CurrentLongitude,CurrentAltitude);%Air density at altitude (Kg/m^3)
PressurePrevious = PressurePrevious0(CurrentLatitude,CurrentLongitude,CurrentAltitude); %Pressure at altitude (Pa)
VerticalWindVelocityPrevious = VerticalWindVelocityPrevious0(CurrentLatitude,CurrentLongitude,CurrentAltitude); %Vertical wind-velocity (m/s)
EastwardsWindVelocityPrevious = EastwardsWindVelocityPrevious0(CurrentLatitude,CurrentLongitude,CurrentAltitude);%Eastwards wind-velocity (m/s)
NorthwardsWindVelocityPrevious = NorthwardsWindVelocityPrevious0(CurrentLatitude,CurrentLongitude,CurrentAltitude); %Northwards wind-velocity (m/s)
Once I've interpolated im using the interpolant to find the atmospheric properties at a given point.
Torsten
Torsten 2023 年 12 月 10 日
The points are spaced every 0.25 lat and long and there is data for 57 different altitudes.
If this is the case, why don't you use GriddedInterpolant instead of ScatteredInterpolant ? The interpolation afterwards will be much faster.

サインインしてコメントする。

採用された回答

Matt J
Matt J 2023 年 12 月 10 日
編集済み: Matt J 2023 年 12 月 10 日
Your data is gridded, so you should be using griddedInterpolant, as opposed to scatteredInterpolant. Gridded interpolation is much faster than scattered interpolation.
TemperaturePrevious0 = griddedInterpolant( {LatData0,LonData0,AltitudeData0}, TemperatureArrayPrevious)
Also...
Once I've interpolated im using the interpolant to find the atmospheric properties at a given point.
...you should not interpolate one point at a time. You should supply a vector of query points and interpolate them in a single call.
  4 件のコメント
Matt J
Matt J 2023 年 12 月 10 日
I've tried the above code but i keep getting the following error:
It means one of the coordinates you are interpolating (Lat, Lon, Altitude) has less than two sample points.
daniel
daniel 2023 年 12 月 10 日
I've got it sorted now, thank you very much for your help. sorry if my lack of knowledge was frustrating.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

タグ

製品


リリース

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by