error whilw downloading Copernicus Marine data via MOTU in MATLAB

I am trying to download Copernicus Marine data via MOTU in MATLAB as explained in
I have downloaded the provided matlab script and modify it as below
% Create the work directory 'data'
out_dir = fullfile(pwd, 'data');
if ~exist(out_dir, 'dir')
mkdir(out_dir)
end
% Copernicus Marine username and password
username = input('user', "s");
password = input('bassword', "s");
% Product and dataset IDs
serviceId = 'GLOBAL_ANALYSISFORECAST_PHY_001_024';
productId = 'cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m';
% Ocean Variable(s)
variables = ["--variable thetao"];
% Time range
date_start = '2022-01-01 12:00:00';
date_end = '2022-01-07 12:00:00';
% Geographic area and depth level
lon = [-15.26, 5.04]; % lon_min, lon_max
lat = [35.57, 51.03]; % lat_min, lat_max
depth = ["0", "100"]; % depth_min, depth_max
% Output filename
filename = 'global_20220101_2022_01_07.nc';
motu_line = sprintf("py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu", ...
" --service-id ", serviceId, "-TDS --product-id ", productId, ...
"--longitude-min ", lon(1), "--longitude-max ", lon(2), ...
"--latitude-min ", lat(1), "--latitude-max ", lat(2), ...
" --date-min ",date_start," --date-max ",date_end, ...
" --depth-min ", depth(1), " --depth-max ", depth(2), ...
variables(1), ...
" --out-dir ", out_dir, " --out-name ", filename, ...
" --user ", username, " --pwd ", password);
disp(motu_line)
system(motu_line)
After many trails, I have the following error:
py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu
2023-11-10 22:55:24.028 [ERROR] Execution failed: [Excp 13] User (option 'user') is mandatory when 'cas' authentication is set. Please provide it.
I have Python 3.8 on Windows 10 and I have installed Pandas and motuclient on Python as well. Anyhelp please?

Risposte (1)

motu_line = sprintf("py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu", ...
" --service-id ", serviceId, "-TDS --product-id ", productId, ...
"--longitude-min ", lon(1), "--longitude-max ", lon(2), ...
"--latitude-min ", lat(1), "--latitude-max ", lat(2), ...
" --date-min ",date_start," --date-max ",date_end, ...
" --depth-min ", depth(1), " --depth-max ", depth(2), ...
variables(1), ...
" --out-dir ", out_dir, " --out-name ", filename, ...
" --user ", username, " --pwd ", password);
No format characters such as %s in the first parameter to sprintf. The sprintf() is not going to output any of the additional parameters you pass.
The format for sprintf() is sprintf(FORMAT, param1, param2, param3, ...) where the FORMAT specifies how to convert param1 and so on into output. Each % in FORMAT causes the processing of the next param* (with the exception of %$ sequences) .
When the end of FORMAT has been reached, and there were no % format characters, then sprintf() makes no effort to convert any additional parameters and just drops them.
If the end of FORMAT has been reached and there is at least 1 % sequence, and there are additional values to convert, the FORMAT gets reused from the beginning.
In all situations if a % format sequence requires a value and there are no more values to convert, conversion stops at that point. For example, sprintf('abc %g def %g hij\n', 10 ) would output abc 10 def and then would encounter the %g for which there is no corresponding input value, so it would just stop without going on to hij
You should probably be considering use the string plus, + operator to create the motu_line
motu_line = "py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu" ...
+ " --service-id " + serviceId + "-TDS --product-id " + productId ...
+ "--longitude-min " + lon(1) + "--longitude-max " + lon(2) ...
+ "--latitude-min " + lat(1) + "--latitude-max " + lat(2) ...
+ " --date-min " + date_start + " --date-max " + date_end ...
+ " --depth-min " + depth(1) + " --depth-max " + depth(2) ...
+ variables(1) ...
+ " --out-dir " + out_dir + " --out-name " + filename, ...
+ " --user " + username + " --pwd " + password;
but if so then you should test to see whether the conversion of lat and lon to string is acceptable for your purposes -- the automatic conversion will only hold on to at most 4 decimal places.

13 Commenti

