forked from cgentemann/Saildrone
-
Notifications
You must be signed in to change notification settings - Fork 0
/
icoads.py
31 lines (24 loc) · 837 Bytes
/
icoads.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env python
# coding: utf-8
# In[1]:
import xarray as xr
import numpy as np
import matplotlib.pyplot as plt
import os
adir = 'F:/data/clim_data/icoads/2010s/'
adir2 = 'F:/data/clim_data/icoads/2010s_subset/'
for root, dirs, files in os.walk(adir):
for filename in files:
#print(filename)
file_out=filename[:-3]+'_subset.nc'
ds=xr.open_dataset(adir+filename)
ds.close()
keep=['SST','SI','PT','SNC','DUPC','DUPS','OTZ','DOS','AT','II','ANC']
for var in ds:
if np.logical_not(var in keep):
#else:
ds=ds.drop(var)
cond = (ds.lat>50) & (ds.lat<80) & (ds.SNC==1) & (ds.DUPS==0) & (ds.lon>180) & (ds.lon<215)
subset = ds.where(cond,drop=True)
subset.to_netcdf(adir2+file_out)
print(filename)