gdex-api-client 2.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
File without changes
@@ -0,0 +1,576 @@
1
+ #!/usr/bin/env python
2
+ """List dataset metadata, subset data subset requests,
3
+ check on request status.
4
+
5
+ Usage:
6
+ ```
7
+ gdex_client.py -get_summary <dsnnn.n>
8
+ gdex_client.py -get_metadata <dsnnn.n> <-f>
9
+ gdex_client.py -get_param_summary <dsnnn.n> <-f>
10
+ gdex_client.py -submit [control_file_name]
11
+ gdex_client.py -get_status <RequestIndex> <-proc_status>
12
+ gdex_client.py -download [RequestIndex]
13
+ gdex_client.py -globus_download [RequestIndex]
14
+ gdex_client.py -get_control_file_template <dsnnn.n>
15
+ gdex_client.py -help
16
+ ```
17
+ """
18
+ __version__ = '2.0.0'
19
+ __author__ = 'Doug Schuster (schuster@ucar.edu), Riley Conroy (rpconroy@ucar.edu)'
20
+
21
+ import sys
22
+ import os
23
+ import requests
24
+ import getpass
25
+ import json
26
+ import argparse
27
+ import codecs
28
+ import pdb
29
+
30
+
31
+ BASE_URL = 'https://gdex.ucar.edu/api/'
32
+ DEFAULT_AUTH_FILE = './gdex_token.txt'
33
+
34
+ # Python 2 compatibility
35
+ try:
36
+ input = raw_input
37
+ except NameError:
38
+ pass
39
+
40
+ def query(args=None):
41
+ """Perform a query based on command line like arguments.
42
+
43
+ Args:
44
+ args (list): argument list of querying commands.
45
+
46
+ Returns:
47
+ (dict): Output of json decoded API query.
48
+
49
+ Example:
50
+ ```
51
+ >>> query(['-get_status', '123456'])
52
+
53
+ >>> query(['-get_metadata', 'ds083.2'])
54
+ ```
55
+ """
56
+ parser = get_parser()
57
+ if args is None or len(args) == 0:
58
+ parser.parse_args(['-h'])
59
+ args = parser.parse_args(args)
60
+ args_dict = args.__dict__
61
+ func,params = get_selected_function(args_dict)
62
+ if args_dict['outdir'] and func==download:
63
+ out_dir = args_dict['outdir']
64
+ return func(params, out_dir)
65
+ result = func(params)
66
+ if not args.noprint:
67
+ print(json.dumps(result, indent=3))
68
+ return result
69
+
70
+ def add_ds_str(ds_num):
71
+ """Adds 'ds' to ds_num if needed.
72
+ Throws error if ds number isn't valid.
73
+ """
74
+ ds_num = ds_num.strip()
75
+ if ds_num[0:2] != 'ds':
76
+ ds_num = 'ds' + ds_num
77
+ if len(ds_num) != 7:
78
+ print("'" + ds_num + "' is not valid.")
79
+ sys.exit()
80
+ return ds_num
81
+
82
+ def get_userinfo():
83
+ """Get token from command line."""
84
+ print('Please visit https://gdex.ucar.edu/accounts/profile/ to access token.')
85
+ token = input("Paste that token here: ")
86
+ write_token_file(token)
87
+ return token
88
+
89
+ def write_token_file(token, token_file=DEFAULT_AUTH_FILE):
90
+ """Write token to a file."""
91
+ with open(token_file, "w") as fo:
92
+ fo.write(token)
93
+
94
+ def read_token_file(token_file):
95
+ """Read user information from token file.
96
+
97
+ Args:
98
+ token_file (str): location of token file.
99
+
100
+ Returns:
101
+ (str): token
102
+ """
103
+ with open(token_file, 'r') as f:
104
+ token = f.read()
105
+ return token.strip()
106
+
107
+ def read_control_file(control_file):
108
+ """Reads control file, and return python dict.
109
+
110
+ Args:
111
+ control_file (str): Location of control file to parse.
112
+ Or control file string.
113
+
114
+ Returns:
115
+ (dict) python dict representing control file.
116
+ """
117
+ control_params = {}
118
+ if os.path.exists(control_file):
119
+ myfile = open(control_file, 'r')
120
+ else:
121
+ myfile = control_file.split('\n')
122
+
123
+ for line in myfile:
124
+ line = line.strip()
125
+ if line.startswith('#') or line == "":
126
+ continue
127
+ li = line.rstrip()
128
+ (key, value) = li.split('=', 2)
129
+ control_params[key] = value
130
+
131
+ # Handle empty params
132
+ if 'param' in control_params and control_params['param'].strip() == '':
133
+ all_params = get_all_params(control_params['dataset'])
134
+ control_params['param'] = '/'.join(all_params)
135
+
136
+ try:
137
+ myfile.close()
138
+ except:
139
+ pass
140
+ return control_params
141
+
142
+ def get_parser():
143
+ """Creates and returns parser object.
144
+
145
+ Returns:
146
+ (argparse.ArgumentParser): Parser object from which to parse arguments.
147
+ """
148
+ description = "Queries NCAR GDEX REST API."
149
+ parser = argparse.ArgumentParser(prog='gdex_client', description=description)
150
+ parser.add_argument('-noprint', '-np',
151
+ action='store_true',
152
+ required=False,
153
+ help="Do not print result of queries.")
154
+ parser.add_argument('-outdir', '-od',
155
+ nargs='?',
156
+ required=False,
157
+ help="Change the output directory of downloaded files")
158
+ group = parser.add_mutually_exclusive_group(required=True)
159
+ group.add_argument('-get_summary', '-gsum',
160
+ type=str,
161
+ metavar='<dsid>',
162
+ required=False,
163
+ help="Get a summary of the given dataset.")
164
+ group.add_argument('-get_metadata', '-gm',
165
+ type=str,
166
+ metavar='<dsid>',
167
+ required=False,
168
+ help="Get metadata for a given dataset.")
169
+ group.add_argument('-get_param_summary', '-gpm',
170
+ type=str,
171
+ metavar='<dsid>',
172
+ required=False,
173
+ help="Get only parameters for a given dataset.")
174
+ group.add_argument('-submit', '-s',
175
+ type=str,
176
+ metavar='<control file>',
177
+ required=False,
178
+ help="Submit a request using a control file.")
179
+ group.add_argument('-get_status', '-gs',
180
+ type=str,
181
+ nargs='?',
182
+ const='ALL',
183
+ metavar='<Request Index>',
184
+ required=False,
185
+ help="Get a summary of the given dataset.")
186
+ group.add_argument('-download', '-d',
187
+ type=str,
188
+ required=False,
189
+ metavar='<Request Index>',
190
+ help="Download data given a request id.")
191
+ group.add_argument('-get_filelist', '-gf',
192
+ type=str,
193
+ required=False,
194
+ metavar='<Request Index>',
195
+ help="Query the filelist for a completed request.")
196
+ group.add_argument('-globus_download', '-gd',
197
+ type=str,
198
+ required=False,
199
+ metavar='<Request Index>',
200
+ help="Start a globus transfer for a give request index.")
201
+ group.add_argument('-get_control_file_template', '-gt',
202
+ type=str,
203
+ metavar='<dsid>',
204
+ required=False,
205
+ help="Get a template control file used for subsetting.")
206
+ group.add_argument('-purge', # Sorry no -p
207
+ type=str,
208
+ metavar='<Request Index>',
209
+ required=False,
210
+ help="Purge a request.")
211
+ return parser
212
+
213
+ def check_status(ret, token_file=DEFAULT_AUTH_FILE):
214
+ """Checks that status of return object.
215
+
216
+ Exits if a 401 status code.
217
+
218
+ Args:
219
+ ret (response.Response): Response of a request.
220
+ token_file (str) : password file. Will remove if auth incorrect
221
+
222
+ Returns:
223
+ None
224
+ """
225
+ if ret.status_code == 401: # Not Authorized
226
+ print(ret.content)
227
+ exit(1)
228
+
229
+ def check_file_status(filepath, filesize):
230
+ """Prints file download status as percent of file complete.
231
+
232
+ Args:
233
+ filepath (str): File being downloaded.
234
+ filesize (int): Expected total size of file in bytes.
235
+
236
+ Returns:
237
+ None
238
+ """
239
+ sys.stdout.write('\r')
240
+ sys.stdout.flush()
241
+ size = int(os.stat(filepath).st_size)
242
+ percent_complete = (size/filesize)*100
243
+ sys.stdout.write('%.3f %s' % (percent_complete, '% Completed'))
244
+ sys.stdout.flush()
245
+
246
+ def download_files(filelist, out_dir='./', cookie_file=None):
247
+ """Download files in a list.
248
+
249
+ Args:
250
+ filelist (list): List of web files to download.
251
+ out_dir (str): directory to put downloaded files
252
+
253
+ Returns:
254
+ None
255
+ """
256
+ for _file in filelist:
257
+ file_base = os.path.basename(_file)
258
+ out_file = out_dir + file_base
259
+ print('Downloading',file_base)
260
+ header = requests.head(_file, allow_redirects=True, stream=True)
261
+ filesize = int(header.headers['Content-Length'])
262
+ req = requests.get(_file, allow_redirects=True, stream=True)
263
+ with open(out_file, 'wb') as outfile:
264
+ chunk_size=1048576
265
+ for chunk in req.iter_content(chunk_size=chunk_size):
266
+ outfile.write(chunk)
267
+ if chunk_size < filesize:
268
+ check_file_status(out_file, filesize)
269
+ check_file_status(out_file, filesize)
270
+ print()
271
+
272
+ def encode_url(url, token):
273
+ return url + '?token=' + token
274
+
275
+ def get_authentication(token_file=DEFAULT_AUTH_FILE):
276
+ """Attempts to get authentication.
277
+
278
+ Args:
279
+ token_file (str): location of password file.
280
+
281
+ Returns:
282
+ (tuple): token
283
+ """
284
+ if os.path.isfile(token_file) and os.path.getsize(token_file) > 0:
285
+ return read_token_file(token_file)
286
+ else:
287
+ return get_userinfo()
288
+
289
+
290
+ def get_summary(ds):
291
+ """Returns summary of dataset.
292
+
293
+ Args:
294
+ ds (str): Datset id. e.g. 'ds083.2'
295
+
296
+ Returns:
297
+ dict: JSON decoded result of the query.
298
+ """
299
+ url = BASE_URL + 'summary/'
300
+ url += ds
301
+
302
+ token = get_authentication()
303
+ ret = requests.get(encode_url(url,token))
304
+
305
+ check_status(ret)
306
+ return ret.json()
307
+
308
+ def get_metadata(ds):
309
+ """Return metadata of dataset.
310
+
311
+ Args:
312
+ ds (str): Datset id. e.g. 'ds083.2'
313
+
314
+ Returns:
315
+ dict: JSON decoded result of the query.
316
+ """
317
+ url = BASE_URL + 'metadata/'
318
+ url += ds
319
+
320
+ token = get_authentication()
321
+ ret = requests.get(encode_url(url,token))
322
+
323
+ check_status(ret)
324
+ return ret.json()
325
+
326
+ def get_all_params(ds):
327
+ """Return set of parameters for a dataset.
328
+
329
+ Args:
330
+ ds (str): Datset id. e.g. 'ds083.2'
331
+
332
+ Returns:
333
+ set: All unique params in dataset.
334
+ """
335
+ res = get_param_summary(ds)
336
+ res_data = res['data']['data']
337
+ param_names = set()
338
+ for param in res_data:
339
+ param_names.add(param['param'])
340
+ return param_names
341
+
342
+
343
+ def get_param_summary(ds):
344
+ """Return summary of parameters for a dataset.
345
+
346
+ Args:
347
+ ds (str): Datset id. e.g. 'ds083.2'
348
+
349
+ Returns:
350
+ dict: JSON decoded result of the query.
351
+ """
352
+ url = BASE_URL + 'paramsummary/'
353
+ url += ds
354
+
355
+ token = get_authentication()
356
+ ret = requests.get(encode_url(url,token))
357
+
358
+ check_status(ret)
359
+ return ret.json()
360
+
361
+
362
+ def submit_json(json_file):
363
+ """Submit a GDEX subset or format conversion request using json file or dict.
364
+
365
+ Args:
366
+ json_file (str|dict): json control file to submit.
367
+
368
+ Returns:
369
+ dict: JSON decoded result of the query.
370
+ """
371
+ if type(json_file) is str:
372
+ assert os.path.isfile(json_file)
373
+ with open(json_file) as fh:
374
+ control_dict = json.load(fh)
375
+ else:
376
+ assert type(json_file) is dict
377
+ control_dict = json_file
378
+
379
+ url = BASE_URL + 'submit/'
380
+
381
+ token = get_authentication()
382
+ ret = requests.post(encode_url(url,token), json=control_dict)
383
+
384
+ check_status(ret)
385
+ return ret.json()
386
+
387
+ def submit(control_file_name):
388
+ """Submit a GDEX subset or format conversion request.
389
+ Calls submit json after reading control_file
390
+
391
+ Args:
392
+ control_file_name (str): control file to submit.
393
+
394
+ Returns:
395
+ dict: JSON decoded result of the query.
396
+ """
397
+ _dict = read_control_file(control_file_name)
398
+ return submit_json(_dict)
399
+
400
+
401
+ def get_status(request_idx=None):
402
+ """Get status of request.
403
+ If request_ix not provided, get all open requests
404
+
405
+ Args:
406
+ request_idx (str, Optional): Request Index, typcally a 6-digit integer.
407
+
408
+ Returns:
409
+ dict: JSON decoded result of the query.
410
+ """
411
+ if request_idx is None:
412
+ request_idx = 'ALL'
413
+ url = BASE_URL + 'status/'
414
+ url += str(request_idx)
415
+
416
+
417
+ token = get_authentication()
418
+ ret = requests.get(encode_url(url,token))
419
+
420
+ check_status(ret)
421
+ return ret.json()
422
+
423
+ def get_filelist(request_idx):
424
+ """Gets filelist for request
425
+
426
+ Args:
427
+ request_idx (str): Request Index, typically a 6-digit integer.
428
+
429
+ Returns:
430
+ dict: JSON decoded result of the query.
431
+ """
432
+ url = BASE_URL + 'get_req_files/'
433
+ url += str(request_idx)
434
+
435
+ token = get_authentication()
436
+ ret = requests.get(encode_url(url,token))
437
+
438
+ check_status(ret)
439
+
440
+ return ret.json()
441
+
442
+
443
+ def download(request_idx, out_dir='./'):
444
+ """Download files given request Index
445
+
446
+ Args:
447
+ request_idx (str): Request Index, typically a 6-digit integer.
448
+
449
+ Returns:
450
+ None
451
+ """
452
+ ret = get_filelist(request_idx)
453
+ if len(ret['data']) == 0:
454
+ return ret
455
+
456
+ filelist = ret['data']['web_files']
457
+
458
+ token = get_authentication()
459
+
460
+ web_files = list(map(lambda x: x['web_path'], filelist))
461
+
462
+ # Only download unique files.
463
+ download_files(set(web_files), out_dir)
464
+ return ret
465
+
466
+ def globus_download(request_idx):
467
+ """Begin a globus transfer.
468
+
469
+ Args:
470
+ request_ix (str): Request Index, typically a 6-digit integer.
471
+
472
+ Returns:
473
+ dict: JSON decoded result of the query.
474
+ """
475
+ url = BASE_URL + 'request/'
476
+ url += request_idx
477
+ url += '-globus_download'
478
+
479
+ token = get_authentication()
480
+ ret = requests.get(encode_url(url,token))
481
+
482
+ check_status(ret)
483
+ return ret.json()
484
+
485
+ def get_control_file_template(ds):
486
+ """Write a control file for use in subset requests.
487
+
488
+ Args:
489
+ ds (str): datset id. e.g. 'ds083.2'
490
+
491
+ Returns:
492
+ dict: JSON decoded result of the query.
493
+ """
494
+ url = BASE_URL + 'control_file_template/'
495
+ url += ds
496
+
497
+ token = get_authentication()
498
+ ret = requests.get(encode_url(url,token))
499
+
500
+ check_status(ret)
501
+ return ret.json()
502
+
503
+ def write_control_file_template(ds, write_location='./'):
504
+ """Write a control file for use in subset requests.
505
+
506
+ Args:
507
+ ds (str): datset id. e.g. 'ds083.2'
508
+ write_location (str, Optional): Directory in which to write.
509
+ Defaults to working directory
510
+
511
+ Returns:
512
+ dict: JSON decoded result of the query.
513
+ """
514
+ _json = get_control_file_template(ds)
515
+ control_str = _json['data']['template']
516
+
517
+ template_filename = write_location + add_ds_str(ds) + '_control.ctl'
518
+ if os.path.exists(template_filename):
519
+ print(template_filename + " already exists.\nExiting")
520
+ exit(1)
521
+ with open(template_filename, 'w') as fh:
522
+ fh.write(control_str)
523
+
524
+ return _json
525
+
526
+ def purge_request(request_idx):
527
+ """Write a control file for use in subset requests.
528
+
529
+ Args:
530
+ ds (str): datset id. e.g. 'ds083.2'
531
+ write_location (str, Optional): Directory in which to write.
532
+ Defaults to working directory
533
+
534
+ Returns:
535
+ None
536
+ """
537
+ url = BASE_URL + 'purge/'
538
+ url += request_idx
539
+
540
+ token = get_authentication()
541
+ ret = requests.delete(encode_url(url,token))
542
+
543
+ check_status(ret)
544
+ return ret.json()
545
+
546
+ def get_selected_function(args_dict):
547
+ """Returns correct function based on options.
548
+ Args:
549
+ options (dict) : Command with options.
550
+
551
+ Returns:
552
+ (function): function that the options specified
553
+ """
554
+ # Maps an argument to function call
555
+ action_map = {
556
+ 'get_summary' : get_summary,
557
+ 'get_metadata' : get_metadata,
558
+ 'get_param_summary' : get_param_summary,
559
+ 'submit' : submit,
560
+ 'get_status' : get_status,
561
+ 'download' : download,
562
+ 'get_filelist' : get_filelist,
563
+ 'globus_download' : globus_download,
564
+ 'get_control_file_template' : write_control_file_template,
565
+ 'purge' : purge_request
566
+ }
567
+ for opt,value in args_dict.items():
568
+ if opt in action_map and value is not None:
569
+ return (action_map[opt], value)
570
+
571
+ def main():
572
+ query(sys.argv[1:])
573
+
574
+ if __name__ == "__main__":
575
+ """Calls main method"""
576
+ query(sys.argv[1:])
@@ -0,0 +1,673 @@
1
+ Metadata-Version: 2.4
2
+ Name: gdex-api-client
3
+ Version: 2.0.1
4
+ Summary: CLI and library for calling GDEX API
5
+ Author-email: GDEX data Help <datahelp@ucar.edu>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://gdex.ucar/edu
8
+ Keywords: API,Geoscience,GDEX
9
+ Description-Content-Type: text/markdown
10
+ License-File: LICENSE
11
+ Requires-Dist: requests
12
+ Dynamic: license-file
13
+
14
+ # GDEX apps clients
15
+
16
+ This repository contains the Geoscience Data Exchange (GDEX) API client for python.
17
+
18
+ At this stage, the (GDEX) REST API clients are available for Python (2.x and 3.x), see [src/python](src/python) for more details.
19
+
20
+
21
+ # GDEX External Application API Description
22
+
23
+ ## Table of Contents
24
+ - [General Information](#general-info)
25
+ - [Install](#install)
26
+ - [Curl Syntax](#curl)
27
+ - [Wget Syntax](#wget)
28
+ - [HTTPS GET Commands and Responses](#https-get)
29
+ + [Dataset Summary](#summary)
30
+ + [Dataset Parameter Summary](#param-summary)
31
+ + [Dataset Metadata](#metadata)
32
+ + [Request Status](#status)
33
+ + [Request Filelist](#filelist)
34
+ + [Control File Template](#template)
35
+ - [HTTPS POST Commands and Responses](#https-post)
36
+ + [Submit Subset/Format Conversion Request](#submit)
37
+ - [HTTPS DELETE Commands and Responses](#https-delete)
38
+ + [Purge Request](#Purge)
39
+
40
+ ------
41
+
42
+ ### General Info
43
+
44
+ - We have written a python client to abstract the request and authentication details.
45
+ + The client can be used as a command-line tool or as an imported python module to work with python objects directly.
46
+ + In most cases, the client will print the JSON response after a command is entered.
47
+ + A Jupyter Notebook was created to show the basic functionality of gdex_client.py.
48
+ - [The Jupyter Notebook can be found here](../src/python/gdex_client_example.ipynb)
49
+ + [gdex_client.py can be found here](../src/python/gdex_client.py)
50
+ - All HTTPS requests to to the GDEX API must include a bearer token to access the API.
51
+ + Token information can be found on [you user profile](https://gdex.ucar.edu/accounts/profile)
52
+ - Responses are JSON formatted.
53
+ + Typically, error responses will give an explaination of what went wrong in the value of the `messages` key.
54
+ + If `status` is `ok`, then all relevant data will be in the value of the `result` key.
55
+ - Feel free to contact the GDEX with questions: [datahelp](mailto:datahelp@ucar.edu) or [Riley Conroy](mailto:rpconroy@ucar.edu)
56
+
57
+ ------
58
+ ### Install
59
+
60
+ While the python client can simply be downloaded from github and used provided you have `requests` installed, we also have a package that can be installed using pip:
61
+
62
+ pip install gdex-api-client
63
+
64
+ This gives you command line access to the command `gdex_client` that is a essentially an alias to gdex_client.py.
65
+ Additionally, you can programatically use the module via
66
+
67
+ from gdex_api_client import gdex_client
68
+
69
+ ------
70
+ ### Authentication
71
+
72
+ `POST`, `DELETE`, and some user-specific 'GET' HTTP requests require that you include a bearer token in your URL.
73
+ To do this you would need to first find your token in [you user profile](https://gdex.ucar.edu/accounts/profile).
74
+
75
+ Next, you would append this token to the end of any url using `?token=[bearer token]. For example,
76
+ ```
77
+ https://gdex.ucar.edu/api/status/?token=dkjf93f93jf8n9vdfh
78
+ ```
79
+ This step is abstracted if using the python client, `gdex_client.py`
80
+
81
+ ------
82
+ ### Curl
83
+
84
+ The list below is how to perform HTTPS `GET`, `POST`, and `DELETE` commands using `curl` respectively.
85
+
86
+ curl -X GET [URL]
87
+
88
+ curl -X POST -d @json_control_file -H 'Content-Type:application/json'[URL]
89
+
90
+ curl -X DELETE [URL]
91
+
92
+ URL in these examples could be for example `https://gdex.ucar.edu/api/summary/ds083.2` or `https://gdex.ucar.edu/api/status` or `https://gdex.ucar.edu/api/get_req_files/123456`
93
+
94
+ ------
95
+
96
+ ### WGET
97
+
98
+ The list below is how to perform HTTPS `GET`, `POST`, and `DELETE` commands using `wget` respectively.
99
+
100
+ wget [URL]
101
+
102
+ wget --header='Content-Type:application/json' --post-file [JsonControlFile] [URL]
103
+
104
+ wget --method=delete [URL]
105
+
106
+ URL in these case could be for example `https://gdex.ucar.edu/api/summary/ds083.2` or `https://gdex.ucar.edu/api/request` or `https://gdex.ucar.edu/api/request/123456`
107
+
108
+ ------
109
+
110
+ ### HTTPS GET
111
+
112
+
113
+ ### Summary
114
+
115
+ #### Description
116
+ Returns a summary of datasets and dataset groups that have subsetting available.
117
+
118
+ #### URL
119
+
120
+ ```
121
+ GET https://gdex.ucar.edu/api/summary/[dsnnn.n]
122
+ ```
123
+
124
+ #### Example Response
125
+ ```json
126
+ {
127
+ "request_duration": "0.049611 seconds",
128
+ "https_response": 200,
129
+ "messages": [],
130
+ "result": {
131
+ "subsetting_available": true,
132
+ "data": [
133
+ {
134
+ "request_type": "T",
135
+ "group_index": 0
136
+ },
137
+ {
138
+ "request_type": "T",
139
+ "group_index": 1,
140
+ "title": "GRIB1 6 HOURLY FILES 1999.07.30 to 2007.12.06"
141
+ },
142
+ {
143
+ "request_type": "T",
144
+ "group_index": 2,
145
+ "title": "GRIB2 6 HOURLY FILES 2007.12.06 to current"
146
+ }
147
+ ]
148
+ },
149
+ "request_end": "2020-03-03T10:23:45.197258",
150
+ "request_start": "2020-03-03T10:23:45.147647"
151
+ }
152
+ ```
153
+
154
+ ------
155
+
156
+ ### Param Summary
157
+
158
+ #### Description
159
+
160
+ Returns a summary of only the Parameters in a dataset for subsetting.
161
+
162
+ #### URL
163
+
164
+ ```
165
+ GET https://gdex.ucar.edu/api/paramsummary/[dsnnn.n]
166
+ ```
167
+
168
+ #### Example Response
169
+
170
+ ```json
171
+ {
172
+ "request_duration": "0.173482 seconds",
173
+ "https_response": 200,
174
+ "messages": [],
175
+ "result": {
176
+ "dsid": "083.2",
177
+ "subsetting_available": true,
178
+ "data": [
179
+ {
180
+ "native_format": "WMO_GRIB2",
181
+ "param": "VIS",
182
+ "GCMD_uuid": "9337898d-68dc-43d7-93a9-6afdb4ab1784",
183
+ "units": "m",
184
+ "param_description": "Visibility"
185
+ },
186
+ {
187
+ "param_description": "Categorical snow (yes=1; no=0)",
188
+ "native_format": "WMO_GRIB2",
189
+ "param": "CSNOW"
190
+ },
191
+ {
192
+ "native_format": "WMO_GRIB2",
193
+ "param": "PEVPR",
194
+ "standard_name": "potential_water_evaporation_flux",
195
+ "GCMD_uuid": "b68ab978-6db6-49ee-84e2-5f37b461a998",
196
+ "units": "W m^-2",
197
+ "param_description": "Potential evaporation rate"
198
+ },
199
+ {
200
+ "native_format": "WMO_GRIB2",
201
+ "param": "T CDC",
202
+ "GCMD_uuid": "acb52274-6c0d-4241-a979-3fa3efca6702",
203
+ "units": "%",
204
+ "param_description": "Total cloud cover"
205
+ },
206
+
207
+ ...
208
+
209
+ {
210
+ "native_format": "WMO_GRIB1",
211
+ "param": "ABSV",
212
+ "standard_name": "atmosphere_absolute_vorticity",
213
+ "ISO_TopicCategoryCode": "climatologyMeteorologyAtmosphere",
214
+ "units": "s^-1",
215
+ "GCMD_uuid": "858a80ff-5aa4-4590-b2e2-e88a802a6ee4",
216
+ "param_description": "Absolute vorticity"
217
+ },
218
+ {
219
+ "native_format": "WMO_GRIB1",
220
+ "param": "VVEL",
221
+ "standard_name": "lagrangian_tendency_of_air_pressure",
222
+ "ISO_TopicCategoryCode": "climatologyMeteorologyAtmosphere",
223
+ "units": "Pa s^-1",
224
+ "GCMD_uuid": "841a7ac7-5981-4e93-895f-1b57c3d892a0",
225
+ "param_description": "Vertical velocity (pressure)"
226
+ }
227
+ ]
228
+ },
229
+ "request_end": "2020-03-03T10:52:38.637789",
230
+ "request_start": "2020-03-03T10:52:38.464307"
231
+ }
232
+
233
+ ```
234
+
235
+ ------
236
+
237
+ ### Metadata
238
+
239
+ #### Description
240
+
241
+ Returns full metadata of a dataset available for subsetting.
242
+
243
+ #### URL
244
+
245
+ ```
246
+ GET https://gdex.ucar.edu/api/metadata/[dsnnn.n]
247
+ ```
248
+
249
+ #### Example Response
250
+
251
+ ```json
252
+ {
253
+ "request_duration": "0.173482 seconds",
254
+ "https_response": 200,
255
+ "messages": [],
256
+ "result": {
257
+ "dsid": "083.2",
258
+ "subsetting_available": true,
259
+ "data": [
260
+ {
261
+ "product": "Analysis",
262
+ "param_description": "Convective inhibition",
263
+ "end_date": 200712060600,
264
+ "level": null,
265
+ "native_format": "WMO_GRIB1",
266
+ "gridproj": "latLon",
267
+ "griddef": "360:181:90N:0E:90S:359E:1:1",
268
+ "param": "CIN",
269
+ "levels": [
270
+ {
271
+ "level_description": "Ground or water surface",
272
+ "level": "SFC",
273
+ "level_value": "0"
274
+ },
275
+ {
276
+ "level_value": "0,180",
277
+ "level_description": "Layer between two levels at specified pressure differences from ground to level",
278
+ "level": "SPDY",
279
+ "units": "mbar"
280
+ }
281
+ ],
282
+ "GCMD_uuid": "ebce0874-7635-4094-8ef4-968851873771",
283
+ "units": "J kg^-1",
284
+ "ISO_TopicCategoryCode": "climatologyMeteorologyAtmosphere",
285
+ "start_date": 199907301800
286
+ },
287
+
288
+ ...
289
+
290
+ {
291
+ "product": "Analysis",
292
+ "param_description": "Vertical velocity (pressure)",
293
+ "end_date": 200712060600,
294
+ "level": null,
295
+ "native_format": "WMO_GRIB1",
296
+ "gridproj": "latLon",
297
+ "griddef": "360:181:90N:0E:90S:359E:1:1",
298
+ "param": "VVEL",
299
+ "standard_name": "lagrangian_tendency_of_air_pressure",
300
+ "levels": [
301
+ {
302
+ "level_value": "1000",
303
+ "level_description": "Isobaric surface",
304
+ "level": "ISBL",
305
+ "units": "mbar"
306
+ },
307
+ {
308
+ "level_value": "975",
309
+ "level_description": "Isobaric surface",
310
+ "level": "ISBL",
311
+ "units": "mbar"
312
+ },
313
+ {
314
+ "level_value": "950",
315
+ "level_description": "Isobaric surface",
316
+ "level": "ISBL",
317
+ "units": "mbar"
318
+ },
319
+ {
320
+ "level_value": "925",
321
+ "level_description": "Isobaric surface",
322
+ "level": "ISBL",
323
+ "units": "mbar"
324
+ },
325
+ {
326
+ "level_value": "900",
327
+ "level_description": "Isobaric surface",
328
+ "level": "ISBL",
329
+ "units": "mbar"
330
+ },
331
+ {
332
+ "level_value": "850",
333
+ "level_description": "Isobaric surface",
334
+ "level": "ISBL",
335
+ "units": "mbar"
336
+ },
337
+ {
338
+ "level_value": "800",
339
+ "level_description": "Isobaric surface",
340
+ "level": "ISBL",
341
+ "units": "mbar"
342
+ },
343
+ {
344
+ "level_value": "750",
345
+ "level_description": "Isobaric surface",
346
+ "level": "ISBL",
347
+ "units": "mbar"
348
+ },
349
+ {
350
+ "level_value": "700",
351
+ "level_description": "Isobaric surface",
352
+ "level": "ISBL",
353
+ "units": "mbar"
354
+ },
355
+ {
356
+ "level_value": "650",
357
+ "level_description": "Isobaric surface",
358
+ "level": "ISBL",
359
+ "units": "mbar"
360
+ },
361
+ {
362
+ "level_value": "600",
363
+ "level_description": "Isobaric surface",
364
+ "level": "ISBL",
365
+ "units": "mbar"
366
+ },
367
+ {
368
+ "level_value": "550",
369
+ "level_description": "Isobaric surface",
370
+ "level": "ISBL",
371
+ "units": "mbar"
372
+ },
373
+ {
374
+ "level_value": "500",
375
+ "level_description": "Isobaric surface",
376
+ "level": "ISBL",
377
+ "units": "mbar"
378
+ },
379
+ {
380
+ "level_value": "450",
381
+ "level_description": "Isobaric surface",
382
+ "level": "ISBL",
383
+ "units": "mbar"
384
+ },
385
+ {
386
+ "level_value": "400",
387
+ "level_description": "Isobaric surface",
388
+ "level": "ISBL",
389
+ "units": "mbar"
390
+ },
391
+ {
392
+ "level_value": "350",
393
+ "level_description": "Isobaric surface",
394
+ "level": "ISBL",
395
+ "units": "mbar"
396
+ },
397
+ {
398
+ "level_value": "300",
399
+ "level_description": "Isobaric surface",
400
+ "level": "ISBL",
401
+ "units": "mbar"
402
+ },
403
+ {
404
+ "level_value": "250",
405
+ "level_description": "Isobaric surface",
406
+ "level": "ISBL",
407
+ "units": "mbar"
408
+ },
409
+ {
410
+ "level_value": "200",
411
+ "level_description": "Isobaric surface",
412
+ "level": "ISBL",
413
+ "units": "mbar"
414
+ },
415
+ {
416
+ "level_value": "150",
417
+ "level_description": "Isobaric surface",
418
+ "level": "ISBL",
419
+ "units": "mbar"
420
+ },
421
+ {
422
+ "level_value": "100",
423
+ "level_description": "Isobaric surface",
424
+ "level": "ISBL",
425
+ "units": "mbar"
426
+ },
427
+ {
428
+ "level_description": "Sigma level",
429
+ "level": "SIGL",
430
+ "level_value": "0.995"
431
+ }
432
+ ],
433
+ "GCMD_uuid": "841a7ac7-5981-4e93-895f-1b57c3d892a0",
434
+ "units": "Pa s^-1",
435
+ "ISO_TopicCategoryCode": "climatologyMeteorologyAtmosphere",
436
+ "start_date": 199907301800
437
+ }
438
+ ]
439
+ },
440
+ "request_end": "2020-03-03T11:32:33.317202",
441
+ "request_start": "2020-03-03T11:32:32.453649"
442
+
443
+ ```
444
+
445
+ ------
446
+
447
+ ### Status
448
+
449
+ #### Description
450
+
451
+ Returns that status of a given request index.
452
+ A request index is a six digit integer.
453
+
454
+ An authentication token is needed for this for this request. See [Authentication Section](#authentication) for more details.
455
+
456
+ Or
457
+
458
+ Returns the status of all requests for user.
459
+
460
+ #### URL
461
+
462
+ ```
463
+ GET https://gdex.ucar.edu/api/status/[RequestIndex]
464
+ ```
465
+
466
+ Or,
467
+
468
+ ```
469
+ GET https://gdex.ucar.edu/api/status/
470
+ ```
471
+
472
+ #### Example Response
473
+
474
+ If `[RequestIndex]` is given
475
+
476
+ ```json
477
+ {
478
+ "request_duration": "0.046309 seconds",
479
+ "https_response": 200,
480
+ "messages": [],
481
+ "result":
482
+ {
483
+ "status": "Completed",
484
+ "date_ready": "2020-03-01",
485
+ "request_index": 410935,
486
+ "NCAR_contact": "rpconroy@ucar.edu",
487
+ "rqstid": "LASTNAME410935",
488
+ "request_id": "LASTNAME410935",
489
+ "date_purge": "2020-03-06",
490
+ "date_rqst": "2020-03-01",
491
+ "subset_info": {
492
+ "note": "- Start date: 2018-01-15 00:00\n- End date: 2020-03-16 12:00\n- Parameter(s):\n Pressure\n- Vertical level(s):\n Specified height above ground: 80 m\n- Product(s):\n Analysis\n- Spatial subsetting (single gridpoint):\n Latitude: -29.5\n Longitude: 17\n"
493
+ }
494
+ }
495
+ "request_end": "2020-03-03T11:35:43.433348",
496
+ "request_start": "2020-03-03T11:35:43.387039"
497
+ }
498
+
499
+ ```
500
+
501
+ Or if `[RequestIndex]` is not specified, get all requests
502
+
503
+ ```json
504
+ {
505
+ "request_duration": "0.046309 seconds",
506
+ "https_response": 200,
507
+ "messages": [],
508
+ "result": [
509
+ {
510
+ "status": "Completed",
511
+ "date_ready": "2020-03-01",
512
+ "request_index": 410935,
513
+ "NCAR_contact": "rpconroy@ucar.edu",
514
+ "rqstid": "LASTNAME410935",
515
+ "request_id": "LASTNAME410935",
516
+ "date_purge": "2020-03-06",
517
+ "date_rqst": "2020-03-01",
518
+ "subset_info": {
519
+ "note": "- Start date: 2018-01-15 00:00\n- End date: 2020-03-16 12:00\n- Parameter(s):\n Pressure\n- Vertical level(s):\n Specified height above ground: 80 m\n- Product(s):\n Analysis\n- Spatial subsetting (single gridpoint):\n Latitude: -29.5\n Longitude: 17\n"
520
+ }
521
+ },
522
+ {
523
+ "status": "Completed",
524
+ "date_ready": "2020-03-01",
525
+ "request_index": 410936,
526
+ "NCAR_contact": "rpconroy@ucar.edu",
527
+ "rqstid": "LASTNAME410936",
528
+ "request_id": "LASTNAME410936",
529
+ "date_purge": "2020-03-06",
530
+ "date_rqst": "2020-03-01",
531
+ "subset_info": {
532
+ "note": "- Output format: csv\n- Start date: 2019-09-15 00:00\n- End date: 2020-03-16 12:00\n- Parameter(s):\n u-component of wind\n- Vertical level(s):\n Specified height above ground: 100 m\n- Product(s):\n Analysis\n- Spatial subsetting (single gridpoint):\n Latitude: -43.75\n Longitude: -64.5\n"
533
+ }
534
+ }
535
+ ],
536
+ "request_end": "2020-03-03T11:35:43.433348",
537
+ "request_start": "2020-03-03T11:35:43.387039"
538
+ }
539
+ ```
540
+
541
+ ------
542
+
543
+ ### Filelist
544
+
545
+ #### Description
546
+
547
+ Returns the available files generated from a request.
548
+
549
+ An authentication token is needed for this for this request. See [Authentication Section](#authentication) for more details.
550
+
551
+ #### URL
552
+
553
+ ```
554
+ GET https://gdex.ucar.edu/api/get_req_files/[RequestIndex]
555
+ ```
556
+
557
+ #### Example Response
558
+
559
+ ```json
560
+ {
561
+ "request_duration": "0.01604 seconds",
562
+ "https_response": 200,
563
+ "messages": [],
564
+ "result": {
565
+ "total_size": 156,
566
+ "web_files": [
567
+ {
568
+ "web_path": "https://gdex.ucar.edu/dsrqst/LASTNAME411039/Filename.extension",
569
+ "wfile": "Filename.extension",
570
+ "size": 156
571
+ }
572
+ ]
573
+ },
574
+ "request_end": "2020-03-03T11:42:43.230800",
575
+ "request_start": "2020-03-03T11:42:43.214760"
576
+ }
577
+ ```
578
+
579
+ ------
580
+
581
+ ### Template
582
+
583
+ #### Description
584
+
585
+ Returns an example control file for a give dataset.
586
+
587
+ #### URL
588
+
589
+ ```
590
+ GET https://gdex.ucar.edu/api/control_file_template/[dsxxx.x]
591
+ ```
592
+
593
+ #### Example Response
594
+
595
+ ```json
596
+ {
597
+ "request_duration": "0.007501 seconds",
598
+ "https_response": 200,
599
+ "messages": [],
600
+ "result": {
601
+ "template": "dataset=ds083.2\ndate=201103020000/to/201103151200\nparam=TMP/R H/ABS V\nlevel=ISBL:850/700/500\noformat=netCDF\nnlat=30\nslat=-25\nwlon=-150\nelon=-30\n#groupindex=2\ntargetdir=/glade/scratch\n"
602
+ },
603
+ "request_end": "2020-03-03T11:44:21.842582",
604
+ "request_start": "2020-03-03T11:44:21.835081"
605
+ }
606
+ ```
607
+
608
+ ------
609
+
610
+ ### HTTPS POST
611
+
612
+ ### Submit
613
+
614
+ #### Description
615
+
616
+ Submits a request, where the POST data is json formatted control file.
617
+
618
+ An authentication token is needed for this for this request. See [Authentication Section](#authentication) for more details.
619
+
620
+ #### URL
621
+
622
+ ```
623
+ POST https://gdex.ucar.edu/api/submit
624
+ ```
625
+
626
+ #### Example Response
627
+
628
+ ```json
629
+ {
630
+ "request_duration": "1.171259 seconds",
631
+ "https_response": 200,
632
+ "messages": [],
633
+ "result": {
634
+ "request_id": "411298"
635
+ },
636
+ "request_end": "2020-03-03T11:45:16.513226",
637
+ "request_start": "2020-03-03T11:45:15.341967"
638
+ }
639
+ ```
640
+
641
+ ------
642
+
643
+ ### HTTPS DELETE
644
+
645
+ ### Purge
646
+
647
+ #### Description
648
+
649
+ Deletes a given RequestIndex. This may be necessary as Users may only have up to 8 requests open at a given time. By default an open request will be available for 7 days. Contact the specialist for the dataset to extend the amount of time it is available.
650
+
651
+ An authentication token is needed for this for this request. See [Authentication Section](#authentication) for more details.
652
+
653
+ #### URL
654
+
655
+ ```
656
+ DELETE https://gdex.ucar.edu/api/purge/[RequestIndex]
657
+ ```
658
+
659
+ #### Example Response
660
+
661
+ ```json
662
+ {
663
+ "request_duration": "0.243377 seconds",
664
+ "https_response": 200,
665
+ "messages": [],
666
+ "result": {
667
+ "purge_successful": "true"
668
+ },
669
+ "request_end": "2020-03-03T11:46:17.021646",
670
+ "request_start": "2020-03-03T11:46:16.778269"
671
+ }
672
+ ```
673
+
@@ -0,0 +1,8 @@
1
+ gdex_api_client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ gdex_api_client/gdex_client.py,sha256=kUC6QwstMRiTByK7hwIkM4QBCqzD9lhqihaMInqCBgk,15478
3
+ gdex_api_client-2.0.1.dist-info/licenses/LICENSE,sha256=1EBPUGiqaL35xVdCfA00xRzY8uOJIJE-IyDlasD0uwg,1113
4
+ gdex_api_client-2.0.1.dist-info/METADATA,sha256=oBgg_GIbS8kJDRL9qDxb7xTZdIQ90g4iNfUyHmSmH88,19678
5
+ gdex_api_client-2.0.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
6
+ gdex_api_client-2.0.1.dist-info/entry_points.txt,sha256=vvwqpufRHOHleZHiDNhTsKt-VNTW8ON2QoK9MwCn5RA,65
7
+ gdex_api_client-2.0.1.dist-info/top_level.txt,sha256=RfF77l3GnJ5T_dOSuzC1Q3yTtqnNi1MICk4fi7bjDEg,16
8
+ gdex_api_client-2.0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ gdex_client = gdex_api_client.gdex_client:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018 University Corporation for Atmospheric Research ("UCAR")
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ gdex_api_client