コード例 #1
0
    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)
コード例 #2
0
    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)
コード例 #3
0
 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
コード例 #4
0
 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)
コード例 #5
0
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
コード例 #6
0
 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
コード例 #7
0
 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
コード例 #8
0
 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
コード例 #9
0
 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
コード例 #10
0
 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
コード例 #11
0
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")
コード例 #12
0
 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
コード例 #13
0
 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
コード例 #14
0
 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)
コード例 #15
0
 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
コード例 #16
0
 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
コード例 #17
0
 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)
コード例 #18
0
    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)
コード例 #19
0
 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
コード例 #20
0
 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
コード例 #21
0
    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
コード例 #22
0
 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()
コード例 #23
0
 def test_invalid_fetcher(self):
     with pytest.raises(InvalidFetcher):
         ArgoIndexFetcher(src="invalid_fetcher").to_xarray()
コード例 #24
0
 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)
コード例 #25
0
 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)
コード例 #26
0
 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)
コード例 #27
0
 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)
コード例 #28
0
 def test_url(self):
     loader = ArgoIndexFetcher(src=self.src, cache=True).float(self.requests['float'][0])
     assert isinstance(loader.fetcher.url, str)
コード例 #29
0
 def test_invalid_dataset(self):
     with pytest.raises(ValueError):
         ArgoIndexFetcher(src=self.src, ds='dummy_ds')
コード例 #30
0
 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)