Skip to content

Commit cfb2a4e

Browse files
author
Drew Resnick
committed
edit comments for explaining how grid shift works
1 parent e342906 commit cfb2a4e

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

diagnostics/flow_dep_diag/cropping.py

+4-6
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,13 @@
1212
ds = xr.open_dataset(file_path, decode_times=False)
1313

1414
#the diagnostic assumes your grid has a longitudinal range -180,180
15-
#Shift your grid from 0,360 using the following lines
15+
#Shift your grid from 0,360 using the following lines; this will retain the correct
16+
#coordinates if values are between -180,180
1617
ds.coords['lon'] = (ds.coords['lon'] + 180) % 360 - 180 #shift the values
1718
ds = ds.sortby(ds.lon) #sort them
18-
19-
#in the case your data is not cropped to a
20-
#specific region, this code can be used to select a subset of data within a lat/lon
21-
19+
#cropping the dataset by the bounding box coordinates specified above
2220
mask_lon = (ds.lon >= wlo) & (ds.lon <= elo)
2321
mask_lat = (ds.lat >= sla) & (ds.lat <= nla)
24-
cropped_ds = ds.where(mask_lon & mask_lat, drop=True)
22+
cropped_ds = ds.where(mask_lon & mask_lat, drop=True)
2523

2624
cropped_ds.to_netcdf(output_path)

0 commit comments

Comments
 (0)