예제 #1
0
파일: profile.py 프로젝트: ant6/beprof
def main():
    print('\nProfile')
    p = Profile([[0, 0], [1, 1], [2, 2], [3, 1]], some='exemplary', meta='data')
    print(p)
    print(type(p))
    print("X:", p.x)
    print("Y:", p.y)
    print('M: ', p.metadata)

    p2 = Profile([[1.5, 1], [2.5, 1], [3.5, 2], [4, 1]])
    print("X:", p2.x)
    print("Y:", p2.y)
    print('M: ', p2.metadata)

    b = curve.Curve([[0.5, 1], [1.5, 1], [2, 1], [2.5, 1]], negative='one')

    print('\na: \n')
    print('X: ', b.x)
    print('Y: ', b.y)
    print('M: ', b.metadata)

    diff = functions.subtract(p, b)
    print('type(diff): ', type(diff))
    print("X:", diff.x)
    print("Y:", diff.y)
    print('M: ', diff.metadata)
예제 #2
0
파일: curve.py 프로젝트: DataMedSci/beprof
def main():
    print('\nSubtract method :\n')

    c = Curve([[0.0, 0], [5, 5], [10, 0]])
    print('c: \n', c)
    d = Curve([[0.0, 1], [5, 1], [10, 1]])
    print('d: \n', d)

    c.subtract(d, new_obj=False)
    print('c-d: \n', c)
    print('*********')
    print('X:', c.x)
    print('Y:', c.y)

    print('Newobj creation #1\n\n')
    a = Curve([[0, 0], [1, 1], [2, 2], [3, 1]], positive='example')
    b = Curve([[0.5, 1], [1.5, 1], [2, 1], [2.5, 1]], negative='one')

    print('\na: \n')
    print('X: ', a.x)
    print('Y: ', a.y)
    print('M: ', a.metadata)

    print('\nb: \n')
    print('X: ', b.x)
    print('Y: ', b.y)
    print('M: ', b.metadata)

    diff = functions.subtract(a, b)
    print('\n diff: \n')
    print('X: ', diff.x)
    print('Y: ', diff.y)
    print('M: ', diff.metadata)
    # print(diff.evaluate_at_x([-1, 0, 1, 1.5, 2, 3, 4]))

    dif2 = b.subtract(a, True)
    print('\n dif2: \n')
    print('X: ', dif2.x)
    print('Y: ', dif2.y)
    print('M: ', dif2.metadata)

    print('\n b should be as before:\n')
    print('X: ', b.x)
    print('Y: ', b.y)
    print('M: ', b.metadata)

    print('\nNow calling b.subtract(a) what should change b'
          'so that is looks like dif2')
    b.subtract(a)
    print('\nb: \n')
    print('X: ', b.x)
    print('Y: ', b.y)
    print('M: ', b.metadata)
예제 #3
0
파일: profile.py 프로젝트: matkrak/beprof
def main():
    print('\nProfile')
    p = Profile([[0, 0], [1, 1], [2, 2], [3, 1]], some='exemplary', meta='data')
    print("X:", p.x)
    print("Y:", p.y)
    print("meta:", p.metadata)
    print(p)

    print('\nLateralProfile')
    lp = LateralProfile([[1, 0], [2, 1], [3, 0]], example='foo', anotherex='bar')
    print("X:", lp.x)
    print("Y:", lp.y)
    print("meta:", lp.metadata)
    print(lp)

    print('\nTEST:')
    test = lp.rebinned(0.5, 2)
    print('X:', test.x)
    print('Y:', test.y)
    print('M:', test.metadata)

    print(test)

    for x in (-1, 0, 0.5, 1, 1.5):
        print("x=", x, "y=", p.x_at_y(x), "rev", p.x_at_y(x, reverse=True))

    print("\nFuther testing:\n")
    t2 = test[2:4, :]
    print(t2)

    print("\n last example:\n")
    pp = test.view(Profile)
    print(pp)
    print('M: ', p.metadata)

    p2 = Profile([[1.5, 1], [2.5, 1], [3.5, 2], [4, 1]])
    print("X:", p2.x)
    print("Y:", p2.y)
    print('M: ', p2.metadata)

    b = curve.Curve([[0.5, 1], [1.5, 1], [2, 1], [2.5, 1]], negative='one')

    print('\na: \n')
    print('X: ', b.x)
    print('Y: ', b.y)
    print('M: ', b.metadata)

    diff = functions.subtract(p, b)
    print('type(diff): ', type(diff))
    print("X:", diff.x)
    print("Y:", diff.y)
    print('M: ', diff.metadata)
