Ejemplo n.º 1
0
def gradient(f, *varargs):
    '''Gradient of array
    
    f -- array
    *varargs -- 0, 1, N scalars for sample distance, or (1 or N-d) datasets for sample points
    '''

    if varargs is None or len(varargs) == 0:
        g = _maths.gradient(f)
    else:
        # check for scalars, etc
        from jycore import arange as _ar
        vl = len(varargs)
        nd = f.getRank()
        if vl == 1:
            varargs = [varargs[0]]*nd
            vl = nd
        if vl != nd:
            raise ValueError, "Number of arguments must be 0, 1 or rank of f"

        xlist = []
        for i in range(vl):
            x = varargs[i]
            xlist.append(x if isinstance(x, _ds) else (_ar(f.shape[i])*x)._jdataset())
        g = _maths.gradient(f, xlist)

    if len(g) == 1:
        return g[0]
    return g
Ejemplo n.º 2
0
	def getPolarDataset(self, datasetX, datasetY):
		datasetRho = DatasetMaths.sqrt( DatasetMaths.power(datasetX, 2) + DatasetMaths.power(datasetY, 2) );
		datasetTheta=DatasetMaths.arctan2(datasetY, datasetX);

		datasetThetaInDegree = DatasetMaths.toDegrees(datasetTheta);
		
		return [datasetRho, datasetThetaInDegree];
Ejemplo n.º 3
0
def gradient(f, *varargs):
    '''Gradient of array
    
    f -- array
    *varargs -- 0, 1, N scalars for sample distance, or (1 or N-d) datasets for sample points
    '''

    if varargs is None or len(varargs) == 0:
        g = _maths.gradient(f)
    else:
        # check for scalars, etc
        from .jycore import arange as _ar
        vl = len(varargs)
        nd = f.getRank()
        if vl == 1:
            varargs = [varargs[0]] * nd
            vl = nd
        if vl != nd:
            raise ValueError("Number of arguments must be 0, 1 or rank of f")

        xlist = []
        for i in range(vl):
            x = varargs[i]
            xlist.append(x if isinstance(x, _ds) else (_ar(f.shape[i]) *
                                                       x)._jdataset())
        g = _maths.gradient(f, xlist)

    if len(g) == 1:
        return g[0]
    return g
Ejemplo n.º 4
0
 def renderShapesOntoDataset(self, targetDataset):
     if self.shapesToPaint == {}:
         return targetDataset.clone()
     a = targetDataset.max()
     b = targetDataset.min()
     image = self.renderShapes(targetDataset)
     image.imultiply(b - (a - b))
     return Maths.add(targetDataset, image)
Ejemplo n.º 5
0
	def _process(self,xDataSet, yDataSet):
		dyDataSet = Maths.derivative(xDataSet._jdataset(), yDataSet._jdataset(), self.smoothwidth)
		minVal, maxVal = dyDataSet.min(), dyDataSet.max()
		if maxVal - minVal == 0:
			raise ValueError("There is no edge")

		labels = [label if label != 'slope' else 'top' for label in self.labelList]
		return GaussianPeak(self.name, labels, self.formatString, self.plotPanel)._process(xDataSet, dyDataSet)
Ejemplo n.º 6
0
	def _process(self, xDataSet, yDataSet):
		dyDataSet = dnp.array(Maths.derivative(xDataSet._jdataset(), yDataSet._jdataset(), self.smoothwidth))
		uposC, ufwhmC, uareaC, dposC, dfwhmC, dareaC = self.coarseProcess(xDataSet, dyDataSet)
		gaussian = dnp.fit.function.gaussian

		if abs(dareaC) < 0.2 * uareaC:
			r = dnp.fit.fit([gaussian], xDataSet, dyDataSet,
							[uposC, ufwhmC, uareaC],
							bounds=[
								(uposC - 2 * ufwhmC, uposC + 2 * ufwhmC),
								(0, 2 * ufwhmC),
								(0, 2 * uareaC)],
							ptol=1e-10, optimizer=self.optimizer)
			upos, ufwhm, _uarea = r.parameters
			results = {'upos': upos, 'ufwhm': ufwhm, 'area': _uarea, 'uarea': _uarea, 'fwhm': ufwhm}

		elif uareaC < 0.2 * abs(dareaC):
			r = dnp.fit.fit([gaussian], xDataSet, dyDataSet,
							[dposC, dfwhmC, dareaC],
							bounds=[
								(dposC - 2 * dfwhmC, dposC + 2 * dfwhmC),
								(0, 2 * dfwhmC),
								(2 * dareaC, 0)],
							ptol=1e-10, optimizer=self.optimizer)
			dpos, dfwhm, _darea = r.parameters
			results = {'dpos': dpos, 'dfwhm': dfwhm, 'area': abs(_darea), 'darea': _darea, 'fwhm': dfwhm}

		else:
			r = dnp.fit.fit([gaussian, gaussian], xDataSet, dyDataSet,
							[uposC, ufwhmC, uareaC,dposC, dfwhmC, dareaC],
							bounds=[
								(uposC - 2 * ufwhmC, uposC + 2 * ufwhmC),
								(0, 2 * ufwhmC),
								(0, 2 * uareaC),
								(dposC - 2 * dfwhmC, dposC + 2 * dfwhmC),
								(0, 2 * dfwhmC),
								(2 * dareaC, 0)],
							ptol=1e-10, optimizer=self.optimizer)
			upos, ufwhm, _uarea, dpos, dfwhm, _darea = r.parameters
			results = {'upos': upos,
					'dpos': dpos,
					'ufwhm': ufwhm,
					'dfwhm': dfwhm,
					'uarea': _uarea,
					'darea': _darea,
					'centre': (upos + dpos) / 2.0,
					'width': abs(upos - dpos),
					'area': (_uarea + abs(_darea)) / 2.0,
					'fwhm': (ufwhm + dfwhm) / 2.0}

		self.plotResult(r)
		results['residual'] = r.residual
		return [results.get(label, float('NaN')) for label in self.labelList]
