Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add region selection from file #981

Merged
merged 8 commits into from
Sep 18, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
attr is required
  • Loading branch information
acordonez committed Sep 12, 2023
commit cad4b7e29c1731afe17ed7f9b5f3e89c772d4f48
8 changes: 2 additions & 6 deletions pcmdi_metrics/io/region_from_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import xarray as xr
import xcdat

def region_from_file(data,rgn_path,feature,attr=None):
def region_from_file(data,rgn_path,attr,feature):
# Return data masked from a feature in input file.
# Arguments:
# data: xcdat dataset
Expand All @@ -17,11 +17,7 @@ def region_from_file(data,rgn_path,feature,attr=None):
print("Reading region from file.")
try:
regions_df = gpd.read_file(rgn_path)
if attr is not None:
regions = regionmask.from_geopandas(regions_df,names=attr)
else:
print("Attribute name not provided.")
regions = regionmask.from_geopandas(regions_df)
regions = regionmask.from_geopandas(regions_df,names=attr)
mask = regions.mask(lon, lat)
# Can't match mask by name, rather index of name
val = list(regions_df[attr]).index(feature)
Expand Down
Loading