def get_cvd(data, cvd_type=CVD_TYPE, severity=100): ''' Converts RGB values to CVD space RGB values. Parameters ---------- data: string or 3 x 256 array Colormap name OR array with complete color data. Invalid colormap names throw a ValueError. Refer to _check_cmap for more information. cvd_type: string Type of CVD to be simulated. Options: deuteranomaly or protanomaly. Default: deuteranomaly. severity: int Severity of CVD to be simulated. Can be any integer between 0 and 100. Default: 100 Returns ---------- cvd: 3 x 256 array Colormap data in CVD space ''' rgb, _ = cmu.get_rgb_jab(data, calc_jab=False) cvd_space = { 'name': 'sRGB1+CVD', 'cvd_type': cvd_type, 'severity': severity } cvd = cmu.convert(rgb, cvd_space, CSPACE1) return cvd
import matplotlib.pyplot as plt from mpl_toolkits.mplot3d import Axes3D import numpy as np import cmaputil as cmu import cmaputil.cvdutil as cvu FLABEL = 20 FAX = 16 #%% Get iteration data cmap = 'viridis' # The optimized version of this colormap is cividis! # Get original RGB/Jab t = time() rgb1, jab1 = cmu.get_rgb_jab(cmap) # Get CVD RGB/Jab rgb2, jab2 = cmu.get_rgb_jab(cvu.get_cvd(rgb1, severity=100)) # Make perceptual deltas (for a' vs. b') straight # Need to set a and b before straightening J jab3 = cmu.make_linear(jab2) rgb3 = cmu.convert(jab3, cmu.CSPACE2, cmu.CSPACE1) # Linearize J' jab4, jab5 = cmu.correct_J( jab3) # This will create a figure showing the J bounds if jab4 is not None: rgb4 = cmu.convert(jab4, cmu.CSPACE2, cmu.CSPACE1) rgb4 = np.clip(rgb4, 0, 1)
# Imports import numpy as np import cmaputil as cmu import cmaputil.cvdutil as cvu # Globals FLABEL = 20 FAX = 16 # Input colormap name cmap = 'viridis' # Optimize rgb1, jab1 = cmu.get_rgb_jab(cmap) # Original colormap rgb2, jab2 = cmu.get_rgb_jab(cvu.get_cvd(rgb1)) # CVD colormap jab3 = cmu.make_linear(jab2) # Uniformize hue (a' vs. b') _, jab4 = cmu.correct_J(jab3) # Linearize J' # Convert back to sRGB rgb4 = cmu.convert(jab4, cmu.CSPACE2, cmu.CSPACE1) rgb4 = np.clip(rgb4, 0, 1) # Resimulate CVD in case corrections took the map outside CVD-safe space rgb4 = cvu.get_cvd(rgb4) #%% Creat CDPS plots (shown in Fig 1 and 5 of the paper) # Import test data img_name = 'example_nanosims_image.txt' # Image used for paper
def compare_points(elements_to_plot, element_list, data_by_element, combo_mask, x, y, distances, name1=None, name2=None): data = np.copy(data_by_element) # Find points based on highest and lowest carbon signature c_ind = element_list.index('C') xx = data[c_ind, :] xx = array2img(x, y, xx) xx[np.where(combo_mask != 0)] = np.nan xx[distances > 250] = np.nan p1 = np.where(xx == np.nanmax(xx)) xx[np.where(distances != distances[p1])] = np.nan p2 = np.where(xx == np.nanmin(xx)) # Overlay points on mask rgb, _ = cmu.get_rgb_jab('gray') rgb = np.fliplr(rgb) data[np.where(data <= 0.0)] = 0 combo_mask[combo_mask > 0] = 1 img = cmu.overlay_colormap(combo_mask, rgb) img[p1[0], p1[1]] = [255, 0, 0] img[p2[0], p2[1]] = [0, 0, 255] # Plot plt.figure(figsize=(8, 8)) plt.imshow(img, interpolation='none') plt.axis('off') if name1 is not None: plt.savefig(name1, dpi=FIG_DPI, bbox_inches='tight') plt.show() # Gen bar plot to compare plt.figure(figsize=(8, 4)) i = 1 plt.plot([0, len(elements_to_plot) + 2], [0, 0], 'k', lw=2) for e in elements_to_plot: ind = element_list.index(e) intensities = data[ind, :] img = array2img(x, y, intensities) ratio = img[p1[0], p1[1]] - img[p2[0], p2[1]] # ratio = np.log2(img[p1[0], p1[1]] / img[p2[0], p2[1]]) print(img[p1[0], p1[1]] - img[p2[0], p2[1]]) plt.bar(i, ratio, align='center', color='k', edgecolor='k', bottom=0) # plt.text(i, 0.1 * (ratio / abs(ratio)), '%.2f' % ratio, color='w', fontsize=FLAB) i += 1 # Formatting plt.yticks([], fontsize=FAX) plt.xticks(range(1, len(elements_to_plot) + 1), elements_to_plot, fontsize=FAX) plt.tick_params(axis='x', which='both', bottom='off', top='off') plt.xlabel('Element', fontsize=FLAB) plt.ylabel('log2(Raw Int. Ratio)', fontsize=FLAB) plt.axis([0.5, 6.5, -1.5, 3.15]) if name2 is not None: plt.savefig(name2, bbox_inches='tight', dpi=FIG_DPI) plt.show()