示例#1
0
def splinteractive(xdata,
                   ydata,
                   smoothing=5000,
                   degree=5,
                   presmoothing=0,
                   spline_class=spline_single,
                   xlabel="x",
                   ylabel="y",
                   show_derivative=1,
                   boost_factor=1.1,
                   xmin="same",
                   xmax="same"):
    """

    Give this function x and y data to spline fit and it will fit it, returning an instance of
    spline_single.  It will also ask you if it's okay and you can play with parameters.

    """

    while True:
        # fit it
        x_spline = spline_class(xdata,
                                ydata,
                                smoothing,
                                degree,
                                presmoothing,
                                True,
                                xlabel,
                                ylabel,
                                show_derivative,
                                xmin=xmin,
                                xmax=xmax)

        # ask if it's okay
        if x_spline.message == "": command = raw_input("What now? ")
        else: command = x_spline.message

        try:
            float(command)
            command = "s=" + command
        except:
            print "parsing..."

        # deal with simple commands
        if command in ["y", "Y", "yes"]:
            x_spline.message = "good"
            smoothing = x_spline.smoothing
            return x_spline
        elif command in ["n", "N", "no"]:
            x_spline.message = "no"
            smoothing = x_spline.smoothing
            return x_spline
        elif command in ["q", "Q", "quit", "exit"]:
            x_spline.message = "quit"
            smoothing = x_spline.smoothing
            return x_spline
        elif command in ["l", "L", "line"]:
            x_spline.message = "line"
            smoothing = x_spline.smoothing
            x_spline.plot()
            raw_input("(press <enter> when done looking)")
        elif command in ["d", "D", "derivative", "\n"]:
            x_spline.message = "derivative"
            smoothing = x_spline.smoothing
            x_spline.plot(derivative=1)
            raw_input("(press <enter> when done looking)")
        elif command in ["dd", "DD"]:
            x_spline.message = "derivative 2"
            x_spline.plot(derivative=2)
            smoothing = x_spline.smoothing
            raw_input("(press <enter> when done looking)")
        elif command in ["p", "P", "print", "printer"]:
            x_spline.message = "print"
            smoothing = x_spline.smoothing
            _s.printer()
        elif command == "[":
            x_spline.message = "unboost smoothing"
            smoothing = smoothing / boost_factor
        elif command == "]":
            x_spline.message = "boost smoothing"
            smoothing = smoothing * boost_factor

        # deal with parameter changes
        elif command.split("=")[0].strip() in ["s", "smoothing"]:
            try:
                smoothing = eval(command.split("=")[1].strip())
            except:
                print "Surely you can give me a better number than THAT piece of shit."

        elif command.split("=")[0].strip() in ["d", "degree"]:
            try:
                degree = int(eval(command.split("=")[1].strip()))
            except:
                print "Nice try, ass.  Learn how to enter data."

        elif command.split("=")[0].strip() in ["p", "pre", "presmoothing"]:
            try:
                presmoothing = int(eval(command.split("=")[1].strip()))
            except:
                print "Nice work.  Yeah, not really."

        elif command.split("=")[0].strip() in ["b", "boost"]:
            try:
                boost_factor = float(eval(command.split("=")[1].strip()))
            except:
                print "Nice try smelly fart."

        # idiot at the controls
        else:
            print "You need help.\n"
            print "------- COMMAND EXAMPLES -------\n"
            print "y        Yes, it looks good, move on."
            print "n        No, and there's no hope.  Ignore and move on."
            print "q        Quit."
            print "s=1000   Set the smoothing to 10"
            print "d=3      Set the degree to 3"
            print "p=5      Set the presmoothing to 5"
            print "l        Show me the spline without data"
            print "d        Show me the derivative"
            print "]        Boost the smoothing"
            print "[        Reduce the smoothing"
            print "b=1.2    Set the boost factor to 1.2"

            smoothing = x_spline.smoothing
