def test_get_df(example_config_ts): vds = VdsApiV2() vds.environment = 'staging' rois = getpar_fromtext(example_config_ts, 'rois') product = getpar_fromtext(example_config_ts, 'products') df = vds.get_roi_df(product, rois[0], '2020-01-01', '2020-01-03') assert isinstance(df, pd.DataFrame)
def test_par_from_text(example_config_area): lat_min = getpar_fromtext(example_config_area, 'lat_min') assert lat_min == '66' products = getpar_fromtext(example_config_area, 'products') assert products == 'TEST-PRODUCT_V001_25000' void = getpar_fromtext(example_config_area, 'nonexisting') assert void is None with pytest.raises(RuntimeError): getpar_fromtext('nonexisting.file', 'lat_min')
def ts(ctx, config_file, products, latlons, rois, date_range, fmt, masked, av_win, backward, clim, t, provide_coverage, outfold, verbose): vds = VdsApiV2(ctx.obj['user'], ctx.obj['passwd'], debug=False) if ctx.obj['environment'] is not None: vds.host = ctx.obj['environment'] if ctx.obj['impersonate']: vds.impersonate(ctx.obj['impersonate']) vds.streamlevel = 10 if verbose else 20 click.echo(vds) if outfold: vds.outfold = outfold elif config_file: of = getpar_fromtext(config_file, 'outfold') if of: vds.outfold = of products = list(products) if products else None download_if_unfinished(vds, 4) lats, lons = map(list, zip(*latlons)) if latlons else (None, None) rois = list(rois) if rois else None av_win_dir = 'backward' if backward else 'center' vds.gen_time_series_requests(gen_uri=False, config_file=config_file, products=products, start_time=date_range[0] if date_range else None, end_time=date_range[1] if date_range else None, lats=lats, lons=lons, rois=rois, av_win=av_win, av_win_dir=av_win_dir, masked=masked, clim=clim, t=t, provide_coverage=provide_coverage, file_format=fmt) vds.log_config() vds.submit_async_requests() vds.download_async_files(n_proc=8) vds.summary() vds.logger.info(' ================== Finished ==================')
def grid(ctx, config_file, products, lon_range, lat_range, date_range, fmt, n_proc, outfold, zipped, verbose): vds = VdsApiV2(ctx.obj['user'], ctx.obj['passwd'], debug=False) if ctx.obj['environment'] is not None: vds.host = ctx.obj['environment'] if ctx.obj['impersonate']: vds.impersonate(ctx.obj['impersonate']) vds.streamlevel = 10 if verbose else 20 click.echo(vds) if outfold: vds.outfold = outfold elif config_file: of = getpar_fromtext(config_file, 'outfold') if of: vds.outfold = outfold download_if_unfinished(vds, n_jobs=n_proc) products = list(products) if products else None vds.gen_gridded_data_request(gen_uri=False, config_file=config_file, products=products, start_date=date_range[0], end_date=date_range[1], lat_min=(lat_range[0] if lat_range else None), lat_max=(lat_range[1] if lat_range else None), lon_min=(lon_range[0] if lon_range else None), lon_max=(lon_range[1] if lon_range else None), file_format=fmt, zipped=zipped, nrequests=n_proc) vds.log_config() vds.submit_async_requests() vds.download_async_files(n_proc=n_proc) vds.summary() vds.logger.info(' ================== Finished ==================')
def test_products(credentials, example_config_area): vds = VdsApiBase(credentials['user'], credentials['pw']) assert isinstance(vds.products, Products) assert all([isinstance(p, Product) for p in vds.products]) products = getpar_fromtext(example_config_area, 'products') prod = vds.products[products] assert prod.api_name is not None vds.check_valid_products(products)
def test_rois_getitem(credentials, example_config_ts): vds = VdsApiBase(credentials['user'], credentials['pw']) assert isinstance(vds.rois, Rois) assert all([isinstance(r, Roi) for r in vds.rois]) roi_str, roi_name = getpar_fromtext(example_config_ts, 'rois') assert vds.rois[roi_str].id == int(roi_str) assert vds.rois[int(roi_str)].id == int(roi_str) assert vds.rois[roi_name].name == roi_name
import click_datetime as click_dt import os import time from vds_api_client.vds_api_base import VdsApiBase, getpar_fromtext from vds_api_client.api_v2 import VdsApiV2 from requests import HTTPError setattr(VdsApiV2, '__str__', VdsApiBase.__str__) vds_user = os.environ.get('VDS_USER', None) vds_pass = os.environ.get('VDS_PASS', None) creds = os.path.join(os.environ.get('TEMP', os.environ.get('TMP', '/tmp')), 'vds_creds.vds') if os.path.exists(creds): if vds_user is None or vds_pass is None: user = getpar_fromtext(creds, 'VDS_USER') pas = getpar_fromtext(creds, 'VDS_PASS') else: os.remove(creds) vds_user = '******' if vds_user is None else vds_user pass_show = '$VDS_PASS (Not set)' if vds_pass is None else '$VDS_PASS' def set_win_envar(key, value=''): subprocess.check_output(f'setx {key} "{value}"') def set_linux_envar(key, value=''): """ Function which sets the login credentials in the environment shell files.