Skip to content

Commit 3da6e8b

Browse files
included ERA5 for reading meteorogical output
Keyword: ERA5
1 parent 7db6b80 commit 3da6e8b

2 files changed

Lines changed: 154 additions & 0 deletions

File tree

lib/io/readMETncERA5.m

Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
function [alt, temp, pres, relh, wins, wind, fname] = readMETncERA5(tRange, site, folder, varargin)
2+
% readMETnccloudnet read the cloudnet ecmwf netcdf file
3+
%
4+
% EXAMPLE:
5+
% [alt, temp, pres, relh] = readMETnccloudnet(tRange, site, folder)
6+
%
7+
% INPUTS:
8+
% tRange: 2-element array
9+
% search range.
10+
% site: char
11+
% the location for gdas1. Our server will automatically produce the
12+
% gdas1 products for all our pollynet location. You can find it in
13+
% /lacroshome/cloudnet/data/model/gdas1
14+
%
15+
% KEYWORDS:
16+
% isUseLatestGDAS: logical
17+
% whether to search the latest available GDAS profile (default: false).
18+
%
19+
% OUTPUTS:
20+
% alt: array
21+
% altitute (above ground) for each range bin. [m]
22+
% temp: array
23+
% temperature for each range bin. If no valid data, NaN will be
24+
% filled. [C]
25+
% pres: array
26+
% pressure for each range bin. If no valid data, NaN will be filled.
27+
% [hPa]
28+
% rh: array
29+
% relative humidity for each range bin. If no valid data, NaN will be
30+
% filled. [%]
31+
% wins: array
32+
% wind speed [m/s]
33+
% wind: array
34+
% wind direction. [degree]
35+
% fname: char
36+
% filename (for legacy reasons the name is not changed).
37+
%
38+
% HISTORY:
39+
% - 2023-05-13.:First implementation by martin-rdz
40+
%
41+
% .. Authors: - radenz@tropos.de
42+
43+
p = inputParser;
44+
p.KeepUnmatched = true;
45+
46+
addRequired(p, 'tRange', @isnumeric);
47+
addRequired(p, 'site', @ischar);
48+
addRequired(p, 'folder', @ischar);
49+
50+
parse(p, tRange, site, folder, varargin{:});
51+
52+
midTime = mean(tRange);
53+
54+
[thisyear, thismonth, thisday, thishour, ~, ~] = datevec(midTime);
55+
% /oceanethome/model/ecmwf/profiles/ecmwf/2023/20230512_neumayer_ecmwf.nc
56+
fname = fullfile(folder, sprintf('%04d', thisyear), ...
57+
sprintf('%04d%02d%02d_%s_era5-1-12.nc', ...
58+
thisyear, thismonth, thisday, site));
59+
60+
disp(fname);
61+
62+
% preallocate
63+
alt = NaN;
64+
pres = NaN;
65+
temp = NaN;
66+
relh = NaN;
67+
uwd =NaN;
68+
vwd = NaN;
69+
wins = NaN;
70+
wind =NaN;
71+
72+
filenameList = dir(fname);
73+
if numel(filenameList) == 0
74+
fprintf('ECMWF File (%s) does not exist.\n', fname);
75+
return;
76+
end
77+
% Open the netCDF file
78+
ncid = netcdf.open(fname, 'NOWRITE');
79+
80+
81+
% Get information about the netCDF file
82+
nc_info = ncinfo(fname);
83+
% Extract the variable names
84+
var_names = {nc_info.Variables.Name};
85+
% Display the variable names
86+
%disp(var_names);
87+
88+
% Get the variable ID for the time variable and the variable of interest
89+
%time_varid = netcdf.inqVarID(ncid, 'time');
90+
%data_varid = netcdf.inqVarID(ncid, 'variable_name');
91+
92+
% Read in the time variable and the variable of interest
93+
time = ncread(fname, 'time');
94+
[~, ~, ~, hour, minute, second] = datevec(midTime);
95+
hour_fraction = hour + minute/60 + second/3600;
96+
97+
disp(hour_fraction);
98+
99+
% Find the index of the time value closest to the specified time
100+
[~, index] = min(abs(time - hour_fraction));
101+
102+
height = ncread(fname, 'height');
103+
alt = height(:, index);
104+
105+
% Extract the corresponding data
106+
data = ncread(fname, 'pressure');
107+
pres = data(:, index) ./ 100.;
108+
109+
data = ncread(fname, 'temperature');
110+
temp = data(:, index) - 273.15;
111+
112+
data = ncread(fname, 'rh');
113+
relh = data(:, index) .* 100;
114+
115+
data = ncread(fname, 'uwind');
116+
uwd = data(:, index);
117+
118+
data = ncread(fname, 'vwind');
119+
vwd = data(:, index);
120+
121+
wins = sqrt(uwd.^2 + vwd.^2);
122+
wind = atan2(vwd,uwd)*(180/pi);
123+
124+
% Close the netCDF file
125+
netcdf.close(ncid);
126+
127+
%#[pres, alt, temp, relh, wind, wins] = ceilo_bsc_ModelSonde(gdas1file);
128+
129+
%pres = NaN;
130+
%alt = NaN;
131+
%temp = NaN;
132+
%relh = NaN;
133+
%wind = NaN;
134+
%wins = NaN;
135+
136+
end

lib/io/readMeteor.m

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,24 @@
189189
attri.datetime = measTime;
190190
end
191191

192+
case 'ERA5'
193+
[alt, temp, pres, relh, wins, wind, gdas1File] = readMETncERA5(measTime, ...
194+
p.Results.gdas1Site, p.Results.meteo_folder, ...
195+
'isUseLatestGDAS', p.Results.isUseLatestGDAS);
196+
197+
if isempty(alt)
198+
alt = [];
199+
temp = [];
200+
pres = [];
201+
relh = [];
202+
wins = [];
203+
wind = [];
204+
else
205+
attri.dataSource = p.Results.meteorDataSource;
206+
attri.URL = gdas1File;
207+
attri.datetime = measTime;
208+
end
209+
192210
otherwise
193211
error('Unknown meteorological data source.\n%s\n', ...
194212
p.Results.meteorDataSource)

0 commit comments

Comments
 (0)