def generate_lake_brite_gif(metric, palette='winter_r', duration=0.125, clip_to_lake=True, tween_frames=1, empty_frames=0): """Generate 3D Lake GIF for consumption by LakeBrite""" print "Generating 3D Lake GIFs of %s" % metric a = generate_lake_array(metric, clip_to_lake, tween_frames) max_value = get_max_of_data(a) min_value = get_min_of_data(a) print "Rotating matrix" rotated = [] for index, frame in enumerate(a): rotated.append(zip(*frame)) print "Increasing dimensions" slices = [increase_dimensions(frame, max_value, min_value) for frame in rotated] print "Stackining frames" frames = [stack_frames(frame) for frame in slices] print "Normalizing values" normalized = [normalize_values(frame, max_value, min_value) for frame in frames] # TODO: this should live outside of `generate_lake_brite_gif()` # it lives here because I use `palette` from the arguments # and can't figure out how to bind it to `color_map` otherwise def color_map(x, palette=palette): """To be consumed by np.vectorize to transform nan values to black and provide the color map""" if np.isnan(x): return [0, 0, 0] elif x < 0: return list(cm.get_cmap(palette)(0, bytes=True)[:3]) else: return list(cm.get_cmap(palette)(x, bytes=True)[:3]) print "Mapping values to colors" a = map_value_to_color(normalized, color_map) print "Adding empty frames" with_empties = add_empty_frames(a, empty_frames) print "Converting to numpy array" arrays = [np.fliplr(np.asarray(with_empties[i], 'uint8')) for i, f in enumerate(with_empties)] print "Generating GIFs" path_to_gif = safe_path('gif/lake-animation') generate_gif(arrays, path_to_gif, duration) return '%s.gif' % path_to_gif
def make_temp_gif(): """A single GIF of the entire temperature dataset""" data = csv_to_matrix() max_temp = get_max_of_data(data) min_temp = get_min_of_data(data) three_d_data = increase_dimensions(data, max_temp, min_temp) colored_data = assign_colors(three_d_data, max_temp, min_temp) arrays = [np.asarray(colored_data[i], 'uint8') for i, f in enumerate(colored_data)] generate_gif(arrays, 'temp')
def make_lake_brite_gif(): """A single GIF, "10 slices" tall that contains the USHCN temperature visualization for consumption by Lake Brite""" print "Making USHCN GIF" data = csv_to_matrix() max_temp = get_max_of_data(data) min_temp = get_min_of_data(data) three_d_data = increase_dimensions(data, max_temp, min_temp) colored_data = assign_colors(three_d_data, max_temp, min_temp) add_empties = add_empty_slices(colored_data) frames = make_frames(add_empties) arrays = np.asarray(frames, 'uint8') generate_gif(arrays, 'ushcn/temperature')
def make_three_d_gifs(): """Turn temperature dataset into 3d GIFs for LakeBrite""" data = csv_to_matrix() max_temp = get_max_of_data(data) min_temp = get_min_of_data(data) three_d_data = increase_dimensions(data, max_temp, min_temp) colored_data = assign_colors(three_d_data, max_temp, min_temp) length = len(colored_data) arrays = [] for index, frame in enumerate(colored_data): if index < length - 10: single_frame = colored_data[index:index + 10] frame = stack_frames(single_frame) arrays.append(np.asarray(frame)) generate_gif(arrays, 'temperature/lake')