I masked a geotiff raster with a shapefile as described below
import rasterio
from rasterio.plot import show
import geopandas as gpd
population = rasterio.open('myData.tif')
gdf = gpd.read_file('myFile.shp')
clipped_array, clipped_transform =
rasterio.mask.mask(population, [mapping(ps.iloc[0].geometry)], crop=True)
f,ax=plt.subplots(figsize=(10,10))
gdf.boundary.plot(ax=ax, lw=3, color='red')
show(clipped_array, transform=clipped_transform, ax=ax)
ax.set_xlim([1.82, 2.74])
ax.set_ylim([48.51, 49.14])
Now I would like to save the new data as a .tif
file with coordinates and information.