@author Product owner [email protected]
@author Scrum master, software architect [email protected]
@author Quality assurance, continuous integration manager [email protected]
How to read this file? Use a markdown reader: plugins chrome exists (Once installed in Chrome, open URL chrome://extensions/, and check "Markdown Preview"/Authorise access to file URL.), or for firefox (anchor tags do not work) and also plugin for notepadd++.
Be careful: Markdown format has issue while rendering underscore "_" character which can lead to bad variable name or path.
Motu client "motuclient-python" is a python script used to connect to Motu HTTP server in order to:
- extract the data of a dataset, with geospatial, temporal and variable criterias (default option)
- get the size of an extraction with geospatial, temporal and variable criterias
- get information about a dataset
This program can be integrated into a processing chain in order to automate the downloading of products via the Motu.
From the root folder runs the command:
./patchPOMtoBuild.sh
mvn clean install -Dmaven.test.skip=true
[...]
[INFO] BUILD SUCCESS
[...]
This creates two archives in the target folder:
- motuclient-python-$version-$buildTimestamp-src.tar.gz: Archive containing all the source code
- motuclient-python-$version-$buildTimestamp-bin.tar.gz: Archive ready to be installed
Since motuclient release version 3.X.Y, you must use python version 3.7.10 or later.
_/!_ motuclient does not work with the OpenSSL library release 1.1.1.e. Either use an older version such as the 1.1.1.d or jump to the 1.1.1.f release.
There are two methods to install the client, by using PIP or from a tar.gz file.
setuptools python package has be installed in order to display the motuclient version successfully.
Python Package Index is used to ease installation.
If your host needs a PROXY set it, for example:
export HTTPS_PROXY=http://myCompanyProxy:8080
Then run:
pip install motuclient --upgrade
Now "motuclient" is installed, you can configured it and use it.
Deploy the archive (file motuclient-python-$version-bin.tar.gz available from GitHub release) in the directory of your choice.
tar xvzf motuclient-python-$version-$buildTimestamp-bin.tar.gz
Create a configuration file and set the user and password to use to connect to the CAS server.
"Setuptools" python package has to be installed in order to display the version with option --version, here is how to install it:
If your host needs a PROXY set it, for example:
export HTTPS_PROXY=http://myCompanyProxy:8080
Then run:
sudo apt install python-pip
pip install --upgrade setuptools
All parameters can be defined as command line options or can be written in a configuration file.
The configuration file is a .ini file, encoded in UTF-8 without BOM. This file is located in the following directory:
- on Unix platforms: $HOME/motuclient/motuclient-python.ini
- on Windows platforms: %USERPROFILE%\motuclient\motuclient-python.ini
The expected structure of file is:
[Main]
# Motu credentials
user=john
pwd=secret
motu=http://motu-ip-server:port/motu-web/Motu
service_id=GLOBAL_ANALYSIS_FORECAST_PHY_001_024-TDS
product_id=global-analysis-forecast-phy-001-024-hourly-t-u-v-ssh
date_min=2019-03-27
date_max=2019-03-27
latitude_min=-30
latitude_max=40.0
longitude_min=-10
longitude_max=179.9166717529297
depth_min=0.493
depth_max=0.4942
# Empty or non set means all variables
# 1 or more variables separated by a coma and identified by their standard name
variable=sea_water_potential_temperature,sea_surface_height_above_geoid
# Accept relative or absolute path. The dot character "." is the current folder
out_dir=./out_dir
out_name=test.nc
# Logging
# https://docs.python.org/3/library/logging.html#logging-levels
# log_level=X {CRITICAL:50, ERROR:40, WARNING:30, INFO:20, DEBUG:10, TRACE:0}
log_level=0
# block_size block used to download file (integer expressing bytes) default=65535
# block_size=65535
socket_timeout=120000
# Http proxy to connect to Motu server
# proxy_server=proxy.domain.net:8080
# proxy_user=john
# proxy_pwd=secret
A configuration file in another location can be specified by the --config-file
option. It is even possible to split the configuration into two or more files. This is useful, for example, to keep server configuration in one file and dataset configuration in another:
./motuclient.py --config-file ~/server.ini --config-file ~/mercator.ini
If by chance there is a parameter listed in both configuration files, the value in the last file (e.g. mercator.ini
) is the one actually used.
Note that the password must be encoded in UTF-8.
If it contains UTF-8 special characters, on Windows host only, you only have to double the "percent" character. If password is CMS2017@%! then enter
pwd = CMS2017@%%!
Example of server.ini on Windows host only, with user password is
Password:
loginForTesting2 &~#"'{([-|`_\^@)]=}¨^£$ µ*§!/:.;?,%<>
server.ini:
[Main]
user = [email protected]
pwd = loginForTesting2 &~#"'{([-|`_\^@)]=}¨^£$ µ*§!/:.;?,%%<>
auth-mode = cas
motu = http://motuURL:80/motu-web/Motu
out_dir = J:/dev/CMEMS-CIS-MOTU/git/motu-validkit/output/04-python-client/MOTU-208
Example of server.ini on Linux host only, with user password is
Password:
loginForTesting2 &~#"'{([-|`_\^@)]=}¨^£$ µ*§!/:.;?,%<>
server.ini:
[Main]
user = [email protected]
pwd = loginForTesting2 &~#"'{([-|`_\^@)]=}¨^£$ µ*§!/:.;?,%<>
auth-mode = cas
motu = http://motuURL:80/motu-web/Motu
out_dir = J:/dev/CMEMS-CIS-MOTU/git/motu-validkit/output/04-python-client/MOTU-208
Starts the motu python client.
Since version 1.8.0:
motuclient -h
motuclient [options]
Before version 1.8.0:
python -m motu-client -h
python -m motu-client [options]
Options are listed below.
Method to used when it has been installed with PIP method.
./motuclient.py -h
motuclient.py [options]
Method to used when it has been installed with tar.gz method.
Usefull if host is offline and has no Internet access.
-
-h, --help show this help message and exit
-
-q, --quiet print logs with level WARN in stdout, used to prevent any output in stdout
-
--noisy print logs with level TRACE in stdout
-
--verbose print logs with level DEBUG in stdout
-
--version show program's version number and exit, setuptools python package has be installed to run it successfully
-
--proxy-server=PROXY_SERVER Proxy server (url) used to contact Motu
-
--proxy-user=PROXY_USER Proxy user name (string)
-
--proxy-pwd=PROXY_PWD Proxy password (string)
-
--auth-mode=AUTH_MODE the authentication mode: [default: cas]
- none for no authentication
- basic for basic authentication
- cas for Central Authentication Service
-
-u USER, --user=USER User name (string) for the specified authentication mode
-
-p PWD, --pwd=PWD User password (string) for the specified authentication mode. UTF8 special characters can be used but contraints depending of your operating system must be applyied:
-
Windows users, be careful if your password contain once of the following characters:
- percent: From a Windows batch command, if your password contains a percent character, double the percent character: If password is CMS2017@%! then enter
-u username-p CMS2017@%%!
- space: From a Windows batch command, if your password contains a space character, set password between double quotes: If password is CMS2017 @%! then enter
-u username-p "CMS2017 @%%!"
- double quotes: From a Windows batch command, if your password contains a double quotes character, double the double quotes character: If password is CMS2017"@%! then enter
-u username-p "CMS2017""@%%!"
-
Linux users, be careful if your password contain once of the following characters:
- space: From a Linux bash shell command, if your password contains a space character, set password between double quotes: If password is CMS2017 @% then enter
-u username-p "CMS2017 @%"
- exclamation point: From a Linux bash shell command, if your password contains an exclamation point character, cut the password in two double quotes strings, and append the exclamation point between simple quote: If password is CMS!2017@% then enter
-u username-p "CMS"'!'"2017@%"
- double quotes: From a Linux bash shell command, if your password contains a double quotes character, escape the double quotes character by prefixing it with backslash: If password is CMS2017"@% then enter
-u username-p "CMS2017\"@%"
- grave accent: From a Linux bash shell command, if your password contains a grave accent character, escape the grave accent character by prefixing it with backslash: If password is CMS2017`@% then enter
-u username-p "CMS2017\`@%"
-
-
-m MOTU, --motu=MOTU Motu server url, e.g. "-m http://localhost:8080/motu-web/Motu"
-
-s SERVICE_ID, --service-id=SERVICE_ID The service identifier (string), e.g. -s Mercator_Ocean_Model_Global-TDS
-
-d PRODUCT_ID, --product-id=PRODUCT_ID The product (data set) to download (string), e.g. -d dataset-mercator-psy4v3-gl12-bestestimate-uv
-
-t DATE_MIN, --date-min=DATE_MIN The min date with optional hour resolution (string following format YYYY-MM-DD [HH:MM:SS]), e.g. -t "2016-06-10" or -t "2016-06-10 12:00:00". Be careful to not forget double quotes around the date.
-
-T DATE_MAX, --date-max=DATE_MAX The max date with optional hour resolution (string following format YYYY-MM-DD [HH:MM:SS ]), e.g. -T "2016-06-11" or -T "2016-06-10 12:00:00". Be careful to not forget double quotes around the date.
-
-y LATITUDE_MIN, --latitude-min=LATITUDE_MIN The min latitude (float in the interval [-90 ; 90 ]), e.g. -y -80.5
-
-Y LATITUDE_MAX, --latitude-max=LATITUDE_MAX The max latitude (float in the interval [-90 ; 90 ]), e.g. -Y 80.5
-
-x LONGITUDE_MIN, --longitude-min=LONGITUDE_MIN The min longitude (float), e.g. -x -180
-
-X LONGITUDE_MAX, --longitude-max=LONGITUDE_MAX The max longitude (float), e.g. -X 355.5
-
-z DEPTH_MIN, --depth-min=DEPTH_MIN The min depth (float in the interval [0 ; 2e31 ] or string 'Surface'), e.g. -z 0.49
-
-Z DEPTH_MAX, --depth-max=DEPTH_MAX The max depth (float in the interval [0 ; 2e31 ] or string 'Surface'), e.g. -Z 0.50
-
-v VARIABLE, --variable=VARIABLE The variable (list of strings), e.g. -v salinity -v sst
-
-S, --sync-mode Sets the download mode to synchronous (not recommended). If this parameter is set, Motu server is called with parameter console. Otherwise , Motu server is called with parameter status.
-
-o OUT_DIR, --out-dir=OUT_DIR The output dir where result (download file) is written (string). If it starts with "console", behaviour is the same as with --console-mode.
-
-f OUT_NAME, --out-name=OUT_NAME The output file name (string)
-
--console-mode Write result on stdout. In case of an extraction, write the nc file http URL where extraction result can be downloaded. In case of a getSize or a describeProduct request, display the XML result.
-
-D, --describe-product Get all updated information on a dataset. Output is in XML format, API details
-
--size Get the size of an extraction. Output is in XML format, API details
-
--block-size=BLOCK_SIZE The block used to download file (integer expressing bytes), default=65535 bytes
-
--socket-timeout=SOCKET_TIMEOUT Set a timeout on blocking socket operations (float expressing seconds)
-
--user-agent=USER_AGENT Set the identification string (user-agent) for HTTP requests. By default this value is 'Python-urllib/x.x' (where x.x is the version of the python interpreter)
-
--outputWritten=OUTPUT_FORMAT Set the output format (file type) of the returned file for download requests. By default this value is 'netcdf' and no other value is supported.
In the following examples, variable ${MOTU_USER} and ${MOTU_PASSWORD} are user name and user password used to connect to the CAS server for single sign on.
${MOTU_SERVER_URL} is the URL on the MOTU HTTP(s) server, for example http://localhost:8080/motu-web/Motu.
Commands "./motuclient.py" has to be replaced by "python -m motuclient" if it has been installed with PIP method.
This command writes the extraction result data in file: /data/test.nc
./motuclient.py --verbose --auth-mode=none -m ${MOTU_SERVER_URL} -s HR_MOD_NCSS-TDS -d HR_MOD -z 0.49 -Z 0.50 -x -70 -X 25 -y -75 -Y 10 -t "2016-06-10" -T "2016-06-11" -v salinity -o /data -f test.nc
The HTTP(s) URL is displayed on stdout. This URL is a direct link to the file which is available to be downloaded.
./motuclient.py --quiet --auth-mode=cas -u ${MOTU_USER} -p ${MOTU_PASSWORD} -m ${MOTU_SERVER_URL} -s HR_MOD_NCSS-TDS -d HR_MOD -z 0.49 -Z 0.50 -x -70 -X 25 -y -75 -Y 10 -t "2016-06-10" -T "2016-06-11" -v salinity -o console
See https://github.com/clstoulouse/motu#ClientAPI_GetSize for more details about XML result.
./motuclient.py --size --auth-mode=cas -u ${MOTU_USER} -p ${MOTU_PASSWORD} -m ${MOTU_SERVER_URL} -s HR_MOD_NCSS-TDS -d HR_MOD -z 0.49 -Z 0.50 -x -70 -X 25 -y -75 -Y 10 -t "2016-06-10" -T "2016-06-11" -v salinity -o /data -f getSizeResult.xml
./motuclient.py --quiet --size --auth-mode=cas -u ${MOTU_USER} -p ${MOTU_PASSWORD} -m ${MOTU_SERVER_URL} -s HR_MOD_NCSS-TDS -d HR_MOD -z 0.49 -Z 0.50 -x -70 -X 25 -y -75 -Y 10 -t "2016-06-10" -T "2016-06-11" -v salinity -o console
See https://github.com/clstoulouse/motu#describe-product for more details about XML result.
./motuclient.py -D --auth-mode=cas -u ${MOTU_USER} -p ${MOTU_PASSWORD} -m ${MOTU_SERVER_URL} -s HR_MOD_NCSS-TDS -d HR_MOD -o /data -f describeProductResult.xml
./motuclient.py --quiet -D --auth-mode=cas -u ${MOTU_USER} -p ${MOTU_PASSWORD} -m ${MOTU_SERVER_URL} -s HR_MOD_NCSS-TDS -d HR_MOD -o console
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
This library 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 Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
Example:
pip install motuclient
Collecting motuclient
Using cached https://test-files.pythonhosted.org/packages/4a/7d/41c3bdd973baf119371493c193248349c9b7107477ebf343f3889cabbf48/motuclient-X.Y.Z.zip
Installing collected packages: motuclient
Running setup.py install for motuclient ... done
Successfully installed motuclient-X.Y.Z
Clear your PIP cache: On Windows, delete the folder %HOMEPATH%/pip. On archlinux pip cache is located at ~/.cache/pip. After re run the command:
pip install motuclient
Collecting motuclient
Using https://test-files.pythonhosted.org/packages/4a/7d/41c3bdd973baf119371493c193248349c9b7107477ebf343f3889cabbf48/motuclient-X.Y.Z.zip
Installing collected packages: motuclient
Running setup.py install for motuclient ... done
Successfully installed motuclient-X.Y.Z
From Windows, the command "motuclient.py --version" returns an error.
10:44:24 [ERROR] Execution failed: [Excp 13] User (option 'user') is mandatory when 'cas' authentication is set. Please provide it.
Analyse:
This issue comes from the fact that Windows command line does not pass parameters to python command.
Solution:
Edit the Windows Registry Key "HKEY_CLASSES_ROOT\py_auto_file\shell\open\command" and append at the end of the value %*
Exemple: "C:\dvltSoftware\python\Python27\python.exe" "%1" %*
For example the command "motuclient.py --version" returns this kind of error:
Traceback (most recent call last):
File "C:\dvlt\python\python2.7.18\Scripts\motuclient-script.py", line 11, in <module>
load_entry_point('motuclient==3.0.0.post1', 'console_scripts', 'motuclient')()
File "c:\dvlt\python\python2.7.18\lib\site-packages\motuclient\motuclient.py", line 352, in main
initLogger()
File "c:\dvlt\python\python2.7.18\lib\site-packages\motuclient\motuclient.py", line 336, in initLogger
logging.addLevelName(utils_log.TRACE_LEVEL, 'TRACE')
AttributeError: 'module' object has no attribute 'TRACE_LEVEL'
Analyse:
This issue comes from a too old python installation version. You must use Python 3.7.10 or higher.
Solution:
Find and install the Python 3 distribution for your operating system.