def generate_radiance_filename(filename): prefix = short(filename, 0, 3) decimalhour = lambda t: t.hour + t.minute/60. + t.second/3600. slot = str(int(round(decimalhour(to_datetime(filename))*2))).zfill(2) suffix = short(filename, 4, 6) if not os.path.exists('products/radiance'): os.makedirs('products/radiance') output_filename = 'products/radiance/rad.%s.S%s.%s' % ( prefix, slot, suffix) return output_filename
def generate_radiance_filename(filename): prefix = short(filename, 0, 3) decimalhour = lambda t: t.hour + t.minute / 60. + t.second / 3600. slot = str(int(round(decimalhour(to_datetime(filename)) * 2))).zfill(2) suffix = short(filename, 4, 6) if not os.path.exists('products/radiance'): os.makedirs('products/radiance') output_filename = 'products/radiance/rad.%s.S%s.%s' % (prefix, slot, suffix) return output_filename
def calculate_weights(for_file, files): day = short(for_file, 2, 4) slot = int(short(for_file, 4, 5)[1:]) hour = slot / 2. minute = 60 * (hour % 1) itime = datetime.strptime('%s %i:%i' % (day, int(hour), minute), '%Y.%j %H:%M') times = map(to_datetime, files) diff_t = (times[0] - times[1]).total_seconds() weights = map(lambda t: 1 - abs((itime - t).total_seconds() / diff_t), times) return weights
def radiance(filename): prefix = short(filename, 0, 3) slot = int(round(decimalhour(to_datetime(filename))*2)) suffix = short(filename, 4, 6) output_filename = create_output_path(prefix, slot, suffix) root, is_new = nc.open(filename) radiation = nc.getvar(root, 'globalradiation') with nc.loader(output_filename) as radiance_root: dims_names = list(reversed(radiation.dimensions.keys())) dims_values = list(reversed(radiation.dimensions.values())) create_dims = (lambda name, dimension: radiance_root.create_dimension(name, len(dimension))) (map(lambda name, dimension: create_dims(name, dimension), dims_names, dims_values)) radiance = (nc.getvar(radiance_root, 'radiance', vtype='f4', dimensions=tuple(dims_names))) radiance[:] = radiation[:]*30.*60.*10**-6
def complete(radiance_files): t_slots = set(range(20, 47)) if radiance_files: prefix = short(radiance_files[0], 0, 2) suffix = short(radiance_files[0], -2, None) slot = lambda filename: int(short(filename, 4)[1:]) to_datetime = lambda f: short(f, 2, 4) groups = groupby(sorted(radiance_files), to_datetime) for day, files_by_day in groups: slots_by_day = set(map(slot, list(files_by_day))) new_slots = t_slots - slots_by_day id = lambda s: '%s.S%s' % (day, str(s).zfill(2)) output_file = lambda s: 'products/radiance/%s.%s.%s' % ( prefix, id(s), suffix) radiance_files += map(output_file, new_slots) radiance_files.sort() return radiance_files
def complete(radiance_files): t_slots = set(range(20, 47)) if radiance_files: prefix = short(radiance_files[0], 0, 2) suffix = short(radiance_files[0], -2, None) slot = lambda filename: int(short(filename, 4)[1:]) to_datetime = lambda f: short(f, 2, 4) groups = groupby(sorted(radiance_files), to_datetime) for day, files_by_day in groups: slots_by_day = set(map(slot, list(files_by_day))) new_slots = t_slots - slots_by_day id = lambda s: '%s.S%s' % (day, str(s).zfill(2)) output_file = lambda s: 'products/radiance/%s.%s.%s' % (prefix, id(s), suffix) radiance_files += map(output_file, new_slots) radiance_files.sort() return radiance_files
def radiance(filename): prefix = short(filename, 0, 3) slot = int(round(decimalhour(to_datetime(filename)) * 2)) suffix = short(filename, 4, 6) output_filename = create_output_path(prefix, slot, suffix) root, is_new = nc.open(filename) radiation = nc.getvar(root, 'globalradiation') with nc.loader(output_filename) as radiance_root: dims_names = list(reversed(radiation.dimensions.keys())) dims_values = list(reversed(radiation.dimensions.values())) create_dims = (lambda name, dimension: radiance_root.create_dimension( name, len(dimension))) (map(lambda name, dimension: create_dims(name, dimension), dims_names, dims_values)) radiance = (nc.getvar(radiance_root, 'radiance', vtype='f4', dimensions=tuple(dims_names))) radiance[:] = radiation[:] * 30. * 60. * 10**-6