Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 28d928a9 authored by gmorvan's avatar gmorvan
Browse files

Set of changes to deal with copernicus marine client / clean Forecasts_tools / typos

parent b3be7236
No related branches found
No related tags found
1 merge request!7First commits for the dev_newcopernicus branch
function mercator_name=download_mercator_frcst(lonmin,lonmax,latmin,latmax,...
FRCST_dir,FRCST_prefix,url,Yorig)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Extract a subgrid from ECCO to get a CROCO forcing
% Store that into monthly files.
% Take care of the Greenwitch Meridian.
%
%
% Further Information:
% http://www.croco-ocean.org
%
% This file is part of CROCOTOOLS
%
% CROCOTOOLS is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published
% by the Free Software Foundation; either version 2 of the License,
% or (at your option) any later version.
%
% CROCOTOOLS is distributed in the hope that it will be useful, but
% WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston,
% MA 02111-1307 USA
%
% Copyright (c) 2006 by Pierrick Penven
% e-mail:Pierrick.Penven@ird.fr
%
% Updated 8-Sep-2006 by Pierrick Penven
% Updated 20-Aug-2008 by Matthieu Caillaud & P. Marchesiello
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Get the date
%
l=1;
rundate_str=date;
rundate=datenum(rundate_str)-datenum(Yorig,1,1);
lh=5; % length of hindcast for mercator
lf=6; % length of forecast
%%% test if mercator forecast exist %%%
% mercator time is in julian hours since 1950
time=readdap(url,'time',[])/24;
time(1)
time=time+datenum(1950,1,1);
time(1)
time=time-datenum(Yorig,1,1);
time(1)
rundate
size(time)
stop
while l==1
try
x=find(time==rundate+lf);
foundtime=1;
catch
foundtime=0;
end
if foundtime==1 & ~isempty(x)
disp('time is ok')
else
foundtime=0;
disp('missing forecast')
end
if foundtime==0;
lf=lf-1;
l=1;
else
l=0;
end
end
for i=1:lh
time1(i)=datenum(rundate_str)-(lh+1-i);
end
time2=datenum(rundate_str);
for j=1:lf
time3(j)=datenum(rundate_str)+j;
end
if foundtime==0
time3=[time3 time3(end)];
end
time=cat(2,time1,time2,time3);
% Get time from Opendap
time2=readdap(url,'time',[])/24;
time2=time2+datenum(1950,1,1);
%time2=time2-datenum(Yorig,1,1);
% Get time index
for i=1:length(time)
tndx(i)=find(time2==time(i));
end
%
% start
%
disp([' '])
disp(['Get data for ',rundate_str])
disp(['Minimum Longitude: ',num2str(lonmin)])
disp(['Maximum Longitude: ',num2str(lonmax)])
disp(['Minimum Latitude: ',num2str(latmin)])
disp(['Maximum Latitude: ',num2str(latmax)])
disp([' '])
%
% Create the directory
%
disp(['Making output data directory ',FRCST_dir])
eval(['!mkdir ',FRCST_dir])
%
% Start
%
disp(['Process the dataset: ',url])
%
%
% test if the file exist
%
%
foundfile=0;
fname=url;
warning off
try
x=loaddap('-A -e +v ', fname);
foundfile=1;
catch
foundfile=0;
end
if foundfile==1 & ~isempty(x)
disp(' File found')
else
foundfile=0;
disp(' File does not exist')
end
warning on
%
%
%tindex=x.time.DODS_ML_Size;
%missval=x.ssh.missing_value; %PSY3V1
missval=x.ssh.ml__FillValue; %PSY3V2
% Get the time
%
trange=['[',num2str(min(tndx)-1),':',num2str(max(tndx)-1),']'];
fname=url;
%
%trange=['[',num2str(tindex-1),':',num2str(tindex-1),']'];
%time=readdap(fname,'time',trange);
%time=floor(time+datenum(1950,1,1));
%disp([' Date: ',datestr(time)])
%time=time-datenum(Yorig,1,1);
time=time2(tndx)-datenum(Yorig,1,1);
mercator_name=[FRCST_dir,FRCST_prefix,num2str(rundate),'.cdf'];
%
%if isempty(dir(mercator_name))
if ~exist(mercator_name)
%
%
% Get a subset of the ECCO grid
%
[i1min,i1max,i2min,i2max,i3min,i3max,...
i1min_u,i1max_u,i2min_u,i2max_u,i3min_u,i3max_u,...
jrange,jrange_v,krange,lon,lon_u,lat,lat_v,depth]=...
get_mercator_subgrid(url,lonmin,lonmax,latmin,latmax);
%
% Extract mercator
%
extract_mercator_frcst(FRCST_dir,FRCST_prefix,url,tndx,missval,...
lon,lon_u,lat,lat_v,depth,...
krange,jrange,jrange_v,...
i1min,i1max,i2min,i2max,i3min,i3max,...
i1min_u,i1max_u,i2min_u,i2max_u,i3min_u,i3max_u,...
time,Yorig)
else
disp(' mercator file allready exist')
end
return
function mercator_name=download_mercator_frcst_python(pathCMC,user,password,mercator_type, ...
product_id, ...
lh,lf, ...
lonmin,lonmax,latmin,latmax,zmax, ...
FRCST_dir,FRCST_prefix,raw_mercator_name,Yorig)
function download_mercator_frcst_python(pathCMC,user,password,mercator_type, ...
raw_mercator_name,product_id, ...
lh,lf, ...
lonmin,lonmax,latmin,latmax,zmax, ...
FRCST_dir,FRCST_prefix,mercator_name,Yorig)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Extract a subgrid from mercator to get a CROCO forcing
% Store that into monthly files.
......@@ -42,23 +42,15 @@ download_raw_data=1;
convert_raw2crocotools=1; % convert -> crocotools format data
%
disp(['Making output data directory ',FRCST_dir]) % create directory
eval(['!mkdir ',FRCST_dir])
eval(['!mkdir ',FRCST_dir, ' 2> /dev/null'])
%
% Set variable names according to mercator type data
%
if mercator_type==1,
vars = {'zos' ...
'uo' ...
'vo' ...
'thetao' ...
'so'};
else
vars = {'zos_detided' ...
'uo' ...
'vo' ...
'thetao' ...
'so'};
end
vars = {'zos' ...
'uo' ...
'vo' ...
'thetao' ...
'so'};
%
% Get dates
%
......@@ -66,23 +58,25 @@ rundate_str=date;
rundate=datenum(rundate_str)-datenum(Yorig,1,1);
for i=1:lh+1
time1(i)=datenum(rundate_str)-(lh+2-i);
time1(i)=datenum(rundate_str)-(lh+1-i);
end
time2=datenum(rundate_str);
for j=1:lf+1
time3(j)=datenum(rundate_str)+j;
time3(j)=datenum(rundate_str)+j-2;
end
time=cat(2,time1,time2,time3);
tiempo_inicial = time1(1);
tiempo_inicial_p0 = time1(1+lh);
tiempo_final = time3(end);
%
if (lonmin > 180)
lonmin = lonmin - 360;
end
if (lonmax > 180)
lonmax = lonmax - 360;
end
%
disp([' '])
disp(['Get data for ',rundate_str])
disp(['Minimum Longitude: ',num2str(lonmin)])
disp(['Maximum Longitude: ',num2str(lonmax)])
disp(['Minimum Latitude: ',num2str(latmin)])
......@@ -91,8 +85,15 @@ disp([' '])
if download_raw_data
%
% Get data (now in 4 different files)
get_file_python_mercator(pathCMC,mercator_type, ... %SSH
disp(['--> Extraction Forecasts from operational date run : ', datestr(tiempo_inicial_p0,'yyyy-mm-dd')])
for i=1:lh
disp(['Get Hindcasts : ',datestr(time(i),'yyyy-mm-dd')])
end
disp(['Get ',num2str(lf),' Forecasts : from ',datestr(tiempo_inicial_p0,'yyyy-mm-dd'),' to ',datestr(tiempo_final, 'yyyy-mm-dd')])
%
%
% Get data (now splitted in 4 different files)
get_file_python_mercator(pathCMC,mercator_type, ... % SSH
product_id{1}, ...
vars(1), ...
[lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
......@@ -101,7 +102,7 @@ if download_raw_data
{user password}, ...
[raw_mercator_name(1:end-3),'_z.nc']);
get_file_python_mercator(pathCMC,mercator_type, ... %U, V
get_file_python_mercator(pathCMC,mercator_type, ... % U/V
product_id{2}, ...
vars(2:3), ...
[lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
......@@ -135,12 +136,11 @@ if convert_raw2crocotools
% Convert data format and write in a more CROCOTOOLS
% compatible input file
%
mercator_name=[FRCST_dir,FRCST_prefix,num2str(rundate),'.cdf'];
if exist(mercator_name)
disp('Mercator file already exist => overwrite it')
end
write_mercator_frcst(FRCST_dir,FRCST_prefix,raw_mercator_name, ...
mercator_type,vars,time,Yorig); % write data
mercator_type,mercator_name,vars,time,Yorig); % write data
eval(['! rm -f ',[raw_mercator_name(1:end-3),'*nc '] ]);
end
......
......@@ -50,6 +50,20 @@ makeplot = 0;
%
rundate_str=date;
rundate=datenum(rundate_str)-datenum(Yorig,1,1);
rundate0=rundate;
if strcmp(OGCM,'mercator')
for i=1:hdays+1
time1(i)=datenum(rundate_str)-(hdays+1-i);
end
rundate=datestr(time1(1+hdays),'yyyy-mm-ddT00:00:00Z');
if hdays ~= 0
% date_deb = rundate - hindcast days : example 2024-02-28T00:00:00Z-PT2D
% for a validity date 2 days before run 20240228 00hUTC ...
date_deb=strcat(datestr(time1(1+hdays),'yyyy-mm-ddT00:00:00') ,['-PT',num2str(hdays),'D']);
else
date_deb=rundate;
end
end
%
% Set generic OGCM file name
%
......@@ -60,7 +74,7 @@ if strcmp(OGCM,'ECCO')
%
% ECCO DODS URL
%
% Kalman filter
% Kalman filter
%
url = 'http://ecco.jpl.nasa.gov/thredds/dodsC/las/kf080/kf080_';
%
......@@ -69,6 +83,7 @@ elseif strcmp(OGCM,'mercator')
% MERCATOR : see get_file_python_mercator.m
%
raw_mercator_name=[FRCST_dir,'raw_motu_mercator_',num2str(rundate),'.nc'];
mercator_name=[FRCST_dir,FRCST_prefix,num2str(rundate),'.cdf'];
else
error(['Unknown OGCM: ',OGCM])
end
......@@ -117,21 +132,16 @@ if Download_data
elseif strcmp(OGCM,'mercator')
%
% Use Motu python
% Use of Copernicusmarine client (python)
% -> script download_mercator_frcst_python.m
%
disp('Download data...')
% eval(['OGCM_name=download_', ...
% OGCM,'_frcst_python(pathMotu,user,password,mercator_type,', ...
% 'motu_url_fcst,service_id_fcst,product_id_fcst,', ...
% 'hdays,fdays,', ...
% 'lonmin,lonmax,latmin,latmax,hmax,', ...
% 'FRCST_dir,FRCST_prefix,raw_mercator_name,Yorig);'])
eval(['OGCM_name=download_', ...
eval(['download_', ...
OGCM,'_frcst_python(pathCMC,user,password,mercator_type,', ...
'product_id_fcst,', ...
'raw_mercator_name,product_id,', ...
'hdays,fdays,', ...
'lonmin,lonmax,latmin,latmax,hmax,', ...
'FRCST_dir,FRCST_prefix,raw_mercator_name,Yorig);'])
'FRCST_dir,FRCST_prefix,mercator_name,Yorig);'])
end
end
......@@ -173,11 +183,12 @@ close(nc)
% Initial file
%---------------------------------------------------------------
if makeini==1
ininame=[ini_prefix,num2str(rundate),nc_suffix];
disp(['Create an initial file for ',num2str(rundate);])
%
ininame=[ini_prefix,num2str(date_deb),nc_suffix];
disp(['-> Create an initial file for date ',num2str(date_deb);])
create_inifile(ininame,grdname,CROCO_title,...
theta_s,theta_b,hc,N,...
rundate-hdays,'clobber',vtransform); % starts at 00:00
rundate0-hdays,'clobber',vtransform); % starts at 00:00
nc_ini=netcdf(ininame,'write');
interp_OGCM_frcst(OGCM_name,Roa,interp_method,...
......@@ -185,10 +196,12 @@ if makeini==1
nc_ini,[],lon,lat,angle,h,pm,pn,rmask,...
1,vtransform,obc)
close(nc_ini)
if (isoctave == 0)
eval(['!cp ',ininame,' ',ini_prefix,'hct',nc_suffix])
else
eval(['cp ',ininame,' ',ini_prefix,'hct',nc_suffix])
if hdays ~= 0
if (isoctave == 0)
eval(['!cp ',ininame,' ',ini_prefix,'hct_',num2str(date_deb),nc_suffix])
else
eval(['cp ',ininame,' ',ini_prefix,'hct_',num2str(date_deb),nc_suffix])
end
end
end
......@@ -197,8 +210,10 @@ end
%---------------------------------------------------------------
if makeclim==1 | makebry==1
if makebry==1
bryname=[bry_prefix,num2str(rundate),nc_suffix];
create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
bryname=[bry_prefix,num2str(date_deb),nc_suffix];
disp([' '])
disp(['-> Create bry files from ',num2str(date_deb);])
create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
theta_s,theta_b,hc,N,...
time,time_cycle,'clobber',vtransform);
nc_bry=netcdf(bryname,'write');
......@@ -206,8 +221,9 @@ if makeclim==1 | makebry==1
nc_bry=[];
end
if makeclim==1
clmname=[clm_prefix,num2str(rundate),nc_suffix];
create_climfile(clmname,grdname,CROCO_title,...
clmname=[clm_prefix,num2str(date_deb),nc_suffix];
disp(['-> Create clim files from ',num2str(date_deb);])
create_climfile(clmname,grdname,CROCO_title,...
theta_s,theta_b,hc,N,...
time,time_cycle,'clobber',vtransform);
nc_clm=netcdf(clmname,'write');
......@@ -244,21 +260,21 @@ if makeplot==1
disp(' ')
disp(' Make a few plots...')
if makeini==1
ininame=[ini_prefix,num2str(rundate),nc_suffix];
ininame=[ini_prefix,num2str(date_deb),nc_suffix];
figure
test_clim(ininame,grdname,'temp',1,coastfileplot)
figure
test_clim(ininame,grdname,'salt',1,coastfileplot)
end
if makeclim==1
clmname=[clm_prefix,num2str(rundate),nc_suffix];
clmname=[clm_prefix,num2str(date_deb),nc_suffix];
figure
test_clim(clmname,grdname,'temp',1,coastfileplot)
figure
test_clim(clmname,grdname,'salt',1,coastfileplot)
end
if makebry==1
bryname=[bry_prefix,num2str(rundate),nc_suffix];
bryname=[bry_prefix,num2str(date_deb),nc_suffix];
figure
test_bry(bryname,grdname,'temp',1,obc)
figure
......
function write_mercator_frcst(FRCST_dir,FRCST_prefix,raw_mercator_name,...
mercator_type,vars,time,Yorig)
mercator_type, mercator_name,vars,time,Yorig)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Extract a subset from Marcator using python motu client (cls)
......@@ -34,7 +34,8 @@ function write_mercator_frcst(FRCST_dir,FRCST_prefix,raw_mercator_name,...
% Updated 06-May-2023 by Efrain Rodriguez-Rubio & P. Marchesiello
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
disp([' writing MERCATOR file'])
disp([' '])
disp([' Writing MERCATOR file'])
fname_z=[raw_mercator_name(1:end-3),'_z.nc'];
fname_u=[raw_mercator_name(1:end-3),'_u.nc'];
......@@ -45,24 +46,15 @@ fname_s=[raw_mercator_name(1:end-3),'_s.nc'];
% Get grid and time frame
%
nc = netcdf(fname_u,'r');
if mercator_type==1,
lon = nc{'longitude'}(:);
lat = nc{'latitude'}(:);
depth = nc{'depth'}(:);
time = nc{'time'}(:);
time = time / 24 + datenum(1950,1,1) - datenum(Yorig,1,1);
else
lon = nc{'lon'}(:);
lat = nc{'lat'}(:);
depth = nc{'depth'}(:);
time = nc{'time'}(:);
time = time / 86400 + datenum(2014,1,9) - datenum(Yorig,1,1);
end
lon = nc{'longitude'}(:);
lat = nc{'latitude'}(:);
depth = nc{'depth'}(:);
time = nc{'time'}(:);
time = time / 24 + datenum(1950,1,1) - datenum(Yorig,1,1);
close(nc)
%
% Get SSH
%
%missval = -32767;
disp(' ...SSH')
nc = netcdf(fname_z,'r');
vname=sprintf('%s',vars{1});
......@@ -114,9 +106,8 @@ temp=ncc(:);
missval=ncc.FillValue_(:);
scale_factor=1; %ncc.scale_factor(:);
add_offset=0.; %ncc.add_offset(:);
ktoc=272.15;
temp(temp>=missval)=NaN;
temp = temp.*scale_factor + add_offset; % - ktoc;
temp = temp.*scale_factor + add_offset;
close(nc)
%
% Get SALT
......@@ -135,10 +126,7 @@ close(nc)
%
% Create the Mercator file
%
rundate_str=date;
rundate=datenum(rundate_str)-datenum(Yorig,1,1);
create_OGCM([FRCST_dir,FRCST_prefix,num2str(rundate),'.cdf'],...
create_OGCM( mercator_name,...
lon,lat,lon,lat,lon,lat,depth,time,...
squeeze(temp),squeeze(salt),squeeze(u),...
squeeze(v),squeeze(ssh),Yorig)
......
......@@ -2,14 +2,33 @@
The Copernicus Marine Toolbox is used to download and extract data from the Copernicus Marine Data Store (Global Ocean Physics Reanalysis, Global Ocean Physics Analysis and Forecast, ...) to create oceanic open boundary and initial conditions. [ https://data.marine.copernicus.eu/products ]
All the instruction can be found here https://help.marine.copernicus.eu/en/collections/4060068-copernicus-marine-toolbox. It require to install a dedicated conda env, by default named cmt_1.0.
Note that you can use micromamba instead of mamba to install the python environement.
To use it , you need to activate the cmt_1.0 : `mamba activate cmt_1.0`
All the instructions can be found here :
* 1) https://help.marine.copernicus.eu/en/collections/4060068-copernicus-marine-toolbox
* 2) https://help.marine.copernicus.eu/en/articles/7970514-copernicus-marine-toolbox-installation
Prerequisites :
* install Miniforge3, for instance:
> wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh")
> sh Miniforge3-Linux-x86_64.sh -b -p "$HOME/miniforge/"
> source $HOME/miniforge/etc/profile.d/conda.sh
> source $HOME/miniforge/etc/profile.d/mamba.sh
* install a dedicated mamba env, by default named cmt_1.0 (download copernicusmarine_env.yml See Instructions on 2))
> mamba env create -f copernicusmarine_env.yml
Note that you can use micromamba instead of mamba to install the python environment
* python version >= 3.9 & <=3.12 required
To use it, you need to activate the cmt_1.0 :
> mamba activate cmt_1.0
You will have access to the copernicusmarine executable with various sub-command, very useful to get, extract and download data from the Copernicus Marine Data Store.
> copernicusmarine -h
You will have access to the copernicusmarine executable with various sub-command, very useful to get, extract and download data from the Copernicus Marine Data Store.
To be used in the Matlab croco_tools, in the crocotools_param.m, you need to :
- define the path to the copernicusmarine executable (`pathCMS`) in crocotools_param.m at *section 7, Option for make_OGCM or make_OGCM_mercator*
- define your copernicus marine `login` and `password` in crocotools_param.m at *section 7, Options for for make_OGCM or make_OGCM_mercator*
- define the path to the copernicusmarine executable (`pathCMC`) in crocotools_param.m at *section 7, Option for make_OGCM_frcst or make_OGCM_mercator*
- define your copernicus marine `login` and `password` in crocotools_param.m at *section 7, Options for for make_OGCM_frcst or make_OGCM_mercator*
......@@ -59,7 +59,7 @@ disp([' '])
% Create the directory
%
disp(['Making output data directory ',OGCM_dir])
eval(['!mkdir ',OGCM_dir])
eval(['!mkdir ',OGCM_dir, ' 2> /dev/null'])
%
% Get files and dates
......@@ -68,7 +68,6 @@ eval(['!mkdir ',OGCM_dir])
time1=datenum(Y,M,01);
time2=datenum(Y,M+1,01) - 1;
%time2=datenum(Y,M,02); %for debug
%e debug
time=cat(2,time1,time2);
tiempo_inicial = time(1);
tiempo_final = time(end);
......@@ -84,7 +83,8 @@ raw_mercator_name=[OGCM_dir,'raw_motu_',OGCM_prefix,thedatemonth,'.nc'];
if download_raw_data
%
% Get data
get_file_python_mercator(pathCMC,mercator_type, ...
if mercator_type==1
get_file_python_mercator(pathCMC,mercator_type, ...
product_id, ...
vars, ...
[lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
......@@ -92,6 +92,47 @@ if download_raw_data
datestr(tiempo_final, 'yyyy-mm-dd')}, ...
{user password}, ...
raw_mercator_name);
elseif mercator_type==2
%zos
get_file_python_mercator(pathCMC,mercator_type, ...
product_id{1}, ...
vars{1}, ...
[lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
{datestr(tiempo_inicial,'yyyy-mm-dd') ...
datestr(tiempo_final, 'yyyy-mm-dd')}, ...
{user password}, ...
[raw_mercator_name(1:end-3),'_z.nc']);
%uo/vo
get_file_python_mercator(pathCMC,mercator_type, ...
product_id{2}, ...
{vars{2:3}}, ...
[lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
{datestr(tiempo_inicial,'yyyy-mm-dd') ...
datestr(tiempo_final, 'yyyy-mm-dd')}, ...
{user password}, ...
[raw_mercator_name(1:end-3),'_u.nc']);
%thetao
get_file_python_mercator(pathCMC,mercator_type, ...
product_id{3}, ...
vars{4}, ...
[lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
{datestr(tiempo_inicial,'yyyy-mm-dd') ...
datestr(tiempo_final, 'yyyy-mm-dd')}, ...
{user password}, ...
[raw_mercator_name(1:end-3),'_t.nc']);
%so
get_file_python_mercator(pathCMC,mercator_type, ...
product_id{4}, ...
vars{5}, ...
[lonmin-1 lonmax+1 latmin-1 latmax+1 0 zmax], ...
{datestr(tiempo_inicial,'yyyy-mm-dd') ...
datestr(tiempo_final, 'yyyy-mm-dd')}, ...
{user password}, ...
[raw_mercator_name(1:end-3),'_s.nc']);
end
end %end download_raw_data
......@@ -105,9 +146,17 @@ if convert_raw2crocotools
if exist(mercator_name)
disp('Mercator file already exist => overwrite it')
end
write_mercator(OGCM_dir,OGCM_prefix,raw_mercator_name, ...
mercator_type,vars,time,thedatemonth,Yorig); % write data
eval(['! rm -f ',raw_mercator_name]);
if mercator_type==1
write_mercator(OGCM_dir,OGCM_prefix,raw_mercator_name, ...
mercator_type,vars,time,thedatemonth,Yorig); % write data
eval(['! rm -f ',raw_mercator_name]);
elseif mercator_type==2
write_mercator_multi(OGCM_dir,OGCM_prefix,raw_mercator_name, ...
mercator_type,vars,time,thedatemonth,Yorig); % write data
eval(['! rm -f ',raw_mercator_name(1:end-3),'*.nc']);
end
end
end
......
......@@ -40,25 +40,30 @@ function outname = get_file_python_mercator(pathCMC,...
% => https://help.marine.copernicus.eu/en/collections/4060068-copernicus-marine-toolbox
% => https://help.marine.copernicus.eu/en/articles/8206131-how-to-download-a-copernicus-marine-toolbox-request-in-matlab
%
eval(['! rm ',outname])
command = {sprintf('%s',pathCMC)
sprintf(' subset')
sprintf(' --username %s --password %s',info{1},info{2})
sprintf(' -i %s',product_id)
sprintf(' -t %s -T %s',['"',date{1},'"'],['"',date{2},'"'])
sprintf(' -x %f -X %f',geom(1),geom(2))
sprintf(' -y %f -Y %f',geom(3),geom(4))
sprintf(' -z %f -Z %f',geom(5),geom(6))
sprintf(' -o ./')
sprintf(' -f %s',outname)
sprintf(' --force-download')};
eval(['! rm -f ',outname])
disp([' '])
disp(['Extraction of product: ', product_id])
disp([' '])
command = { sprintf('export PYTHONWARNINGS="ignore"; ')
sprintf('%s',pathCMC)
sprintf(' subset')
sprintf(' --username %s --password %s',info{1},info{2})
sprintf(' -i %s',product_id)
sprintf(' -t %s -T %s',['"',date{1},'"'],['"',date{2},'"'])
sprintf(' -x %f -X %f',geom(1),geom(2))
sprintf(' -y %f -Y %f',geom(3),geom(4))
sprintf(' -z %f -Z %f',geom(5),geom(6))
sprintf(' -o ./')
sprintf(' -f %s',outname)
sprintf(' --force-download')};
for k =1:length(vars)
if isa(vars,'cell')
for k =1:size(vars,2)
command{end+1}=sprintf(' -v %s',vars{k});
end
end
disp([command{:}])
system([command{:}]);
end
......@@ -109,10 +109,9 @@ if Download_data==1
mo_max=12;
end
for M=mo_min:mo_max
%motu_url_reana
thedatemonth=['Y',num2str(Y),'M',num2str(M)];
download_mercator_python(pathCMC,user,password,1,...
product_id_reana, ...
download_mercator_python(pathCMC,user,password,mercator_type,...
product_id, ...
Y,M, ...
lonmin,lonmax,latmin,latmax,hmax, ...
OGCM_dir,OGCM_prefix,thedatemonth,Yorig)
......@@ -154,7 +153,8 @@ if makeini==1
% Process the time in Yorig time (i.e days since Yorig-01-01)
%
tini=datenum(Ymin,Mmin,1)-datenum(Yorig,1,1);
disp(['Create an initial file for ',datestr(tini+datenum(Yorig,1,1));])
disp([' '])
disp(['=> Create an initial file for ',datestr(tini+datenum(Yorig,1,1));])
create_inifile(ininame,grdname,CROCO_title,...
theta_s,theta_b,hc,N,...
tini,'clobber', vtransform);
......@@ -211,10 +211,10 @@ if makeclim==1 | makebry==1
OGCM_time=nc{'time'}(:);
ntimes=length(OGCM_time);
if ntimes==1
dt=30; % monthly files (SODA..)
dt=30; % monthly files
itolap_a=1; itolap_p=1;
itolap_tot=itolap_a + itolap_p;
disp(['Reduced overlap for monthly SODA files'])
disp(['Reduced overlap for monthly files'])
disp(['...'])
else
dt=max(gradient(OGCM_time));
......@@ -254,6 +254,8 @@ if makeclim==1 | makebry==1
if makebry==1
bryname=[bry_prefix,'Y',num2str(Y),...
'M',num2str(sprintf(Mth_format,M)),nc_suffix];
disp([' '])
disp(['=> Create bry file : ', bryname ])
create_bryfile(bryname,grdname,CROCO_title,[1 1 1 1],...
theta_s,theta_b,hc,N,...
croco_time,0,'clobber',vtransform);
......
......@@ -40,13 +40,11 @@ disp([' writing MERCATOR file'])
% Get grid and time frame
%
nc = netcdf(raw_mercator_name);
if mercator_type==1,
lon = nc{'longitude'}(:);
lat = nc{'latitude'}(:);
depth = nc{'depth'}(:);
time = nc{'time'}(:);
time = time / 24 + datenum(1950,1,1) - datenum(Yorig,1,1);
end
lon = nc{'longitude'}(:);
lat = nc{'latitude'}(:);
depth = nc{'depth'}(:);
time = nc{'time'}(:);
time = time / 24 + datenum(1950,1,1) - datenum(Yorig,1,1);
%
% Get SSH
%
......@@ -95,9 +93,8 @@ temp=ncc(:);
missval=ncc.FillValue_(:);
scale_factor=ncc.scale_factor(:);
add_offset=ncc.add_offset(:);
ktoc=272.15;
temp(temp<=missval)=NaN;
temp = temp.*scale_factor + add_offset; % - ktoc;
temp = temp.*scale_factor + add_offset;
%
% Get SALT
%
......
function extract_mercator_frcst(FRCST_dir,FRCST_prefix,url,tndx,missval,...
lon,lon_u,lat,lat_v,depth,...
krange,jrange,jrange_v,...
i1min,i1max,i2min,i2max,i3min,i3max,...
i1min_u,i1max_u,i2min_u,i2max_u,i3min_u,i3max_u,...
time,Yorig)
function write_mercator_multi(OGCM_dir,OGCM_prefix,raw_mercator_name,...
mercator_type,vars,time,thedatemonth,Yorig)
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Extract a subset from Mercator using DODS
% Write it in a local file (keeping the classic
% SODA netcdf format)
%
% Extract a subset from Mercator in the case of
% using python
% Write mercator multi files for analysis and forecast
%
% Further Information:
% http://www.croco-ocean.org
......@@ -35,82 +30,122 @@ function extract_mercator_frcst(FRCST_dir,FRCST_prefix,url,tndx,missval,...
% e-mail:Pierrick.Penven@ird.fr
%
% Updated 9-Sep-2006 by Pierrick Penven
% Updated 19-May-2011 by Andres Sepulveda & Gildas Cambon
% Updated 12-Feb-2016 by P. Marchesiello
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
disp([' Download MERCATOR'])
trange=['[',num2str(min(tndx)-1),':',num2str(max(tndx)-1),']'];
%trange=['[',num2str(tindex-1),':',num2str(tindex-1),']'];
disp([' writing MERCATOR multifiles '])
fname_z=[raw_mercator_name(1:end-3),'_z.nc'];
fname_u=[raw_mercator_name(1:end-3),'_u.nc'];
fname_t=[raw_mercator_name(1:end-3),'_t.nc'];
fname_s=[raw_mercator_name(1:end-3),'_s.nc'];
%
% Get the time
% Get grid and time frame
%
%vname='Have';
%fname=[prefix,vname,suffix];
%time=readdap(fname,'time',trange)
%time=floor(time/24+datenum(1970,1,1));
%disp([' Date: ',datestr(time)])
%time=time-datenum(Yorig,1,1)
nc = netcdf(fname_u);
lon = nc{'longitude'}(:);
lat = nc{'latitude'}(:);
depth = nc{'depth'}(:);
time = nc{'time'}(:);
time = time / 24 + datenum(1950,1,1) - datenum(Yorig,1,1);
%
% Get SSH
%
disp(' ...SSH')
vname='ssh';
fname='';
ssh=getdap(url,fname,vname,...
trange,'',jrange,...
i1min,i1max,i2min,i2max,i3min,i3max);
ssh=shiftdim(ssh,2);
nc = netcdf(fname_z,'r');
vname=sprintf('%s',vars{1});
ncc=nc{vname};
ssh=ncc(:);
missval=ncc.FillValue_(:);
scale_factor=1;
add_offset=0;
ssh(ssh>=missval)=NaN;
%scale_factor=ncc.scale_factor(:);
%add_offset=ncc.add_offset(:);
%ssh(ssh<=missval)=NaN;
ssh = ssh.*scale_factor + add_offset;
close(nc) % close raw_mercator_name
%
%
% Get U
%
disp(' ...U')
vname='u';
u=getdap(url,fname,vname,...
trange,krange,jrange,...
i1min_u,i1max_u,i2min_u,i2max_u,i3min_u,i3max_u);
u=permute(u,[4 3 1 2]);
nc = netcdf(fname_u,'r');
vname=sprintf('%s',vars{2});
ncc=nc{vname};
u=ncc(:);
missval=ncc.FillValue_(:);
scale_factor=1;
add_offset=0;
u(u>=missval)=NaN;
%scale_factor=ncc.scale_factor(:);
%add_offset=ncc.add_offset(:);
%u(u<=missval)=NaN;
u = u.*scale_factor + add_offset;
close(nc) % close raw_mercator_name
%
% Get V
%
disp(' ...V')
vname='v';
v=getdap(url,fname,vname,...
trange,krange,jrange_v,...
i1min,i1max,i2min,i2max,i3min,i3max);
v=permute(v,[4 3 1 2]);
nc = netcdf(fname_u,'r');
vname=sprintf('%s',vars{3});
ncc=nc{vname};
v=ncc(:);
missval=ncc.FillValue_(:);
scale_factor=1;
add_offset=0;
v(v>=missval)=NaN;
%scale_factor=ncc.scale_factor(:);
%add_offset=ncc.add_offset(:);
%v(v<=missval)=NaN;
v = v.*scale_factor + add_offset;
close(nc) % close raw_mercator_name
%
% Get TEMP
%
disp(' ...TEMP')
vname='temperature';
temp=getdap(url,fname,vname,...
trange,krange,jrange,...
i1min,i1max,i2min,i2max,i3min,i3max);
temp=permute(temp,[4 3 1 2]);
nc = netcdf(fname_t,'r');
vname=sprintf('%s',vars{4});
ncc=nc{vname};
temp=ncc(:);
missval=ncc.FillValue_(:);
scale_factor=1;
add_offset=0;
temp(temp>=missval)=NaN;
%scale_factor=ncc.scale_factor(:);
%add_offset=ncc.add_offset(:);
%temp(temp<=missval)=NaN;
temp = temp.*scale_factor + add_offset;
close(nc) % close raw_mercator_name
%
% Get SALT
%
disp(' ...SALT')
vname='salinity';
salt=getdap(url,fname,vname,...
trange,krange,jrange,...
i1min,i1max,i2min,i2max,i3min,i3max);
salt=permute(salt,[4 3 1 2]);
nc = netcdf(fname_s,'r');
vname=sprintf('%s',vars{5});
ncc=nc{vname};
salt=ncc(:);
missval=ncc.FillValue_(:);
scale_factor=1;
add_offset=0;
salt(salt>=missval)=NaN;
%scale_factor=ncc.scale_factor(:);
%add_offset=ncc.add_offset(:);
%salt(salt<=missval)=NaN;
salt = salt.*scale_factor + add_offset;
close(nc) % close raw_mercator_name
%
% Create the Mercator file
%
% Create the ECCO file
rundate_str=date;
rundate=datenum(rundate_str)-datenum(Yorig,1,1);
create_OGCM([FRCST_dir,FRCST_prefix,num2str(rundate),'.cdf'],...
lon,lat,lon_u,lat,lon,lat_v,depth,time,...
create_OGCM([OGCM_dir,OGCM_prefix,thedatemonth,'.cdf'],...
lon,lat,lon,lat,lon,lat,depth,time,...
squeeze(temp),squeeze(salt),squeeze(u),...
squeeze(v),squeeze(ssh),Yorig)
%
return
end
......@@ -353,7 +353,7 @@ Download_data = 1; % Get data from OPENDAP sites
level = 0; % AGRIF level; 0 = parent grid
%
NCEP_version = 3; % NCEP version:
% [ CFSR up-to-date product are recommandated ]
% [ CFSR up-to-date product are recommended ]
% 1: NCEP/NCAR Reanalysis, 1/1/1948 - present
% 2: NCEP-DOE Reanalysis, 1/1/1979 - present
% 3: CFSR (Climate Forecast System Reanalysis),
......@@ -429,28 +429,62 @@ clm_prefix = [CROCO_files_dir,'croco_clm_',OGCM,'_']; % generic climatology
ini_prefix = [CROCO_files_dir,'croco_ini_',OGCM,'_']; % generic initial file name
OGCM_prefix = [OGCM,'_']; % generic OGCM file name
% MERCATOR cases:
% =============
mercator_type=1; % 1 --> 1/12 deg Mercator global reanalysis (1993 -> 202101)
% 2 --> 1/12 deg Mercator global analysis (202011 -> )
% (now -> 10days : P1-P10)
% (now -1day : P0)
% (7days from now -> now-1day : Near Real Time analysis)
% (more than 15days from now : Best analysis)
% 3 --> 1/12 deg Mercator global forecast (See Section 8.)
% (daily forecast from 00h UTC up to 10 days,
% updated daily at 12h UTC)
% 4 --> 1/24 deg Mercator Mediterranean analysis/forecast (See Section 8.)
% (daily forecast from 00h UTC up to 10 days,
% updated daily at 16h UTC)
% =============
% To download CMEMS data: set login/password (http://marine.copernicus.eu)
% and path to copernicusmarine executable
% see Oforc_OGCM/Copernicus_Marine_Toolbox_installation.md
%
% Various sets of data are proposed in the Copernicus web site
%
if strcmp(OGCM,'mercator')
%
pathCMC='/path/to/home/copernicusmarine'; % copernicusmarine client
%
user = 'XXXX';
password = 'XXXX';
%
if mercator_type==1
% ========================
% For GLORYS 12 reanalysis extraction + download using python motuclient
% For GLORYS 12 reanalysis extraction
% ========================
% To download CMEMS data: set login/password (http://marine.copernicus.eu) and path to copernicusmarine executable
% see Oforc_OGCM/Copernicus_Marine_Toolbox_installation.md
pathCMC = '/path/to/home/copernicusmarine';
%
user = 'XXXX';
password = 'XXXX';
%
raw_mercator_name = 'mercator';
kdata='MONTHLY' ; % or DAILY
service_id_reana='GLOBAL_MULTIYEAR_PHY_001_030-TDS';
if strcmp(kdata,'DAILY')
product_id_reana='cmems_mod_glo_phy_my_0.083_P1D-m';
elseif strcmp(kdata,'MONTHLY')
product_id_reana='cmems_mod_glo_phy_my_0.083_P1M-m'
kdata='MONTHLY' ; % DAILY or MONTHLY
if strcmp(kdata,"DAILY")
product_id='cmems_mod_glo_phy_my_0.083_P1D-m';
elseif strcmp(kdata,"MONTHLY")
product_id='cmems_mod_glo_phy_my_0.083_P1M-m';
else
disp('Please specify what reanalysis frequency you want (DAILY or MONTHLY)')
disp("Please specify what kind of data you want (DAILY or MONTHLY)")
end
elseif mercator_type==2
% ========================
% 2 -> For analysis PSY4
% ========================
product_id={'cmems_mod_glo_phy_anfc_0.083deg_P1D-m' ...
'cmems_mod_glo_phy-cur_anfc_0.083deg_P1D-m', ...
'cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m', ...
'cmems_mod_glo_phy-so_anfc_0.083deg_P1D-m'};
%
else
disp('Not a mercator_type value known ...')
disp([' '])
end
%
end
%
% Number of OGCM bottom levels to remove
......@@ -485,14 +519,14 @@ wkb_obc= [1 1 1 1];
%
FRCST_dir = [FORC_DATA_DIR,'Forecast/']; % path to local OGCM data directory
%
% Number of hindcast/forecast days
% Number of hindcast / forecast days
%
if strcmp(OGCM,'ECCO')
hdays=1;
fdays=6;
elseif strcmp(OGCM,'mercator')
hdays=1;
fdays=3;
fdays=10;
end
%
% Local time= UTC + timezone
......@@ -503,25 +537,31 @@ timezone = +2;
%
add_tides_fcst = 1; % 1: add tides
%
% MERCATOR case:
% MERCATOR cases:
% =============
%
% Various sets of data are proposed in the Copernicus web site
%
if strcmp(OGCM,'mercator')
if mercator_type==3
% ========================
% 3 -> For Global Forecast PSY4
% ========================
product_id={'cmems_mod_glo_phy_anfc_0.083deg_P1D-m' ...
'cmems_mod_glo_phy-cur_anfc_0.083deg_P1D-m', ...
'cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m', ...
'cmems_mod_glo_phy-so_anfc_0.083deg_P1D-m'};
elseif mercator_type==4
% ========================
% 4 -> For Mediterannean Forecast PSY4 4.2km
% ========================
product_id={'cmems_mod_med_phy-ssh_anfc_4.2km_P1D-m', ...
'cmems_mod_med_phy-cur_anfc_4.2km_P1D-m', ...
'cmems_mod_med_phy-tem_anfc_4.2km_P1D-m', ...
'cmems_mod_med_phy-sal_anfc_4.2km_P1D-m'};
mercator_type=1; % 1 --> 1/12 deg Mercator forecast
% 2 --> high-resolution regional grids
if mercator_type==1
product_id_fcst={'cmems_mod_glo_phy_anfc_0.083deg_P1D-m', ...
'cmems_mod_glo_phy-cur_anfc_0.083deg_P1D-m', ...
'cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m', ...
'cmems_mod_glo_phy-so_anfc_0.083deg_P1D-m'};
elseif mercator_type==2
product_id_fcst={'cmems_mod_med_phy-ssh_anfc_4.2km_P1D-m', ...
'cmems_mod_med_phy-cur_anfc_4.2km_P1D-m', ...
'cmems_mod_med_phy-tem_anfc_4.2km_P1D-m', ...
'cmems_mod_med_phy-sal_anfc_4.2km_P1D-m'};
else
disp('Not a mercator_type value known ...')
disp([' '])
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