コード例 #1
0
ファイル: _spline.py プロジェクト: Spinmob/spinmob
def load_spline_array(path=None, text="Give me a spline array to load, jerkface! No, YOU'RE the jerkface."):
    a = _s.load_object(path, text)

    b = copy_spline_array(a)
    b._path = a._path
    _s.save_object(b, b._path)

    return b    
コード例 #2
0
ファイル: _spline.py プロジェクト: Spinmob/spinmob
def generate_spline_array(data, y_parameter="field", smoothing=5000, degree=5, presmoothing=0, coarsen=0, autosave=True, show_derivative=1, text="Give me some files to make a spline with.", simple=0):
    """

    Asks for a bunch of data files, plots and spline-fits the data (verifying at each step),
    and generates a spline_2d object instance filled with the results.

    """

    # create an instance of the spline_2d class
    s = spline_array()

    s.ylabel = y_parameter
    
    # have the user select a file
    paths = _s.DialogMultipleFiles('DIS AND DAT|*.dat', text=text, default_directory=data.directory)
    if paths == []: return

    # loop over each data file, fit it, plot it, ask if it's okay, and move on
    for n in range(0,len(paths)):
        print("spline "+str(n+1)+"/"+str(len(paths)+1))

        # fill up the xdata, ydata, and key            
        data.get_data(paths[n])

        print("y_parameter = "+str(data.constants[y_parameter]))

        # if this is just a simple interpolator, make a simple one
        if simple:
            x_spline = spline_single(data.xdata, data.ydata, plot=True, xlabel=data.xlabel, ylabel=data.ylabel, xmin="same", xmax="same", simple=1)

            a = input("ya: ")
            if a in ["quit", "q"]: return s
            if a in ["y", "yes", "\n"]: s.add_x_spline(data.constants[y_parameter], x_spline)

        # otherwise, we have to do the whole spline plot/fitting thingy
        else:
            data.plot(coarsen=coarsen)
            x_spline = splot("gca", smoothing, degree, presmoothing, interactive=True, show_derivative=show_derivative, simple=simple)
            
            if x_spline.message == "quit": return s
            if x_spline.message == "good": s.add_x_spline(data.constants[y_parameter], x_spline)

        s.xlabel = x_spline.xlabel
        s.zlabel = x_spline.ylabel

        # update the parameters as specified by the user
        presmoothing = x_spline.presmoothing
        smoothing    = x_spline.smoothing
        degree       = x_spline.degree

    print("Complete! "+str(len(paths))+" file and "+str(len(s.x_splines))+" successful splines.")

    s.simple = simple
    if autosave: _s.save_object(s)
    return s    
コード例 #3
0
def load_spline_array(
        path="ask",
        text="Give me a spline array to load, jerkface! No, YOU'RE the jerkface."
):
    a = _s.load_object(path, text)

    b = copy_spline_array(a)
    b._path = a._path
    _s.save_object(b, b._path)

    return b
コード例 #4
0
def generate_spline_array(data,
                          y_parameter="field",
                          smoothing=5000,
                          degree=5,
                          presmoothing=0,
                          coarsen=0,
                          autosave=True,
                          show_derivative=1,
                          text="Give me some files to make a spline with.",
                          simple=0):
    """

    Asks for a bunch of data files, plots and spline-fits the data (verifying at each step),
    and generates a spline_2d object instance filled with the results.

    """

    # create an instance of the spline_2d class
    s = spline_array()

    s.ylabel = y_parameter

    # have the user select a file
    paths = _s.DialogMultipleFiles('DIS AND DAT|*.dat',
                                   text=text,
                                   default_directory=data.directory)
    if paths == []: return

    # loop over each data file, fit it, plot it, ask if it's okay, and move on
    for n in range(0, len(paths)):
        print "spline " + str(n + 1) + "/" + str(len(paths) + 1)

        # fill up the xdata, ydata, and key
        data.get_data(paths[n])

        print "y_parameter = " + str(data.constants[y_parameter])

        # if this is just a simple interpolator, make a simple one
        if simple:
            x_spline = spline_single(data.xdata,
                                     data.ydata,
                                     plot=True,
                                     xlabel=data.xlabel,
                                     ylabel=data.ylabel,
                                     xmin="same",
                                     xmax="same",
                                     simple=1)

            a = raw_input("ya: ")
            if a in ["quit", "q"]: return s
            if a in ["y", "yes", "\n"]:
                s.add_x_spline(data.constants[y_parameter], x_spline)

        # otherwise, we have to do the whole spline plot/fitting thingy
        else:
            data.plot(coarsen=coarsen)
            x_spline = splot("gca",
                             smoothing,
                             degree,
                             presmoothing,
                             interactive=True,
                             show_derivative=show_derivative,
                             simple=simple)

            if x_spline.message == "quit": return s
            if x_spline.message == "good":
                s.add_x_spline(data.constants[y_parameter], x_spline)

        s.xlabel = x_spline.xlabel
        s.zlabel = x_spline.ylabel

        # update the parameters as specified by the user
        presmoothing = x_spline.presmoothing
        smoothing = x_spline.smoothing
        degree = x_spline.degree

    print "Complete! " + str(len(paths)) + " file and " + str(len(
        s.x_splines)) + " successful splines."

    s.simple = simple
    if autosave: _s.save_object(s)
    return s