#!/bin/python
if mat.shape[0] == mat.shape[1]: return mat min_a = num.argmin(mat.shape) max_a = num.argmax(mat.shape)
width = mat.shape[max_a] - mat.shape[min_a]
if min_a == 0: padding = ((width, 0), (0, 0)) elif min_a == 1: padding = ((0, 0), (0, width)) return num.pad(mat, pad_width=padding, mode='constant', constant_values=0.)
""" Deramp through fitting a bilinear plane Data is also de-meaned """ raise TypeError('Displacement has to be 2-dim array')
mx[~num.isnan(mx)]) my[~num.isnan(my)])
""" Deramp through lsq a bilinear plane Data is also de-meaned """ if displ.ndim != 2: raise TypeError('Displacement has to be 2-dim array')
# form a relative coordinate grid c_grid = num.mgrid[0:displ.shape[0], 0:displ.shape[1]]
# separate and flatten coordinate grid into x and y vectors for each !point ix = c_grid[0].flat iy = c_grid[1].flat displ_f = displ.flat
# reduce vectors taking out all NaN's displ_nonan = displ_f[num.isfinite(displ_f)] ix = ix[num.isfinite(displ_f)] iy = iy[num.isfinite(displ_f)]
# form kernel/design derampMatrix (c, x, y) GT = num.matrix([num.ones(len(ix)), ix, iy]) G = GT.T
# generalized kernel matrix (quadtratic) GTG = GT * G # generalized inverse GTGinv = GTG.I
# lsq estimates of ramp parameter ramp_paras = displ_nonan * (GTGinv * GT).T
# ramp values ramp_nonan = ramp_paras * GT ramp_f = num.multiply(displ_f, 0.)
# insert ramp values in full vectors num.place(ramp_f, num.isfinite(displ_f), num.array(ramp_nonan).flatten()) ramp_f = ramp_f.reshape(displ.shape[0], displ.shape[1])
return displ - ramp_f
"""Trim displacement matrix from all NaN rows and columns """ raise ValueError('Displacement has to be 2-dim array')
raise ValueError('Displacement is all NaN.')
R1 = 6371009. d2r = num.deg2rad sin = num.sin cos = num.cos a = sin(d2r(alat-blat)/2)**2 + cos(d2r(alat)) * cos(d2r(blat))\ * sin(d2r(alon-blon)/2)**2 c = 2. * num.arctan2(num.sqrt(a), num.sqrt(1.-a)) return R1 * c
else:
fset=cache_return_setter, doc=func_doc)
# number of floating points: mn = num.nanmin(data) mx = num.nanmax(data) if not num.isfinite(mx) or num.isfinite(mn): return 3, 6 precission = int(round(num.log10((100. / (mx-mn))))) if precission < 0: precission = 0 # length of the number in the label: length = max(len(str(int(mn))), len(str(int(mx)))) + precission return precission, length
if num.isinf(v): return 'inf' elif num.isnan(v): return 'nan'
if v % 1 == 0.: return '{value:d}'.format(value=v)
if abs(v) < (10.**-(ndigits-2)): return '{value:e}'.format(value=v)
p = num.ceil(num.log10(num.abs(v))) if p <= 0.: f = {'d': 1, 'f': ndigits - 1} else: p = int(p) f = {'d': p, 'f': ndigits - p}
return '{value:{d}.{f}f}'.format(value=v, **f)
""" Subject - Obsever model realization """
return self.notify(*args, **kwargs)
self._mute = True
self._mute = False
""" Subscribe a listening callback to this subject """ else:
""" Unsubscribe a listening callback from this subject """ try: self._listeners.remove(listener) except Exception: raise AttributeError('%s was not subscribed!', listener.__name__)
for l in self._listeners: self.unsubscribe(l)
return
def _call(func, *args, **kwargs): if k not in func.__code__.co_varnames: k.pop(k) except AttributeError: kwargs = {}
return self[attr]
self[attr] = value
Subject '''.split() |