<s> """<STR_LIT>""" <EOL> __version__ = "<STR_LIT>" <EOL> import os <EOL> from PyOpenColorIO . Constants import INTERP_LINEAR <EOL> from utils . ocio_helper import ( <EOL> OCIO_LUTS_FORMATS , create_ocio_processor , is_3d_lut <EOL> ) <EOL> from utils . lut_utils import get_3d_list_values <EOL> import matplotlib <EOL> import itertools <EOL> from utils import matplotlib_helper as mplh <EOL> import ntpath <EOL> class PlotThatLutException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> DEFAULT_SAMPLE = <NUM_LIT> <EOL> DEFAULT_CUBE_SIZE = <NUM_LIT> <EOL> def show_plot ( fig , filename ) : <EOL> """<STR_LIT>""" <EOL> if mplh . WEB_MODE : <EOL> split_filename = os . path . splitext ( filename ) <EOL> filename = '<STR_LIT>' . format ( split_filename [ <NUM_LIT:0> ] , <EOL> split_filename [ <NUM_LIT:1> ] . replace ( "<STR_LIT:.>" , "<STR_LIT:_>" ) ) <EOL> current_dir = os . path . dirname ( os . path . abspath ( __file__ ) ) <EOL> current_dir = os . path . join ( os . path . dirname ( current_dir ) , '<STR_LIT>' ) <EOL> export_path = '<STR_LIT>' . format ( filename ) <EOL> abs_export_path = '<STR_LIT>' . format ( current_dir , <EOL> filename ) <EOL> print abs_export_path <EOL> fig . savefig ( abs_export_path ) <EOL> return export_path <EOL> else : <EOL> matplotlib . pyplot . show ( ) <EOL> return "<STR_LIT>" <EOL> def plot_curve ( lutfiles , samples_count , processors , draw_red_curve = True , <EOL> draw_green_curve = True , draw_blue_curve = True , <EOL> display_markers = False ) : <EOL> """<STR_LIT>""" <EOL> from matplotlib . pyplot import ( title , plot , xlabel , ylabel , grid , <EOL> figure ) <EOL> fig = figure ( ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> figure_title = "<STR_LIT>" <EOL> for lutfile in lutfiles : <EOL> filename = os . path . basename ( lutfile ) <EOL> figure_title = "<STR_LIT>" . format ( figure_title , filename ) <EOL> title ( figure_title ) <EOL> xlabel ( "<STR_LIT>" ) <EOL> ylabel ( "<STR_LIT>" ) <EOL> grid ( True ) <EOL> markers_it = itertools . cycle ( mplh . MARKERS ) <EOL> reds_it = itertools . cycle ( mplh . REDS ) <EOL> greens_it = itertools . cycle ( mplh . GREENS ) <EOL> blues_it = itertools . cycle ( mplh . BLUES ) <EOL> for lutfile , processor in itertools . izip ( lutfiles , processors ) : <EOL> max_value = samples_count - <NUM_LIT:1.0> <EOL> red_values = [ ] <EOL> green_values = [ ] <EOL> blue_values = [ ] <EOL> input_range = [ ] <EOL> for code_value in range ( <NUM_LIT:0> , samples_count ) : <EOL> norm_value = code_value / max_value <EOL> res = processor . applyRGB ( [ norm_value , norm_value , norm_value ] ) <EOL> red_values . append ( res [ <NUM_LIT:0> ] ) <EOL> green_values . append ( res [ <NUM_LIT:1> ] ) <EOL> blue_values . append ( res [ <NUM_LIT:2> ] ) <EOL> input_range . append ( norm_value ) <EOL> marker = markers_it . next ( ) <EOL> markersize = <NUM_LIT:0> <EOL> if display_markers : <EOL> markersize = <NUM_LIT:4> <EOL> labelbase = os . path . splitext ( ntpath . basename ( lutfile ) ) [ <NUM_LIT:0> ] <EOL> if draw_red_curve : <EOL> if not draw_blue_curve and not draw_green_curve : <EOL> label = labelbase <EOL> else : <EOL> label = "<STR_LIT>" . format ( labelbase ) <EOL> plot ( input_range , red_values , color = reds_it . next ( ) , marker = marker , <EOL> label = label , linewidth = <NUM_LIT:1> , markersize = markersize ) <EOL> if draw_green_curve : <EOL> if not draw_blue_curve and not draw_red_curve : <EOL> label = labelbase <EOL> else : <EOL> label = "<STR_LIT>" . format ( labelbase ) <EOL> plot ( input_range , green_values , color = greens_it . next ( ) , <EOL> marker = marker , label = label , linewidth = <NUM_LIT:1> , <EOL> markersize = markersize ) <EOL> if draw_blue_curve : <EOL> if not draw_green_curve and not draw_red_curve : <EOL> label = labelbase <EOL> else : <EOL> label = "<STR_LIT>" . format ( labelbase ) <EOL> plot ( input_range , blue_values , color = blues_it . next ( ) , marker = marker , <EOL> label = label , linewidth = <NUM_LIT:1> , markersize = markersize ) <EOL> matplotlib . pyplot . legend ( loc = <NUM_LIT:4> ) <EOL> return show_plot ( fig , filename ) <EOL> def plot_cube ( lutfile , cube_size , processor ) : <EOL> """<STR_LIT>""" <EOL> from matplotlib . pyplot import title , figure <EOL> import mpl_toolkits . mplot3d <EOL> processed_values = get_3d_list_values ( cube_size , processor , <EOL> hexa_values = True ) <EOL> red_values = processed_values [ '<STR_LIT>' ] <EOL> green_values = processed_values [ '<STR_LIT>' ] <EOL> blue_values = processed_values [ '<STR_LIT>' ] <EOL> input_colors = processed_values [ '<STR_LIT>' ] <EOL> fig = figure ( ) <EOL> fig . canvas . set_window_title ( '<STR_LIT>' ) <EOL> axis = fig . add_subplot ( <NUM_LIT> , projection = '<STR_LIT>' ) <EOL> axis . set_xlabel ( '<STR_LIT>' ) <EOL> axis . set_ylabel ( '<STR_LIT>' ) <EOL> axis . set_zlabel ( '<STR_LIT>' ) <EOL> axis . set_xlim ( min ( red_values ) , max ( red_values ) ) <EOL> axis . set_ylim ( min ( green_values ) , max ( green_values ) ) <EOL> axis . set_zlim ( min ( blue_values ) , max ( blue_values ) ) <EOL> filename = os . path . basename ( lutfile ) <EOL> title ( filename ) <EOL> axis . scatter ( red_values , green_values , blue_values , c = input_colors , <EOL> marker = "<STR_LIT:o>" ) <EOL> return show_plot ( fig , filename ) <EOL> def supported_formats ( ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" . format ( '<STR_LIT:U+002CU+0020>' . join ( OCIO_LUTS_FORMATS ) ) <EOL> def plot_that_lut ( lutfiles , plot_type = None , count = None , inverse = False , <EOL> prelutfile = None , postlutfile = None , display_markers = False ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( lutfiles , list ) : <EOL> lutfiles = [ lutfiles ] <EOL> mplh . set_matplotlib_backend ( ) <EOL> processors = [ ] <EOL> for lutfile in lutfiles : <EOL> fileext = os . path . splitext ( lutfile ) [ <NUM_LIT:1> ] <EOL> if not fileext : <EOL> raise PlotThatLutException ( ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( lutfile ) ) <EOL> if fileext not in OCIO_LUTS_FORMATS : <EOL> raise PlotThatLutException ( "<STR_LIT>" <EOL> . format ( fileext , supported_formats ( ) ) ) <EOL> processors . append ( create_ocio_processor ( lutfile , INTERP_LINEAR , <EOL> inverse , prelutfile , <EOL> postlutfile ) ) <EOL> if not plot_type or plot_type == '<STR_LIT>' : <EOL> if is_3d_lut ( processors [ <NUM_LIT:0> ] , lutfiles [ <NUM_LIT:0> ] ) : <EOL> plot_type = '<STR_LIT>' <EOL> else : <EOL> plot_type = '<STR_LIT>' <EOL> if not count or count == '<STR_LIT>' : <EOL> if '<STR_LIT>' in plot_type : <EOL> count = DEFAULT_SAMPLE <EOL> else : <EOL> count = DEFAULT_CUBE_SIZE <EOL> print "<STR_LIT>" . format ( plot_type , count ) <EOL> if '<STR_LIT>' in plot_type : <EOL> draw_red_curve = True <EOL> draw_green_curve = True <EOL> draw_blue_curve = True <EOL> if '<STR_LIT>' in plot_type : <EOL> draw_green_curve = False <EOL> draw_blue_curve = False <EOL> elif '<STR_LIT>' in plot_type : <EOL> draw_red_curve = False <EOL> draw_blue_curve = False <EOL> elif '<STR_LIT>' in plot_type : <EOL> draw_red_curve = False <EOL> draw_green_curve = False <EOL> return plot_curve ( lutfiles , count , processors , <EOL> draw_red_curve = draw_red_curve , <EOL> draw_green_curve = draw_green_curve , <EOL> draw_blue_curve = draw_blue_curve , <EOL> display_markers = display_markers ) <EOL> elif plot_type == '<STR_LIT>' : <EOL> return plot_cube ( lutfiles [ <NUM_LIT:0> ] , count , processors [ <NUM_LIT:0> ] ) <EOL> else : <EOL> raise PlotThatLutException ( ( <EOL> "<STR_LIT>" <EOL> "<STR_LIT>" <EOL> ) . format ( plot_type ) ) </s>
