def filter_merge_clusters(clusters, max_block_size_multi=5, min_block_pop=50, buffer_amount=150):
	"""
	The vectors created by create_clusters() are a single square for each raster pixel.
	This function does the follows:
	- Remove overly large clusters, caused by defects in the input raster.
	- Remove clusters with population below a certain threshold.
	- Buffer the remaining clusters and merge those that overlap.

	Parameters
	----------
	clusters: geopandas.GeoDataFrame
		The unprocessed clusters created by create_clusters()
	max_block_size_multi: int, optional
		Remove clusters that are more than this many times average size. Default 5.
	min_block_pop: int, optional
		Remove clusters with below this population. Default 50.
	buffer_amount: int, optional
		Distance in metres by which to buffer the clusters before merging. Default 150.

	Returns
	-------
	clusters: geopandas.GeoDataFrame
		The processed clusters.
	"""

	# remove blocks that are too big (basically artifacts)
	clusters['area_m2'] = clusters.geometry.area
	clusters = clusters[clusters['area_m2'] < clusters['area_m2'].mean() * max_block_size_multi]

	# remove blocks with too few people
	clusters = clusters[clusters['raster_val'] > min_block_pop]

	# buffer outwards so that nearby blocks will overlap
	clusters['geometry'] = clusters.geometry.buffer(buffer_amount)

	# and dissolve the thousands of blocks into a single layer (with no attributes!)
	clusters['same'] = 1
	clusters = clusters.dissolve(by='same')

	# To get our attributes back, we convert the dissolves polygon into singleparts
	# This means each contiguous bubble becomes its own polygon and can store its own attributes
	crs = clusters.crs
	clusters = clusters.explode()
	clusters = clusters.reset_index()

	# no longer needed in GeoPandas >= 0.4.0
	# clusters['geometry'] = clusters[0]
	# clusters = gpd.GeoDataFrame(clusters)
	# clusters.crs = crs

	clusters = clusters.drop(columns=['same', 'level_1', 'raster_val'])  # raster_val is no longer meaningful
	

	# And then add the polygon's area back to its attributes
	clusters["area_m2"] = clusters['geometry'].area

	return clusters