Module Expr Str Import alias Import alias Import alias Import alias Import alias ImportFrom alias FunctionDef arguments args NameParam NameParam NameParam defaults Num body With Call AttributeLoad NameLoad attr body With Call AttributeLoad NameLoad attr NameLoad NameStore body Assign NameStore AttributeLoad NameLoad attr Delete SubscriptDel NameLoad Index Str Expr Call AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr Expr Call AttributeLoad NameLoad attr keyword Num keyword Num keyword Str With Call AttributeLoad NameLoad attr NameLoad Str NameLoad NameStore body FunctionDef arguments args defaults body For TupleStore NameStore NameStore Call AttributeLoad NameLoad attr body Assign NameStore Call AttributeLoad NameLoad attr keyword NameLoad Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr keyword AttributeLoad NameLoad attr Expr Yield TupleLoad NameLoad NameLoad NameLoad decorator_list With Call AttributeLoad AttributeLoad NameLoad attr attr keyword NameLoad NameStore body Assign NameStore DictComp Call AttributeLoad NameLoad attr NameLoad NameLoad NameLoad TupleLoad NameLoad NameLoad comprehension TupleStore NameStore NameStore NameStore Call NameLoad For NameStore Call AttributeLoad AttributeLoad NameLoad attr attr NameLoad body Assign TupleStore NameStore NameStore SubscriptLoad NameLoad Index NameLoad Expr Call AttributeLoad NameLoad attr NameLoad keyword NameLoad decorator_list If CompareEq NameLoad Str body Import alias Assign NameStore Call AttributeLoad NameLoad attr keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword Str Expr Call AttributeLoad NameLoad attr Str keyword Str keyword NameLoad keyword Call AttributeLoad NameLoad attr keyword Str Assign NameStore Call AttributeLoad NameLoad attr Expr Call NameLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr AttributeLoad NameLoad attr
N/A N/A concurrent-cpu-bound.py

Operate on a raster dataset window-by-window using a ThreadPoolExecutor.

Simulates a CPU-bound thread situation where multiple threads can improve performance.

With -j 4, the program returns in about 1/4 the time as with -j 1.
 N/A concurrent.futures N/A multiprocessing N/A time N/A numpy N/A rasterio rasterio._example compute main N/A N/A infile outfile num_workers N/A 4 N/A N/A N/A N/A rasterio drivers N/A N/A N/A N/A rasterio open infile src N/A N/A meta N/A src meta N/A N/A meta N/A transform N/A N/A N/A meta update affine N/A src affine N/A N/A N/A meta update blockxsize 256 blockysize 256 tiled yes N/A N/A N/A rasterio open outfile w meta dst N/A jobs N/A N/A N/A N/A N/A N/A ij window N/A N/A dst block_windows N/A N/A data N/A N/A src read window window N/A result N/A N/A numpy zeros N/A data shape dtype N/A data dtype N/A N/A N/A data result window N/A N/A N/A N/A N/A concurrent futures ThreadPoolExecutor max_workers num_workers executor N/A N/A future_to_window N/A N/A N/A executor submit compute data res N/A res window N/A N/A data res window N/A jobs N/A future N/A N/A N/A concurrent futures as_completed future_to_window N/A N/A N/A result window N/A future_to_window N/A future N/A N/A N/A dst write result window window N/A N/A N/A __name__ __main__ N/A N/A argparse N/A parser N/A N/A argparse ArgumentParser description Concurrent raster processing demo N/A N/A N/A parser add_argument input metavar INPUT help Input file name N/A N/A N/A parser add_argument output metavar OUTPUT help Output file name N/A N/A N/A parser add_argument -j metavar NUM_JOBS type int default N/A N/A multiprocessing cpu_count help Number of concurrent jobs N/A args N/A N/A parser parse_args N/A N/A main N/A args input N/A args output N/A args j