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
def read(filename, vars, altitude=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 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) dx['.'] = META dx['.'] = {x: dx['.'][x] for x in vars if x in dx['.']} return dx
def read(filename, vars, altitude=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']) if altitude is None: altitude = d['altitude'] else: altitude = np.full(n, altitude, 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) # 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 '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
def read(filename, vars, altitude=None, lon=None, lat=None, **kwargs): d = ds.from_netcdf(filename, vars) n = d['backscatter'].shape[0] d['altitude'] = d['altitude'] if altitude is None and 'altitude' in d else \ np.full(n, altitude, np.float64) d['lon'] = d['lon'] if lon is None and 'longitude' in d else \ np.full(n, lon, np.float64) d['lat'] = d['lat'] if lat is None and 'latitude' in d else \ np.full(n, lat, np.float64) d['.']['altitude'] = META['altitude'] d['.']['lon'] = META['lon'] d['.']['lat'] = META['lat'] d['.'] = { x: d['.'][x] for x in vars if x in d['.'] } return d
def get(*args, **opts): if len(args) != 2: raise TypeError('Usage: get <path> <input>') path = args[0].split('/') input_ = args[1] d = ds.from_netcdf(input_, []) if len(path) == 2 and path[0] == '' and path[1] == '': j = json.dumps(d['.']['.'], sort_keys=True, indent=4, cls=NumpyEncoder) print(j) elif len(path) == 2 and path[0] == '': attr = path[1] print(d['.']['.'][attr]) elif len(path) == 2: var = path[0] attr = path[1] print(d['.'][var][attr]) elif len(path) == 1: var = path[0] j = json.dumps(d['.'][var], sort_keys=True, indent=4, cls=NumpyEncoder) print(j)
def read(filename, vars, **kwargs): d = ds.from_netcdf(filename, vars) return d
def read(filename): return ds.from_netcdf(filename)