diff --git a/mapchete/__init__.py b/mapchete/__init__.py index d5f5b46b..c3dc02dd 100644 --- a/mapchete/__init__.py +++ b/mapchete/__init__.py @@ -69,7 +69,8 @@ def __init__(self, config, with_cache=False): config = MapcheteConfig(config) assert isinstance(config, MapcheteConfig) self.config = config - config.output + # TODO assert this line is really not necessary + # config.output py_compile.compile(self.config.process_file, doraise=True) self.process_name = os.path.splitext( os.path.basename(self.config.process_file))[0] @@ -189,17 +190,13 @@ def write(self, process_tile): error = "no errors" else: message = "write" - try: - if self.config.mode == "continue" and ( - self.config.output.tiles_exist(process_tile) - ): - error = "exists, not overwritten" - else: - self.config.output.write(copy(process_tile)) - error = "no errors" - except Exception as e: - raise - error = e + if self.config.mode == "continue" and ( + self.config.output.tiles_exist(process_tile) + ): + error = "exists, not overwritten" + else: + self.config.output.write(copy(process_tile)) + error = "no errors" endtime = time.time() elapsed = "%ss" % (round((endtime - starttime), 3)) LOGGER.info( diff --git a/mapchete/cli/execute.py b/mapchete/cli/execute.py index d83d2d7c..b5515b48 100755 --- a/mapchete/cli/execute.py +++ b/mapchete/cli/execute.py @@ -2,7 +2,6 @@ """Command line utility to execute a Mapchete process.""" import os -import argparse from functools import partial from multiprocessing import cpu_count from multiprocessing.pool import Pool diff --git a/mapchete/formats/__init__.py b/mapchete/formats/__init__.py index 99322323..737cb339 100644 --- a/mapchete/formats/__init__.py +++ b/mapchete/formats/__init__.py @@ -26,7 +26,7 @@ def available_output_formats(): v.load().OutputData.METADATA["driver_name"]) except AttributeError: pass - except: + except Exception: raise return output_formats @@ -45,7 +45,7 @@ def available_input_formats(): for v in pkg_resources.iter_entry_points(_DRIVERS_ENTRY_POINT): try: input_formats.append(v.load().InputData.METADATA["driver_name"]) - except: + except Exception: pass return input_formats @@ -139,7 +139,7 @@ def _file_ext_to_driver(): mapping[ext].append(driver_name) else: mapping[ext] = [driver_name] - except: + except Exception: pass if not mapping: raise RuntimeError("no drivers could be found") diff --git a/mapchete/formats/default/png.py b/mapchete/formats/default/png.py index 7e2e60c0..20cece7e 100644 --- a/mapchete/formats/default/png.py +++ b/mapchete/formats/default/png.py @@ -137,7 +137,7 @@ def read(self, output_tile): data=data, mask=np.stack((mask, mask, mask, )) ) - except: + except Exception: output_tile.data = self.empty(output_tile) return output_tile @@ -286,7 +286,7 @@ def prepare_data(self, data): assert band.shape == band.mask.shape out_data += (band, ) out_mask += (band.mask, ) - except: + except AssertionError: out_data += (band.data, ) out_mask += ( np.where(band.data == self.nodata, True, False), ) @@ -306,7 +306,7 @@ def prepare_data(self, data): try: assert data.shape == data.mask.shape return data.astype("uint8") - except: + except AssertionError: return ma.MaskedArray( data=data.astype("uint8"), mask=np.where(data == self.nodata, True, False), diff --git a/mapchete/io/raster.py b/mapchete/io/raster.py index b86c36ae..b0444883 100644 --- a/mapchete/io/raster.py +++ b/mapchete/io/raster.py @@ -64,9 +64,7 @@ def read_raster_window(input_file, tile, indexes=None, resampling="nearest"): for band_idx in band_indexes: yield _get_warped_edge_array( tile=tile, input_file=input_file, band_idx=band_idx, - dst_bounds=tile.bounds, dst_shape=tile.shape, - dst_affine=tile.affine, dst_crs=tile.crs, resampling=resampling - ) + resampling=resampling) # If tile boundaries don't exceed pyramid boundaries, simply read window # once. @@ -80,8 +78,7 @@ def read_raster_window(input_file, tile, indexes=None, resampling="nearest"): def _get_warped_edge_array( - tile=None, input_file=None, band_idx=None, dst_bounds=None, dst_shape=None, - dst_affine=None, dst_crs=None, resampling="nearest" + tile=None, input_file=None, band_idx=None, resampling="nearest" ): tile_boxes = clip_geometry_to_srs_bounds( tile.bbox, tile.tile_pyramid, multipart=True) diff --git a/mapchete/io/vector.py b/mapchete/io/vector.py index d175b82e..399bcceb 100644 --- a/mapchete/io/vector.py +++ b/mapchete/io/vector.py @@ -80,13 +80,10 @@ def reproject_geometry( try: bbox_intersection = crs_bbox.intersection(geometry_4326) except TopologicalError: - try: - bbox_intersection = crs_bbox.intersection( - geometry_4326.buffer(0) - ) - warnings.warn("geometry fixed after clipping") - except: - raise + bbox_intersection = crs_bbox.intersection( + geometry_4326.buffer(0) + ) + warnings.warn("geometry fixed after clipping") # clip geometry dst_crs boundaries return _reproject_geom( bbox_intersection, @@ -115,7 +112,7 @@ def _reproject_geom( if validity_check: try: assert out_geom.is_valid - except: + except AssertionError: raise RuntimeError("invalid geometry after reprojection") return out_geom @@ -143,7 +140,7 @@ def read_vector_window(input_file, tile, validity_check=True): """ try: assert os.path.isfile(input_file) - except: + except AssertionError: raise IOError("input file does not exist: %s" % input_file) # Check if potentially tile boundaries exceed tile matrix boundaries on # the antimeridian, the northern or the southern boundary. @@ -158,10 +155,9 @@ def read_vector_window(input_file, tile, validity_check=True): tile.bbox, tile.tile_pyramid, multipart=True) return chain.from_iterable( _get_reprojected_features( - input_file=input_file, dst_bounds=bbox.bounds, dst_crs=tile.crs, - validity_check=validity_check) - for bbox in tile_boxes - ) + input_file=input_file, dst_bounds=bbox.bounds, + dst_crs=tile.crs, validity_check=validity_check) + for bbox in tile_boxes) else: features = _get_reprojected_features( input_file=input_file, dst_bounds=tile.bounds, @@ -199,7 +195,7 @@ def write_vector_window(in_tile, out_schema, out_tile, out_path): if clipped.geom_type != target_type: try: out_geom = clean_geometry_type(clipped, target_type) - except: + except Exception: warnings.warn("failed geometry cleaning during writing") continue if out_geom: @@ -336,5 +332,4 @@ def extract_from_tile(in_tile, out_tile): return [ feature for feature in in_tile.data - if shape(feature["geometry"]).touches(out_tile.bbox) - ] + if shape(feature["geometry"]).touches(out_tile.bbox)]