Exemplo n.º 1
0
def read(filename, vars, altitude=None, lon=None, lat=None, **kwargs):
    dep_vars = list(set([y for x in vars if x in VARS for y in VARS[x]]))
    d = ds.from_netcdf(
        filename,
        dep_vars,
    )
    dx = {}
    n, m = d['beta_raw'].shape
    if altitude is None:
        altitude = d['altitude']
    if 'time' in vars:
        dx['time'] = d['time'] / (24.0 * 60.0 * 60.0) + 2416480.5
        dx['time_bnds'] = misc.time_bnds(dx['time'],
                                         dx['time'][1] - dx['time'][0])
    if 'backscatter' in vars:
        dx['backscatter'] = d['beta_raw'] * 1e-11 * CALIBRATION_COEFF
    if 'zfull' in vars:
        zfull1 = d['range'] + altitude
        dx['zfull'] = np.tile(zfull1, (n, 1))
    if 'altitude' in vars:
        dx['altitude'] = np.full(n, altitude, np.float64)
    if 'lon' in vars:
        dx['lon'] = np.full(n, lon, np.float64)
    if 'lat' in vars:
        dx['lat'] = np.full(n, lat, np.float64)
    dx['.'] = META
    dx['.'] = {x: dx['.'][x] for x in vars if x in VARS}
    return dx
Exemplo n.º 2
0
def read(filename, vars, altitude=None, lon=None, lat=None, **kwargs):
	dep_vars = list(set([y for x in vars if x in VARS for y in VARS[x]]))
	d = ds.read(filename, dep_vars)
	dx = {}
	if 'time' in vars:
		n = len(d['time'])
		dx['time'] = d['time']/86400. + 2440587.5
		dx['time_bnds'] = misc.time_bnds(dx['time'], dx['time'][1] - dx['time'][0])
	if 'altitude' in vars:
		dx['altitude'] = d['altitude'][:,0].astype(np.float64).filled(np.nan)
	if 'zfull' in vars:
		range_ = d['range'].astype(np.float64).filled(np.nan)
		dx['zfull'] = np.tile(range_, (n, 1))
		dx['zfull'] = (dx['zfull'].T + dx['altitude']).T
	if 'lon' in vars:
		dx['lon'] = np.full(n, lon, np.float64)
	if 'lat' in vars:
		dx['lat'] = np.full(n, lat, np.float64)
	if 'backscatter' in vars:
		profile_data = d['profile_data'].astype(np.float64).filled(np.nan)
		dx['backscatter'] = profile_data*CALIBRATION_COEFF
		n, m = dx['backscatter'].shape
		j = np.max(np.nonzero(np.any(np.isfinite(dx['backscatter']), axis=0)))
		dx['backscatter'] = dx['backscatter'][:,:(j + 1)]
		if 'zfull' in vars:
			dx['zfull'] = dx['zfull'][:,:(j + 1)]
	dx['.'] = META
	dx['.'] = {
		x: dx['.'][x]
		for x in vars
		if x in VARS
	}
	return dx
Exemplo n.º 3
0
def read(dirname, track, warnings=[], step=1. / 24.):
    dd_index = ds.readdir(dirname,
                          variables=['time0', 'latitude', 'longitude'],
                          jd=True)
    start_time = track['time'][0]
    end_time = track['time'][1]
    dd = []
    for d_index in dd_index:
        time = d_index['time0']
        lon = d_index['longitude']
        lon = np.where(lon < 0., 360. + lon, lon)
        lat = d_index['latitude']
        filename = d_index['filename']
        ii = np.where((time >= start_time - GRACE_TIME)
                      & (time <= end_time + GRACE_TIME))[0]
        for i in ii:
            i2 = np.argmin(np.abs(track['time'] - time[i]))
            lon0 = track['lon'][i2]
            lat0 = track['lat'][i2]
            l = np.argmin((lon - lon0)**2 + (lat - lat0)**2)
            j, k = np.unravel_index(l, lon.shape)
            # print('<- %s' % filename)
            d = ds.read(filename,
                        variables=VARIABLES,
                        sel={
                            'time0': i,
                            'rlat': j,
                            'rlon': k
                        })
            if not set(VARIABLES).issubset(d.keys()):
                continue
            clw = d['model_qcl']
            cli = d['model_qcf']
            cl = 100. * np.ones(len(clw), dtype=np.float64)
            ps = 2 * d['model_press'][0] - d['model_press'][1]
            orog = max(0., 2 * d['hybridt32'][0] - d['hybridt32'][1])
            pfull = d['model_press']
            zfull = d['hybridt32']
            ta = d['theta_lev_temp']
            newshape4 = (1, len(clw))
            newshape3 = (1, )
            d_new = {
                'clw': clw.reshape(newshape4),
                'cli': cli.reshape(newshape4),
                'ta': ta.reshape(newshape4),
                'cl': cl.reshape(newshape4),
                'pfull': pfull.reshape(newshape4),
                'zfull': zfull.reshape(newshape4),
                'ps': [ps],
                'orog': [orog],
                'lon': np.array([lon[j, k]]),
                'lat': np.array([lat[j, k]]),
                'time': np.array([time[i]]),
                '.': META,
            }
            dd.append(d_new)
    d = ds.op.merge(dd, 'time')
    if 'time' in d:
        d['time_bnds'] = misc.time_bnds(d['time'], step)
    return d