Many thanks for your reply.
I tried the string plus, + operator but I recieved the following error in the last code line
Undefined unary operator '+' for input arguments of type 'string'.
Error in ?? (line ??)
+ " --user " + username + " --pwd " + password;
motu_line = "py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu" ...
+ " --service-id " + serviceId + "-TDS --product-id " + productId ...
+ "--longitude-min " + lon(1) + "--longitude-max " + lon(2) ...
+ "--latitude-min " + lat(1) + "--latitude-max " + lat(2) ...
+ " --date-min " + date_start + " --date-max " + date_end ...
+ " --depth-min " + depth(1) + " --depth-max " + depth(2) ...
+ variables(1) ...
+ " --out-dir " + out_dir + " --out-name " + filename ...
+ " --user " + username + " --pwd " + password;
Thank you for your reply but I recieved the following message now.
py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu --service-id GLOBAL_ANALYSISFORECAST_PHY_001_024-TDS --product-id cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m--longitude-min -15.26--longitude-max 5.04--latitude-min 35.57--latitude-max 51.03 --date-min 2022-01-01 12:00:00 --date-max 2022-01-07 12:00:00 --depth-min 0 --depth-max 100--variable thetao --out-dir C:\Users\rmd_0\Downloads\data --out-name global_20220101_2022_01_07.nc --user --pwd
Usage: motuclient.py [options]
motuclient.py: error: no such option: -1
ans =
2
motu_line = "py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu" ...
+ " --service-id " + serviceId + "-TDS --product-id " + productId ...
+ " --longitude-min " + lon(1) + " --longitude-max " + lon(2) ...
+ " --latitude-min " + lat(1) + " --latitude-max " + lat(2) ...
+ " --date-min " + date_start + " --date-max " + date_end ...
+ " --depth-min " + depth(1) + " --depth-max " + depth(2) ...
+ variables(1) ...
+ " --out-dir " + out_dir + " --out-name " + filename ...
+ " --user " + username + " --pwd " + password;
Many thanks but I still recieve this error
[ERROR] Execution failed: [Excp 14] Password (option 'pwd') is mandatory for user '--pwd'.
motu_line = "py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu" ...
+ " --service-id " + serviceId + "-TDS --product-id " + productId ...
+ " --longitude-min " + lon(1) + " --longitude-max " + lon(2) ...
+ " --latitude-min " + lat(1) + " --latitude-max " + lat(2) ...
+ " --date-min " + date_start + " --date-max " + date_end ...
+ " --depth-min " + depth(1) + " --depth-max " + depth(2) ...
+ variables(1) ...
+ " --out-dir " + out_dir + " --out-name " + filename ...
+ " --user " + username + " --pwd " + password;
Unfortunately still has the same error
[ERROR] Execution failed: [Excp 14] Password (option 'pwd') is mandatory for user '--pwd'. Please provide it.
You would get that error if you responded with just a carriage return at the point where it asked for your username.
I have provided my username and password which are correct at the start of the code.
By running the code, it confirms the username then the password, then I recieve this error
py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu --service-id GLOBAL_ANALYSISFORECAST_PHY_001_024-TDS --product-id cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m --longitude-min -15.26 --longitude-max 5.04 --latitude-min 35.57 --latitude-max 51.03 --date-min 2022-01-01 12:00:00 --date-max 2022-01-07 12:00:00 --depth-min 0 --depth-max 100--variable thetao --out-dir C:\Users\rmd_0\Downloads\data --out-name global_20220101_2022_01_07.nc --user --pwd
2023-11-15 22:04:32.205 [ERROR] Execution failed: [Excp 14] Password (option 'pwd') is mandatory for user '--pwd'. Please provide it.
ans =
1
Here is my full code with the usename and password,
% Create the work directory 'data'
out_dir = fullfile(pwd, 'data');
if ~exist(out_dir, 'dir')
mkdir(out_dir)
end
% Copernicus Marine username and password
username = input('abassam', "s");
password = input('Zamalek61', "s");
% Product and dataset IDs
serviceId = 'GLOBAL_ANALYSISFORECAST_PHY_001_024';
productId = 'cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m';
% Ocean Variable(s)
variables = ["--variable thetao"];
% Time range
date_start = '2022-01-01 12:00:00';
date_end = '2022-01-07 12:00:00';
% Geographic area and depth level
lon = [-15.26, 5.04]; % lon_min, lon_max
lat = [35.57, 51.03]; % lat_min, lat_max
depth = ["0", "100"]; % depth_min, depth_max
% Output filename
filename = 'global_20220101_2022_01_07.nc';
motu_line = "py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu" ...
+ " --service-id " + serviceId + "-TDS --product-id " + productId ...
+ " --longitude-min " + lon(1) + " --longitude-max " + lon(2) ...
+ " --latitude-min " + lat(1) + " --latitude-max " + lat(2) ...
+ " --date-min " + date_start + " --date-max " + date_end ...
+ " --depth-min " + depth(1) + " --depth-max " + depth(2) ...
+ variables(1) ...
+ " --out-dir " + out_dir + " --out-name " + filename ...
+ " --user " + username + " --pwd " + password;
disp(motu_line)
system(motu_line)
motu_line = "py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu" ...
+ " --service-id " + serviceId + "-TDS --product-id " + productId ...
+ " --longitude-min " + lon(1) + " --longitude-max " + lon(2) ...
+ " --latitude-min " + lat(1) + " --latitude-max " + lat(2) ...
+ " --date-min '" + date_start + "' --date-max '" + date_end ...
+ "' --depth-min " + depth(1) + " --depth-max " + depth(2) ...
+ variables(1) ...
+ " --out-dir " + out_dir + " --out-name " + filename ...
+ " --user " + username + " --pwd " + password;
Again. The same error
py -m motuclient --motu https://nrt.cmems-du.eu/motu_web/Motu --service-id GLOBAL_ANALYSISFORECAST_PHY_001_024-TDS --product-id cmems_mod_glo_phy-thetao_anfc_0.083deg_P1D-m --longitude-min -15.26 --longitude-max 5.04 --latitude-min 35.57 --latitude-max 51.03 --date-min '2022-01-01 12:00:00' --date-max '2022-01-07 12:00:00' --depth-min 0 --depth-max 100--variable thetao --out-dir C:\Users\rmd_0\Downloads\data --out-name global_20220101_2022_01_07.nc --user --pwd
2023-11-16 03:49:09.636 [ERROR] Execution failed: [Excp 14] Password (option 'pwd') is mandatory for user '--pwd'. Please provide it.
ans =
1
motu_line = "py -m motuclient --motu 'https://nrt.cmems-du.eu/motu_web/Motu'" ...
+ " --service-id " + serviceId + "-TDS --product-id " + productId ...
+ " --longitude-min " + lon(1) + " --longitude-max " + lon(2) ...
+ " --latitude-min " + lat(1) + " --latitude-max " + lat(2) ...
+ " --date-min '" + date_start + "' --date-max '" + date_end ...
+ "' --depth-min " + depth(1) + " --depth-max " + depth(2) ...
+ " " + variables(1) ...
+ " --out-dir '" + out_dir + "' --out-name " + filename ...
+ " --user " + username + " --pwd " + password;
Regarding the code, I received the following message from the support team of CopernicusMarineService.
The error you received means that there is an error in the code spell (lack of space between the parameters, wrong spell parameters, ...). So it is recommended to double check the command line.
Looking at your request, I see that there is no space after --depth-max 100 .
Also, maybe you need to use quote marks instead of apostrophes around the dates.
Here is the example of a correct MOTU request to compare it to yours:
python -m motuclient --motu https://nrt.cmems-du.eu/motu-web/Motu --service-id MEDSEA_ANALYSISFORECAST_PHY_006_013-TDS --product-id cmems_mod_med_phy-tem_anfc_4.2km_P1D-m --longitude-min 11.278194265352782 --longitude-max 17.322023164435105 --latitude-min 35.62677046686681 --latitude-max 39.17599884720039 --date-min "2023-09-01 00:00:00" --date-max "2023-09-08 23:59:59" --depth-min 1.0182366371154785 --depth-max 26.20039939880371 --variable thetao --out-dir <OUTPUT_DIRECTORY> --out-name <OUTPUT_FILENAME> --user <USERNAME> --pwd <PASSWORD>
I hope this help!

Accedi per commentare.

Prodotti

Release

R2019b

Richiesto:

il 10 Nov 2023

Commentato:

il 16 Nov 2023

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by