예제 #4
0
파일: curve.py 프로젝트: ant6/beprof
    def subtract(self, curve2, new_obj=False):
        """
        Method that calculates difference between 2 curves
        (or subclasses of curves). Domain of self must be in
        domain of curve2 what means min(self.x) >= min(curve2.x)
        and max(self.x) <= max(curve2.x).
        Might modify self, and can return the result or None

        Use subtract as -= operator, check whether returned value is None:
        >>> Curve([[0, 0], [1, 1], [2, 2], [3, 1]]).subtract(\
            Curve([[-1, 1], [5, 1]])) is None
        True

        Use subtract again but return a new object this time.
        >>> Curve([[0, 0], [1, 1], [2, 2], [3, 1]]).subtract(\
            Curve([[-1, 1], [5, 1]]), new_obj=True).y
        DataSet([-1.,  0.,  1.,  0.])

        Try using wrong inputs to create a new object,
        and check whether it throws an exception:
        >>> Curve([[0, 0], [1, 1], [2, 2], [3, 1]]).subtract(\
            Curve([[1, -1], [2, -1]]), new_obj=True) is None
        Traceback (most recent call last):
        ...
        Exception: curve2 does not include self domain


        :param curve2: second object to calculate difference
        :param new_obj: if True, method is creating new object
            instead of modifying self
        :return: None if new_obj is False (but will modify self)
            or type(self) object containing the result
        """
        # domain1 = [a1, b1]
        # domain2 = [a2, b2]
        a1, b1 = np.min(self.x), np.max(self.x)
        a2, b2 = np.min(curve2.x), np.max(curve2.x)

        # check whether domain condition is satisfied
        if a2 > a1 or b2 < b1:
            logger.error("Domain of self must be in domain of given curve")
            raise Exception("curve2 does not include self domain")
        # if we want to create and return a new object
        # rather then modify existing one
        if new_obj:
            return functions.subtract(self, curve2.change_domain(self.x))
        values = curve2.evaluate_at_x(self.x)
        self.y = self.y - values
        return None
예제 #5
0
파일: curve.py 프로젝트: matkrak/beprof
    def subtract(self, curve2, newobj=False):
        '''
        Method that calculates difference between 2 curves (or subclasses of curves). Domain of self must be in
        domain of curve2 what means min(self.x) >= min(curve2.x) and max(self.x) <= max(curve2.x)
        Might modify self, and can return the result or None

        Use subtract as -= operator, check whether returned value is None:
        >>> Curve([[0, 0], [1, 1], [2, 2], [3, 1]]).subtract(Curve([[-1, 1], [5, 1]]))
        None

        Use subtract again but return a new object this time. Check if it works OK.
        >>> Curve([[0, 0], [1, 1], [2, 2], [3, 1]]).subtract(Curve([[-1, 1], [5, 1]]), newobj=True).y
        [-1.  0.  1.  0.]

        Try using wrong inputs to create new object, and check whether it is None as expected:
        >>> Curve([[0, 0], [1, 1], [2, 2], [3, 1]]).subtract(Curve([[1, -1], [2, -1]]), newobj=True)
        None

        :param curve2: second object to calculate difference
        :param newobj: if True method is creating new object instead of modifying self
        :return: None if newobj is False (but will modify self)
                 Or type(self) object containing the result
        '''
        # domain1 = [a1, b1]
        # domain2 = [a2, b2]
        a1, b1 = np.min(self.x), np.max(self.x)
        a2, b2 = np.min(curve2.x), np.max(curve2.x)

        # check whether domains condition is satisfied
        if a2 > a1 or b2 < b1:
            # will be logging error here and an exeption, but
            # there is a separate issue. For now just print
            print('Error - curve2 domain does not include self domain')
            return None
        # if one want to create and return a new object rather then modify self
        if newobj:
            return functions.subtract(self, curve2.change_domain(self.x))
        values = curve2.evaluate_at_x(self.x)
        self.y = self.y - values
        return None