Exemplo n.º 4
0
def read(dirname, track, warnings=[], step=3. / 24.):
    dd_index = ds.readdir(dirname, variables=['time', 'lat', 'lon'], jd=True)
    start_time = track['time'][0]
    end_time = track['time'][-1]
    dd = []
    for d_index in dd_index:
        time = d_index['time']
        lat = d_index['lat']
        lon = d_index['lon']
        lon = np.where(lon < 0., 360. + lon, lon)
        filename = d_index['filename']
        ii = np.nonzero((time >= start_time) & (time < end_time))[0]
        for i in ii:
            t = time[i]
            i2 = np.argmin(np.abs(track['time'] - time[i]))
            lat0 = track['lat'][i2]
            lon0 = track['lon'][i2]
            j = np.argmin(np.abs(lat - lat0))
            k = np.argmin(np.abs(lon - lon0))
            d = ds.read(filename,
                        variables=VARIABLES,
                        sel={
                            'time': i,
                            'lat': j,
                            'lon': k
                        })
            clw = d['QL'][::-1]
            cli = d['QI'][::-1]
            cl = d['CLOUD'][::-1] * 100.
            ps = d['PS']
            orog = d['PHIS'] / 9.80665
            pfull = d['PL'][::-1]
            zfull = d['H'][::-1]
            ta = d['T'][::-1]
            nlev = len(clw)
            newshape4 = (1, nlev)
            newshape3 = (1, )
            d_new = {
                'clw': clw.reshape(newshape4),
                'cli': cli.reshape(newshape4),
                'ta': ta.reshape(newshape4),
                'cl': cl.reshape(newshape4),
                'pfull': pfull.reshape(newshape4),
                'zfull': zfull.reshape(newshape4),
                'ps': ps.reshape(newshape3),
                'orog': orog.reshape(newshape3),
                'lat': np.array([lat[j]]),
                'lon': np.array([lon[k]]),
                'time': np.array([t]),
                '.': META,
            }
            dd.append(d_new)
    d = ds.op.merge(dd, 'time')
    if 'time' in d:
        d['time_bnds'] = misc.time_bnds(d['time'], step)
    d['.'] = META
    return d
