Last active
May 27, 2021 03:01
-
-
Save cbur24/70b161f168bf608613f4968bed20c189 to your computer and use it in GitHub Desktop.
Create xarray mask from vector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xarray as xr | |
import geopandas as gpd | |
from dea_tools.spatial import xr_rasterize | |
#read shapefile | |
mask_vector = gpd.read_file('mask.shp') | |
#import xarray ds | |
ds = xr.open_dataset('testing.nc') | |
#create mask using ds as template | |
mask = xr_rasterize(gdf=mask_vector, ds) | |
#mask the ds using the rasterized shape | |
ds = ds.where(mask) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment