Comments (2)
Actually I rediscovered your excellent ray
solution!
@ray.remote
class Actor(object):
def __init__(self, aoi_id=None, id_column=None, band_names=None):
self.aoi_id = aoi_id
self.id_column = id_column
self.band_names = band_names
# While the names can differ, these three arguments are required.
# For ``ParallelTask``, the callable function within an ``Actor`` must be named exec_task.
def exec_task(self, data_block_id, data_slice, window_id):
data_block = data_block_id[data_slice]
left, bottom, right, top = data_block.gw.bounds
aoi_sub = self.aoi_id.cx[left:right, bottom:top]
if aoi_sub.empty:
return aoi_sub
# Return a GeoDataFrame for each actor
return gw.extract(data_block,
aoi_sub,
id_column=self.id_column,
band_names=self.band_names)
ray.init(num_cpus=8)
for band_name in ["B12", "B11", "B2", "B6", "EVI", "hue"]:
for poly_i, poly_label in zip([0,1],['34S_19E_258N','34S_19E_259N']):
with rio.Env(GDAL_CACHEMAX=256*1e6) as env:
band_name = 'B12'
file_glob = f"*{band_name}*.tif"
f_list = sorted(glob(file_glob))
df_id = ray.put(gpd.read_file(polys[poly_i]).to_crs('EPSG:4326'))
band_names=[i.split('.ti')[0] for i in f_list]
# Since we are iterating over the image block by block, we do not need to load
# a lazy dask array (i.e., chunked).
with gw.open(f_list,
band_names=band_names,
stack_dim='band',
chunks=16) as src:
# Setup the pool of actors, one for each resource available to ``ray``.
actor_pool = ActorPool([Actor.remote(aoi_id=df_id, id_column='id', band_names=band_names)
for n in range(0, int(ray.cluster_resources()['CPU']))])
# Setup the task object
pt = ParallelTask(src, row_chunks=4096, col_chunks=4096, scheduler='ray', n_chunks=1000)
results = pt.map(actor_pool)
del df_id, actor_pool
ray.shutdown()
results2 = [df.reset_index(drop=True) for df in results if len(df) > 0]
result = pd.concat(results2, ignore_index=True,axis=0)
result = pd.DataFrame(result.drop(columns='geometry'))
result.to_parquet(f'./{band_name}_{poly_label}.parquet',
engine='auto',
compression='snappy')
There was one issue with the example, for gw.open
the example online had chunks=None
and I needed to replace that with some valid value.
ray
is extremely fast...
from geowombat.
Hmm, what do your array chunks look like after opening the file list?
from geowombat.
Related Issues (20)
- Expand pinned python version HOT 1
- Feedstock Issues HOT 1
- Failed to Install Geowombat on pip and conda HOT 12
- Requirement differences between package & conda-forge HOT 6
- Coordinating efforts on potential new geospatial Xarray accessor HOT 2
- Regression capability in geowombat HOT 3
- ARM Installation Issues HOT 9
- Apply interpolation HOT 4
- Stac import HOT 2
- series.apply big tiff / bad block
- EVI equation is wrong HOT 2
- Support for pyproj 3.4.1? HOT 8
- mosaic bounds HOT 4
- fit_predict
- Stack & Mosaic Advice? HOT 6
- writing with Bigtiff HOT 2
- [] in open trigger stacking
- polygon_to_array returns shorter y dimension than source rasters HOT 26
- band names HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from geowombat.