Ejemplo n.º 7
0
def interp(x, xp, fp, left=None, right=None):
    '''Linearly interpolate'''
    x = _asarray(x)
        
    xp = _asarray(xp)
    fp = _asarray(fp)
    if left is None:
        left = fp[0]
    if right is None:
        right = fp[-1]
    r = _asarray(_maths.interpolate(xp._jdataset(), fp._jdataset(), x._jdataset(), left, right))
    if x.ndim == 0:
        return r.item()
    return r
Ejemplo n.º 8
0
def interp(x, xp, fp, left=None, right=None):
    '''Linearly interpolate'''
    x = _asarray(x)
        
    xp = _asarray(xp)
    fp = _asarray(fp)
    if left is None:
        left = fp[0]
    if right is None:
        right = fp[-1]
    r = _asarray(_maths.interpolate(xp._jdataset(), fp._jdataset(), x._jdataset(), left, right))
    if x.ndim == 0:
        return r.item()
    return r
Ejemplo n.º 9
0
def square(a, out=None):
    '''Square of input'''
    return _maths.square(a, out)
Ejemplo n.º 10
0
def floor(a, out=None):
    '''Largest integer smaller or equal to input'''
    return _maths.floor(a, out)
Ejemplo n.º 11
0
def log1p(x, out=None):
    '''Natural logarithm of (x+1)'''
    return _maths.log1p(x, out)
Ejemplo n.º 12
0
def expm1(x, out=None):
    '''Exponential of (x-1)'''
    return _maths.expm1(x, out)
Ejemplo n.º 13
0
def diff(a, order=1, axis=-1):
    '''Difference of input'''
    return _maths.difference(a, order, axis)
Ejemplo n.º 14
0
def log10(a, out=None):
    '''Logarithm of input to base 10'''
    return _maths.log10(a, out)
Ejemplo n.º 15
0
def power(a, p, out=None):
    '''Input raised to given power'''
    return _maths.power(a, p, out)
Ejemplo n.º 16
0
def sign(a, out=None):
    '''Sign of input, indicated by -1 for negative, +1 for positive and 0 for zero'''
    return _maths.signum(a, out)
Ejemplo n.º 17
0
def sqrt(a, out=None):
    '''Square root of input'''
    return _maths.sqrt(a, out)
Ejemplo n.º 18
0
def square(a, out=None):
    '''Square of input'''
    return _maths.square(a, out)
Ejemplo n.º 19
0
def expm1(x, out=None):
    '''Exponential of (x-1)'''
    return _maths.expm1(x, out)
Ejemplo n.º 20
0
def exp(a, out=None):
    '''Exponential of input'''
    return _maths.exp(a, out)
Ejemplo n.º 21
0
def log1p(x, out=None):
    '''Natural logarithm of (x+1)'''
    return _maths.log1p(x, out)
Ejemplo n.º 22
0
def rint(a, out=None):
    '''Round elements of input to nearest integers'''
    return _maths.rint(a, out)
Ejemplo n.º 23
0
def floor(a, out=None):
    '''Largest integer smaller or equal to input'''
    return _maths.floor(a, out)
Ejemplo n.º 24
0
def rad2deg(a, out=None):
    '''Convert from radian to degree'''
    return _maths.toDegrees(a, out)
Ejemplo n.º 25
0
def phase(a, keepzeros=False):
    '''Calculate phase of input by dividing by amplitude
    
    keepzeros -- if True, pass zeros through, else return complex NaNs
    '''
    return _maths.phaseAsComplexNumber(a, keepzeros)
Ejemplo n.º 26
0
def clip(a, a_min, a_max, out=None):
    '''Clip input to given bounds (replace NaNs with midpoint of bounds)'''
    return _maths.clip(a, a_min, a_max, out)
Ejemplo n.º 27
0
def log(a, out=None):
    '''Natural logarithm of input'''
    return _maths.log(a, out)
Ejemplo n.º 28
0
def ceil(a, out=None):
    '''Smallest integer greater or equal to input'''
    return _maths.ceil(a, out)
Ejemplo n.º 29
0
def log(a, out=None):
    '''Natural logarithm of input'''
    return _maths.log(a, out)
Ejemplo n.º 30
0
def arctanh(a, out=None):
    '''Inverse hyperbolic tangent of input'''
    return _maths.arctanh(a, out)
Ejemplo n.º 31
0
def rint(a, out=None):
    '''Round elements of input to nearest integers'''
    return _maths.rint(a, out)
Ejemplo n.º 32
0
def log10(a, out=None):
    '''Logarithm of input to base 10'''
    return _maths.log10(a, out)
Ejemplo n.º 33
0
def trunc(a, out=None):
    '''Truncate elements of input to nearest integers'''
    return _maths.truncate(a, out)
Ejemplo n.º 34
0
def exp(a, out=None):
    '''Exponential of input'''
    return _maths.exp(a, out)
Ejemplo n.º 35
0
def rad2deg(a, out=None):
    '''Convert from radian to degree'''
    return _maths.toDegrees(a, out)
Ejemplo n.º 36
0
def sqrt(a, out=None):
    '''Square root of input'''
    return _maths.sqrt(a, out)
Ejemplo n.º 37
0
def deg2rad(a, out=None):
    '''Convert from degree to radian'''
    return _maths.toRadians(a, out)
Ejemplo n.º 38
0
def power(a, p, out=None):
    '''Input raised to given power'''
    return _maths.power(a, p, out)
Ejemplo n.º 39
0
def sign(a, out=None):
    '''Sign of input, indicated by -1 for negative, +1 for positive and 0 for zero'''
    return _maths.signum(a, out)
Ejemplo n.º 40
0
def ceil(a, out=None):
    '''Smallest integer greater or equal to input'''
    return _maths.ceil(a, out)
Ejemplo n.º 41
0
def negative(a, out=None):
    '''Negate input'''
    return _maths.negative(a, out)
Ejemplo n.º 42
0
def trunc(a, out=None):
    '''Truncate elements of input to nearest integers'''
    return _maths.truncate(a, out)
Ejemplo n.º 43
0
def clip(a, a_min, a_max, out=None):
    '''Clip input to given bounds (replace NaNs with midpoint of bounds)'''
    return _maths.clip(a, a_min, a_max, out)
Ejemplo n.º 44
0
def deg2rad(a, out=None):
    '''Convert from degree to radian'''
    return _maths.toRadians(a, out)
Ejemplo n.º 45
0
def minimum(a, b, out=None):
    '''Item-wise minimum'''
    return _maths.minimum(a, b)
Ejemplo n.º 46
0
def negative(a, out=None):
    '''Negate input'''
    return _maths.negative(a, out)
Ejemplo n.º 47
0
def diff(a, order=1, axis=-1):
    '''Difference of input'''
    return _maths.difference(a, order, axis)
Ejemplo n.º 48
0
def minimum(a, b, out=None):
    '''Item-wise minimum'''
    return _maths.minimum(a, b)
Ejemplo n.º 49
0
def cbrt(a):
    '''Cube root of input'''
    return _maths.cbrt(a)
Ejemplo n.º 50
0
def dividez(a, b):
    '''Divide one array-like object by another with items that are zero divisors set to zero'''
    return _maths.dividez(a, b)
Ejemplo n.º 51
0
def tanh(a, out=None):
    '''Hyperbolic tangent of input'''
    return _maths.tanh(a, out)
Ejemplo n.º 52
0
def abs(a, out=None): #@ReservedAssignment
    '''Absolute value of input'''
    return _maths.abs(a, out)
Ejemplo n.º 53
0
def arctanh(a, out=None):
    '''Inverse hyperbolic tangent of input'''
    return _maths.arctanh(a, out)
Ejemplo n.º 54
0
def dividez(a, b):
    '''Divide one array-like object by another with items that are zero divisors set to zero'''
    return _maths.dividez(a, b)
Ejemplo n.º 55
0
def arccosh(a, out=None):
    '''Inverse hyperbolic cosine of input'''
    return _maths.arccosh(a, out)
Ejemplo n.º 56
0
def phase(a, keepzeros=False):
    '''Calculate phase of input by dividing by amplitude
    
    keepzeros -- if True, pass zeros through, else return complex NaNs
    '''
    return _maths.phaseAsComplexNumber(a, keepzeros)
Ejemplo n.º 57
0
def tanh(a, out=None):
    '''Hyperbolic tangent of input'''
    return _maths.tanh(a, out)
Ejemplo n.º 58
0
def cbrt(a):
    '''Cube root of input'''
    return _maths.cbrt(a)
Ejemplo n.º 59
0
def arccosh(a, out=None):
    '''Inverse hyperbolic cosine of input'''
    return _maths.arccosh(a, out)