예제 #6
0
파일: curve.py 프로젝트: matkrak/beprof
def main():
    c = Curve([[0, 0], [5, 5], [10, 0]])
    print("X:", c.x)
    print("Y:", c.y)
    for x in (0.5, 1, 1.5, 2.0, 4.5):
        print("x=", x, "y=", c.y_at_x(x))

    print('\n', '*'*30, 'Metadata testing\n')

    k = Curve([[0, 1], [1, 2], [2, 3], [4, 0]], meta1='example 1', meta2='example 2')
    print('X:', k.x)
    print('Y:', k.y)
    print('M:', k.metadata)

    print('\n__str__:\n', k)
    print('Futher tests:\n')

    k2 = k.view(np.ndarray)
    print(k2)

    k3 = k[1:2,:]
    print(k3)

    print("X:", c.x)
    print("Y:", c.y)
    new = k.change_domain([1, 2, 3, 10])
    print("X:", new.x)
    print("Y:", new.y)
    print('M:', new.metadata)

    k2 = k.view(np.ndarray)
    print(k2)


    k3 = k[1:2,:]
    print(k3)

    print("X:", k.x)
    print("Y:", k.y)
    test = k.rebinned(0.7, -1)
    print("X:", test.x)
    print("Y:", test.y)
    print('M:', test.metadata)

    print('\nSubtract method :\n')

    c = Curve([[0.0, 0], [5, 5], [10, 0]])
    print('c: \n', c)
    d = Curve([[0.0, 1], [5, 1], [10, 1]])
    print('d: \n', d)

    c.subtract(d, newobj=False)
    print('c-d: \n', c)
    print('*********')
    print('X:', c.x)
    print('Y:', c.y)

    print('Newobj creation #1\n\n')
    a = Curve([[0, 0], [1, 1], [2, 2], [3, 1]], positive='example')
    b = Curve([[0.5, 1], [1.5, 1], [2, 1], [2.5, 1]], negative='one')

    print('\na: \n')
    print('X: ', a.x)
    print('Y: ', a.y)
    print('M: ', a.metadata)

    print('\nb: \n')
    print('X: ', b.x)
    print('Y: ', b.y)
    print('M: ', b.metadata)

    diff = functions.subtract(a, b)
    print('\n diff: \n')
    print('X: ', diff.x)
    print('Y: ', diff.y)
    print('M: ', diff.metadata)
    # print(diff.evaluate_at_x([-1, 0, 1, 1.5, 2, 3, 4]))

    dif2 = b.subtract(a, True)
    print('\n dif2: \n')
    print('X: ', dif2.x)
    print('Y: ', dif2.y)
    print('M: ', dif2.metadata)

    print('\n b should be as before:\n')
    print('X: ', b.x)
    print('Y: ', b.y)
    print('M: ', b.metadata)

    print('\nNow calling b.subtract(a) what should change b so that is looks like dif2')
    b.subtract(a)
    print('\nb: \n')
    print('X: ', b.x)
    print('Y: ', b.y)
    print('M: ', b.metadata)



    k2 = k.view(np.ndarray)
    print(k2)

    k3 = k[1:2,:]
    print(k3)