-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from slaclab/apply_formatting_linting
Apply formatting with auto-formatter
- Loading branch information
Showing
57 changed files
with
2,550 additions
and
2,281 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,45 +1,47 @@ | ||
import numpy | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
class Stats(object): | ||
def __init__(self, shape): | ||
self._n = 0 | ||
self._x = numpy.zeros(shape)##, dtype=double) | ||
self._xx = numpy.zeros(shape)##, dtype=double) | ||
self._xy = numpy.zeros(shape)##, dtype=double) | ||
self._x = numpy.zeros(shape) ##, dtype=double) | ||
self._xx = numpy.zeros(shape) ##, dtype=double) | ||
self._xy = numpy.zeros(shape) ##, dtype=double) | ||
|
||
def mean(self): | ||
return self._x/self._n | ||
return self._x / self._n | ||
|
||
def rms(self): | ||
return ((self._xx/self._n - (self._x/self._n)**2)).clip(0)**0.5 | ||
return ((self._xx / self._n - (self._x / self._n) ** 2)).clip(0) ** 0.5 | ||
|
||
def corr(self, yMean, ySigma): | ||
## return (self._xy -self._x*yMean)/self._n | ||
if ySigma >0: | ||
## return (self._xy -self._x*yMean)/self._n | ||
if ySigma > 0: | ||
rmsPosDef = self.rms().clip(0.000001, self.rms().max()) | ||
return numpy.double((self._xy -self._x*yMean)/(self._n*ySigma*rmsPosDef)) | ||
return numpy.double((self._xy - self._x * yMean) / (self._n * ySigma * rmsPosDef)) | ||
else: | ||
return None | ||
|
||
def accumulate(self, x, y=0): | ||
self._n += 1 | ||
self._x += x | ||
self._xx += x*x | ||
self._xy += x*y | ||
self._xx += x * x | ||
self._xy += x * y | ||
|
||
|
||
|
||
if __name__ == '__main__': | ||
if __name__ == "__main__": | ||
a = numpy.zeros([10]) | ||
s = Stats(a.shape) | ||
for i in range(10000): | ||
d = numpy.sin((numpy.array(list(range(10)))+i)/3.14159) | ||
d = numpy.sin((numpy.array(list(range(10))) + i) / 3.14159) | ||
s.accumulate(d, d[7]) | ||
|
||
print("mean: " + str(s.mean())) | ||
print("rms: " + str(s.rms())) | ||
print("s.corr(s.mean()[7], s.rms()[7]): " + str(s.corr(s.mean()[7], s.rms()[7]))) | ||
logger.info("mean: " + str(s.mean())) | ||
logger.info("rms: " + str(s.rms())) | ||
logger.info("s.corr(s.mean()[7], s.rms()[7]): " + str(s.corr(s.mean()[7], s.rms()[7]))) | ||
logger.info("s.corr(s.mean()[7], s.rms()[7]): " + str(s.corr(s.mean()[7], s.rms()[7]))) |
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,54 +1,59 @@ | ||
import numpy as np | ||
from scipy.stats import binned_statistic | ||
import logging | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def makeProfile(x, y, bins, range=None, spread=False): | ||
## NaN for empty bins are suppressed | ||
## using mean root(N) for non-empty bins to calculate 0 var weights | ||
## | ||
## spread=True to return standard deviation instead of standard error | ||
|
||
meansObj = binned_statistic(x, [y, y**2], bins=bins, range=range, statistic='mean') | ||
meansObj = binned_statistic(x, [y, y**2], bins=bins, range=range, statistic="mean") | ||
means, means2 = meansObj.statistic | ||
countsObj = binned_statistic(x, y, bins=bins, range=range, statistic='count') | ||
stdObj = binned_statistic(x, y, bins=bins, range=range, statistic='std') | ||
countsObj = binned_statistic(x, y, bins=bins, range=range, statistic="count") | ||
stdObj = binned_statistic(x, y, bins=bins, range=range, statistic="std") | ||
bin_N = countsObj.statistic | ||
usefulBins = np.bitwise_and(bin_N>0, ~np.isnan(means)) | ||
if bin_N.sum()==0: | ||
usefulBins = np.bitwise_and(bin_N > 0, ~np.isnan(means)) | ||
if bin_N.sum() == 0: | ||
##no data | ||
print("no data in profile") | ||
logger.error("no data in profile") | ||
return None, None, None | ||
|
||
##yErr = np.sqrt(means2 - means**2) | ||
yErr = stdObj.statistic | ||
if not spread: | ||
root_N = np.sqrt(bin_N) | ||
root_N[root_N==0] = root_N[usefulBins].mean() | ||
yErr = yErr/root_N | ||
root_N[root_N == 0] = root_N[usefulBins].mean() | ||
yErr = yErr / root_N | ||
##yErr = yErr.clip(0, 6666666.) | ||
|
||
bin_edges = meansObj.bin_edges | ||
bin_centers = (bin_edges[:-1] + bin_edges[1:])/2. | ||
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2.0 | ||
return bin_centers[usefulBins], means[usefulBins], yErr[usefulBins] | ||
|
||
|
||
def plotProfile(x, y, yErr): | ||
plt.errorbar(x=x, y=y, yerr=yErr, linestyle='none', marker='.') | ||
plt.errorbar(x=x, y=y, yerr=yErr, linestyle="none", marker=".") | ||
|
||
|
||
def selectedClusters(clusters, row, col, lowEnerygCut, highEnergyCut, nPixelCut=4, isSquare=1): | ||
pass | ||
|
||
|
||
def goodClusters(clusters, row, col, nPixelCut=4, isSquare=None): | ||
##print(clusters) | ||
pixelRowCol = np.bitwise_and((clusters[:,:,1] == row), | ||
(clusters[:,:,2] == col)) | ||
pixelRowCol = np.bitwise_and((clusters[:, :, 1] == row), (clusters[:, :, 2] == col)) | ||
if isSquare is None: | ||
small = clusters[:,:,3]<nPixelCut | ||
small = clusters[:, :, 3] < nPixelCut | ||
else: | ||
small = np.bitwise_and((clusters[:,:,3]<nPixelCut), (clusters[:,:,4]==isSquare)) | ||
small = np.bitwise_and((clusters[:, :, 3] < nPixelCut), (clusters[:, :, 4] == isSquare)) | ||
return clusters[np.bitwise_and(small, pixelRowCol)] | ||
|
||
|
||
def getClusterEnergies(clusters): | ||
##print(clusters) | ||
return clusters[:, 0] |
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,31 +1,47 @@ | ||
import argparse | ||
|
||
|
||
class ArgumentParser: | ||
def __init__(self): | ||
self.parser = argparse.ArgumentParser( | ||
description='Configures calibration suite, overriding experimentHash', | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter | ||
description="Configures calibration suite, overriding experimentHash", | ||
formatter_class=argparse.ArgumentDefaultsHelpFormatter, | ||
) | ||
self.parser.add_argument("-e", "--exp", help="experiment") | ||
self.parser.add_argument("-l", "--location", help="hutch location, e.g. MfxEndstation or DetLab") | ||
self.parser.add_argument("-r", "--run", type=int, help="run") | ||
self.parser.add_argument("-R", "--runRange", help="run range, format ...") | ||
self.parser.add_argument("--fivePedestalRun", type=int, help="5 pedestal run") | ||
self.parser.add_argument("--fakePedestal", type=str, help="fake pedestal file") | ||
self.parser.add_argument("-c", "--camera", type=int, help="camera.n") | ||
self.parser.add_argument("-p", "--path", type=str, help="the base path to the output directory") | ||
self.parser.add_argument("-n", "--nModules", type=int, help="nModules") | ||
self.parser.add_argument( | ||
"-d", "--detType", type=str, default="", help="Epix100, Epix10ka, Epix10kaQuad, Epix10ka2M, ..." | ||
) | ||
self.parser.add_argument("--maxNevents", type=int, default="666666", help="max number of events to analyze") | ||
self.parser.add_argument( | ||
"--skipNevents", type=int, default=0, help="max number of events to skip at the start of each step" | ||
) | ||
self.parser.add_argument( | ||
"--configScript", | ||
type=str, | ||
default="experimentSuiteConfig.py", | ||
help="name of python config file to load if any", | ||
) | ||
self.parser.add_argument('-e', '--exp', help='experiment') | ||
self.parser.add_argument('-l', '--location', help='hutch location, e.g. MfxEndstation or DetLab') | ||
self.parser.add_argument('-r', '--run', type=int, help='run') | ||
self.parser.add_argument('-R', '--runRange', help='run range, format ...') | ||
self.parser.add_argument('--fivePedestalRun', type=int, help='5 pedestal run') | ||
self.parser.add_argument('--fakePedestal', type=str, help='fake pedestal file') | ||
self.parser.add_argument('-c', '--camera', type=int, help='camera.n') | ||
self.parser.add_argument('-p', '--path', type=str, help='the base path to the output directory') | ||
self.parser.add_argument('-n', '--nModules', type=int, help='nModules') | ||
self.parser.add_argument('-d', '--detType', type=str, default='', help='Epix100, Epix10ka, Epix10kaQuad, Epix10ka2M, ...') | ||
self.parser.add_argument('--maxNevents', type=int, default='666666', help='max number of events to analyze') | ||
self.parser.add_argument('--skipNevents', type=int, default=0, help='max number of events to skip at the start of each step') | ||
self.parser.add_argument('--configScript', type=str, default='experimentSuiteConfig.py', help='name of python config file to load if any') | ||
self.parser.add_argument('--detObj', help='"raw", "calib", "image"') | ||
self.parser.add_argument('-f','--files', type=str, default=None, help='run analysis on file or comma-separated files') | ||
self.parser.add_argument('-cf', '--configFile', type=str, help='config file path, can be relative or full path') | ||
self.parser.add_argument('-L','--label', type=str, help='analysis label') | ||
self.parser.add_argument('-t', '--threshold', help="threshold (ADU or keV or wave8) depending on --detObj") | ||
self.parser.add_argument('--fluxCut', type=float, help="minimum flux to be included in analysis") | ||
self.parser.add_argument('--special', type=str, help='comma-separated list of special behaviors - maybe this is too lazy. E.g. positiveParity,doKazEvents,...') | ||
|
||
self.parser.add_argument("--detObj", help='"raw", "calib", "image"') | ||
self.parser.add_argument( | ||
"-f", "--files", type=str, default=None, help="run analysis on file or comma-separated files" | ||
) | ||
self.parser.add_argument("-cf", "--configFile", type=str, help="config file path, can be relative or full path") | ||
self.parser.add_argument("-L", "--label", type=str, help="analysis label") | ||
self.parser.add_argument("-t", "--threshold", help="threshold (ADU or keV or wave8) depending on --detObj") | ||
self.parser.add_argument("--fluxCut", type=float, help="minimum flux to be included in analysis") | ||
self.parser.add_argument( | ||
"--special", | ||
type=str, | ||
help="comma-separated list of special behaviors - maybe this is too lazy. E.g. positiveParity,doKazEvents,...", | ||
) | ||
|
||
def parse_args(self): | ||
return self.parser.parse_args() | ||
return self.parser.parse_args() |
Oops, something went wrong.