Example #1
0
def test__tempnc():
    url = "https://data.ioos.us/gliders/erddap/tabledap/cp_336-20170116T1254.nc"
    data = urlopen(url).read()
    with _tempnc(data) as tmp:
        # Check that the file was exists.
        assert os.path.exists(tmp)
        # Confirm that it is a netCDF file.
        assert tmp.endswith("nc")
    # Check that the file was removed.
    assert not os.path.exists(tmp)
Example #2
0
    def to_xarray(self, **kw):
        """Load the data request into a xarray.Dataset.

        Accepts any `xr.open_dataset` keyword arguments.
        """
        import xarray as xr

        url = self.get_download_url(response="nc")
        data = urlopen(url, params=self.params, **self.requests_kwargs).read()
        with _tempnc(data) as tmp:
            return xr.open_dataset(tmp.name, **kw)
Example #3
0
    def to_iris(self, **kw):
        """Load the data request into an iris.CubeList.

        Accepts any `iris.load_raw` keyword arguments.
        """
        import iris

        url = self.get_download_url(response="nc")
        data = urlopen(url, params=self.params, **self.requests_kwargs).read()
        with _tempnc(data) as tmp:
            cubes = iris.load_raw(tmp.name, **kw)
            cubes.realise_data()
            return cubes
Example #4
0
    def to_iris(self, **kw):
        """Load the data request into an iris.CubeList.

        Accepts any `iris.load_raw` keyword arguments.
        """
        import iris

        url = self.get_download_url(response="ncCF", **kw)
        data = urlopen(url, auth=self.auth).read()
        with _tempnc(data) as tmp:
            cubes = iris.load_raw(tmp, **kw)
            try:
                cubes.realise_data()
            except ValueError:
                iris.cube.CubeList([cube.data for cube in cubes])
            return cubes