Skip to content

Instantly share code, notes, and snippets.

@bekozi
Last active September 15, 2016 16:05
Show Gist options
  • Save bekozi/7a1c082f1ce5483a362534b0120e4571 to your computer and use it in GitHub Desktop.
Save bekozi/7a1c082f1ce5483a362534b0120e4571 to your computer and use it in GitHub Desktop.
import ocgis
from shapely.geometry import box
from shapely.geometry.multipolygon import MultiPolygon
path = '/media/benkoziol/Extra Drive 1/data/ocgis_test_data/CanCM4/tas_day_CanCM4_decadal2000_r2i1p1_20010101-20101231.nc'
rd = ocgis.RequestDataset(path)
wrapped_state = rd.get().spatial.wrapped_state
# If the data is on a 0 to 360 coordinate system, "unwrap" the bounding box.
if wrapped_state == ocgis.constants.WrappedState.UNWRAPPED:
geom = [160, -20, 340, 20]
# If the data is on a -180 to 180 coordinate system, break the bounding box into two elements and pass to the subsetter.
else:
geom1 = box(*[160, -20, 180, 20])
geom2 = box(*[-180, -20, -20, 20])
geom = MultiPolygon([geom1, geom2])
ops = ocgis.OcgOperations(dataset=rd, geom=geom)
ret = ops.execute()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment