本文整理汇总了Python中backend.add_record函数的典型用法代码示例。如果您正苦于以下问题:Python add_record函数的具体用法?Python add_record怎么用?Python add_record使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了add_record函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: lambda_values
def lambda_values(evt,pulse_energy,sum_over_bkg_frames,fit_bkg,sample_params,outkey=""):
frame_expected_phc = numpy.dot(sample_params,numpy.array([pulse_energy**3,pulse_energy**2,pulse_energy,1]))
lambdav = sum_over_bkg_frames*frame_expected_phc/fit_bkg.sum()
lambdav[lambdav<=0] = 1e-30
v = evt["analysis"]
add_record(v, "analysis", outkey+"lambda_values", lambdav)
add_record(v, "analysis", outkey+"expected_phc", frame_expected_phc)
示例2: assemble
def assemble(evt, type, key, x, y, nx=None, ny=None, subset=None, outkey=None):
"""Asesembles a detector image given some geometry and adds assembled image to ``evt["analysis"]["assembled - " + key]``.
Args:
:evt: The event variable
:type(str): The event type (e.g. photonPixelDetectors)
:key(str): The event key (e.g. CCD)
:x(int ndarray): X coordinates
:y(int ndarray): Y coordinates
Kwargs:
:nx(int): Total width of assembled image (zero padding)
:ny(int): Total height of assembled image (zero padding)
:Authors:
Benedikt J. Daurer ([email protected])
"""
if not key in initialized:
if subset is not None:
x_ss = []
y_ss = []
for i in subset:
panel = i / 2
asic = i % 2
x_ss.append(x[panel,:,(asic*194):((asic+1)*194)])
y_ss.append(y[panel,:,(asic*194):((asic+1)*194)])
x_ss = np.hstack(x_ss)
y_ss = np.hstack(y_ss)
else:
x_ss = x
y_ss = y
assembled, height, width, shape, y_ss, x_ss = utils.array.assembleImage(x_ss, y_ss ,nx=nx, ny=ny, return_indices=True)
initialized[key] = {
'assembled':assembled,
'height':height,
'width':width,
'shape':shape,
'y':y_ss,
'x':x_ss
}
assembled = initialized[key]['assembled']
height = initialized[key]['height']
width = initialized[key]['width']
shape = initialized[key]['shape']
y = initialized[key]['y']
x = initialized[key]['x']
if subset is not None:
data = []
for i in subset:
panel = i / 2
asic = i % 2
data.append(evt[type][key].data[panel,:,(asic*194):((asic+1)*194)])
data = np.hstack(data)
else:
data = evt[type][key].data
assembled[height-shape[0]:, :shape[1]][y,x] = data
if outkey is None:
add_record(evt["analysis"], "analysis", "assembled - "+key, assembled)
else:
add_record(evt["analysis"], "analysis", outkey, assembled)
示例3: radial
def radial(evt, type, key, mask=None, cx=None, cy=None):
"""Compute the radial average of a detector image given the center position (and a mask).
Adds the records ``evt["analysis"]["radial average - " + key]`` and ``evt["analysis"]["radial distance - " + key]``.
.. note:: This feature depends on the python package `libspimage <https://github.com/FilipeMaia/libspimage>`_.
Args:
:evt: The event variable
:type(str): The event type (e.g. photonPixelDetectors)
:key(str): The event key (e.g. CCD)
Kwargs:
:mask: Binary mask, pixels that are masked out are not counted into the radial average.
:cx(float): X-coordinate of the center position. If None the center will be in the middle.
:cy(float): Y-coordinate of the center position. If None the center will be in the middle.
:Authors:
Max F. Hantke ([email protected])
"""
success, spimage = utils.io.load_spimage()
if not success:
print "Skipping analysis.pixel_detector.radial"
return
image = evt[type][key].data
r, img_r = spimage.radialMeanImage(image, msk=mask, cx=cx, cy=cy, output_r=True)
valid = np.isfinite(img_r)
if valid.sum() > 0:
r = r[valid]
img_r = img_r[valid]
add_record(evt["analysis"], "analysis", "radial distance - " + key, r)
add_record(evt["analysis"], "analysis", "radial average - " + key, img_r)
示例4: bgsub
def bgsub(evt, type, key, bg):
data = evt[type][key].data
if bg is not None:
dataCorrected = data - bg
else:
dataCorrected = data
add_record(evt["analysis"], "analysis", "bgsub - " + key, dataCorrected)
示例5: bin
def bin(evt, type, key, binning, mask=None):
"""Bin a detector image given a binning factor (and mask).
Adds the records ``evt["analysis"]["binned image - " + key]`` and ``evt["analysis"]["binned mask - " + key]``.
.. note:: This feature depends on the python package `libspimage <https://github.com/FilipeMaia/libspimage>`_.
Args:
:evt: The event variable
:type(str): The event type (e.g. photonPixelDetectors)
:key(str): The event key (e.g. CCD)
:binning(int): The linear binning factor
Kwargs:
:mask: Binary mask, pixels that are masked out are not counted into the binned value.
:Authors:
Max F. Hantke ([email protected])
"""
success, spimage = utils.io.load_spimage()
if not success:
print "Skipping analysis.pixel_detector.bin"
return
image = evt[type][key].data
binned_image, binned_mask = spimage.binImage(image, binning, msk=mask, output_binned_mask=True)
add_record(evt["analysis"], "analysis", "binned image - "+key, binned_image)
if binned_mask is not None:
add_record(evt["analysis"], "analysis", "binned mask - "+key, binned_mask)
示例6: photon_error
def photon_error(evt, type_data, key_data, type_fit, key_fit, adu_per_photon):
import scipy.misc
data = np.array(evt[type_data][key_data].data / (1.*adu_per_photon), dtype="float")
fit = np.array(evt[type_fit][key_fit].data / (1.*adu_per_photon), dtype="float")
data_best = fit.round()
data = data.copy()
M = fit != 0
M *= data > 0
M *= data_best > 0
K = data[M]
W = fit[M]
Ks = data_best[M]
# Stirling
lKf = K*np.log(K)-K
tmp = K < 5
if tmp.sum():
lKf[tmp] = np.log( scipy.misc.factorial(K[tmp], exact=False) )
# Stirling
lKsf = Ks*np.log(Ks)-Ks
tmp = Ks < 5
if tmp.sum():
lKsf[tmp] = np.log( scipy.misc.factorial(Ks[tmp], exact=False) )
error = ( Ks * np.log(W) - lKsf ) - ( K * np.log(W) - lKf )
error = error.sum()
add_record(evt["analysis"], "analysis", "photon error", error, unit='')
示例7: hitrate
def hitrate(evt, hit, history=100, unit='percent', outkey="hitrate"):
"""Counts hits and adds current hit rate to ``evt["analysis"][outkey]``.
Args:
:evt: The event variable
:hit: A boolean (True for hit, False for miss)
Kwargs:
:history(int): Buffer length, default = 100
:outkey(str): Data key of resulting ``Record``, default is "hitrate"
:unit(str): Unit of hitrate, 'fraction' or 'percent', default is 'fraction'
:Authors:
Benedikt J. Daurer ([email protected])
Tomas Ekeberg
"""
global hitrate_counters
if outkey not in hitrate_counters or hitrate_counters[outkey].maxlen != history:
hitrate_counters[outkey] = collections.deque([], history)
hitrate_counters[outkey].append(bool(hit))
hitcount = np.array(hitrate_counters[outkey].count(True))
ipc.mpi.sum("hitcount - " + outkey, hitcount)
v = evt["analysis"]
if (ipc.mpi.is_main_worker()):
hitrate = hitcount[()] / (ipc.mpi.nr_workers() * float(len(hitrate_counters[outkey])))
if unit == 'fraction':
add_record(v, "analysis", outkey, hitrate)
elif unit == 'percent':
add_record(v, "analysis", outkey, 100.*hitrate)
示例8: radial
def radial(evt, type, key, mask=None, cx=None, cy=None):
"""Compute the radial average of a detector image given the center position (and a mask) and saves it to ``evt["analysis"]["radial average - " + key]`` and the radial distances are saved to``evt["analysis"]["radial distance - " + key]``
Args:
:evt: The event variable
:type(str): The event type (e.g. photonPixelDetectors)
:key(str): The event key (e.g. CCD)
Kwargs:
:mask: Binary mask, pixels that are masked out are not counted into the radial average.
:cx(float): X-coordinate of the center position. If None the center will be in the middle.
:cy(float): Y-coordinate of the center position. If None the center will be in the middle.
:Authors:
Max F. Hantke ([email protected])
"""
import spimage
image = evt[type][key].data
r, img_r = spimage.radialMeanImage(image, msk=mask, cx=cx, cy=cy, output_r=True)
valid = np.isfinite(img_r)
if valid.sum() > 0:
r = r[valid]
img_r = img_r[valid]
add_record(evt["analysis"], "analysis", "radial distance - "+key, r)
add_record(evt["analysis"], "analysis", "radial average - "+key, img_r)
示例9: someAnalysis
def someAnalysis(evt, type, key, keyword=None):
"""An example for an analysis module. Please document here in the docstring:
- what the module is doing
- what arguments need to be passed
- what the module returns (adds to the event variable)
- who the authors are
Args:
:evt: The event variable
:type(str): The event type
:key(str): The event key
Kwargs:
:keyword(type): Kewyword description (default = None)
:Authors:
Name (email),
Name (email)
"""
# ADD YOUR CODE HERE
#
# something = ....
add_record(evt["analysis"], "analysis", "somethingNew"+key, something, unit=some_unit)
示例10: commonModeCSPAD2x2
def commonModeCSPAD2x2(evt, type, key, mask=None):
"""Subtraction of common mode using median value of masked pixels (left and right half of detector are treated separately).
Adds a record ``evt["analysis"]["cm_corrected - " + key]``.
Args:
:evt: The event variable
:type(str): The event type (e.g. photonPixelDetectors)
:key(str): The event key (e.g. CCD)
Kwargs:
:mask: Binary mask
:Authors:
Max F. Hantke ([email protected])
Benedikt J. Daurer ([email protected])
"""
data = evt[type][key].data
dataCorrected = np.copy(data)
lData = data[:,:data.shape[1]/2]
rData = data[:,data.shape[1]/2:]
if mask is None:
lMask = np.ones(shape=lData.shape, dtype="bool")
rMask = np.ones(shape=rData.shape, dtype="bool")
else:
lMask = mask[:,:data.shape[1]/2] == False
rMask = mask[:,data.shape[1]/2:] == False
if lMask.sum() > 0:
dataCorrected[:,:data.shape[1]/2] -= np.median(lData[lMask])
if rMask.sum() > 0:
dataCorrected[:,data.shape[1]/2:] -= np.median(rData[rMask])
add_record(evt["analysis"], "analysis", "cm_corrected - " + key, dataCorrected)
示例11: absolute_error
def absolute_error(evt, type_a, key_a, type_b, key_b, out_key=None):
"""Returning the absolute error between two records as a new record."""
a = evt[type_a][key_a]
b = evt[type_b][key_b]
if out_key is None:
out_key = "abs(%s - %s)" %(a.name, b.name)
add_record(evt["analysis"], "analysis", out_key, abs(a.data-b.data), unit='')
示例12: getMaskedParticles
def getMaskedParticles(evt, type, key, output, thresh = 20, minX = 800, maxX = 1500, minY = 0, maxY = 1700, kw = 5):
"""Black-box method to create a masked version of a camera
image where individual illuminated particles constitute a mask."""
outimg = np.zeros(evt[type][key].data.shape, np.dtype(np.uint8))
kernel = np.ones((kw*2+1,kw*2+1), np.uint8)
outimg[minY:maxY, minX:maxX] = evt[type][key].data[minY:maxY,minX:maxX] > thresh
outimg = cv2.dilate(outimg, kernel)
# cv2.adaptiveThreshold(evt[type][key].data.astype(np.uint8), 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
add_record(evt["analysis"], "analysis", output, outimg)
示例13: cmc_pnccd
def cmc_pnccd(evt, type, key):
try:
data = evt[type][key].data
except:
print "NO DATA!"
return
if data is None:
return
dataCorrected = utils.array.cmc_pnccd(data)
add_record(evt["analysis"], "analysis", "cmc_pnccd - " + key, dataCorrected)
示例14: countContours
def countContours(evt, type, key, maskedKey, outimage, outvector):
imageoutput = np.ndarray(evt[type][key].data.shape, np.uint8)
(contours,_) = cv2.findContours(evt["analysis"][maskedKey].data, cv2.RETR_LIST, cv2.CHAIN_APPROX_NONE)
for i in xrange(len(contours)):
cv2.drawContours(imageoutput, contours, i, i + 1, -1)
needed_labels = np.arange(1, len(contours))
counts = scipy.ndimage.measurements.sum(evt[type][key].data, imageoutput, needed_labels)
add_record(evt["analysis"], "analysis", outimage, imageoutput)
add_record(evt["analysis"], "analysis", outvector, counts)
示例15: sphereModel
def sphereModel(evt, type, key_centerx, key_centery, key_diameter, key_intensity,
shape, wavelength=1., pixelsize=110, distance=1000, adu_per_photon=1,
quantum_efficiency=1, material='virus', poisson=False):
"""Return sphere model.
.. note:: For this function, `libspimage <https://github.com/FilipeMaia/libspimage>`_ needs to be installed.
Args:
:evt: The event variable
:type(str): The event type, e.g. analysis
:key_centerx(str): The event key of the estimated off center shift in x
:key_centery(str): The event key of the estimated off center shift in y
:key_diameter(str): The event key of the estimated diameter
:key_intensity(str): The event key of the estimated intensity
:shape(tuple): The shape of the fit
Kwargs:
:wavelength(float): Photon wavelength [nm] (default = 1)
:pixelsize(int): Side length of a pixel [um] (default=110)
:distance(int): Distance from interaction to detector [mm] (default = 1000)
:adu_per_photon(int): ADUs per photon (default = 1)
:quantum_efficiency(float): Quantum efficiency of the detector (default = 1)
:material(str): Material of particle, e.g. virus, protein, water, ... (default = virus)
:poisson(bool): If True, apply poisson sampling (default = False)
:Authors:
Benedikt J. Daurer ([email protected]),
Max Hantke,
Filipe Maia
"""
success, spimage = utils.io.load_spimage()
if not success:
print "Skipping analysis.sizing.sphereModel"
return
centerx = evt[type][key_centerx].data
centery = evt[type][key_centery].data
diameter = evt[type][key_diameter].data * 1e-9
intensity = evt[type][key_intensity].data * 1e-3 / 1e-12
wavelength *= 1e-9
distance *= 1e-3
pixelsize *= 1e-6
size = spimage.sphere_model_convert_diameter_to_size(diameter, wavelength,
pixelsize, distance)
scaling = spimage.sphere_model_convert_intensity_to_scaling(intensity, diameter,
wavelength, pixelsize,
distance, quantum_efficiency,
adu_per_photon, material)
fit = spimage.I_sphere_diffraction(scaling,
spimage.rgrid(shape, (centerx, centery)),
size)
if poisson:
fit = np.random.poisson(fit)
add_record(evt["analysis"], "analysis", "fit", fit, unit='ADU')