Exemplo n.º 5
0
def read(dirname, track, warnings=[], step=3. / 24.):
    dd_index = ds.readdir(dirname, variables=['XTIME'], jd=True)
    start_time = track['time'][0]
    end_time = track['time'][-1]
    dd = []
    for d_index in dd_index:
        time = d_index['XTIME'][0]
        time0 = d_index['.']['.']['SIMULATION_START_DATE']
        time0 = aq.from_iso(time0.replace('_', 'T'))
        if time < 2000000.:
            time = time0 + time / (24. * 60.)
        filename = d_index['filename']
        if (time >= start_time - step * 0.5) & (time < end_time + step * 0.5):
            k = np.argmin(np.abs(track['time'] - time))
            lon0 = track['lon'][k]
            lat0 = track['lat'][k]
            d = ds.read(filename, variables=VARS, sel={'Time': 0})
            lon = np.where(d['XLONG'] < 0., 360. + d['XLONG'], d['XLONG'])
            lat = d['XLAT']
            l = np.argmin((lon - lon0)**2 + (lat - lat0)**2)
            i, j = np.unravel_index(l, lon.shape)
            clw = d['QCLOUD'][:, i, j]
            cli = d['QICE'][:, i, j]
            cl = 100. * np.ones(len(clw), dtype=np.float64)
            ps = d['PSFC'][i, j]
            orog = d['HGT'][i, j]
            pfull = d['PB'][:, i, j] + d['P'][:, i, j]
            zfull = (d['PHB'][:, i, j] + d['PH'][:, i, j]) / 9.81
            zfull = 0.5 * (zfull[1:] + zfull[:-1])
            theta = d['T'][:, i, j] + d['T00']
            ta = theta * (pfull / ps)**KAPPA
            newshape3 = [1] + list(clw.shape)
            newshape2 = [1] + list(ps.shape)
            d_new = {
                'clw': clw.reshape(newshape3),
                'cli': cli.reshape(newshape3),
                'ta': ta.reshape(newshape3),
                'cl': cl.reshape(newshape3),
                'pfull': pfull.reshape(newshape3),
                'zfull': zfull.reshape(newshape3),
                'ps': ps.reshape(newshape2),
                'orog': orog.reshape(newshape2),
                'lon': np.array([lon[i, j]]),
                'lat': np.array([lat[i, j]]),
                'time': np.array([time]),
                '.': META,
            }
            dd.append(d_new)
    d = ds.op.merge(dd, 'time')
    if 'time' in d:
        d['time_bnds'] = misc.time_bnds(d['time'], step, start_time, end_time)
        d['time'] = np.mean(d['time_bnds'], axis=1)
    d['.'] = META
    return d
Exemplo n.º 6
0
def read(filename, vars,
	altitude=None,
	lon=None,
	lat=None,
	calibration_coeff=CALIBRATION_COEFF,
	fix_cl_range=False,
	cl_crit_range=6000,
	**kwargs
):
	dep_vars = list(set([y for x in vars if x in VARS for y in VARS[x]]))
	required_vars = dep_vars + DEFAULT_VARS
	d = ds.from_netcdf(
		filename,
		required_vars
	)
	dx = {}
	dx['time'] = d['time']/(24.0*60.0*60.0) + 2440587.5
	dx['time_bnds'] = misc.time_bnds(dx['time'], dx['time'][1] - dx['time'][0])

	n = len(dx['time'])
	range_ = d['vertical_resolution'][0]*d['level']
	if 'zfull' in vars:
		zfull1 = range_
		dx['zfull'] = np.tile(zfull1, (n, 1))
		if altitude is not None:
			dx['zfull'] += altitude
	if 'backscatter' in vars:
		dx['backscatter'] = d['backscatter']*calibration_coeff
		mask = range_ > 6000
		if fix_cl_range is True:
			for i in range(n):
				if d['detection_status'][i] == b'0':
					dx['backscatter'][i,mask] *= (range_[mask]/6000)**2
	if 'altitude' in vars:
		dx['altitude'] = np.full(n, altitude, np.float64)
	if 'lon' in vars:
		dx['lon'] = np.full(n, lon, np.float64)
	if 'lat' in vars:
		dx['lat'] = np.full(n, lat, np.float64)
	dx['.'] = META
	dx['.'] = {
		x: dx['.'][x]
		for x in vars
		if x in dx['.']
	}
	return dx
Exemplo n.º 7
0
def read(filename, vars, altitude=None, lon=None, lat=None, **kwargs):
    dep_vars = list(set([y for x in vars if x in VARS for y in VARS[x]]))
    d = ds.read(filename, dep_vars)
    dx = {}
    if 'time' in vars:
        n = len(d['time'])
        dx['time'] = d['time'] / 86400. + 2440587.5
        dx['time_bnds'] = misc.time_bnds(dx['time'],
                                         dx['time'][1] - dx['time'][0])
    if 'altitude' in vars:
        dx['altitude'] = d['elevation']
    if 'zfull' in vars:
        dx['zfull'] = np.tile(d['range'], (n, 1))
        dx['zfull'] = (dx['zfull'].T + dx['altitude']).T
    if 'lon' in vars:
        dx['lon'] = np.full(n, lon, np.float64)
    if 'lat' in vars:
        dx['lat'] = np.full(n, lat, np.float64)
    if 'backscatter' in vars:
        dx['backscatter'] = d['beta_att'] * CALIBRATION_COEFF
    dx['.'] = META
    dx['.'] = {x: dx['.'][x] for x in vars if x in VARS}
    return dx
