Skip to content
Snippets Groups Projects
Commit 32696848 authored by pierre.rousselot_ird.fr's avatar pierre.rousselot_ird.fr
Browse files

New interpolation grid if downward adcp & add specific script

parent 787f8ba0
No related branches found
No related tags found
No related merge requests found
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Merge subsurface ADCP mooring data %
% Autor: P. Rousselot / Date: 03/2020 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; close all;
%% Variables
FileToMerge1 = 'F:\Encours\PIRATA_ADCP-MOORINGS\Convert_ADCP/ADCP_23W0N_2001_2015.nc'; %.nc file to merge with
FileToMerge2 = 'F:\Encours\PIRATA_ADCP-MOORINGS\23W\0_Final_Files/ADCP_0N23W_2015_2016_1d_up_down.nc'; %.nc file to merge
% FileToMerge3 = '/media/irdcampagnes/PIRATA/PIRATA_ADCP-MOORINGS/10W/0_Final_Files/ADCP_10W0N_2004_2005_1d.nc'; %.nc file to merge
% FileToMerge1 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX/ADCP_0N130E_2013_2013_1d.nc'; %.nc file to merge with
% FileToMerge2 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX/ADCP_0N130E_2013_2016_1d.nc'; %.nc file to merge
step_subsampling = 1; % 1=daily
plot_data = 1;
mooring.name = '23W0N';
freq = 'Variable';
% mooring.name = '0N130E';
% freq = '75';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Read first .nc file
ncfile1.time = ncread(FileToMerge1,'TIME');
ncfile1.depth = ncread(FileToMerge1,'DEPTH');
ncfile1.u = ncread(FileToMerge1,'U')';
ncfile1.v = ncread(FileToMerge1,'V')';
%% Read second .nc file
ncfile2.time = ncread(FileToMerge2,'TIME');
ncfile2.depth = ncread(FileToMerge2,'DEPTH');
ncfile2.u = ncread(FileToMerge2,'UCUR');
ncfile2.v = ncread(FileToMerge2,'VCUR');
% %% Read third .nc file
% ncfile3.time = ncread(FileToMerge3,'TIME');
% ncfile3.depth = ncread(FileToMerge3,'DEPTH');
% ncfile3.u = ncread(FileToMerge3,'UCUR');
% ncfile3.v = ncread(FileToMerge3,'VCUR');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Create depth matrix
depth = max(vertcat(ncfile1.depth,ncfile2.depth)):ncfile1.depth(2)-ncfile1.depth(1):min(vertcat(ncfile1.depth,ncfile2.depth));
depth = fliplr(depth);
max(vertcat(ncfile1.depth,ncfile2.depth))
% min(vertcat(ncfile1.depth,ncfile2.depth))
depth = 0:5:1000;
%% Create time matrix
time = vertcat(ncfile1.time,ncfile2.time);
[YY,MM,DD,hh,mm,ss] = datevec(time+datenum(1950,01,01));
time = julian(YY,MM,DD,hh,mm,ss);
%time = time + datenum(1950,1,1,0,0,0) + datenum(2020,01,01); % -0.5 is necessary to remove 12h00 introduced by datetime function starting at noon instead of midnight as performed by julian function previously used
time = time*ones(1,length(depth));
%% Create u/v matrix
for ii = 1:length(ncfile1.time)
u1(ii,:) = interp1(ncfile1.depth,ncfile1.u(ii,:),depth);
v1(ii,:) = interp1(ncfile1.depth,ncfile1.v(ii,:),depth);
end
for ii = 1:length(ncfile2.time)
u2(ii,:) = interp1(ncfile2.depth,ncfile2.u(ii,:),depth);
v2(ii,:) = interp1(ncfile2.depth,ncfile2.v(ii,:),depth);
end
% for ii = 1:length(ncfile3.time)
% u3(ii,:) = interp1(ncfile3.depth,ncfile3.u(ii,:),depth);
% v3(ii,:) = interp1(ncfile3.depth,ncfile3.v(ii,:),depth);
% end
u = vertcat(u1,u2);
v = vertcat(v1,v2);
u = u';
v = v';
% create a continuous series of daily data, ranging from min(d) to max(d)
final_time = ceil(min(min(time))):1:floor(max(max(time)));
ADCP_final.u = NaN(length(depth),length(final_time));
ADCP_final.v = NaN(length(depth),length(final_time));
for i_time = 1:length(final_time)
for j_time = 1:length(time)
if final_time(i_time) == time(j_time,1)
ADCP_final.u(:,i_time)=u(:,j_time);
ADCP_final.v(:,i_time)=v(:,j_time);
end
end
end
time = final_time;
time = time'*ones(1,length(depth));
time = time';
u = ADCP_final.u;
v = ADCP_final.v;
%% Plot data
if plot_data
niv_u = (-1.5:0.05:1);
niv_v = (-1.8:0.05:1.5);
depth = depth.*ones(length(time),1);
depth = depth';
%date1 = julian(ncfile1.time(1));
%date2 = julian(ncfile2.time(end));
date1 = datestr(ncfile1.time(1)+datenum(1950,01,01),'yyyy');
date2 = datestr(ncfile2.time(end)+datenum(1950,01,01),'yyyy');
hf=figure('position', [0, 0, 1400, 1000]);
%u
subplot(2,1,1);
colormap jet
[C,h] = contourf(time,depth,u,niv_u);
set(h,'LineColor','none');
caxis(niv_u([1 end]));
h=colorbar;
ylabel(h,'U [m s^-^1]');
set(gca,'ydir', 'reverse');
ylabel('Depth (m)');
ylim([0,max(max(depth))]);
%datetick('x','mm-yyyy');
gregtick;
title({[mooring.name, ' - ' num2str(date1) ' to ' num2str(date2) ' - ZONAL VELOCITY - RDI ',num2str(freq),' kHz (filtered from tide)']});
%v
subplot(2,1,2);
[C,h] = contourf(time,depth,v,niv_v);
set(h,'LineColor','none');
caxis(niv_v([1 end]));
h = colorbar;
ylabel(h,'V [m s^-^1]');
set(gca,'ydir', 'reverse');
ylabel('Depth (m)');
ylim([0,max(max(depth))]);
gregtick;
title({[mooring.name, ' - ' num2str(date1) ' to ' num2str(date2) ' - MERIDIONAL VELOCITY - RDI ',num2str(freq),' kHz (filtered from tide)']});
graph_name = ['ADCP_' mooring.name '_' num2str(date1) '_' num2str(date2) '_U_V_daily'];
set(hf,'Units','Inches');
pos = get(hf,'Position');
set(hf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
print(hf,graph_name,'-dpdf','-r300');
end
%% Write netcdf file
time = time(1,:)';
timed = gregorian(time);
timed(:,5) = 0;
timed(:,6) = 0;
time = datenum(timed)-datenum(1950,01,01);
disp('****')
disp('Creating .nc file')
yr_start = datestr(time(1)+datenum(1950,01,01), 'yyyy');
yr_end = datestr(time(end)+datenum(1950,01,01), 'yyyy');
ncid = netcdf.create(['ADCP_',mooring.name,'_',num2str(yr_start),'_',num2str(yr_end),'.nc'],'NC_CLOBBER');
%create dimension
dimidz = netcdf.defDim(ncid, 'DEPTH', size(depth,2));
dimidt = netcdf.defDim(ncid, 'TIME', netcdf.getConstant('NC_UNLIMITED'));
%Define IDs for the dimension variables (pressure,time,latitude,...)
time_ID = netcdf.defVar(ncid,'TIME','double',dimidt);
netcdf.putAtt(ncid, time_ID, 'long_name', 'Time');
netcdf.putAtt(ncid, time_ID, 'axis', 'T');
netcdf.putAtt(ncid, time_ID, 'units', 'days since 1950-01-01T00:00:00Z');
netcdf.putAtt(ncid, time_ID, 'time_origin', '1-JAN-1950:00:00:00');
depth_ID = netcdf.defVar(ncid,'DEPTH','double',dimidz);
netcdf.putAtt(ncid, depth_ID, 'long_name', 'Depth');
netcdf.putAtt(ncid, depth_ID, 'axis', 'Z');
netcdf.putAtt(ncid, depth_ID, 'units', 'meters');
netcdf.putAtt(ncid, depth_ID, 'positive', 'down');
netcdf.putAtt(ncid, depth_ID, 'point_spacing', 'even');
%Define the main variable ()
u_ID = netcdf.defVar(ncid,'U','double',[dimidz dimidt]);
netcdf.putAtt(ncid, u_ID, 'long_name', 'Zonal velocities');
v_ID = netcdf.defVar(ncid,'V','double',[dimidz dimidt]);
netcdf.putAtt(ncid, v_ID, 'long_name', 'Meridional velocities');
%We are done defining the NetCdf
netcdf.endDef(ncid);
%Then store the dimension variables in
netcdf.putVar(ncid, depth_ID, depth);
netcdf.putVar(ncid, time_ID, 0, length(time), time);
%Then store my main variable
netcdf.putVar(ncid, u_ID, u);
netcdf.putVar(ncid, v_ID, v);
%We're done, close the netcdf
netcdf.close(ncid);
disp('****')
\ No newline at end of file
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Merge subsurface ADCP mooring data % % Merge subsurface ADCP mooring data %
% Autor: P. Rousselot / Date: 03/2020 % % Autor: P. Rousselot / Date: 03/2020 %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all; close all; %clear all; close all;
%% Variables %% Variables
FileToMerge1 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX2/ADCP_0N130E_2010_2010_1d.nc'; %.nc file to merge with FileToMerge1 = 'F:\Encours\PIRATA_ADCP-MOORINGS\Convert_ADCP/ADCP_23W0N_2001_2015.nc'; %.nc file to merge with
FileToMerge2 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX/ADCP_0N130E_2013_2016_1d.nc'; %.nc file to merge FileToMerge2 = 'F:\Encours\PIRATA_ADCP-MOORINGS\23W\0_Final_Files/ADCP_0N23W_2015_2016_1d_up_down.nc'; %.nc file to merge
FileToMerge3 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX2/ADCP_0N130E_2010_2012_1d.nc'; %.nc file to merge %FileToMerge2 = 'F:\Encours\PIRATA_ADCP-MOORINGS\23W\v2\2008-2009\ADCP_23W0N_2008_2009_1d.nc';
% FileToMerge1 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX/ADCP_0N130E_2013_2013_1d.nc'; %.nc file to merge with % FileToMerge3 = '/media/irdcampagnes/PIRATA/PIRATA_ADCP-MOORINGS/10W/0_Final_Files/ADCP_10W0N_2004_2005_1d.nc'; %.nc file to merge
% FileToMerge2 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX/ADCP_0N130E_2013_2016_1d.nc'; %.nc file to merge % FileToMerge1 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX/ADCP_0N130E_2013_2013_1d.nc'; %.nc file to merge with
step_subsampling = 1; % 1=daily % FileToMerge2 = '/home/proussel/Documents/OUTILS/ADCP/ADCP_mooring_data_processing/IDMX/ADCP_0N130E_2013_2016_1d.nc'; %.nc file to merge
plot_data = 1; step_subsampling = 1; % 1=daily
mooring.name = '0N130E'; plot_data = 1;
freq = '75'; mooring.name = '23W0N';
% mooring.name = '0N130E'; freq = 'Variable';
% freq = '75'; % mooring.name = '0N130E';
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % freq = '75';
%% Read first .nc file %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
ncfile1.time = ncread(FileToMerge1,'time'); %% Read first .nc file
ncfile1.depth = ncread(FileToMerge1,'depth'); ncfile1.time = ncread(FileToMerge1,'TIME');
ncfile1.u = ncread(FileToMerge1,'u'); ncfile1.depth = ncread(FileToMerge1,'DEPTH');
ncfile1.v = ncread(FileToMerge1,'v'); ncfile1.u = ncread(FileToMerge1,'U')';
ncfile1.v = ncread(FileToMerge1,'V')';
%% Read second .nc file
ncfile2.time = ncread(FileToMerge2,'time'); %% Read second .nc file
ncfile2.depth = ncread(FileToMerge2,'depth'); ncfile2.time = ncread(FileToMerge2,'TIME');
ncfile2.u = ncread(FileToMerge2,'u'); ncfile2.depth = ncread(FileToMerge2,'DEPTH');
ncfile2.v = ncread(FileToMerge2,'v'); ncfile2.u = ncread(FileToMerge2,'UCUR');
ncfile2.v = ncread(FileToMerge2,'VCUR');
%% Read third .nc file
ncfile3.time = ncread(FileToMerge3,'time'); % %% Read third .nc file
ncfile3.depth = ncread(FileToMerge3,'depth'); % ncfile3.time = ncread(FileToMerge3,'TIME');
ncfile3.u = ncread(FileToMerge3,'u'); % ncfile3.depth = ncread(FileToMerge3,'DEPTH');
ncfile3.v = ncread(FileToMerge3,'v'); % ncfile3.u = ncread(FileToMerge3,'UCUR');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % ncfile3.v = ncread(FileToMerge3,'VCUR');
%% Create depth matrix %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
depth = max(vertcat(ncfile1.depth,ncfile2.depth)):ncfile1.depth(2)-ncfile1.depth(1):min(vertcat(ncfile1.depth,ncfile2.depth)); %% Create depth matrix
depth = fliplr(depth); % depth = max(vertcat(ncfile1.depth,ncfile2.depth)):ncfile1.depth(2)-ncfile1.depth(1):min(vertcat(ncfile1.depth,ncfile2.depth));
% depth = fliplr(depth);
%% Create time matrix max(vertcat(ncfile1.depth,ncfile2.depth))
time = vertcat(ncfile1.time,ncfile3.time,ncfile2.time); min(vertcat(ncfile1.depth,ncfile2.depth))
time = time*ones(1,length(depth)); depth = 0:5:1000;
%% Create u/v matrix %% Create time matrix
for ii = 1:length(ncfile1.time) time = vertcat(ncfile1.time,ncfile2.time);
u1(ii,:) = interp1(ncfile1.depth,ncfile1.u(ii,:),depth); [YY,MM,DD,hh,mm,ss] = datevec(time+datenum(1950,01,01));
v1(ii,:) = interp1(ncfile1.depth,ncfile1.v(ii,:),depth); time = julian(YY,MM,DD,hh,mm,ss);
end %time = time + datenum(1950,1,1,0,0,0) + datenum(2020,01,01); % -0.5 is necessary to remove 12h00 introduced by datetime function starting at noon instead of midnight as performed by julian function previously used
for ii = 1:length(ncfile2.time) %time = time*ones(1,length(depth));
u2(ii,:) = interp1(ncfile2.depth,ncfile2.u(ii,:),depth);
v2(ii,:) = interp1(ncfile2.depth,ncfile2.v(ii,:),depth); % time = time + datetime(1950,1,1,0,0,0); % -0.5 is necessary to remove 12h00 introduced by datetime function starting at noon instead of midnight as performed by julian function previously used
end % time = time*ones(1,length(depth));
for ii = 1:length(ncfile3.time)
u3(ii,:) = interp1(ncfile3.depth,ncfile3.u(ii,:),depth); %% Create u/v matrix
v3(ii,:) = interp1(ncfile3.depth,ncfile3.v(ii,:),depth); for ii = 1:length(ncfile1.time)
end u1(ii,:) = interp1(ncfile1.depth,ncfile1.u(ii,:),depth);
u = vertcat(u1,u3,u2); v1(ii,:) = interp1(ncfile1.depth,ncfile1.v(ii,:),depth);
v = vertcat(v1,v3,v2); end
for ii = 1:length(ncfile2.time)
%% Plot data u2(ii,:) = interp1(ncfile2.depth,ncfile2.u(ii,:),depth);
if plot_data v2(ii,:) = interp1(ncfile2.depth,ncfile2.v(ii,:),depth);
niv_u = (-1.5:0.05:0.9); end
niv_v = (-1.8:0.05:1.5); % for ii = 1:length(ncfile3.time)
depth = depth.*ones(length(time),1); % u3(ii,:) = interp1(ncfile3.depth,ncfile3.u(ii,:),depth);
date1 = julian(ncfile1.time(1)); % v3(ii,:) = interp1(ncfile3.depth,ncfile3.v(ii,:),depth);
date2 = julian(ncfile2.time(end)); % end
u = vertcat(u1,u2);
hf=figure('position', [0, 0, 1400, 1000]); v = vertcat(v1,v2);
%u
subplot(2,1,1); time = time*ones(1,length(depth));
colormap jet
[C,h] = contourf(time,depth,u,niv_u);
set(h,'LineColor','none'); %% Plot data
caxis(niv_u([1 end])); if plot_data
h=colorbar; niv_u = (-1.5:0.05:0.9);
ylabel(h,'U [m s^-^1]'); niv_v = (-1.8:0.05:1.5);
set(gca,'ydir', 'reverse'); depth = depth.*ones(length(time),1);
ylabel('Depth (m)'); date1 = datestr(ncfile1.time(1)+datenum(1950,01,01),'YYYY');
ylim([0,max(max(depth))]); date2 = datestr(ncfile2.time(end)+datenum(1950,01,01),'YYYY');
gregtick;
title({[mooring.name, ' - ' num2str(date1(1)) ' to ' num2str(date2(1)) ' - ZONAL VELOCITY - RDI ',num2str(freq),' kHz (filtered from tide)']}); hf=figure('position', [0, 0, 1400, 1000]);
%u
%v subplot(2,1,1);
subplot(2,1,2); colormap jet
[C,h] = contourf(time,depth,v,niv_v); [C,h] = contourf(time,depth,u,niv_u);
set(h,'LineColor','none'); set(h,'LineColor','none');
caxis(niv_v([1 end])); caxis(niv_u([1 end]));
h = colorbar; h=colorbar;
ylabel(h,'V [m s^-^1]'); ylabel(h,'U [m s^-^1]');
set(gca,'ydir', 'reverse'); set(gca,'ydir', 'reverse');
ylabel('Depth (m)'); ylabel('Depth (m)');
ylim([0,max(max(depth))]); ylim([0,max(max(depth))]);
gregtick; gregtick;
title({[mooring.name, ' - ' num2str(date1(1)) ' to ' num2str(date2(1)) ' - MERIDIONAL VELOCITY - RDI ',num2str(freq),' kHz (filtered from tide)']}); title({[mooring.name, ' - ' num2str(date1) ' to ' num2str(date2) ' - ZONAL VELOCITY - RDI ',num2str(freq),' kHz (filtered from tide)']});
graph_name = ['ADCP_' mooring.name '_' num2str(date1(1)) '_' num2str(date2(1)) '_U_V_daily']; %v
set(hf,'Units','Inches'); subplot(2,1,2);
pos = get(hf,'Position'); [C,h] = contourf(time,depth,v,niv_v);
set(hf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]) set(h,'LineColor','none');
print(hf,graph_name,'-dpdf','-r300'); caxis(niv_v([1 end]));
end h = colorbar;
ylabel(h,'V [m s^-^1]');
%% Write netcdf file set(gca,'ydir', 'reverse');
time = time(:,1); ylabel('Depth (m)');
timed = gregorian(time); ylim([0,max(max(depth))]);
timed(:,5) = 0; gregtick;
timed(:,6) = 0; title({[mooring.name, ' - ' num2str(date1) ' to ' num2str(date2) ' - MERIDIONAL VELOCITY - RDI ',num2str(freq),' kHz (filtered from tide)']});
time = datenum(timed)-datenum(1950,01,01);
graph_name = ['ADCP_' mooring.name '_' num2str(date1) '_' num2str(date2) '_U_V_daily'];
disp('****') set(hf,'Units','Inches');
disp('Creating .nc file') pos = get(hf,'Position');
yr_start = datestr(time(1)+datenum(1950,01,01), 'yyyy'); set(hf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)])
yr_end = datestr(time(end)+datenum(1950,01,01), 'yyyy'); print(hf,graph_name,'-dpdf','-r300');
end
ncid = netcdf.create(['ADCP_',mooring.name,'_',num2str(yr_start),'_',num2str(yr_end),'.nc'],'NC_CLOBBER');
%% Write netcdf file
%create dimension time = time(:,1);
dimidz = netcdf.defDim(ncid, 'DEPTH', size(depth,2)); timed = gregorian(time);
dimidt = netcdf.defDim(ncid, 'TIME', netcdf.getConstant('NC_UNLIMITED')); timed(:,5) = 0;
%Define IDs for the dimension variables (pressure,time,latitude,...) timed(:,6) = 0;
time_ID = netcdf.defVar(ncid,'TIME','double',dimidt); time = datenum(timed)-datenum(1950,01,01);
netcdf.putAtt(ncid, time_ID, 'long_name', 'Time');
netcdf.putAtt(ncid, time_ID, 'axis', 'T'); disp('****')
netcdf.putAtt(ncid, time_ID, 'units', 'days since 1950-01-01T00:00:00Z'); disp('Creating .nc file')
netcdf.putAtt(ncid, time_ID, 'time_origin', '1-JAN-1950:00:00:00'); yr_start = datestr(time(1)+datenum(1950,01,01), 'yyyy');
depth_ID = netcdf.defVar(ncid,'DEPTH','double',dimidz); yr_end = datestr(time(end)+datenum(1950,01,01), 'yyyy');
netcdf.putAtt(ncid, depth_ID, 'long_name', 'Depth');
netcdf.putAtt(ncid, depth_ID, 'axis', 'Z'); ncid = netcdf.create(['ADCP_',mooring.name,'_',num2str(yr_start),'_',num2str(yr_end),'.nc'],'NC_CLOBBER');
netcdf.putAtt(ncid, depth_ID, 'units', 'meters');
netcdf.putAtt(ncid, depth_ID, 'positive', 'down'); %create dimension
netcdf.putAtt(ncid, depth_ID, 'point_spacing', 'even'); dimidz = netcdf.defDim(ncid, 'DEPTH', size(depth,2));
%Define the main variable () dimidt = netcdf.defDim(ncid, 'TIME', netcdf.getConstant('NC_UNLIMITED'));
u_ID = netcdf.defVar(ncid,'U','double',[dimidz dimidt]); %Define IDs for the dimension variables (pressure,time,latitude,...)
netcdf.putAtt(ncid, u_ID, 'long_name', 'Zonal velocities'); time_ID = netcdf.defVar(ncid,'TIME','double',dimidt);
v_ID = netcdf.defVar(ncid,'V','double',[dimidz dimidt]); netcdf.putAtt(ncid, time_ID, 'long_name', 'Time');
netcdf.putAtt(ncid, v_ID, 'long_name', 'Meridional velocities'); netcdf.putAtt(ncid, time_ID, 'axis', 'T');
%We are done defining the NetCdf netcdf.putAtt(ncid, time_ID, 'units', 'days since 1950-01-01T00:00:00Z');
netcdf.endDef(ncid); netcdf.putAtt(ncid, time_ID, 'time_origin', '1-JAN-1950:00:00:00');
%Then store the dimension variables in depth_ID = netcdf.defVar(ncid,'DEPTH','double',dimidz);
netcdf.putVar(ncid, depth_ID, depth(1,:)); netcdf.putAtt(ncid, depth_ID, 'long_name', 'Depth');
netcdf.putVar(ncid, time_ID, 0, length(time), time); netcdf.putAtt(ncid, depth_ID, 'axis', 'Z');
%Then store my main variable netcdf.putAtt(ncid, depth_ID, 'units', 'meters');
netcdf.putVar(ncid, u_ID, u'); netcdf.putAtt(ncid, depth_ID, 'positive', 'down');
netcdf.putVar(ncid, v_ID, v'); netcdf.putAtt(ncid, depth_ID, 'point_spacing', 'even');
%We're done, close the netcdf %Define the main variable ()
netcdf.close(ncid); u_ID = netcdf.defVar(ncid,'U','double',[dimidz dimidt]);
netcdf.putAtt(ncid, u_ID, 'long_name', 'Zonal velocities');
v_ID = netcdf.defVar(ncid,'V','double',[dimidz dimidt]);
netcdf.putAtt(ncid, v_ID, 'long_name', 'Meridional velocities');
%We are done defining the NetCdf
netcdf.endDef(ncid);
%Then store the dimension variables in
netcdf.putVar(ncid, depth_ID, depth(1,:));
netcdf.putVar(ncid, time_ID, 0, length(time), time);
%Then store my main variable
netcdf.putVar(ncid, u_ID, u');
netcdf.putVar(ncid, v_ID, v');
%We're done, close the netcdf
netcdf.close(ncid);
disp('****') disp('****')
\ No newline at end of file
...@@ -16,26 +16,26 @@ clear all;close all; ...@@ -16,26 +16,26 @@ clear all;close all;
addpath('.\moored_adcp_proc'); addpath('.\moored_adcp_proc');
% Location of ADCP up and down data % Location of ADCP up and down data
fpath = '.\data_example\up_and_down\'; fpath = 'F:\Encours\PIRATA_ADCP-MOORINGS\23W\v2\2015-2016\';
% Directory for outputs % Directory for outputs
fpath_output = '.\data_example\up_and_down\'; fpath_output = 'F:\Encours\PIRATA_ADCP-MOORINGS\23W\v2\2015-2016\';
% Contour levels for u anv v fields % Contour levels for u anv v fields
niv_u = (-1.5:0.1:1.5); niv_u = (-1.5:0.1:1.5);
niv_v = (-0.5:0.1:0.5); niv_v = (-0.5:0.1:0.5);
%% combine up and down %% combine up and down
load([fpath, 'FR22-10W0N_508_instr_01_int_filt_sub']); load([fpath, 'up\23W0N_1140_instr_01_int_filt_sub']);
adcp_up=adcp; adcp_up=adcp;
up_u=data.uintfilt; up_u=data.uintfilt;
up_v=data.vintfilt; up_v=data.vintfilt;
up_z=data.Z; up_z=data.Z;
up_time=data.inttim; up_time=data.inttim;
npts_up= data.npts_up; %npts_up= data.npts_up;
freq_up=adcp_up.config.sysconfig.frequency; freq_up=adcp_up.config.sysconfig.frequency;
load([fpath, 'FR22-10W0N_509_instr_02_int_filt_sub_down']); load([fpath, 'dn\23W0N_2627_instr_01_int_filt_sub']);
adcp_down=adcp; adcp_down=adcp;
down_u=data.uintfilt; down_u=data.uintfilt;
down_v=data.vintfilt; down_v=data.vintfilt;
...@@ -54,12 +54,15 @@ distance_between_instruments = 3; ...@@ -54,12 +54,15 @@ distance_between_instruments = 3;
distance_between_up_and_down = adcp_up.config.cell/2 + adcp_up.config.blank + distance_between_instruments + adcp_down.config.blank + adcp_down.config.cell/2; distance_between_up_and_down = adcp_up.config.cell/2 + adcp_up.config.blank + distance_between_instruments + adcp_down.config.blank + adcp_down.config.cell/2;
%calculate real minimum down ADCP depth %calculate real minimum down ADCP depth
up_z = fliplr(up_z); up_z = fliplr(up_z);
depth_down_ADCP = up_z(min(npts_up)+1) + ceil(distance_between_up_and_down); depth_down_ADCP = up_z(end) + ceil(distance_between_up_and_down);
%interval grid between up and down ADCP %interval grid between up and down ADCP
interval_grid = max(up_z)+adcp_up.config.cell/2-1:adcp_up.config.cell/2:min(depth_down_ADCP)-adcp_up.config.cell/2+1; interval_grid = max(up_z)+adcp_up.config.cell/2-1:adcp_up.config.cell/2:min(depth_down_ADCP)-adcp_up.config.cell/2+1;
%on applique l'offset sur les profondeurs de l'ADCP down %on applique l'offset sur les profondeurs de l'ADCP down
offset_ADCP_down = min(down_z) - min(depth_down_ADCP); offset_ADCP_down = min(down_z) - min(depth_down_ADCP);
down_z = down_z - offset_ADCP_down; down_z = down_z - offset_ADCP_down;
% down_z = flip(down_z);
% down_u = flip(down_u);
% down_v = flip(down_v);
% initialisation de la matrice combine up + down % initialisation de la matrice combine up + down
[B,a] = size(down_u); [B1,a1] = size(up_u); [B,a] = size(down_u); [B1,a1] = size(up_u);
...@@ -79,72 +82,84 @@ for i = 1:length(down_u) ...@@ -79,72 +82,84 @@ for i = 1:length(down_u)
end end
%% figure finale %% figure finale
z_final = [up_z interval_grid down_z]; Z = [up_z interval_grid down_z];
inttim = down_time;
bin_start = 1;
bin_end = length(Z);
uintfilt = u_final;
vintfilt = v_final;
%% Figure
niv_u = (-1:0.05:1);
niv_v = (-1:0.05:1);
close all
hf=figure('position', [0, 0, 1400, 1000]); hf=figure('position', [0, 0, 1400, 1000]);
%u %u
subplot(2,1,1); subplot(2,1,1);
[~,h] = contourf(down_time,z_final,u_final,niv_u); colormap jet
[C,h] = contourf(inttim,Z(bin_start:bin_end),uintfilt(bin_start:bin_end,:),niv_u);
set(h,'LineColor','none'); set(h,'LineColor','none');
caxis(niv_u([1 end])); caxis(niv_u([1 end]));
h=colorbar; h=colorbar;
ylabel(h,'U [m s^-^1]'); ylabel(h,'U [m s^-^1]');
set(gca,'ydir', 'reverse'); set(gca,'ydir', 'reverse');
ylabel('Depth (m)'); ylabel('Depth (m)');
gregtick ylim([0,round(max(Z))]);
title({[mooring.name, ' - ZONAL VELOCITY - ADCP UP : RDI ',num2str(freq_up),' kHz - ADCP DOWN : RDI ',num2str(freq_down),' kHz']}); %change figure label in HH:MM
gregtick;
title({[mooring.name, ' - ZONAL VELOCITY - RDI 150 kHz and 75 kHz (filtered from tide)']});
%v %v
subplot(2,1,2); subplot(2,1,2);
[C,h] = contourf(down_time,z_final,v_final,niv_v); [C,h] = contourf(inttim,Z(bin_start:bin_end),vintfilt(bin_start:bin_end,:),niv_v);
set(h,'LineColor','none'); set(h,'LineColor','none');
caxis(niv_v([1 end])); caxis(niv_v([1 end]));
h=colorbar; h = colorbar;
ylabel(h,'V [m s^-^1]'); ylabel(h,'V [m s^-^1]');
set(gca,'ydir', 'reverse'); set(gca,'ydir', 'reverse');
ylabel('Depth (m)'); ylabel('Depth (m)');
gregtick ylim([0,round(max(Z))]);
title({[mooring.name, ' - MERIDIONAL VELOCITY - ADCP UP : RDI ',num2str(freq_up),' kHz - ADCP DOWN : RDI ',num2str(freq_down),' kHz']}); %change figure label in HH:MM
gregtick;
% Save combined data title({[mooring.name, ' - ZONAL VELOCITY - RDI 150 kHz and 75 kHz (filtered from tide)']});
data.time = down_time;
data.u_final = u_final;
data.v_final = v_final; graph_name = [fpath_output, mooring.name '_up_down_U_V_int_filt_sub'];
data.z_final = z_final;
save([fpath, mooring.name '_UP_DOWN_int_filt_sub.mat'],'adcp','mooring','data','raw');
graph_name = [fpath_output, mooring.name '_U_V_UP_DOWN_int_filt_sub'];
set(hf,'Units','Inches'); set(hf,'Units','Inches');
pos = get(hf,'Position'); pos = get(hf,'Position');
set(hf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]) set(hf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]);
print(hf,graph_name,'-dpdf','-r300'); print(hf,graph_name,'-dpdf','-r300');
% rmpath %% Write netcdf file
rmpath('.\moored_adcp_proc'); disp('****')
disp('Creating .nc file')
[yr_start , ~, ~] = gregorian(inttim(1));
[yr_end, ~, ~] = gregorian(inttim(length(inttim)));
%% Write netcdf file ncid = netcdf.create([fpath_output,'ADCP_',mooring.name,'_',num2str(yr_start),'_',num2str(yr_end),'_1d.nc'],'NC_WRITE');
[yr_start , ~, ~] = gregorian(down_time(1));
[yr_end, ~, ~] = gregorian(down_time(length(down_time)));
ncid=netcdf.create([fpath_output,'ADCP_',mooring.name, '_',num2str(yr_start),'_',num2str(yr_end),'_1d.nc'],'NC_WRITE');
%create dimension %create dimension
dimidt = netcdf.defDim(ncid,'time',length(down_time)); dimidt = netcdf.defDim(ncid,'time',length(inttim));
dimidz = netcdf.defDim(ncid,'depth',length(z_final)); dimidz = netcdf.defDim(ncid,'depth',length(Z));
%Define IDs for the dimension variables (pressure,time,latitude,...) %Define IDs for the dimension variables (pressure,time,latitude,...)
time_ID=netcdf.defVar(ncid,'time','double',dimidt); time_ID = netcdf.defVar(ncid,'time','double',dimidt);
depth_ID=netcdf.defVar(ncid,'depth','double',dimidz); depth_ID = netcdf.defVar(ncid,'depth','double',dimidz);
%Define the main variable () %Define the main variable ()
u_ID = netcdf.defVar(ncid,'u','double',[dimidt dimidz]); u_ID = netcdf.defVar(ncid,'u','double',[dimidt dimidz]);
v_ID = netcdf.defVar(ncid,'v','double',[dimidt dimidz]); v_ID = netcdf.defVar(ncid,'v','double',[dimidt dimidz]);
%We are done defining the NetCdf %We are done defining the NetCdf
netcdf.endDef(ncid); netcdf.endDef(ncid);
%Then store the dimension variables in %Then store the dimension variables in
netcdf.putVar(ncid,time_ID,down_time); netcdf.putVar(ncid,time_ID,inttim);
netcdf.putVar(ncid,depth_ID,z_final); netcdf.putVar(ncid,depth_ID,Z);
%Then store my main variable %Then store my main variable
netcdf.putVar(ncid,u_ID,u_final); netcdf.putVar(ncid,u_ID,uintfilt');
netcdf.putVar(ncid,v_ID,v_final); netcdf.putVar(ncid,v_ID,vintfilt');
%We're done, close the netcdf %We're done, close the netcdf
netcdf.close(ncid); netcdf.close(ncid);
disp('****')
% -------------------------------------------------------------------------------------------
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% template_combine_adcp_up_and_down.m
% -------------------------------
% Author : Jrmie HABASQUE - IRD
% -------------------------------
% INPUTS:
% - ADCP up data processed (output of template_get_adcp_data.m)
% - ADCP down data processed (output of template_get_adcp_data.m)
% OUTPUTS:
% - U and V fields interpolated on a regulard grid, filtered and subsampled
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all;close all;
% path
addpath('.\moored_adcp_proc');
% Location of ADCP up and down data
fpath = '.\data_example\up_and_down\';
% Directory for outputs
fpath_output = './23W/';
% Contour levels for u anv v fields
niv_u = (-1.5:0.1:1.5);
niv_v = (-0.5:0.1:0.5);
%% combine up and down
load('C:\Users\proussel\Documents\OUTILS\ADCP\ADCP_mooring_data_processing\23W\2008-2009\up\23W0N_1001_instr_01_int_filt_sub');
adcp_up=adcp;
up_u=data.uintfilt;
up_v=data.vintfilt;
up_z=data.Z;
up_time=data.inttim;
%npts_up= data.npts_up;
freq_up=adcp_up.config.sysconfig.frequency;
load('C:\Users\proussel\Documents\OUTILS\ADCP\ADCP_mooring_data_processing\23W\2008-2009\dn\23W0N_1023_instr_02_int_filt_sub');
adcp_down=adcp;
down_u=data.uintfilt;
down_v=data.vintfilt;
down_z=data.Z;
down_time=data.inttim;
freq_down = adcp_down.config.sysconfig.frequency;
% distance between deepest measurement of the upward looking and
% shallowest measurement of the downward looking ADCP
% half distance of 1st bin in upward ADCP +
% blank of upward ADCP +
% distance between instruments +
% blank of downward ADCP +
% half distance of 1st bin in downward ADCP.
distance_between_instruments = 3;
distance_between_up_and_down = adcp_up.config.cell/2 + adcp_up.config.blank + distance_between_instruments + adcp_down.config.blank + adcp_down.config.cell/2;
%calculate real minimum down ADCP depth
up_z = fliplr(up_z);
depth_down_ADCP = 148 + ceil(distance_between_up_and_down);
%interval grid between up and down ADCP
interval_grid = max(up_z)+adcp_up.config.cell/2-1:adcp_up.config.cell/2:min(depth_down_ADCP)-adcp_up.config.cell/2+1;
%on applique l'offset sur les profondeurs de l'ADCP down
offset_ADCP_down = min(down_z) - min(depth_down_ADCP);
down_z = down_z - offset_ADCP_down;
down_z = flip(down_z);
down_u = flip(down_u);
down_v = flip(down_v);
% initialisation de la matrice combine up + down
[B,a] = size(down_u); [B1,a1] = size(up_u);
BB = B+B1+1 ;
DOWN = NaN(BB,a);
V_DOWN = NaN(BB,a);
u_final = NaN(BB,a);
v_final = NaN(BB,a);
% on alimente la matrice avec les donnes up
u_final(1:B1,1:a1) = up_u(B1:-1:1,:);
v_final(1:B1,1:a1) = up_v(B1:-1:1,:);
for i = 1:length(down_u)
u_final(B1+length(interval_grid)+1:B1+length(interval_grid)+B,i) = down_u(:,i);
v_final(B1+length(interval_grid)+1:B1+length(interval_grid)+B,i) = down_v(:,i);
end
%% figure finale
Z = [up_z interval_grid down_z];
inttim = down_time;
bin_start = 1;
bin_end = 52;
uintfilt = u_final;
vintfilt = v_final;
%% Figure
niv_u = (-1:0.05:1);
niv_v = (-1:0.05:1);
close all
hf=figure('position', [0, 0, 1400, 1000]);
%u
subplot(2,1,1);
colormap jet
[C,h] = contourf(inttim,Z(bin_start:bin_end),uintfilt(bin_start:bin_end,:),niv_u);
set(h,'LineColor','none');
caxis(niv_u([1 end]));
h=colorbar;
ylabel(h,'U [m s^-^1]');
set(gca,'ydir', 'reverse');
ylabel('Depth (m)');
ylim([0,round(max(Z))]);
%change figure label in HH:MM
gregtick;
title({[mooring.name, ' - ZONAL VELOCITY - RDI 150 kHz and 75 kHz (filtered from tide)']});
%v
subplot(2,1,2);
[C,h] = contourf(inttim,Z(bin_start:bin_end),vintfilt(bin_start:bin_end,:),niv_v);
set(h,'LineColor','none');
caxis(niv_v([1 end]));
h = colorbar;
ylabel(h,'V [m s^-^1]');
set(gca,'ydir', 'reverse');
ylabel('Depth (m)');
ylim([0,round(max(Z))]);
%change figure label in HH:MM
gregtick;
title({[mooring.name, ' - ZONAL VELOCITY - RDI 150 kHz and 75 kHz (filtered from tide)']});
graph_name = [fpath_output, mooring.name '_up_down_U_V_int_filt_sub'];
set(hf,'Units','Inches');
pos = get(hf,'Position');
set(hf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]);
print(hf,graph_name,'-dpdf','-r300');
%% Write netcdf file
disp('****')
disp('Creating .nc file')
[yr_start , ~, ~] = gregorian(inttim(1));
[yr_end, ~, ~] = gregorian(inttim(length(inttim)));
ncid = netcdf.create([fpath_output,'ADCP_',mooring.name,'_',num2str(yr_start),'_',num2str(yr_end),'_1d.nc'],'NC_WRITE');
%create dimension
dimidt = netcdf.defDim(ncid,'time',length(inttim));
dimidz = netcdf.defDim(ncid,'depth',length(data.Z));
%Define IDs for the dimension variables (pressure,time,latitude,...)
time_ID = netcdf.defVar(ncid,'time','double',dimidt);
depth_ID = netcdf.defVar(ncid,'depth','double',dimidz);
%Define the main variable ()
u_ID = netcdf.defVar(ncid,'u','double',[dimidt dimidz]);
v_ID = netcdf.defVar(ncid,'v','double',[dimidt dimidz]);
%We are done defining the NetCdf
netcdf.endDef(ncid);
%Then store the dimension variables in
netcdf.putVar(ncid,time_ID,inttim);
netcdf.putVar(ncid,depth_ID,data.Z);
%Then store my main variable
netcdf.putVar(ncid,u_ID,data.uintfilt');
netcdf.putVar(ncid,v_ID,data.vintfilt');
%We're done, close the netcdf
netcdf.close(ncid);
disp('****')
% -------------------------------------------------------------------------------------------
This diff is collapsed.
This diff is collapsed.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% template_get_adcp_data.m
% -------------------------------
% Author : Pierre ROUSSELOT - IRD (pierre.rousselot@ird.fr)
% Jeremie HABASQUE - IRD (jeremie.habasque@ird.fr)
% -------------------------------
% INPUTS:
% - binary raw file with .000 extension
% OUTPUTS:
% - U and V fields interpolated on a regulard grid, filtered and subsampled
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
close all; clear
addpath(genpath('../ADCP_mooring_data_processing'));
addpath('/home/proussel/Documents/OUTILS/TOOLS/nansuite'); % NaNSuitePath
%% META information:
% Location rawfile
rawfile = 'FR10W000.000'; % binary file with .000 extension
fpath_output = './10W/'; % Output directory
% Cruise/mooring info
cruise.name = 'PIRATA'; % cruise name
mooring.name = '10W0N'; % '0N10W'
mooring.lat = '00°00.000'; % latitude [°']
mooring.lon = '-10°00.000'; % longitude [°']
clock_drift = 0; % [seconds]
% ADCP info
adcp.sn = 500; % ADCP serial number
adcp.type = '300 khz'; % Type : Quartermaster, longranger
adcp.direction = 'up'; % upward-looking 'up', downward-looking 'dn'
adcp.instr_depth = 100; % nominal instrument depth
instr = 1; % this is just for name convention and sorting of all mooring instruments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Convert variables
latDegInd = strfind(mooring.lat,'°');
lonDegInd = strfind(mooring.lon,'°');
mooring.lat = str2double(mooring.lat(1:latDegInd-1))+str2double(mooring.lat(latDegInd+1:end-1))/60;
mooring.lon = str2double(mooring.lon(1:lonDegInd-1))+str2double(mooring.lon(lonDegInd+1:end-1))/60;
clock_drift = clock_drift/3600; % convert into hrs
%% Read rawfile
disp('****')
raw_file = [fpath_output, mooring.name '_' num2str(adcp.sn) '_instr_' sprintf('%02d',instr) '_raw.mat'];
% if exist(raw_file)
% fprintf('Read %s\n', raw_file);
% load(raw_file)
% else
% fprintf('Read %s\n', rawfile);
% raw = read_os3(rawfile,'all');
% save(raw_file,'raw','-v7.3');
% end
load('UV_hour_10w_int10.mat')
d0=datenum(2004,2,6,0,0,0);
d1=datenum(2005,6,17,22,0,0);
adcp_2003_time=d0:1/12:d1;
adcp_2003_time = adcp_2003_time';
u2 = uvmat(:,1:5976)/100;
v2 = uvmat(:,5977:5976*2)/100;
adcp_2003_bin_length = 4;
dpt1 = 4:adcp_2003_bin_length:104;
[YY,MM,DD,hh,mm,ss] = datevec(adcp_2003_time);
time=julian(YY,MM,DD,hh,mm,ss);
% Data structure
u_interp = u2';
v_interp = v2';
ts_interp = NaN;
data.time = time;
Z = dpt1;
reply_ts = 0;
%% Horizontal interpolation, filtering and subsampling
disp('****')
horz_interp = 1;
filt = 1;
sub = 1;
[uintfilt,vintfilt,tsintfilt,inttim,utid_baro,vtid_baro] = adcp_filt_sub(data,u_interp',v_interp',ts_interp',1:length(Z),reply_ts, filt, sub);
% saveas(figure(5),[fpath_output,mooring.name,'_',num2str(adcp.sn),'_instr_',num2str(instr),'_','data_raw_filt_subsampled_1'],'fig')
% saveas(figure(6),[fpath_output,mooring.name,'_',num2str(adcp.sn),'_instr_',num2str(instr),'_','data_raw_filt_subsampled_2'],'fig')
if horz_interp == 0
uintfilt = u_interp';
vintfilt = v_interp';
inttim = data.time;
end
%% Save interpolated data
disp('****')
bin_start = input('Determine first bin indice with good interpolated data: '); % bin indice where good interpolated data for the whole dataset start
disp('****')
bin_end = input('Determine last bin indice with good interpolated data: '); % bin indice where good interpolated data for the whole dataset start
data.uintfilt = uintfilt(bin_start:bin_end,:);
data.vintfilt = vintfilt(bin_start:bin_end,:);
if reply_ts == 1
data.tsintfilt = tsintfilt(bin_start:bin_end,:);
end
data.Z = Z(bin_start:bin_end);
data.inttim = inttim;
%save([fpath_output, mooring.name '_' num2str(adcp.sn) '_instr_' sprintf('%02d',instr) '_int_filt_sub.mat'],'adcp','mooring','data');
%% Figure
niv_u = (-1:0.05:1);
niv_v = (-1:0.05:1);
close all
hf=figure('position', [0, 0, 1400, 1000]);
%u
subplot(2,1,1);
colormap jet
[C,h] = contourf(inttim,Z(bin_start:bin_end),uintfilt(bin_start:bin_end,:),niv_u);
set(h,'LineColor','none');
caxis(niv_u([1 end]));
h=colorbar;
ylabel(h,'U [m s^-^1]');
set(gca,'ydir', 'reverse');
ylabel('Depth (m)');
ylim([0,round(max(Z))]);
%change figure label in HH:MM
gregtick;
if filt
title({['10W0N - ZONAL VELOCITY - RDI 150 kHz (filtered from tide)']});
else
title({[mooring.name, ' - ZONAL VELOCITY - RDI ',num2str(freq),' kHz']});
end
%v
subplot(2,1,2);
[C,h] = contourf(inttim,Z(bin_start:bin_end),vintfilt(bin_start:bin_end,:),niv_v);
set(h,'LineColor','none');
caxis(niv_v([1 end]));
h = colorbar;
ylabel(h,'V [m s^-^1]');
set(gca,'ydir', 'reverse');
ylabel('Depth (m)');
ylim([0,round(max(Z))]);
%change figure label in HH:MM
gregtick;
if filt
title({['10W0N - MERIDIONAL VELOCITY - RDI 150 kHz (filtered from tide)']});
else
title({[mooring.name, ' - MERIDIONAL VELOCITY - RDI ',num2str(freq),' kHz']});
end
graph_name = ['10W0N_nb150khz_U_V_int_filt_sub'];
set(hf,'Units','Inches');
pos = get(hf,'Position');
set(hf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]);
print(hf,graph_name,'-dpdf','-r300');
if reply_ts == 1
hf=figure('position', [0, 0, 1400, 500]);
colormap jet
pcolor(inttim,Z(bin_start:bin_end),tsintfilt(bin_start:bin_end,:)); shading interp;
h = colorbar;
ylabel(h,'Target Strength [dB1]');
set(gca,'ydir', 'reverse');
ylabel('Depth (m)');
ylim([0,round(max(Z))]);
%change figure label in HH:MM
gregtick;
if filt
title({[mooring.name, ' - TARGET STRENGTH - RDI ',num2str(freq),' kHz (filtered from tide)']});
else
title({[mooring.name, ' - TARGET STRENGTH - RDI ',num2str(freq),' kHz']});
end
graph_name = [fpath_output, mooring.name, '_nb150khz_TS_int_filt_sub'];
set(hf,'Units','Inches');
pos = get(hf,'Position');
set(hf,'PaperPositionMode','Auto','PaperUnits','Inches','PaperSize',[pos(3), pos(4)]);
saveas(hf,graph_name,'jpeg');
end
% %% Plot tide
% hf=figure('position', [0, 0, 1400, 1000]);
% niv_tide = (-5:0.2:5);
% utid_baro = utid_baro * 100;
% vtid_baro = vtid_baro * 100;
% %u
% subplot(2,1,1);
% colormap jet
% [C,h] = contourf(inttim,Z(bin_start:bin_end),utid_baro(bin_start:bin_end,:),niv_tide);
% set(h,'LineColor','none');
% caxis(niv_tide([1 end]));
% h=colorbar;
% ylabel(h,'U [cm s^-^1]');
% set(gca,'ydir', 'reverse');
% ylabel('Depth (m)');
% ylim([0,adcp.instr_depth]);
% %change figure label in HH:MM
% gregtick;
% title({[mooring.name, ' - ZONAL TIDE VELOCITY - RDI ',num2str(freq),' kHz']});
%
% %v
% subplot(2,1,2);
% [C,h] = contourf(inttim,Z(bin_start:bin_end),vtid_baro(bin_start:bin_end,:),niv_tide);
% set(h,'LineColor','none');
% caxis(niv_tide([1 end]));
% h = colorbar;
% ylabel(h,'V [cm s^-^1]');
% set(gca,'ydir', 'reverse');
% ylabel('Depth (m)');
% ylim([0,adcp.instr_depth]);
% %change figure label in HH:MM
% gregtick;
% title({[mooring.name, ' - MERIDIONAL TIDE VELOCITY - RDI ',num2str(freq),' kHz']});
%% Write netcdf file
disp('****')
disp('Creating .nc file')
[yr_start , ~, ~] = gregorian(inttim(1));
[yr_end, ~, ~] = gregorian(inttim(length(inttim)));
ncid = netcdf.create(['ADCP_10W0N_',num2str(yr_start),'_',num2str(yr_end),'_1d.nc'],'NC_WRITE');
%create dimension
dimidt = netcdf.defDim(ncid,'time',length(inttim));
dimidz = netcdf.defDim(ncid,'depth',length(data.Z));
%Define IDs for the dimension variables (pressure,time,latitude,...)
time_ID = netcdf.defVar(ncid,'time','double',dimidt);
depth_ID = netcdf.defVar(ncid,'depth','double',dimidz);
%Define the main variable ()
u_ID = netcdf.defVar(ncid,'u','double',[dimidt dimidz]);
v_ID = netcdf.defVar(ncid,'v','double',[dimidt dimidz]);
if reply_ts == 1
ts_ID = netcdf.defVar(ncid,'ts','double',[dimidt dimidz]);
end
%We are done defining the NetCdf
netcdf.endDef(ncid);
%Then store the dimension variables in
netcdf.putVar(ncid,time_ID,inttim);
netcdf.putVar(ncid,depth_ID,data.Z);
%Then store my main variable
netcdf.putVar(ncid,u_ID,data.uintfilt');
netcdf.putVar(ncid,v_ID,data.vintfilt');
if reply_ts == 1
netcdf.putVar(ncid,ts_ID,data.tsintfilt');
end
%We're done, close the netcdf
netcdf.close(ncid);
disp('****')
% -------------------------------------------------------------------------------------------
...@@ -16,21 +16,21 @@ addpath('/home/proussel/Documents/OUTILS/TOOLS/nansuite'); % NaNSuitePath ...@@ -16,21 +16,21 @@ addpath('/home/proussel/Documents/OUTILS/TOOLS/nansuite'); % NaNSuitePath
%% META information: %% META information:
% Location rawfile % Location rawfile
rawfile = 'IDMX2/_RDI_000.000'; % binary file with .000 extension rawfile = '_RDI_000.000'; % binary file with .000 extension
fpath_output = './IDMX2/'; % Output directory fpath_output = './10W/'; % Output directory
% Cruise/mooring info % Cruise/mooring info
cruise.name = 'INDOMIX'; % cruise name cruise.name = 'PIRATA'; % cruise name
mooring.name = '0N130E'; % '0N10W' mooring.name = '10W0N'; % '0N10W'
mooring.lat = '00°04.066'; % latitude [°'] mooring.lat = '00°00.000'; % latitude [°']
mooring.lon = '129°12.41'; % longitude [°'] mooring.lon = '-10°00.000'; % longitude [°']
clock_drift = 0; % [seconds] clock_drift = 0; % [seconds]
% ADCP info % ADCP info
adcp.sn = 13952; % ADCP serial number adcp.sn = 509; % ADCP serial number
adcp.type = '75 khz Quartermaster'; % Type : Quartermaster, longranger adcp.type = '150 khz Quartermaster'; % Type : Quartermaster, longranger
adcp.direction = 'up'; % upward-looking 'up', downward-looking 'dn' adcp.direction = 'up'; % upward-looking 'up', downward-looking 'dn'
adcp.instr_depth = 632; % nominal instrument depth adcp.instr_depth = 300; % nominal instrument depth
instr = 1; % this is just for name convention and sorting of all mooring instruments instr = 1; % this is just for name convention and sorting of all mooring instruments
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
...@@ -428,23 +428,45 @@ disp('Saving raw data') ...@@ -428,23 +428,45 @@ disp('Saving raw data')
save([fpath_output, mooring.name '_' num2str(adcp.sn) '_instr_' sprintf('%02d',instr) '.mat'],'adcp','mooring','data','-v7.3'); save([fpath_output, mooring.name '_' num2str(adcp.sn) '_instr_' sprintf('%02d',instr) '.mat'],'adcp','mooring','data','-v7.3');
%% Interpolate data on a regular vertical grid %% Interpolate data on a regular vertical grid
Z = fliplr(blen/2:blen:max(z(:))+blen); if strcmp(adcp.direction,'up')
Zmax = max(Z); Z = fliplr(blen/2:blen:max(z(:))+blen);
u_interp = NaN(length(time),length(Z)); Zmax = max(Z);
v_interp = NaN(length(time),length(Z)); u_interp = NaN(length(time),length(Z));
if reply_ts == 1 v_interp = NaN(length(time),length(Z));
ts_interp = NaN(length(time),length(Z)); if reply_ts == 1
end ts_interp = NaN(length(time),length(Z));
end
for i=1:length(time)
% indice correspondant sur la grille finale Z for i=1:length(time)
ind = round((Zmax-z(1,i))/blen)+1; % indice correspondant sur la grille finale Z
% filling the grid ind = round((Zmax-z(1,i))/blen)+1;
npts = min([length(Z)+ind+1 length(bin)]); % filling the grid
u_interp(i,ind:ind+npts-1) = u1(1:npts,i); npts = min([length(Z)+ind+1 length(bin)]);
v_interp(i,ind:ind+npts-1) = v1(1:npts,i); u_interp(i,ind:ind+npts-1) = u1(1:npts,i);
v_interp(i,ind:ind+npts-1) = v1(1:npts,i);
if reply_ts == 1
ts_interp(i,ind:ind+npts-1) = data.ts.ts(1:npts,i);
end
end
else
Z = (round(min(data.depth))+blen/2:blen:max(z(:))+blen);
Zmax = min(Z);
u_interp = NaN(length(time),length(Z));
v_interp = NaN(length(time),length(Z));
if reply_ts == 1 if reply_ts == 1
ts_interp(i,ind:ind+npts-1) = data.ts.ts(1:npts,i); ts_interp = NaN(length(time),length(Z));
end
for i=1:length(time)
% indice correspondant sur la grille finale Z
ind = -(round((Zmax-z(1,i))/blen)-1);
% filling the grid
npts = min([length(Z)-ind-1 length(bin)]);
u_interp(i,ind:ind+npts-1) = u1(1:npts,i);
v_interp(i,ind:ind+npts-1) = v1(1:npts,i);
if reply_ts == 1
ts_interp(i,ind:ind+npts-1) = data.ts.ts(1:npts,i);
end
end end
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment