Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

motuclient 1.8.4 and Python script #19

Open
GeoTuxMan opened this issue Dec 17, 2019 · 5 comments
Open

motuclient 1.8.4 and Python script #19

GeoTuxMan opened this issue Dec 17, 2019 · 5 comments

Comments

@GeoTuxMan
Copy link

Hello !

After I install motuclient 1.8.4 (with pip), I try to run motuclient from a Python script:

`import datetime
import time
from datetime import timedelta

time_min = datetime.date.today().isoformat()
time_max = (datetime.date.today()+timedelta(days=3)).isoformat()
nc_name = time.strftime("%d_%m_%Y_%H_%M.nc")

os.system("C:\Python27\python.exe -m motuclient -u lbuga -p 9YxKdFEK -m http://nrt.cmems-du.eu/motu-web/Motu -s BLKSEA_ANALYSIS_FORECAST_PHYS_007_001-TDS -d sv03-bs-cmcc-tem-an-fc-h -t time_min -T time_max -x 28.5 -X 32.5 -y 42.5 -Y 46.0 -z 2.501 -Z 266.0668 -v votemper -o out_dir/NC -f nc_name %*")`

and I got this error:
motuclient is a package and cannot be directly executed

Look forward for some tips.

Cheers !
George

@clstoulouse
Copy link
Owner

Hi,

Can you try from a command line:
motuclient -h

Then from python script:

import os
os.system("motuclient -h")
Usage: motuclient [options]
...

Have you the same display ?

Regards

@GeoTuxMan
Copy link
Author

C:\Python27\motuclient -h
'motuclient' is not recognized as an internal or external command, operable program or batch file

import os
os.system("motuclient -h")
1

@GeoTuxMan
Copy link
Author

Solved with this:

`cmems_user= "lbuga"
cmems_pass= "9YxKdFEK"
motu_server ="http://nrt.cmems-du.eu/motu-web/Motu"
product_id="BLKSEA_ANALYSIS_FORECAST_PHYS_007_001-TDS"
dataset_id="sv03-bs-cmcc-tem-an-fc-h"
lon_min="28.5"
lon_max="32.5"
lat_min="42.5"
lat_max="46.0"
date_min=datetime.date.today().isoformat()
date_max=(datetime.date.today()+timedelta(days=3)).isoformat()
variable1 = "votemper"
Out_dir = "out_dir/NC"
nc_name = time.strftime("%d_%m_%Y_%H_%M.nc")

command_string = "python -m motuclient --user " + str(cmems_user) + " --pwd " + str(cmems_pass) +" --motu " + str(motu_server) + " --service-id " + str(product_id) + " --product-id " + str(dataset_id) + " --longitude-min " + str(lon_min) + " --longitude-max " + str(lon_max) + " --latitude-min " + str(lat_min) + " --latitude-max " + str(lat_max) + " --date-min " + str(date_min) + " --date-max " + str(date_max) + " --variable " + str(variable1) + " --out-dir " + str(Out_dir) + " --out-name " + str(nc_name)

os.system(command_string)`

@johanvdw
Copy link

From a python script, you can also fake a motu client:

 from motu_utils import motu_api
 from optparse import OptionParser

     print("getting update from %s to %s" % (date_min, date_max))
     options = {'log_level': None, 'user': xxx, 'pwd': xxx,
                'auth_mode': 'cas', 'proxy':False, 'proxy_server': None,
                'proxy_user': None, 'proxy_pwd': None,
                'motu': 'https://nrt.cmems-du.eu/motu-web/Motu',
                'service_id': service_id,
                'product_id': 'MetO-NWS-PHY-dm-BED', 'date_min': date_min,
                'date_max': date_max,
                'latitude_min': 51.0, 'latitude_max': 56.0,
                'longitude_min': 1.0, 'longitude_max': 8.0, 'depth_min': None,
                'depth_max': None, 'variable': ['bottomT', 'bottomT'], 'sync': None,
                'describe': None, 'size': None, 'out_dir': path,
                'out_name': f'{service_id}_{date_min}_{date_max}.nc',
                'block_size': 65536, 'socket_timeout': None, 'user_agent': None, 'outputWritten': None,
                'console_mode': None, 'config_file': None}
 
     # we create a fake option parser because this is what the motu api expects:
     # a parsed result from optionparser rather than a normal dict
     op = OptionParser()
     for o in options:
         op.add_option('--'+o, dest=o, default=options[o])
     (_options, args) = op.parse_args()
 
     motu_api.execute_request(_options)

This is a dirty workaround, but works. Would be nicer though if the api supported using a dict rather than only an optionparser result.

@camrinbraun
Copy link

Is there a solution to this? I'm still getting the same error as OP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants