Skip to content

xray methods using shapefile as mask? #501

@slharris

Description

@slharris

Can we set a shapefile as a mask for each netcdf file and run xray methods for values within the shapefile region?

for example if I want to create a timeseries of monthly mean temperature for 'mystate' from a netcdf file that contains data for the whole country:

filepath = r"DATA/temp/_/_temp.nc"
shapefile = r"DATA/mystate.shp"

ds=xray.open_mfdataset(filepath)
ds_variable=ds['temp']
monthlymean=ds_variable.resample('1MS', dim='time', how='mean')
meanmonthlyofmystate=monthlymean.groupby('time').mean() #add somewhere here the shapefile
meanmonthlyofmystate.to_pandas().plot()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions