else:
return path else:
isort = num.argsort(x) iorder = num.empty(isort.size, dtype=num.int) iorder[isort] = num.arange(isort.size) return iorder
return 2**int(math.ceil(math.log(i) / math.log(2.)))
for v in d.values(): v.sort(key=sort)
return '%g m' % dist return '%.0f m' % dist return '%.1f km' % (dist / km) else:
elif 3600. <= t < 24 * 3600.: return s + util.time_to_str(t, format='%H:%M h') else: return s + '%.1f d' % (t / (24. * 3600.))
except AttributeError: def nanmedian(a, axis=None): if axis is None: return num.median(a[num.isfinite(a)]) else: shape_out = list(a.shape) shape_out.pop(axis) out = num.empty(shape_out, dtype=a.dtype) out[...] = num.nan for iout in num.ndindex(tuple(shape_out)): iin = list(iout) iin[axis:axis] = [slice(0, a.shape[axis])] b = a[tuple(iin)] out[iout] = num.median(b[num.isfinite(b)])
return out
except KeyError as e: raise GrondError( 'invalid placeholder "%s" in template: "%s"' % (str(e), template)) except ValueError: raise GrondError( 'malformed placeholder in template: "%s"' % template)
raise AttributeError('Groups must be a list of strings.')
def name_nogroups(self):
value = self.scaled(value) unit = self.get_unit_suffix() return format % dict(value=value, unit=unit)
else:
else:
return list(v/self.scale_factor for v in x) else:
return tuple(v*self.scale_factor for v in x) return list(v*self.scale_factor for v in x) else:
basepath, self.path_prefix or self._parent_path_prefix)
self._basepath, new_basepath), self.path_prefix))
new_basepath, self.path_prefix or self._parent_path_prefix)
op.normpath(xjoin(self._basepath, xjoin(path_prefix, path)))) else: extra( op.normpath(xjoin(self._basepath, xjoin(path_prefix, p)))) for p in path]
return xrelpath(path, self.get_basepath())
toks = s.split('.') if len(toks) == 1: return '*.%s.*.*' % s elif len(toks) == 2: return '%s.*.*' % s elif len(toks) == 3: return '%s.*' % s elif len(toks) == 4: return s else: raise GrondError('Invalid net.sta.loc.cha pattern: %s' % s)
# --select="magnitude_min:5 tag_contains:a,b "
'min': lambda data, key, value: data[key] >= value, 'max': lambda data, key, value: data[key] <= value, 'is': lambda data, key, value: data[key] == value}
'in': lambda data, key, values: data[key] in values}
'contains': lambda data, key, values: any(d in values for d in data[key])}
selected_operators_n_1, selected_operators_n_n):
for condition in expression.split(): condition = condition.strip() if condition not in g_conditions: try: argument, value = condition.split(':', 1) except ValueError: raise SelectionError( 'Invalid condition in selection expression: ' '"%s", must be "ARGUMENT:VALUE"' % condition)
argument = argument.strip()
try: key, operator = argument.rsplit('_', 1) except ValueError: raise SelectionError( 'Invalid argument in selection expression: ' '"%s", must be "KEY_OPERATOR"' % argument)
if operator not in selected_operators: raise SelectionError( 'Invalid operator in selection expression: ' '"%s", available: %s' % ( operator, ', '.join('"%s"' % s for s in sorted( list(selected_operators)))))
g_conditions[condition] = key, operator, value
yield g_conditions[condition]
results = [] for (key, operator, value) in _parse_selected_expression(expression): if key not in data: raise SelectionError( 'Invalid key in selection expression: ' '"%s", available:\n %s' % ( key, '\n '.join(sorted(data.keys()))))
typ = types[key] if not isinstance(typ, tuple): if operator in selected_operators_1_1: results.append( selected_operators_1_1[operator](data, key, typ(value))) elif operator in selected_operators_1_n: values = list(typ(v) for v in value.split(',')) results.append( selected_operators_1_n[operator](data, key, values)) else: raise SelectionError( 'Cannot use operator "%s" with argument "%s".' % ( operator, key))
else: if operator in selected_operators_n_1: results.append( selected_operators_n_1[operator](data, key, typ[1](value))) elif operator in selected_operators_n_n: values = typ[0](typ[1](v) for v in value.split(',')) results.append( selected_operators_n_n[operator](data, key, values)) else: raise SelectionError( 'Cannot use operator "%s" with argument "%s".' % ( operator, key))
return all(results)
Forbidden GrondError Path HasPaths Parameter StringID '''.split() |