2 % TS_AT_TEST tests the TS_AT interpolation function.
4 % This function generates a synthetic dataset of variable values defined
5 % on a grid with random perturbations of coordinates
6 % and verifies the TS_AT function by checking if the interpolation
7 % at random points preserves linear functions
17 % Generate xlon and xlat as uniform with random perturbations
18 xlon = repmat(linspace(-180, 180, 100), [100, 1]) + rand(100) - 0.5;
19 xlat = repmat(linspace(-90, 90, 100)', [1, 100]) + rand(100) - 0.5;
21 % Define v as a linear function a*xlon + b*xlat
25 v = repmat(v, [1, 1, 10]); % Repeat the same pattern for 10 time steps
27 % Verify that ts_at returns a*lon + b*lat for several random (lon, lat)
29 lon = rand()*360 - 180; % Random longitude between -180 and 180
30 lat = rand()*180 - 90; % Random latitude between -90 and 90
31 ts = ts_at(lon, lat, xlon, xlat, v);
32 expected_ts = a*lon + b*lat;
33 err=abs(ts - expected_ts)
34 assert(all(abs(err) < 1e-5), 'Test failed!');
37 disp('All tests passed.');