subset_interim.py 761 Bytes
Newer Older
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
30
31
""" Read a latitude strip from annual files and write it into a single file."""

__author__ = "Carl Schreck"
__email__ = "cjschrec@ncsu.edu"
__copyright__ = "Copyright 2019, North Carolina State University"
__license__ = "BSD-3.0"

import xarray as xr
import sys
sys.path.append('/home/carl/lib/python')
import cjs
import tarfile, os, glob

cjs.tstamp('Here we go!')
var_name = 'u850'
basedir = '/home/carl/data/era-interim/'

cjs.tstamp('Open')
in_files = glob.glob(basedir + '/' + var_name + '.201*.nc')
in_files.sort()
ds = xr.open_mfdataset(in_files, concat_dim='time')

cjs.tstamp('Read/Write')
ds.encoding['_FillValue'] = -9999.
ds.to_netcdf(basedir + 'total/' + var_name + '.nc' )

cjs.tstamp('Closing')
ds.close()

cjs.tstamp('Thank you, come again.')