parent
c2ae657f5b
commit
1dddfa040e
|
@ -10,7 +10,6 @@ class Color():
|
|||
]
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def __init__(self,
|
||||
model = 'RGB',
|
||||
color = np.zeros(3,'d')):
|
||||
|
@ -49,20 +48,17 @@ class Color():
|
|||
self.color = np.array(color,'d')
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def __repr__(self):
|
||||
"""Color model and values."""
|
||||
return 'Model: %s Color: %s'%(self.model,str(self.color))
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def __str__(self):
|
||||
"""Color model and values."""
|
||||
return self.__repr__()
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def convertTo(self,toModel = 'RGB'):
|
||||
def convert_to(self,toModel = 'RGB'):
|
||||
"""
|
||||
Change the color model permanently.
|
||||
|
||||
|
@ -88,8 +84,7 @@ class Color():
|
|||
return self
|
||||
|
||||
|
||||
# ------------------------------------------------------------------
|
||||
def expressAs(self,asModel = 'RGB'):
|
||||
def express_as(self,asModel = 'RGB'):
|
||||
"""
|
||||
Return the color in a different model.
|
||||
|
||||
|
@ -99,7 +94,7 @@ class Color():
|
|||
color model
|
||||
|
||||
"""
|
||||
return self.__class__(self.model,self.color).convertTo(asModel)
|
||||
return self.__class__(self.model,self.color).convert_to(asModel)
|
||||
|
||||
|
||||
|
||||
|
@ -293,6 +288,7 @@ class Color():
|
|||
self.model = converted.model
|
||||
self.color = converted.color
|
||||
|
||||
|
||||
def _XYZ2CIELAB(self):
|
||||
"""
|
||||
Convert CIE XYZ to CIE Lab.
|
||||
|
@ -498,13 +494,13 @@ class Colormap():
|
|||
def interpolate_linear(lo, hi, frac):
|
||||
"""Linear interpolation between lo and hi color at given fraction; output in model of lo color."""
|
||||
interpolation = (1.0 - frac) * np.array(lo.color[:]) \
|
||||
+ frac * np.array(hi.expressAs(lo.model).color[:])
|
||||
+ frac * np.array(hi.express_as(lo.model).color[:])
|
||||
|
||||
return Color(lo.model,interpolation)
|
||||
|
||||
if self.interpolate == 'perceptualuniform':
|
||||
return interpolate_Msh(self.left.expressAs('MSH').color,
|
||||
self.right.expressAs('MSH').color,fraction)
|
||||
return interpolate_Msh(self.left.express_as('MSH').color,
|
||||
self.right.express_as('MSH').color,fraction)
|
||||
elif self.interpolate == 'linear':
|
||||
return interpolate_linear(self.left,
|
||||
self.right,fraction)
|
||||
|
@ -528,7 +524,7 @@ class Colormap():
|
|||
"""
|
||||
format = format.lower() # consistent comparison basis
|
||||
frac = 0.5*(np.array(crop) + 1.0) # rescale crop range to fractions
|
||||
colors = [self.color(float(i)/(steps-1)*(frac[1]-frac[0])+frac[0]).expressAs(model).color for i in range(steps)]
|
||||
colors = [self.color(float(i)/(steps-1)*(frac[1]-frac[0])+frac[0]).express_as(model).color for i in range(steps)]
|
||||
if format == 'paraview':
|
||||
colormap = ['[\n {{\n "ColorSpace": "RGB", "Name": "{}", "DefaultMap": true,\n "RGBPoints" : ['.format(name)] \
|
||||
+ [' {:4d},{:8.6f},{:8.6f},{:8.6f},'.format(i,color[0],color[1],color[2],) \
|
||||
|
|
|
@ -38,7 +38,6 @@ class bcolors:
|
|||
self.CROSSOUT = ''
|
||||
|
||||
|
||||
# -----------------------------
|
||||
def srepr(arg,glue = '\n'):
|
||||
"""
|
||||
Join arguments as individual lines.
|
||||
|
@ -57,7 +56,7 @@ def srepr(arg,glue = '\n'):
|
|||
return glue.join(str(x) for x in arg)
|
||||
return arg if isinstance(arg,str) else repr(arg)
|
||||
|
||||
# -----------------------------
|
||||
|
||||
def croak(what, newline = True):
|
||||
"""
|
||||
Write formated to stderr.
|
||||
|
@ -70,11 +69,11 @@ def croak(what, newline = True):
|
|||
Separate items of what by newline. Defaults to True.
|
||||
|
||||
"""
|
||||
if what is not None:
|
||||
if not what:
|
||||
sys.stderr.write(srepr(what,glue = '\n') + ('\n' if newline else ''))
|
||||
sys.stderr.flush()
|
||||
|
||||
# -----------------------------
|
||||
|
||||
def report(who = None,
|
||||
what = None):
|
||||
"""
|
||||
|
@ -86,27 +85,25 @@ def report(who = None,
|
|||
croak( (emph(who)+': ' if who is not None else '') + (what if what is not None else '') + '\n' )
|
||||
|
||||
|
||||
# -----------------------------
|
||||
def emph(what):
|
||||
"""Formats string with emphasis."""
|
||||
return bcolors.BOLD+srepr(what)+bcolors.ENDC
|
||||
|
||||
# -----------------------------
|
||||
|
||||
def deemph(what):
|
||||
"""Formats string with deemphasis."""
|
||||
return bcolors.DIM+srepr(what)+bcolors.ENDC
|
||||
|
||||
# -----------------------------
|
||||
|
||||
def delete(what):
|
||||
"""Formats string as deleted."""
|
||||
return bcolors.DIM+srepr(what)+bcolors.ENDC
|
||||
|
||||
# -----------------------------
|
||||
|
||||
def strikeout(what):
|
||||
"""Formats string as strikeout."""
|
||||
return bcolors.CROSSOUT+srepr(what)+bcolors.ENDC
|
||||
|
||||
# -----------------------------
|
||||
def execute(cmd,
|
||||
streamIn = None,
|
||||
wd = './',
|
||||
|
@ -140,10 +137,11 @@ def execute(cmd,
|
|||
out = out.decode('utf-8').replace('\x08','')
|
||||
error = error.decode('utf-8').replace('\x08','')
|
||||
os.chdir(initialPath)
|
||||
if process.returncode != 0: raise RuntimeError('{} failed with returncode {}'.format(cmd,process.returncode))
|
||||
if process.returncode != 0:
|
||||
raise RuntimeError('{} failed with returncode {}'.format(cmd,process.returncode))
|
||||
return out,error
|
||||
|
||||
# -----------------------------
|
||||
|
||||
class extendableOption(Option):
|
||||
"""
|
||||
Used for definition of new option parser action 'extend', which enables to take multiple option arguments.
|
||||
|
@ -164,11 +162,13 @@ class extendableOption(Option):
|
|||
else:
|
||||
Option.take_action(self, action, dest, opt, value, values, parser)
|
||||
|
||||
# from https://gist.github.com/aubricus/f91fb55dc6ba5557fbab06119420dd6a
|
||||
|
||||
def progressBar(iteration, total, prefix='', bar_length=50):
|
||||
"""
|
||||
Call in a loop to create terminal progress bar.
|
||||
|
||||
From https://gist.github.com/aubricus/f91fb55dc6ba5557fbab06119420dd6a
|
||||
|
||||
Parameters
|
||||
----------
|
||||
iteration : int
|
||||
|
@ -202,7 +202,8 @@ def progressBar(iteration, total, prefix='', bar_length=50):
|
|||
|
||||
sys.stderr.write('\r{} {} {}'.format(prefix, bar, remaining_time)),
|
||||
|
||||
if iteration == total: sys.stderr.write('\n')
|
||||
if iteration == total:
|
||||
sys.stderr.write('\n')
|
||||
sys.stderr.flush()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue