Skip to content

Commit

Permalink
Fixed bug in ERA5Offline in dwind
Browse files Browse the repository at this point in the history
  • Loading branch information
e5k committed Jan 19, 2022
1 parent d1b8e55 commit d226669
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 15 deletions.
Binary file modified CODE/VAR/prefs.mat
Binary file not shown.
2 changes: 1 addition & 1 deletion CODE/dependencies/plot_google_map.m
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@
'Matlab error was: %s\n\n' ...
'Possible reasons: missing write permissions, no network connection, quota exceeded, or some other error.\n' ...
'Consider using an API key if quota problems persist.\n\n' ...
'To debug, try pasting the following URL in your browser, which may result in a more informative error:\n%s']);
'To debug, try pasting the following URL in your browser, which may result in a more informative error:\n%s'], lasterr, url);
varargout{1} = [];
varargout{2} = [];
varargout{3} = [];
Expand Down
5 changes: 3 additions & 2 deletions CODE/dwind/dwind.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function dwind(varargin)
%
% Optional arguments:
% 'intMeth' : Interpolation method, accepts 'Linear' (default), 'Nearest', 'Pchip', 'Cubic', 'Spline'
% 'intExt' : Number of cells (±x, ±y) around vent used for interpolation (default: 2)
% 'intExt' : Number of cells (x, y) around vent used for interpolation (default: 2)
% 'outDir' : Output folder (default = windName)

if nargin==0
Expand Down Expand Up @@ -526,6 +526,7 @@ function download(wind)
fprintf('Select folder containing the ERA-Interim .nc files\n');
wind.ncDir = uigetdir( ...
'Select folder containing the ERA-Interim .nc files');

end

save(fullfile(wind.folder, 'wind.mat'),'wind')
Expand Down Expand Up @@ -564,7 +565,7 @@ function download(wind)
delete('download_ECMWF.py');

% Offline mode
elseif strcmp(wind.db, 'InterimOff')
elseif strcmp(wind.db, 'InterimOff') || strcmp(wind.db, 'ERA5Off')

%% NOAA
else
Expand Down
38 changes: 26 additions & 12 deletions CODE/dwind/process_wind.m
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,8 @@ function process_wind(varargin)


% Case ECMWF ERA-Interim Offline
elseif strcmp(wind.db, 'InterimOff')
in_path = wind.ncDir;
elseif strcmp(wind.db, 'InterimOff') || strcmp(wind.db, 'ERA5Off')
in_path = wind.ncDir;
fl = dir(fullfile(in_path, '*.nc'));
stor = struct;

Expand All @@ -141,17 +141,22 @@ function process_wind(varargin)

% Find vent coordinates
if i==1
latI(1) = find(stor(i).LAT == wind.lat_min);
latI(2) = find(stor(i).LAT == wind.lat_max);
latI = fliplr(latI);
lonI(1) = find(stor(i).LON == wind.lon_min);
lonI(2) = find(stor(i).LON == wind.lon_max);
if length(stor(i).LAT) == 1 || length(stor(i).LON) == 1
latI = stor(i).LAT;
lonI = stor(i).LON;
else
latI(1) = find(stor(i).LAT == wind.lat_min);
latI(2) = find(stor(i).LAT == wind.lat_max);
latI = fliplr(latI);
lonI(1) = find(stor(i).LON == wind.lon_min);
lonI(2) = find(stor(i).LON == wind.lon_max);
end
end

stor(i).HGT = ncread(fullfile(in_path, fl(i).name), 'z')/9.80665;
stor(i).UWND = ncread(fullfile(in_path, fl(i).name), 'u');
stor(i).VWND = ncread(fullfile(in_path, fl(i).name), 'v');
stor(i).time = double(ncread(fullfile(in_path, fl(i).name), 'time'))/24 + datenum(1900,1,1,0,0,0);
stor(i).time = double(ncread(fullfile(in_path, fl(i).name), 'time'))/24 + datenum(1900,1,1,0,0,0);
end

% Do some tests to see if the timestamp is correct
Expand Down Expand Up @@ -187,11 +192,18 @@ function process_wind(varargin)
fprintf('\tInterpolating and writing ascii files, please wait...\n')
for iT = 1:size(UWND,4) % Loop through time
for iL = 1:size(UWND,3) % Loop through levels
% No interpolation
if length(stor(i).LAT) == 1 || length(stor(i).LON) == 1
u = UWND(1,1,iL,iT);
v = VWND(1,1,iL,iT);
z = HGT(1,1,iL,iT);
else
% Interpolate to vent coordinates
u = intVent(UWND, stor(i).LON, stor(i).LAT, latI, lonI, wind, iL, iT);
v = intVent(VWND, stor(i).LON, stor(i).LAT, latI, lonI, wind, iL, iT);
z = intVent(HGT, stor(i).LON, stor(i).LAT, latI, lonI, wind, iL, iT);

u = intVent(UWND, stor(i).LON, stor(i).LAT, latI, lonI, wind, iL, iT);
v = intVent(VWND, stor(i).LON, stor(i).LAT, latI, lonI, wind, iL, iT);
z = intVent(HGT, stor(i).LON, stor(i).LAT, latI, lonI, wind, iL, iT);
end

speed = sqrt(u.^2+v.^2); % Wind speed
angle = atan2d(u,v); % Wind direction
angle(angle<0) = 360+angle(angle<0); % Get rid of negative value
Expand Down Expand Up @@ -226,6 +238,8 @@ function process_wind(varargin)
fprintf('\tInterpolating and writing ascii files, please wait...\n')
for iT = 1:size(UWND,4) % Loop through time
for iL = 1:size(UWND,3) % Loop through levels


% Interpolate to vent coordinates
u = intVent(UWND, LON, LAT, [1, length(LAT)], [1, length(LON)], wind, iL, iT);
v = intVent(VWND, LON, LAT, [1, length(LAT)], [1, length(LON)], wind, iL, iT);
Expand Down
Binary file removed test/wind.mat
Binary file not shown.

0 comments on commit d226669

Please sign in to comment.