#!/usr/bin/env python # -*- coding: utf-8 -*- import xarray as xr import numpy as np from datetime import datetime # Load dataset with xarray with xr.open_dataset('eddy_trajectory_nrt_3.0exp_cyclonic_20180101_20190828.nc', decode_cf=False) as h: lon_min, lon_max, lat_min, lat_max = 1, 5, -28, -27 t = 25150 # Select a specific eddy with date and area, only some observations subset = h.sel(obs=(h.longitude > lon_min) & (h.longitude < lon_max) & (h.latitude > lat_min) & (h.latitude < lat_max) & (h.time == 25147)) # Extract full track subset = h.isel(obs=np.in1d(h.track, subset.track)) # Store selected data print(subset) subset.to_netcdf('output_eddy.nc')