Beispiel #1
0
def test_dem_create(tmpdir):
    with bbox({
            'xmin': 11.5,
            'xmax': 11.9,
            'ymin': 51,
            'ymax': 51.5
    }, crs=4326) as box:
        with pytest.raises(RuntimeError):
            files = dem_autoload([box], 'foobar')
        vrt = dem_autoload([box], 'SRTM 3Sec', vrt='/vsimem/test.vrt')
    out = os.path.join(str(tmpdir), 'srtm.tif')
    dem_create(src=vrt, dst=out, t_srs=32632, tr=(90, 90))
    assert os.path.isfile(out)
Beispiel #2
0
def geocode_and_stack(infile: Path,
                      outfile: Path,
                      temp_dir: Path = Path("tmp/"),
                      dem_type="AW3D30",
                      **kwargs):
    """Process one sentinel 1 zip file. The main preprocessing is done inside geocode.
    
    In the future, this may be rewritten to allow more control over the processing graph"""

    bbox = identify(str(infile)).bbox()
    print("Downloading DEM files")
    vrt = dem_autoload(geometries=[bbox],
                       demType=dem_type,
                       vrt=f"{dem_type}.vrt",
                       buffer=0.01)
    print("Converting DEM Files")
    dem_create(vrt, str(f"{dem_type}.tif"))

    geocode(str(infile),
            str(temp_dir),
            externalDEMFile=str(f"{dem_type}.tif"),
            **kwargs)
    os.remove(f"{dem_type}.tif")

    file_list = [
        str(file) for file in temp_dir.iterdir() if file.suffix == ".tif"
    ]
    print("Stacking GeoTiffs")
    stack_geotiffs(file_list, str(outfile))
    shutil.rmtree(temp_dir)
Beispiel #3
0
def test_autoload(auxdata_dem_cases, travis):
    # delete all target files to test downloading them again
    home = os.path.expanduser('~')
    demdir = os.path.join(home, '.snap', 'auxdata', 'dem')
    locals = [
        os.path.join(demdir, x, os.path.basename(y[0]))
        for x, y in auxdata_dem_cases
    ]
    for item in locals:
        if os.path.isfile(item):
            os.remove(item)
    with bbox({
            'xmin': 11.5,
            'xmax': 11.9,
            'ymin': 51,
            'ymax': 51.5
    }, crs=4326) as box:
        # if the following is run in a loop, it is not possible to see which demType failed
        # Travis CI does not support ftp access;
        # see https://blog.travis-ci.com/2018-07-23-the-tale-of-ftp-at-travis-ci
        if not travis:
            files = dem_autoload([box], 'AW3D30')
            assert len(files) == 1
            files = dem_autoload([box], 'AW3D30', product='stk')
            assert len(files) == 1
        files = dem_autoload([box], 'SRTM 1Sec HGT')
        assert len(files) == 1
        files = dem_autoload([box], 'SRTM 3Sec')
        assert len(files) == 1
        with pytest.raises(RuntimeError):
            files = dem_autoload([box], 'TDX90m')
        with pytest.raises(RuntimeError):
            dem_autoload([box], 'AW3D30', product='foobar')
Beispiel #4
0
                           t_srs=4326,
                           buffer=0.00)

    sys.exit()

    dem_id = args.dem.replace(' ', '-')
    dem_base = 'dem_snap_{}'.format(dem_id)

    dem_snap = os.path.join(args.path, dem_base + '.tif')
    if not os.path.isfile(dem_snap):

        # compile vrt of tiles covering aoi
        with Vector(args.aoi) as site:
            vrt = dem_autoload(geometries=[site],
                               demType=args.dem,
                               vrt='/vsimem/{}.vrt'.format(dem_base),
                               buffer=0.1,
                               username='******',
                               password='******')

        # create a DEM GTiff file from the VRT
        dem_create(src=vrt,
                   dst=dem_snap,
                   t_srs=args.srs,
                   tr=(args.res, args.res),
                   geoid_convert=True)
        print('Created SNAP dem file: ' + dem_snap)

    # create gamma dem files
    dem_base = 'dem_gamma_{}'.format(dem_id)
    dem_gamma = os.path.join(args.path, dem_base)
import os
from spatialist import gdalwarp, Vector

#set directories
maindir = '/exports/csce/datastore/geos/groups/MSCGIS/s1937352/DEM_Uganda'
os.chdir(maindir)

#specify shapefile of region of interest
roi = '/exports/csce/datastore/geos/groups/MSCGIS/s1937352/DEM_Uganda/UgandaBigBox.shp'

epsg = 21036  #specify epsg
demType = 'SRTM 1Sec HGT'  #specify dem type (Others: AW3D30, SRTM 3Sec)
dem_name = 'UgandaBig10'
dem_path = f'{maindir}/{dem_name}/.tif'
if not os.path.isfile(dem_path):
    #create VRT with the specified DEM and Bounding Box
    with Vector(roi) as bbox:
        vrt = dem_autoload(geometries=[bbox],
                           demType=demType,
                           vrt=f'/{dem_name}.vrt',
                           buffer=0.1)
    # create a tif from the VRT with a given resolution
    dem_create(src=vrt,
               dst=dem_path,
               t_srs=epsg,
               tr=(10, 10),
               geoid_convert=True)

# convert tif to Gamma files (dem, dem_par)
gammastring = f'dem_import UgandaBig10.tif UgandaB.dem UgandaB.dem_par - - /opt/gamma/20190613/DIFF/scripts/egm96.dem /opt/gamma/20190613/DIFF/scripts/egm96.dem_par'
os.system(gammastring)