def _query_sources(self, query): """ Query all sources and return the results as a single ImageSource. Multiple sources will be merged into a single image. """ # directly return get_map without merge if ... if (len(self.sources) == 1 and not self.image_merger and # no special image_merger (like BandMerger) not (self.sources[0].coverage and # no clipping coverage self.sources[0].coverage.clip and self.sources[0].coverage.intersects(query.bbox, query.srs)) ): try: return self.sources[0].get_map(query) except BlankImage: return None def get_map_from_source(source): try: img = source.get_map(query) except BlankImage: return None, None else: return (img, source.coverage) layers = [] for layer in async_.imap(get_map_from_source, self.sources): if layer[0] is not None: layers.append(layer) return merge_images(layers, size=query.size, bbox=query.bbox, bbox_srs=query.srs, image_opts=self.tile_mgr.image_opts, merger=self.image_merger)
def test_map_with_exception(self): def func(x): raise Exception() try: list(imap(func, list(range(40)))) except Exception: pass else: assert False, 'exception expected'
def test_map(self): def func(x): time.sleep(0.05) return x start = time.time() result = list(imap(func, list(range(40)))) stop = time.time() duration = stop - start assert duration < 0.5, "took %s" % duration assert len(result) == 40