-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move some PyAna submodules to PyAnaMisc pkg with empty __init__.py
- Loading branch information
Showing
12 changed files
with
218 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 1 addition & 28 deletions
29
src/simplebuild_dgcode/data/pkgs/PyAnalysis/PyAna/python/_fix_backend_gtk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1 @@ | ||
#To avoid confusing users with useless(?) warnings such as the following: | ||
# | ||
#/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py:250: Warning: Source ID 2 was not found when attempting to remove it | ||
# gobject.source_remove(self._idle_event_id) | ||
# | ||
#we monkey-patch FigureCanvasGTK.destroy and block stderr while it is invoked. | ||
# | ||
#Hopefully in some future version of matplotlib this warning will disappear by itself. | ||
import sys,os | ||
try: | ||
from matplotlib.backends.backend_gtk import FigureCanvasGTK | ||
if hasattr(FigureCanvasGTK,'destroy'): | ||
_FigureCanvasGTK_destroy = FigureCanvasGTK.destroy | ||
def patched_FigureCanvasGTK_destroy(self): | ||
_stderr = sys.stderr | ||
null = open(os.devnull,'wb') | ||
try: | ||
sys.stderr.flush() | ||
sys.stderr = null | ||
_FigureCanvasGTK_destroy(self) | ||
finally: | ||
sys.stderr.flush() | ||
sys.stderr = _stderr | ||
null.close() | ||
FigureCanvasGTK.destroy=patched_FigureCanvasGTK_destroy | ||
except ImportError: | ||
#Something unexpected, but let us not break stuff for users because of it! | ||
pass | ||
import PyAnaMisc._fix_backend_gtk |
119 changes: 1 addition & 118 deletions
119
src/simplebuild_dgcode/data/pkgs/PyAnalysis/PyAna/python/dyncmap.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,118 +1 @@ | ||
from __future__ import division | ||
__all__=['dynamic_2d_colormap'] | ||
|
||
import numpy as np | ||
from matplotlib.colors import LinearSegmentedColormap | ||
|
||
def dynamic_2d_colormap(data,imgobj=None,ncols=65536): | ||
#attempt to use high-precision floating point for intermediate calculations: | ||
try: | ||
import decimal | ||
_=decimal.Context(prec=999) | ||
hpfloat,hpabs,hpmin,hpmax=_.create_decimal,_.abs,_.min,_.max | ||
hpceil = lambda x : x.to_integral_value(rounding=decimal.ROUND_CEILING) | ||
except ImportError: | ||
import math | ||
hpfloat,hpabs,hpmin,hpmax,hpceil=float,abs,min,max,math.ceil | ||
|
||
hpncols=hpfloat(ncols) | ||
zero,one=hpfloat(0.0),hpfloat(1.0) | ||
#figure out limits (remember that all values in data might be masked): | ||
rawmin = np.min(data) | ||
rawmax = np.max(data) | ||
if rawmin is np.ma.masked and rawmax is np.ma.masked: | ||
rawmin,rawmax = -one, one | ||
datamin = hpfloat(rawmin) | ||
datamax = hpfloat(rawmax) | ||
ddata=datamax-datamin | ||
if ddata: | ||
datamin -= hpfloat(0.005)*hpabs(ddata) | ||
datamax += hpfloat(0.005)*hpabs(ddata) | ||
else: | ||
datamin -= hpfloat(0.5); | ||
datamax += hpfloat(0.5); | ||
|
||
#NB: In principle there is a bug here, ispos+isneg should be based on | ||
#rawmin/rawmax not datamin/datamax. However, at least the code in | ||
#NCSABVal/scripts/sabstudio is relying on the present behaviour, so we can't | ||
#just fix it right away: | ||
ispos=datamin>=zero | ||
isneg=datamax<=zero | ||
#ispos=rawmin>=zero | ||
#isneg=rawmax<=zero | ||
|
||
if ispos and datamin<zero: | ||
datamin=zero | ||
if isneg and datamax>zero: | ||
datamax=zero | ||
if not ispos and not isneg: | ||
#make sure that 0.0 falls on a "bin-edge" in the colormap, so as to | ||
#not let small positive values accidentally acquire blue values or | ||
#vice versa: | ||
assert datamax>zero and datamin<zero | ||
d0=(datamax-datamin)/hpncols | ||
m=hpmin(datamax,-datamin) | ||
k=hpmax(hpceil(m/d0),4)#at least 4 bins on the smallest side | ||
assert k<hpncols | ||
eps=(k*(datamax-datamin)-hpncols*m)/(hpncols-k) | ||
if datamax > -datamin: datamin -= eps | ||
else: datamax += eps | ||
# d=(datamax-datamin)/hpncols | ||
|
||
#relative root-mean-square clipped to [0.0001,0.3]: | ||
npmean=np.mean(np.square(data)) | ||
if npmean is np.ma.masked: | ||
rms = hpfloat(0.1) | ||
else: | ||
rms=hpmax(hpfloat(0.0001), | ||
hpmin(hpfloat(0.3), | ||
hpfloat(np.sqrt(npmean))/(datamax-datamin))) | ||
if datamin>=0.0: | ||
cdict = {'red': [(0.0, 0.10, 0.10), | ||
(float(rms), 0.7, 0.7), | ||
(float(3*rms), 1.0, 1.0), | ||
(1.0, 1.0, 1.0)], | ||
'green': [(0.0, 0.0, 0.0), | ||
(1.0, 1.0, 1.0)], | ||
'blue': [(0.0, 0.0, 0.0), | ||
(1.0, 0.1, 0.1)]} | ||
elif datamax<=0.0: | ||
cdict = {'red': [(0.0, 0.1, 0.1), | ||
(1.0, 0.0, 0.0)], | ||
'green': [(0.0, 1.0, 1.0), | ||
(1.0, 0.0, 0.0)], | ||
'blue': [(0.0, 1.0, 1.0), | ||
(float(one-3*rms), 1.0, 1.0), | ||
(float(one-rms), 0.7, 0.7), | ||
(1.0, 0.1, 0.1)]} | ||
else: | ||
rneg = - datamin / ( datamax - datamin ) | ||
dbin = one/hpncols | ||
#In rneg-dbin to rneg+dbin, we keep equal mix of red and blue, so | ||
#numerical errors won't show e.g. very small positive values as blue or | ||
#vice versa: | ||
cdict = {'red': [(0.0, 0.1, 0.1), | ||
(float(rneg-dbin), 0.0, 0.1), | ||
(float(rneg+dbin), 0.1, 0.1), | ||
(float(rneg+hpmax(hpfloat(2)*dbin,(one-rneg)*rms)), 0.7, 0.7), | ||
(float(rneg+hpmax(hpfloat(3)*dbin,(one-rneg)*rms*hpfloat(3))), 1.0, 1.0), | ||
(1.0, 1.0, 1.0)], | ||
'green': [(0.0, 1.0, 1.0), | ||
(float(rneg-dbin), 0.0, 0.0), | ||
(float(rneg+dbin), 0.0, 0.0), | ||
(1.0, 1.0, 1.0)], | ||
'blue': [(0.0, 1.0, 1.0), | ||
(float(rneg-hpmax(hpfloat(3)*dbin,rneg*hpfloat(3)*rms)), 1.0, 1.0), | ||
(float(rneg-hpmax(hpfloat(2)*dbin,rneg*rms)), 0.7, 0.7), | ||
(float(rneg-dbin), 0.1, 0.1), | ||
(float(rneg+dbin), 0.1, 0.0), | ||
(1.0, 0.1, 0.1)]} | ||
#for k,v in cdict.items(): | ||
# print k,v | ||
import matplotlib.colors | ||
cmap=LinearSegmentedColormap('dynamic_rbcmap', cdict, N=ncols, gamma=1.0) | ||
cmap.set_bad('black')#color of masked values (if any) | ||
if imgobj: | ||
imgobj.set_clim(float(datamin),float(datamax)) | ||
imgobj.set_cmap(cmap) | ||
return float(datamin),float(datamax),cmap | ||
from PyAnaMisc.dyncmap import dynamic_2d_colormap |
7 changes: 7 additions & 0 deletions
7
src/simplebuild_dgcode/data/pkgs/PyAnalysis/PyAnaMisc/pkg.info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package() | ||
|
||
###################################################################### | ||
|
||
Package providing standalone modules (empty __init__.py!) related to PyAna. | ||
|
||
primary author: thomas.kittelmann@ess.eu |
29 changes: 29 additions & 0 deletions
29
src/simplebuild_dgcode/data/pkgs/PyAnalysis/PyAnaMisc/python/_fix_backend_gtk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#To avoid confusing users with useless(?) warnings such as the following: | ||
# | ||
#/usr/lib64/python2.7/site-packages/matplotlib/backends/backend_gtk.py:250: Warning: Source ID 2 was not found when attempting to remove it | ||
# gobject.source_remove(self._idle_event_id) | ||
# | ||
#we monkey-patch FigureCanvasGTK.destroy and block stderr while it is invoked. | ||
# | ||
#Hopefully in some future version of matplotlib this warning will disappear by itself. | ||
import sys | ||
import os | ||
try: | ||
from matplotlib.backends.backend_gtk import FigureCanvasGTK | ||
if hasattr(FigureCanvasGTK,'destroy'): | ||
_FigureCanvasGTK_destroy = FigureCanvasGTK.destroy | ||
def patched_FigureCanvasGTK_destroy(self): | ||
_stderr = sys.stderr | ||
null = open(os.devnull,'wb') | ||
try: | ||
sys.stderr.flush() | ||
sys.stderr = null | ||
_FigureCanvasGTK_destroy(self) | ||
finally: | ||
sys.stderr.flush() | ||
sys.stderr = _stderr | ||
null.close() | ||
FigureCanvasGTK.destroy=patched_FigureCanvasGTK_destroy | ||
except ImportError: | ||
#Something unexpected, but let us not break stuff for users because of it! | ||
pass |
117 changes: 117 additions & 0 deletions
117
src/simplebuild_dgcode/data/pkgs/PyAnalysis/PyAnaMisc/python/dyncmap.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
__all__=['dynamic_2d_colormap'] | ||
|
||
import numpy as np | ||
from matplotlib.colors import LinearSegmentedColormap | ||
|
||
def dynamic_2d_colormap(data,imgobj=None,ncols=65536): | ||
#attempt to use high-precision floating point for intermediate calculations: | ||
try: | ||
import decimal | ||
_=decimal.Context(prec=999) | ||
hpfloat,hpabs,hpmin,hpmax=_.create_decimal,_.abs,_.min,_.max | ||
hpceil = lambda x : x.to_integral_value(rounding=decimal.ROUND_CEILING) | ||
except ImportError: | ||
import math | ||
hpfloat,hpabs,hpmin,hpmax,hpceil=float,abs,min,max,math.ceil | ||
|
||
hpncols=hpfloat(ncols) | ||
zero,one=hpfloat(0.0),hpfloat(1.0) | ||
#figure out limits (remember that all values in data might be masked): | ||
rawmin = np.min(data) | ||
rawmax = np.max(data) | ||
if rawmin is np.ma.masked and rawmax is np.ma.masked: | ||
rawmin,rawmax = -one, one | ||
datamin = hpfloat(rawmin) | ||
datamax = hpfloat(rawmax) | ||
ddata=datamax-datamin | ||
if ddata: | ||
datamin -= hpfloat(0.005)*hpabs(ddata) | ||
datamax += hpfloat(0.005)*hpabs(ddata) | ||
else: | ||
datamin -= hpfloat(0.5); | ||
datamax += hpfloat(0.5); | ||
|
||
#NB: In principle there is a bug here, ispos+isneg should be based on | ||
#rawmin/rawmax not datamin/datamax. However, at least the code in | ||
#NCSABVal/scripts/sabstudio is relying on the present behaviour, so we can't | ||
#just fix it right away: | ||
ispos=datamin>=zero | ||
isneg=datamax<=zero | ||
#ispos=rawmin>=zero | ||
#isneg=rawmax<=zero | ||
|
||
if ispos and datamin<zero: | ||
datamin=zero | ||
if isneg and datamax>zero: | ||
datamax=zero | ||
if not ispos and not isneg: | ||
#make sure that 0.0 falls on a "bin-edge" in the colormap, so as to | ||
#not let small positive values accidentally acquire blue values or | ||
#vice versa: | ||
assert datamax>zero and datamin<zero | ||
d0=(datamax-datamin)/hpncols | ||
m=hpmin(datamax,-datamin) | ||
k=hpmax(hpceil(m/d0),4)#at least 4 bins on the smallest side | ||
assert k<hpncols | ||
eps=(k*(datamax-datamin)-hpncols*m)/(hpncols-k) | ||
if datamax > -datamin: datamin -= eps | ||
else: datamax += eps | ||
# d=(datamax-datamin)/hpncols | ||
|
||
#relative root-mean-square clipped to [0.0001,0.3]: | ||
npmean=np.mean(np.square(data)) | ||
if npmean is np.ma.masked: | ||
rms = hpfloat(0.1) | ||
else: | ||
rms=hpmax(hpfloat(0.0001), | ||
hpmin(hpfloat(0.3), | ||
hpfloat(np.sqrt(npmean))/(datamax-datamin))) | ||
if datamin>=0.0: | ||
cdict = {'red': [(0.0, 0.10, 0.10), | ||
(float(rms), 0.7, 0.7), | ||
(float(3*rms), 1.0, 1.0), | ||
(1.0, 1.0, 1.0)], | ||
'green': [(0.0, 0.0, 0.0), | ||
(1.0, 1.0, 1.0)], | ||
'blue': [(0.0, 0.0, 0.0), | ||
(1.0, 0.1, 0.1)]} | ||
elif datamax<=0.0: | ||
cdict = {'red': [(0.0, 0.1, 0.1), | ||
(1.0, 0.0, 0.0)], | ||
'green': [(0.0, 1.0, 1.0), | ||
(1.0, 0.0, 0.0)], | ||
'blue': [(0.0, 1.0, 1.0), | ||
(float(one-3*rms), 1.0, 1.0), | ||
(float(one-rms), 0.7, 0.7), | ||
(1.0, 0.1, 0.1)]} | ||
else: | ||
rneg = - datamin / ( datamax - datamin ) | ||
dbin = one/hpncols | ||
#In rneg-dbin to rneg+dbin, we keep equal mix of red and blue, so | ||
#numerical errors won't show e.g. very small positive values as blue or | ||
#vice versa: | ||
cdict = {'red': [(0.0, 0.1, 0.1), | ||
(float(rneg-dbin), 0.0, 0.1), | ||
(float(rneg+dbin), 0.1, 0.1), | ||
(float(rneg+hpmax(hpfloat(2)*dbin,(one-rneg)*rms)), 0.7, 0.7), | ||
(float(rneg+hpmax(hpfloat(3)*dbin,(one-rneg)*rms*hpfloat(3))), 1.0, 1.0), | ||
(1.0, 1.0, 1.0)], | ||
'green': [(0.0, 1.0, 1.0), | ||
(float(rneg-dbin), 0.0, 0.0), | ||
(float(rneg+dbin), 0.0, 0.0), | ||
(1.0, 1.0, 1.0)], | ||
'blue': [(0.0, 1.0, 1.0), | ||
(float(rneg-hpmax(hpfloat(3)*dbin,rneg*hpfloat(3)*rms)), 1.0, 1.0), | ||
(float(rneg-hpmax(hpfloat(2)*dbin,rneg*rms)), 0.7, 0.7), | ||
(float(rneg-dbin), 0.1, 0.1), | ||
(float(rneg+dbin), 0.1, 0.0), | ||
(1.0, 0.1, 0.1)]} | ||
#for k,v in cdict.items(): | ||
# print k,v | ||
import matplotlib.colors | ||
cmap=LinearSegmentedColormap('dynamic_rbcmap', cdict, N=ncols, gamma=1.0) | ||
cmap.set_bad('black')#color of masked values (if any) | ||
if imgobj: | ||
imgobj.set_clim(float(datamin),float(datamax)) | ||
imgobj.set_cmap(cmap) | ||
return float(datamin),float(datamax),cmap |
43 changes: 43 additions & 0 deletions
43
src/simplebuild_dgcode/data/pkgs/PyAnalysis/PyAnaMisc/python/fpe.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
def disableFPEDuringCall(obj,fctname): | ||
import Core.misc | ||
if not Core.misc.is_debug_build(): | ||
return | ||
orig = getattr(obj,fctname) | ||
import Core.FPE | ||
nofpectxmgr = Core.FPE.DisableFPEContextManager | ||
def safefct(*args,**kwargs): | ||
with nofpectxmgr(): | ||
return orig(*args,**kwargs) | ||
setattr(obj,fctname,safefct) | ||
|
||
__standardFixesDone = [False] | ||
def standardMPLFixes(): | ||
global __standardFixesDone | ||
if __standardFixesDone[0]: | ||
return | ||
__standardFixesDone[0] = True | ||
import Core.misc | ||
if not Core.misc.is_debug_build(): | ||
return | ||
|
||
try: | ||
import matplotlib.pyplot | ||
except ImportError: | ||
return#do nothing | ||
|
||
import matplotlib.figure | ||
import matplotlib.scale | ||
try: | ||
import matplotlib.backends.backend_pdf | ||
except ImportError: | ||
pass | ||
disableFPEDuringCall(matplotlib.pyplot,'tight_layout') | ||
disableFPEDuringCall(matplotlib.figure.Figure,'tight_layout') | ||
disableFPEDuringCall(matplotlib.figure.Figure,'savefig') | ||
disableFPEDuringCall(matplotlib.pyplot,'show') | ||
disableFPEDuringCall(matplotlib.pyplot,'plot') | ||
disableFPEDuringCall(matplotlib.pyplot,'savefig') | ||
if hasattr(matplotlib.scale,'LogTransformBase'): | ||
disableFPEDuringCall(matplotlib.scale.LogTransformBase,'transform_non_affine') | ||
if hasattr(matplotlib.scale,'LogTransform'): | ||
disableFPEDuringCall(matplotlib.scale.LogTransform,'transform_non_affine') |
2 changes: 1 addition & 1 deletion
2
src/simplebuild_dgcode/data/pkgs/SimpleHists/SimpleHists/pkg.info
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.