Exemplo n.º 8
0
def read(filename, vars, altitude=None, lon=None, lat=None, **kwargs):
    d = ds.read(filename, VARIABLES, jd=True)
    mask = d['elevation_angle'] == 0.0
    dx = {}
    n, m = d['nrb_copol'].shape

    altitude = d['gps_altitude'] if altitude is None else \
     np.full(n, altitude, np.float64)
    lon = d['gps_longitude'] if lon is None else \
     np.full(n, lon, np.float64)
    lat = d['gps_latitude'] if lat is None else \
     np.full(n, lat, np.float64)

    if 'time' in vars:
        dx['time'] = d['time']
        dx['time_bnds'] = misc.time_bnds(dx['time'],
                                         dx['time'][1] - dx['time'][0])
    if 'zfull' in vars:
        dx['zfull'] = np.full((n, m), np.nan, np.float64)
        for i in range(n):
            range_ = 0.5 * d['bin_time'][i] * d['c'] * (np.arange(m) + 0.5)
            dx['zfull'][i, :] = range_ * np.sin(
                d['elevation_angle'][i] / 180.0 * np.pi)
            dx['zfull'][i, :] += altitude[i]
    if 'backscatter' in vars:
        dx['backscatter'] = (d['nrb_copol'] +
                             2. * d['nrb_crosspol']) * CALIBRATION_COEFF
    if 'altitude' in vars:
        dx['altitude'] = altitude
    if 'lon' in vars:
        dx['lon'] = lon
    if 'lat' in vars:
        dx['lat'] = lat
    dx['.'] = META
    dx['.'] = {x: dx['.'][x] for x in vars if x in dx['.']}
    return dx
Exemplo n.º 9
0
def read(dirname, track, warnings=[], step=1./24.):
	d_orog = ds.read(os.path.join(dirname, 'qrparm.orog.nc'), [
		'latitude',
		'longitude',
		'surface_altitude',
	])

	dd_idx = ds.readdir(dirname,
		variables=['TALLTS', 'latitude_t', 'longitude_t', 'DALLTH_zsea_theta'],
		jd=True,
		full=True,
		warnings=warnings,
	)
	start_time = track['time'][0]
	end_time = track['time'][-1]

	dd = []
	for d_idx in dd_idx:
		if 'TALLTS' not in d_idx:
			continue

		time = d_idx['TALLTS']
		lat = d_idx['latitude_t']
		lon = d_idx['longitude_t']
		filename = d_idx['filename']

		ii = np.nonzero(
			(time >= start_time - step*0.5) &
			(time < end_time + step*0.5)
		)[0]
		for i in ii:
			t = time[i]
			i2 = np.argmin(np.abs(track['time'] - time[i]))
			lat0 = track['lat'][i2]
			lon0 = track['lon'][i2]
			j = np.argmin(np.abs(lat - lat0))
			k = np.argmin(np.abs(lon - lon0))
			d = ds.read(filename, VARS,
				sel={'TALLTS': [i], 'latitude_t': j, 'longitude_t': k},
				jd=True,
			)
			for a, b in TRANS.items():
				if a in d.keys():
					ds.rename(d, a, b)
			d['lat'] = np.array([d['lat']])
			d['lon'] = np.array([d['lon']])
			d['.']['lat']['.dims'] = ['time']
			d['.']['lon']['.dims'] = ['time']
			orog = d_orog['surface_altitude'][j,k]
			d['zfull'] = d['eta']*85000. + orog*(1. - d['eta']/d['eta'][51])**2
			d['zfull'] = d['zfull'].reshape([1, len(d['zfull'])])
			d['.']['zfull'] = {'.dims': ['time', 'level']}
			d['orog'] = np.array([orog], np.float64)
			d['.']['orog'] = {'.dims': ['time']}
			del d['eta']
			dd.append(d)
	d = ds.op.merge(dd, 'time')
	d['cl'] *= 100.
	if 'time' in d:
		d['time_bnds'] = misc.time_bnds(d['time'], step, start_time, end_time)
		d['time'] = np.mean(d['time_bnds'], axis=1)
	d['.'] = META
	return d
Exemplo n.º 10
0
def read(dirname, track, warnings=[], step=6. / 24.):
    dd_index = ds.readdir(
        dirname,
        variables=['time', 'latitude', 'longitude', 'level_height'],
        jd=True,
        full=True,
        warnings=warnings,
    )
    start_time = track['time'][0]
    end_time = track['time'][-1]
    d_var = {}
    for var in VARIABLES:
        dd = []
        for d_index in dd_index:
            if var not in d_index['.']:
                continue
            time = d_index['time']
            time_half = misc.half(time)
            lat = d_index['latitude']
            lon = d_index['longitude']
            level_height = d_index['level_height']
            filename = d_index['filename']
            ii = np.nonzero((time_half[1:] >= start_time)
                            & (time_half[:-1] < end_time))[0]
            for i in ii:
                t = time[i]
                i2 = np.argmin(np.abs(track['time'] - time[i]))
                lat0 = track['lat'][i2]
                lon0 = track['lon'][i2]
                j = np.argmin(np.abs(lat - lat0))
                k = np.argmin(np.abs(lon - lon0))
                d = ds.read(filename,
                            variables=[var],
                            sel={
                                'time': i,
                                'latitude': j,
                                'longitude': k
                            })
                d_new = {
                    'lat': np.array([lat[j]]),
                    'lon': np.array([lon[k]]),
                    'time': np.array([t]),
                    'level_height': np.array([level_height]),
                    '.': META,
                }
                d_new['.']['level_height'] = {'.dims': ['level']}
                d_new[TRANS[var]] = d[var].reshape([1] + list(d[var].shape))
                if TRANS[var] == 'cl':
                    d_new[TRANS[var]] *= 100.
                dd.append(d_new)
        if len(dd) > 0:
            d_var[TRANS[var]] = ds.op.merge(dd, 'time')
    time_list = [set(d_var[var]['time']) for var in d_var.keys()]
    time = time_list[0].intersection(*time_list[1:]) \
     if len(time_list) > 0 \
     else set()
    d = {}
    d['.'] = {}
    if len(time) == 0:
        return None
    for var in d_var.keys():
        idx = [i for i, t in enumerate(d_var[var]['time']) if t in time]
        ds.select(d_var[var], {'time': idx})
        d[var] = d_var[var][var]
        d['lat'] = d_var[var]['lat']
        d['lon'] = d_var[var]['lon']
        d['time'] = d_var[var]['time']
        d['level_height'] = d_var[var]['level_height']
    if 'ps' not in d:
        n, m = d['pfull'].shape
        d['ps'] = np.full(n, np.nan, dtype=np.float64)
        for i in range(n):
            d['ps'][i] = 2 * d['pfull'][i, 0] - d['pfull'][i, 1]
    if 'zfull' not in d:
        n, m = d['pfull'].shape
        d['zfull'] = np.full((n, m), np.nan, dtype=np.float64)
        for i in range(n):
            d['zfull'][i, :] = d['level_height']
    del d['level_height']
    if 'orog' not in d:
        n, m = d['zfull'].shape
        d['orog'] = np.full(n, np.nan, dtype=np.float64)
        for i in range(n):
            d['orog'][i] = 2 * d['zfull'][i, 0] - d['zfull'][i, 1]
    if 'time' in d:
        d['time_bnds'] = misc.time_bnds(d['time'], step)
    d['.'] = META
    return d
