Skip to content

Commit

Permalink
edit comments for explaining how grid shift works
Browse files Browse the repository at this point in the history
  • Loading branch information
Drew Resnick committed Jul 9, 2021
1 parent e342906 commit cfb2a4e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions diagnostics/flow_dep_diag/cropping.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@
ds = xr.open_dataset(file_path, decode_times=False)

#the diagnostic assumes your grid has a longitudinal range -180,180
#Shift your grid from 0,360 using the following lines
#Shift your grid from 0,360 using the following lines; this will retain the correct
#coordinates if values are between -180,180
ds.coords['lon'] = (ds.coords['lon'] + 180) % 360 - 180 #shift the values
ds = ds.sortby(ds.lon) #sort them

#in the case your data is not cropped to a
#specific region, this code can be used to select a subset of data within a lat/lon

#cropping the dataset by the bounding box coordinates specified above
mask_lon = (ds.lon >= wlo) & (ds.lon <= elo)
mask_lat = (ds.lat >= sla) & (ds.lat <= nla)
cropped_ds = ds.where(mask_lon & mask_lat, drop=True)
cropped_ds = ds.where(mask_lon & mask_lat, drop=True)

cropped_ds.to_netcdf(output_path)

0 comments on commit cfb2a4e

Please sign in to comment.