text
stringlengths
0
828
logging.warning(""%s is not a DICOM file !"" % step_id)
except IntegrityError:
# TODO: properly deal with concurrency problems
logging.warning(""A problem occurred with the DB ! A rollback will be performed..."")
conn.db_session.rollback()
return tags"
3941,"def regularized_function(x,y,func,bins=None,range=None):
""""""Compute func() over data aggregated in bins.
(x,y) --> (x', func(Y')) with Y' = {y: y(x) where x in x' bin}
First the data is collected in bins x' along x and then func is applied to
all data points Y' that have been collected in the bin.
:Arguments:
x
abscissa values (for binning)
y
ordinate values (func is applied)
func
a numpy ufunc that takes one argument, func(Y')
bins
number or array
range
limits (used with number of bins)
:Returns:
F,edges
function and edges (midpoints = 0.5*(edges[:-1]+edges[1:]))
""""""
_x = numpy.asarray(x)
_y = numpy.asarray(y)
# setup of bins from numpy.histogram
if (range is not None):
mn, mx = range
if (mn > mx):
raise ValueError('max must be larger than min in range parameter.')
if not numpy.iterable(bins):
if range is None:
range = (_x.min(), _x.max())
mn, mx = [float(mi) for mi in range]
if mn == mx:
mn -= 0.5
mx += 0.5
bins = numpy.linspace(mn, mx, bins+1, endpoint=True)
else:
bins = numpy.asarray(bins)
if (numpy.diff(bins) < 0).any():
raise ValueError('bins must increase monotonically.')
sorting_index = numpy.argsort(_x)
sx = _x[sorting_index]
sy = _y[sorting_index]
# boundaries in SORTED data that demarcate bins; position in bin_index is the bin number
bin_index = numpy.r_[sx.searchsorted(bins[:-1], 'left'),
sx.searchsorted(bins[-1], 'right')]
# naive implementation: apply operator to each chunk = sy[start:stop] separately
#
# It's not clear to me how one could effectively block this procedure (cf
# block = 65536 in numpy.histogram) because there does not seem to be a
# general way to combine the chunks for different blocks, just think of
# func=median
F = numpy.zeros(len(bins)-1) # final function
F[:] = [func(sy[start:stop]) for start,stop in izip(bin_index[:-1],bin_index[1:])]
return F,bins"
3942,"def unit_rules_restore(root):
# type: (Nonterminal) -> Nonterminal
""""""
Transform parsed tree for grammar with removed unit rules.
The unit rules will be returned back to the tree.
:param root: Root of the parsed tree.
:return: Modified tree.
""""""
items = Traversing.post_order(root)
items = filter(lambda x: isinstance(x, ReducedUnitRule), items)
for rule in items:
parent_nonterm = rule.from_symbols[0] # type: Nonterminal
# restore chain of unit rules
for r in rule.by_rules:
created_rule = r() # type: Rule
parent_nonterm._set_to_rule(created_rule)
created_rule._from_symbols.append(parent_nonterm)
created_nonterm = r.toSymbol() # type: Nonterminal
created_rule._to_symbols.append(created_nonterm)
created_nonterm._set_from_rule(created_rule)
parent_nonterm = created_nonterm
# restore last rule
last_rule = rule.end_rule() # type: Rule
last_rule._from_symbols.append(parent_nonterm)
parent_nonterm._set_to_rule(last_rule)
for ch in rule.to_symbols: # type: Nonterminal
ch._set_from_rule(last_rule)
last_rule._to_symbols.append(ch)
return root"
3943,"def remaining_bytes(self, meta=True):
""""""