Exemplo n.º 1
0
 def test_get_wradlib_data_path(self):
     wrl_data_path = os.environ.get("WRADLIB_DATA", None)
     del os.environ["WRADLIB_DATA"]
     with pytest.raises(EnvironmentError):
         util.get_wradlib_data_path()
     if wrl_data_path is not None:
         os.environ["WRADLIB_DATA"] = wrl_data_path
Exemplo n.º 2
0
 def test_get_wradlib_data_path(self):
     wrl_data_path = os.environ.get('WRADLIB_DATA', None)
     del os.environ['WRADLIB_DATA']
     self.assertRaises(EnvironmentError,
                       lambda: util.get_wradlib_data_path())
     filename = 'rainbow/2013070308340000dBuZ.azi'
     os.environ['WRADLIB_DATA'] = os.path.join(wrl_data_path, filename)
     self.assertRaises(EnvironmentError,
                       lambda: util.get_wradlib_data_path())
     os.environ['WRADLIB_DATA'] = wrl_data_path
     filename = os.path.join(wrl_data_path, "test.dat")
     self.assertRaises(EnvironmentError,
                       lambda: util.get_wradlib_data_file(filename))
Exemplo n.º 3
0
 def test_get_wradlib_data_path(self):
     wrl_data_path = os.environ.get('WRADLIB_DATA', None)
     del os.environ['WRADLIB_DATA']
     self.assertRaises(EnvironmentError,
                       lambda: util.get_wradlib_data_path())
     filename = 'rainbow/2013070308340000dBuZ.azi'
     os.environ['WRADLIB_DATA'] = os.path.join(wrl_data_path, filename)
     self.assertRaises(EnvironmentError,
                       lambda: util.get_wradlib_data_path())
     os.environ['WRADLIB_DATA'] = wrl_data_path
     filename = os.path.join(wrl_data_path, "test.dat")
     self.assertRaises(EnvironmentError,
                       lambda: util.get_wradlib_data_file(filename))
Exemplo n.º 4
0
def get_srtm(extent, version=2, resolution=3, merge=True, download=None):
    """
    Get NASA SRTM elevation data

    Parameters
    ----------
    extent : str
        lonmin, lonmax, latmin, latmax
    version : int
        srtm version (2 or 3)
    resolution : int
        resolution of SRTM data (1, 3 or 30)
    merge : bool
        True to merge the tiles in one dataset
    download : dict
        download options (see download_srtm)

    Returns
    -------
    dataset : gdal.Dataset
        Raster dataset containing elevation information
    """

    extent = [int(np.floor(x)) for x in extent]
    lonmin, lonmax, latmin, latmax = extent

    filelist = []
    for latitude in range(latmin, min(latmax, 0)):
        for longitude in range(lonmin, min(lonmax, 0)):
            georef = "S%02gW%03g" % (-latitude, -longitude)
            filelist.append(georef)
        for longitude in range(max(lonmin, 0), lonmax + 1):
            georef = "S%02gE%03g" % (-latitude, longitude)
            filelist.append(georef)
    for latitude in range(max(0, latmin), latmax + 1):
        for longitude in range(lonmin, min(lonmax, 0)):
            georef = "N%02gW%03g" % (latitude, -longitude)
            filelist.append(georef)
        for longitude in range(max(lonmin, 0), lonmax + 1):
            georef = "N%02gE%03g" % (latitude, longitude)
            filelist.append(georef)
    if version == 3:
        filelist = ["%s.SRTMGL%s" % (f, resolution) for f in filelist]

    filelist = ["%s.hgt.zip" % (f) for f in filelist]

    wrl_data_path = util.get_wradlib_data_path()
    srtm_path = os.path.join(wrl_data_path, "geo")
    if not os.path.exists(srtm_path) and download is not None:
        os.makedirs(srtm_path)
    demlist = []
    for filename in filelist:
        path = os.path.join(srtm_path, filename)
        if os.path.exists(path):
            demlist.append(path)
            continue
        if download is not None:
            download_srtm(filename, path, version, resolution, **download)
            if os.path.exists(path):
                demlist.append(path)

    demlist = [gdal.Open(d) for d in demlist]
    if not merge:
        return demlist
    dem = gdal.Warp("", demlist, format="MEM")

    return dem
Exemplo n.º 5
0
 def test_get_wradlib_data_path_requires(self):
     filename = os.path.join(util.get_wradlib_data_path(), "test.dat")
     with pytest.raises(EnvironmentError):
         util.get_wradlib_data_file(filename)