Exemplo n.º 11
0
def read0(type_, dirname, track, warnings=[], step=1. / 24.):
    dd_idx = ds.readdir(
        dirname,
        variables=['time', 'latitude', 'longitude'],
        jd=True,
        full=True,
        warnings=warnings,
    )
    start_time = track['time'][0]
    end_time = track['time'][-1]

    vars = {
        'surf': VARS_SURF,
        'plev': VARS_PLEV,
    }[type_]

    trans = {
        'surf': TRANS_SURF,
        'plev': TRANS_PLEV,
    }[type_]

    dd = []
    for d_idx in dd_idx:
        time = d_idx['time']
        lat = d_idx['latitude']
        lon = d_idx['longitude']
        filename = d_idx['filename']

        ii = np.nonzero((time >= start_time - step * 0.5)
                        & (time < end_time + step * 0.5))[0]
        for i in ii:
            t = time[i]
            i2 = np.argmin(np.abs(track['time'] - time[i]))
            lat0 = track['lat'][i2]
            lon0 = track['lon'][i2]
            j = np.argmin(np.abs(lat - lat0))
            k = np.argmin(np.abs(lon - lon0))
            d = ds.read(
                filename,
                vars,
                sel={
                    'time': [i],
                    'latitude': j,
                    'longitude': k
                },
                jd=True,
            )
            for a, b in trans.items():
                if a in d.keys():
                    ds.rename(d, a, b)
            d['lat'] = np.array([d['lat']])
            d['lon'] = np.array([d['lon']])
            d['.']['lat']['.dims'] = ['time']
            d['.']['lon']['.dims'] = ['time']
            if type_ == 'plev':
                d['pfull'] = d['pfull'].reshape([1, len(d['pfull'])])
                d['.']['pfull']['.dims'] = ['time', 'level']
                d['cl'] = d['cl'][:, ::-1]
                d['clw'] = d['clw'][:, ::-1]
                d['cli'] = d['cli'][:, ::-1]
                d['ta'] = d['ta'][:, ::-1]
                d['zfull'] = d['zfull'][:, ::-1]
                d['pfull'] = d['pfull'][:, ::-1]
            dd.append(d)
    d = ds.op.merge(dd, 'time')
    if 'time' in d:
        d['time_bnds'] = misc.time_bnds(d['time'], step, start_time, end_time)
        d['time'] = np.mean(d['time_bnds'], axis=1)
    if 'pfull' in d:
        d['pfull'] = 1e2 * d['pfull']
    if 'zfull' in d:
        d['zfull'] /= 9.80665
    if 'orog' in d:
        d['orog'] /= 9.80665
    if 'cl' in d:
        d['cl'] *= 100.
    d['.'] = META
    return d
Exemplo n.º 12
0
def read(dirname, track, warnings=[], step=6. / 24.):
    d_ll = ds.read(os.path.join(dirname, 'LL125.nc'),
                   ['latitude', 'longitude', 'z'])
    lat_ll = d_ll['latitude']
    lon_ll = d_ll['longitude']
    orog_ll = d_ll['z'][0, :, :] / 9.80665

    dd_idx = ds.readdir(
        dirname,
        variables=['time', 'latitude', 'longitude'],
        jd=True,
        full=True,
        warnings=warnings,
    )
    start_time = track['time'][0]
    end_time = track['time'][-1]
    d_out = {}
    for var in VARS:
        dd = []
        var2 = TRANS[var]
        for d_idx in dd_idx:
            if var not in d_idx['.']:
                continue
            time = d_idx['time']
            lat = d_idx['latitude']
            lon = d_idx['longitude']
            filename = d_idx['filename']
            ii = np.nonzero((time >= start_time - step * 0.5)
                            & (time < end_time + step * 0.5))[0]
            for i in ii:
                t = time[i]
                i2 = np.argmin(np.abs(track['time'] - time[i]))
                lat0 = track['lat'][i2]
                lon0 = track['lon'][i2]
                j = np.argmin(np.abs(lat - lat0))
                k = np.argmin(np.abs(lon - lon0))
                j_ll = np.argmin(np.abs(lat_ll - lat0))
                k_ll = np.argmin(np.abs(lon_ll - lon0))
                d = ds.read(
                    filename,
                    VARS_AUX + [var],
                    sel={
                        'time': [i],
                        'latitude': j,
                        'longitude': k,
                    },
                    jd=True,
                )
                for a, b in TRANS.items():
                    if a in d.keys():
                        ds.rename(d, a, b)
                d['lat'] = np.array([d['lat']])
                d['lon'] = np.array([d['lon']])
                d['orog'] = np.array([orog_ll[j_ll, k_ll]])
                d['.']['lat']['.dims'] = ['time']
                d['.']['lon']['.dims'] = ['time']
                d['.']['orog'] = {'.dims': ['time']}
                if 'pfull' in ds.get_vars(d):
                    d['pfull'] = d['pfull'].reshape([1, len(d['pfull'])])
                    d['.']['pfull']['.dims'] = ['time', 'pfull']
                    d['pfull'] = d['pfull'][:, ::-1]
                    d[var2] = d[var2][:, ::-1]
                    ds.select(d, {'pfull': np.arange(27)})
                dd.append(d)
        d = ds.op.merge(dd, 'time')
        for var_aux in VARS_AUX:
            if TRANS[var_aux] in ds.get_vars(d_out) \
             and TRANS[var_aux] in ds.get_vars(d) \
             and not np.all(d_out[TRANS[var_aux]] == d[TRANS[var_aux]]):
                raise ValueError('%s: Field differs between input files' %
                                 TRANS[var_aux])
        d_out.update(d)
    d_out['pfull'] = d_out['pfull'] * 1e2
    if 'time' in d_out:
        d_out['time_bnds'] = misc.time_bnds(d_out['time'], step, start_time,
                                            end_time)
        d_out['time'] = np.mean(d_out['time_bnds'], axis=1)
    d_out['.'] = META
    return d_out
