def __testthis(self): for access_point in self.args: if access_point == "profile": for arg in self.args["profile"]: with argopy.set_options(local_ftp=self.local_ftp): fetcher = ArgoIndexFetcher(src=self.src).profile( *arg).fetcher df = fetcher.to_dataframe() assert isinstance(df, pd.core.frame.DataFrame) if access_point == "float": for arg in self.args["float"]: with argopy.set_options(local_ftp=self.local_ftp): fetcher = ArgoIndexFetcher( src=self.src).float(arg).fetcher df = fetcher.to_dataframe() assert isinstance(df, pd.core.frame.DataFrame) if access_point == "region": for arg in self.args["region"]: with argopy.set_options(local_ftp=self.local_ftp): fetcher = ArgoIndexFetcher( src=self.src).region(arg).fetcher df = fetcher.to_dataframe() assert isinstance(df, pd.core.frame.DataFrame)
def __testthis(self): for access_point in self.args: # Acces point not implemented yet for erddap # if access_point == 'profile': # for arg in self.args['profile']: # fetcher = ArgoIndexFetcher(src=self.src).profile(*arg).fetcher # try: # ds = fetcher.to_xarray() # assert isinstance(ds, xr.Dataset) # except ErddapServerError: # # Test is passed even if something goes wrong with the erddap server # pass # except Exception: # print("ERROR ERDDAP request:\n", fetcher.cname()) # pass if access_point == "float": for arg in self.args["float"]: fetcher = ArgoIndexFetcher(src=self.src).float(arg).fetcher ds = fetcher.to_xarray() assert isinstance(ds, xr.Dataset) if access_point == "region": for arg in self.args["region"]: fetcher = ArgoIndexFetcher(src=self.src).region(arg).fetcher ds = fetcher.to_xarray() assert isinstance(ds, xr.Dataset)
def test_invalid_accesspoint(self): # Use the first valid data source with pytest.raises(InvalidFetcherAccessPoint): ArgoIndexFetcher(src=self.src).invalid_accesspoint.to_xarray( ) # Can't get data if access point not defined first with pytest.raises(InvalidFetcherAccessPoint): ArgoIndexFetcher(src=self.src).to_xarray( ) # Can't get data if access point not defined first
def test_url(self): loader = ArgoIndexFetcher(src='erddap', cache=True).float(2901623) assert isinstance(loader.fetcher.url, str) # loader = ArgoIndexFetcher(src='erddap', cache=True).profile(2901623, 12) # assert isinstance(loader.fetcher.url, str) loader = ArgoIndexFetcher(src='erddap', cache=True).region( [-60, -40, 40., 60., '2007-08-01', '2007-09-01']) assert isinstance(loader.fetcher.url, str)
def test_invalid_accesspoint(): src = list( AVAILABLE_INDEX_SOURCES.keys())[0] # Use the first valid data source with pytest.raises(InvalidFetcherAccessPoint): ArgoIndexFetcher(src=src).invalid_accesspoint.to_xarray( ) # Can't get data if access point not defined first with pytest.raises(InvalidFetcherAccessPoint): ArgoIndexFetcher(src=src).to_xarray( ) # Can't get data if access point not defined first
def test_caching_index(self): cachedir = os.path.expanduser(os.path.join("~", ".argopytest_tmp")) try: # 1st call to load index from erddap and save to cachedir: ds = ArgoIndexFetcher(src='erddap', cache=True, cachedir=cachedir).float(6902746).to_xarray() # 2nd call to load from cached file ds = ArgoIndexFetcher(src='erddap', cache=True, cachedir=cachedir).float(6902746).to_xarray() assert isinstance(ds, xr.Dataset) == True shutil.rmtree(cachedir) except: shutil.rmtree(cachedir) raise
def test_nocache(self): with argopy.set_options(cachedir="dummy", local_ftp=self.local_ftp): loader = ArgoIndexFetcher(src=self.src, cache=False).profile(2901623, 2) loader.to_xarray() with pytest.raises(FileSystemHasNoCache): loader.fetcher.cachepath
def test_cachepath_notfound(self): with tempfile.TemporaryDirectory() as testcachedir: with argopy.set_options(cachedir=testcachedir): loader = ArgoIndexFetcher(src=self.src, cache=True).float( self.requests['float'][0]) with pytest.raises(CacheFileNotFound): loader.fetcher.cachepath
def test_nocache(self): with tempfile.TemporaryDirectory() as testcachedir: with argopy.set_options(cachedir=testcachedir): loader = ArgoIndexFetcher(src=self.src, cache=False).float(self.requests['float'][0]) loader.to_xarray() with pytest.raises(FileSystemHasNoCache): loader.fetcher.cachepath
def test_nocache(self): with argopy.set_options(cachedir=self.testcachedir): loader = ArgoIndexFetcher(src='erddap', cache=False).float(6902746) loader.to_xarray() with pytest.raises(FileSystemHasNoCache): loader.fetcher.cachepath shutil.rmtree(self.testcachedir) # Make sure the cache is empty
def main(kind, args): """ Build and run the download script for ARGO GDAC data """ import argopy from argopy import IndexFetcher as ArgoIndexFetcher argopy.set_options(src="localftp", local_ftp=ARGO_localFTP) argopy.set_options(mode="expert") index_loader = ArgoIndexFetcher() if kind == "region": region = [ float(args[0]), float(args[1]), float(args[2]), float(args[3]), *args[4:], ] print(region) argo_df = index_loader.region(region).to_dataframe() elif kind == "floats": argo_df = index_loader.float(args).to_dataframe() dl_list = build_dl(argo_df, ARGO_localFTP) print("Download commands built, launching subshell") launch_shell(dl_list) print("Done")
def test_clearcache(self): with tempfile.TemporaryDirectory() as testcachedir: with argopy.set_options(cachedir=testcachedir, local_ftp=self.local_ftp): loader = ArgoIndexFetcher(src=self.src, cache=True).profile(*self.requests['profile'][0]) loader.to_xarray() loader.clear_cache() with pytest.raises(CacheFileNotFound): loader.fetcher.cachepath
def test_cachepath_notfound(self): testcachedir = os.path.expanduser(os.path.join("~", ".argopytest_tmp")) with argopy.set_options(cachedir=testcachedir, local_ftp=self.local_ftp): loader = ArgoIndexFetcher(src=self.src, cache=True).profile(2901623, 2) with pytest.raises(CacheFileNotFound): loader.fetcher.cachepath shutil.rmtree(testcachedir) # Make sure the cache folder is cleaned
def test_caching(self): with tempfile.TemporaryDirectory() as testcachedir: with argopy.set_options(cachedir=testcachedir): loader = ArgoIndexFetcher(src=self.src, cache=True).float(self.requests['float'][0]) # 1st call to load and save to cache: loader.to_xarray() # 2nd call to load from cached file: ds = loader.to_xarray() assert isinstance(ds, xr.Dataset) assert isinstance(loader.fetcher.cachepath, str)
def test_nocache(self): with tempfile.TemporaryDirectory() as testcachedir: with argopy.set_options(cachedir=testcachedir, local_ftp=self.local_ftp): loader = ArgoIndexFetcher( src=self.src, cache=False).profile(*self.requests['profile'][0]) loader.to_dataframe() with pytest.raises(FileSystemHasNoCache): loader.fetcher.cachepath
def test_clearcache(self): with tempfile.TemporaryDirectory() as testcachedir: with argopy.set_options(cachedir=testcachedir): loader = ArgoIndexFetcher(src=self.src, cache=True).float( self.requests['float'][0]) loader.to_xarray( ) # 1st call to load from source and save in memory loader.to_xarray( ) # 2nd call to load from memory and save in cache loader.clear_cache() with pytest.raises(CacheFileNotFound): loader.fetcher.cachepath
def test_caching(self): with tempfile.TemporaryDirectory() as testcachedir: with argopy.set_options(cachedir=testcachedir, local_ftp=self.local_ftp): loader = ArgoIndexFetcher(src=self.src, cache=True).float( self.requests['float'][0]) # 1st call to load and save to cache: loader.to_dataframe() # 2nd call to load from cached file: df = loader.to_dataframe() assert isinstance(df, pd.core.frame.DataFrame) assert isinstance(loader.fetcher.cachepath, str)
def __testthis(self): for access_point in self.args: if access_point == "profile": for arg in self.args["profile"]: with argopy.set_options(local_ftp=self.local_ftp): fetcher = ArgoIndexFetcher(src=self.src).profile(*arg).fetcher ds = fetcher.to_xarray() assert isinstance(ds, xr.Dataset) if access_point == "float": for arg in self.args["float"]: with argopy.set_options(local_ftp=self.local_ftp): fetcher = ArgoIndexFetcher(src=self.src).float(arg).fetcher ds = fetcher.to_xarray() assert isinstance(ds, xr.Dataset) if access_point == "region": for arg in self.args["region"]: with argopy.set_options(local_ftp=self.local_ftp): fetcher = ArgoIndexFetcher(src=self.src).region(arg).fetcher ds = fetcher.to_xarray() assert isinstance(ds, xr.Dataset)
def test_caching_float(self): testcachedir = os.path.expanduser(os.path.join("~", ".argopytest_tmp")) with argopy.set_options(cachedir=testcachedir, local_ftp=self.local_ftp): try: loader = ArgoIndexFetcher(src=self.src, cache=True).float(6901929) # 1st call to load from erddap and save to cachedir: ds = loader.to_xarray() # 2nd call to load from cached file: ds = loader.to_xarray() assert isinstance(ds, xr.Dataset) assert isinstance(loader.fetcher.cachepath, str) shutil.rmtree(testcachedir) except Exception: shutil.rmtree(testcachedir) raise
def test_caching_index(self): with argopy.set_options(cachedir=self.testcachedir): try: loader = ArgoIndexFetcher(src='erddap', cache=True).float(6902746) # 1st call to load from erddap and save to cachedir: ds = loader.to_xarray() # 2nd call to load from cached file: ds = loader.to_xarray() assert isinstance(ds, xr.Dataset) assert isinstance(loader.fetcher.cachepath, str) shutil.rmtree(self.testcachedir) except ErddapServerError: # Test is passed when something goes wrong because of the erddap server, not our fault ! shutil.rmtree(self.testcachedir) pass except Exception: shutil.rmtree(self.testcachedir) raise
def __testthis(self, dataset): for access_point in self.args: if access_point == 'profile': for arg in self.args['profile']: with argopy.set_options(local_ftp=self.local_ftp): try: ds = ArgoIndexFetcher(src=self.src).profile( *arg).to_xarray() assert isinstance(ds, xr.Dataset) except Exception: print( "ERROR LOCALFTP request:\n", ArgoIndexFetcher(src=self.src).profile( *arg).fetcher.cname()) pass if access_point == 'float': for arg in self.args['float']: with argopy.set_options(local_ftp=self.local_ftp): try: ds = ArgoIndexFetcher( src=self.src).float(arg).to_xarray() assert isinstance(ds, xr.Dataset) except Exception: print( "ERROR LOCALFTP request:\n", ArgoIndexFetcher( src=self.src).float(arg).fetcher.cname()) pass if access_point == 'region': for arg in self.args['region']: with argopy.set_options(local_ftp=self.local_ftp): try: ds = ArgoIndexFetcher( src=self.src).region(arg).to_xarray() assert isinstance(ds, xr.Dataset) except Exception: print( "ERROR LOCALFTP request:\n", ArgoIndexFetcher( src=self.src).region(arg).fetcher.cname()) pass
def test_noresults(self): with argopy.set_options(local_ftp=self.local_ftp): with pytest.raises(DataNotFound): ArgoIndexFetcher(src=self.src).region( [-70, -65, 30.0, 35.0, "2030-01-01", "2030-06-30"]).to_dataframe()
def test_invalid_fetcher(self): with pytest.raises(InvalidFetcher): ArgoIndexFetcher(src="invalid_fetcher").to_xarray()
def test_bar_plot_region(self): with argopy.set_options(local_ftp=self.local_ftp): for arg in self.requests["region"]: loader = ArgoIndexFetcher(src=self.src).region(arg).load() self.__test_bar_plot(loader.index)
def test_traj_plot_profile(self): with argopy.set_options(local_ftp=self.local_ftp): for arg in self.requests["profile"]: loader = ArgoIndexFetcher(src=self.src).profile(*arg).load() self.__test_traj_plot(loader.index)
def __test_region(self, bk, **ftc_opts): """ Test float index fetching for a given backend """ for arg in self.args["region"]: options = {**self.fetcher_opts, **ftc_opts} f = ArgoIndexFetcher(src=bk, **options).region(arg) assert isinstance(f.to_xarray(), xr.Dataset)
def __test_profile(self, bk, **ftc_opts): """ Test profile index fetching for a given backend """ for arg in self.args["profile"]: options = {**self.fetcher_opts, **ftc_opts} f = ArgoIndexFetcher(src=bk, **options).profile(*arg) assert isinstance(f.to_xarray(), xr.Dataset)
def test_url(self): loader = ArgoIndexFetcher(src=self.src, cache=True).float(self.requests['float'][0]) assert isinstance(loader.fetcher.url, str)
def test_invalid_dataset(self): with pytest.raises(ValueError): ArgoIndexFetcher(src=self.src, ds='dummy_ds')
def __test_float(self, bk, **ftc_opts): """ Test float index fetching for a given backend """ for arg in self.args['float']: options = {**self.fetcher_opts, **ftc_opts} ds = ArgoIndexFetcher(src=bk, **options).float(arg).to_xarray() assert isinstance(ds, xr.Dataset)