예제 #1
0
파일: shared.py 프로젝트: SiggyF/gislib
def command(sourcepath):
    """ Do something spectacular. """
    dataset = gdal.Open(sourcepath)
    sdp = pyramids.SingleDatasetPyramid(dataset)
    from arjan.monitor import Monitor; mon = Monitor() 
    pool = multiprocessing.Pool(initializer=init, initargs=(sdp,))
    pool.map(func, range(1000))
    mon.check('') 
    print(sdp.levels[-1].array)
예제 #2
0
파일: sandbox.py 프로젝트: nens/threedi-wms
def command(sourcepath, targetpath, timestep=None):
    """ Do something spectacular. """
    quaddataset = quads.get_dataset(sourcepath)
    ascdriver = gdal.GetDriverByName(b'aaigrid')
    ascdriver.CreateCopy(b'arjen.asc', quaddataset)

    quaddata = quaddataset.ReadAsArray()

    if timestep is None:
        logger.debug('Calculating maximum flow velocity.')
        with Dataset(sourcepath) as dataset:
            fvx = dataset.variables['ucx'][:].max(0)
            fvy = dataset.variables['ucy'][:].max(0)
    else:
        with Dataset(sourcepath) as dataset:
            logger.debug('Calculating flow velocity for time = {}.'.format(
                dataset.variables['time'][timestep],
            ))
            fvx = dataset.variables['ucx'][:][timestep]
            fvy = dataset.variables['ucy'][:][timestep]

    # Create linear array
    fv = np.ma.array(
        np.empty(fvx.size + 1),
        mask=True,
    )

    # Fill with flowvelocity from netcdf
    fv[0:-1] = np.sqrt(fvx ** 2 + fvy ** 2)

    # Create mem dataset
    mem_driver = gdal.GetDriverByName(b'mem')
    fvdataset = mem_driver.Create(
        b'',
        quaddataset.RasterXSize,
        quaddataset.RasterYSize,
        1,
        gdal.GDT_Float32,
    )
    fvdataset.SetGeoTransform(quaddataset.GetGeoTransform())
    fvband = fvdataset.GetRasterBand(1)
    fvband.Fill(-999)
    fvband.SetNoDataValue(-999)
    fvband.WriteArray(fv[quaddata].filled(-999))

    # Create asciifile
    asc_driver = gdal.GetDriverByName(b'aaigrid')
    asc_driver.CreateCopy(
        targetpath,
        fvdataset,
        options=[b'DECIMAL_PRECISION=3']
    )

    # Creating asciifile via vsimem to show capability
    # Note that we need to
    vsipath = '/vsimem/' + targetpath

    from arjan.monitor import Monitor
    mon = Monitor()

    for i in range(500):
        vsipath = '/vsimem/' + targetpath + str(i)
        asc_driver.CreateCopy(
            vsipath,
            fvdataset,
            options=[b'DECIMAL_PRECISION=3']
        )
    mon.check('')
    a = np.ones(10000000)
    mon.check('ones')

    vsifile = gdal.VSIFOpenL(vsipath, b'r')
    with open(targetpath + '.demo', 'w') as demofile:
        demofile.write(gdal.VSIFReadL(
            gdal.VSIStatL(vsipath).size,  # Size
            1,                            # Count
            vsifile
        ))
    gdal.VSIFCloseL(vsifile)