Exemplo n.º 13
0
def read(filename, vars, altitude=None, lon=None, lat=None, **kwargs):
	dep_vars = list(set([y for x in vars if x in VARS for y in VARS[x]]))
	required_vars = dep_vars + DEFAULT_VARS
	d = ds.from_netcdf(
		filename,
		required_vars
	)
	mask = d['elevation_angle'] == 0.0
	dx = {}
	n = len(d['year'])

	altitude = d['altitude'] if altitude is None else \
		np.full(n, altitude, np.float64)
	lon = d['longitude'] if lon is None else \
		np.full(n, lon, np.float64)
	lat = d['latitude'] if lat is None else \
		np.full(n, lat, np.float64)

	if 'time' in vars:
		dx['time'] = np.array([
			(dt.datetime(y, m, day, H, M, S) - dt.datetime(1970, 1, 1)).total_seconds()/(24.0*60.0*60.0) + 2440587.5
			for y, m, day, H, M, S
			in zip(d['year'], d['month'], d['day'], d['hour'], d['minute'], d['second'])
		], np.float64)
		tres = parse_temporal_resolution(d['.']['.']['temporal_resolution'])
		dx['time_bnds'] = misc.time_bnds(dx['time'], tres)
		# dx['time'] += 13.0/24.0
	if 'zfull' in vars:
		zfull1 = np.outer(
			np.sin(d['elevation_angle']/180.0*np.pi),
			d['range_nrb']*1e3
		)
		dx['zfull'] = np.tile(zfull1, (n, 1))
		for i in range(n):
			dx['zfull'][i,:] += altitude[i]
	if 'backscatter' in vars:
		dx['backscatter'] = (d['copol_nrb'] + 2.*d['crosspol_nrb'])*CALIBRATION_COEFF
	if 'altitude' in vars:
		dx['altitude'] = altitude
	if 'lon' in vars:
		dx['lon'] = lon
	if 'lat' in vars:
		dx['lat'] = lat
	# if 'backscatter_x' in vars:
	# 	dx['backscatter_x'] = d['copol_nrb']*CALIBRATION_COEFF
	# if 'backscatter_y' in vars:
	# 	dx['backscatter_y'] = d['crosspol_nrb']*CALIBRATION_COEFF
	dx['.'] = META
		# 'backscatter_x': {
		# 	'.dims': ['time', 'level'],
		# 	'long_name': 'copolarized_attenuated_backscatter_coefficient',
		# 	'units': 'm-1 sr-1',
		# },
		# 'backscatter_y': {
		# 	'.dims': ['time', 'level'],
		# 	'long_name': 'crosspolarized_attenuated_backscatter_coefficient',
		# 	'units': 'm-1 sr-1',
		# },
	dx['.'] = {
		x: dx['.'][x]
		for x in vars
		if x in dx['.']
	}
	return dx