示例#2
0
def splinteractive(xdata, ydata, smoothing=5000, degree=5, presmoothing=0, spline_class=spline_single, xlabel="x", ylabel="y", show_derivative=1, boost_factor=1.1, xmin="same", xmax="same"):
    """

    Give this function x and y data to spline fit and it will fit it, returning an instance of
    spline_single.  It will also ask you if it's okay and you can play with parameters.

    """    

    while True:        
        # fit it
        x_spline = spline_class(xdata, ydata, smoothing, degree, presmoothing, True, xlabel, ylabel, show_derivative, xmin=xmin, xmax=xmax)
        
        # ask if it's okay
        if x_spline.message == "": command = input("What now? ")
        else:                      command = x_spline.message
        
        try:
            float(command)
            command = "s="+command
        except:
            print("parsing...")

        # deal with simple commands
        if   command in ["y", "Y", "yes"]:
            x_spline.message = "good"
            smoothing = x_spline.smoothing
            return x_spline
        elif command in ["n", "N", "no"]:
            x_spline.message = "no"
            smoothing = x_spline.smoothing
            return x_spline
        elif command in ["q", "Q", "quit", "exit"]:
            x_spline.message = "quit"
            smoothing = x_spline.smoothing
            return x_spline
        elif command in ["l", "L", "line"]:
            x_spline.message = "line"
            smoothing = x_spline.smoothing
            x_spline.plot()
            input("(press <enter> when done looking)")
        elif command in ["d", "D", "derivative", "\n"]:
            x_spline.message = "derivative"
            smoothing = x_spline.smoothing
            x_spline.plot(derivative=1)
            input("(press <enter> when done looking)")
        elif command in ["dd", "DD"]:
            x_spline.message = "derivative 2"
            x_spline.plot(derivative=2)
            smoothing = x_spline.smoothing
            input("(press <enter> when done looking)")
        elif command in ["p", "P", "print", "printer"]:
            x_spline.message = "print"
            smoothing = x_spline.smoothing
            _s.printer()
        elif command == "[":
            x_spline.message = "unboost smoothing"
            smoothing = smoothing / boost_factor
        elif command == "]":
            x_spline.message = "boost smoothing"
            smoothing = smoothing * boost_factor

        # deal with parameter changes
        elif command.split("=")[0].strip() in ["s", "smoothing"]:
            try: smoothing = eval(command.split("=")[1].strip())
            except: print("Surely you can give me a better number than THAT piece of shit.")

        elif command.split("=")[0].strip() in ["d", "degree"]:
            try: degree = int(eval(command.split("=")[1].strip()))
            except: print("Nice try, ass.  Learn how to enter data.")

        elif command.split("=")[0].strip() in ["p", "pre", "presmoothing"]:
            try: presmoothing = int(eval(command.split("=")[1].strip()))
            except: print("Nice work.  Yeah, not really.")

        elif command.split("=")[0].strip() in ["b", "boost"]:
            try: boost_factor = float(eval(command.split("=")[1].strip()))
            except: print("Nice try smelly fart.")

        # idiot at the controls
        else:
            print("You need help.\n")
            print("------- COMMAND EXAMPLES -------\n")
            print("y        Yes, it looks good, move on.")
            print("n        No, and there's no hope.  Ignore and move on.")
            print("q        Quit.")
            print("s=1000   Set the smoothing to 10")
            print("d=3      Set the degree to 3")
            print("p=5      Set the presmoothing to 5")
            print("l        Show me the spline without data")
            print("d        Show me the derivative")
            print("]        Boost the smoothing")
            print("[        Reduce the smoothing")
            print("b=1.2    Set the boost factor to 1.2")

            smoothing = x_spline.smoothing
示例#3
0
                    return return_value
                            
            elif clower in ['t', 'transfer']:

                if fit_parameters==None or fit_errors==None:
                    print "\nERROR: Nothing to transfer!"

                else:
                    for n in range(len(fit_parameters)):
                        self.p0[n] = fit_parameters[n]

            elif clower in ['n', 'no', 'next']:
                return {'command':'n','settings':settings}

            elif clower in ['p', 'print']:
                _s.printer()
                hold_plot = True

            elif clower in ['zo', 'zoomout']:                
                # if we haven't set the min and max yet, use the axes bounds.                
                if not settings['min']: 
                    settings['min'] = []                    
                    for a in axes1s: settings['min'].append(a.get_xlim()[0])
                    
                if not settings['max']:
                    settings['max'] = []
                    for a in axes1s: settings['max'].append(a.get_xlim()[1])
                                    
                x0 = _n.array(settings['min'])
                x1 = _n.array(settings['max'])
                xc = 0.5*(x0+x1)