Ejemplo n.º 1
0
    def clear_all_data(self):

        self.XYjob = XY_Job()  # XYjob may hold nonlinear fit object
        self.linear_fitL = []  # list of candidate linear fits
        self.selected_spline_objL = []  # list of candidate spline fits

        for pagename in ['Simple Fit', 'Exhaustive Fit']:
            self.pageD[pagename].selected_linfitL = []
            self.pageD[pagename].Equations_Listbox.delete(0, END)
            self.pageD[pagename].Pcentstddev_Listbox.delete(0, END)
            self.pageD[pagename].Stddev_Listbox.delete(0, END)

        self.pageD['Data'].clear_all_data()

        self.pageD['Code Gen'].Listbox_1.delete(0, END)
        self.pageD['Math'].Listbox_1.delete(0, END)
        self.pageD['Spline'].Listbox_1.selection_clear(0, 5)

        # remove any constant entry widgets and pack_forget Improve Button
        self.pageD['Non-Linear Fit'].ImproveFit_Button.pack_forget()
        self.pageD['Non-Linear Fit'].SetConst_Button.pack_forget()

        for e in self.pageD['Non-Linear Fit'].constEntryWidgetL:
            e.pack_forget()
            del (e)

        for pagename in [
                'Data', 'Simple Fit', 'Spline', 'Math', 'Exhaustive Fit',
                'Non-Linear Fit', 'Code Gen'
        ]:
            self.pageD[pagename].ShowHelp_Button_Click(None)
            self.pageD[pagename].pageFrame.update_idletasks()

        self.PlotWin.start_new_plot()
        #self.PlotWin.add_curve([1,2,3],[4,6,9], label='Sample Data', show_pts=1, show_line=1,
        #    linewidth=2, markersize=20)
        #self.PlotWin.final_touches( title_str='Sample Plot', show_grid=True, show_legend=True)
        self.PlotWin.show_it()
Ejemplo n.º 2
0
    def clear_all_data(self):

        self.XYjob = XY_Job() # XYjob may hold nonlinear fit object
        self.linear_fitL = [] # list of candidate linear fits
        self.selected_spline_objL = [] # list of candidate spline fits

        for pagename in ['Simple Fit','Exhaustive Fit']:
            self.pageD[pagename].selected_linfitL = []
            self.pageD[pagename].Equations_Listbox.delete(0, END)
            self.pageD[pagename].Pcentstddev_Listbox.delete(0, END)
            self.pageD[pagename].Stddev_Listbox.delete(0, END)


        self.pageD['Data'].clear_all_data()
            
        self.pageD['Code Gen'].Listbox_1.delete(0, END)
        self.pageD['Math'].Listbox_1.delete(0, END)
        self.pageD['Spline'].Listbox_1.selection_clear(0, 5)
        
        
        # remove any constant entry widgets and pack_forget Improve Button
        self.pageD['Non-Linear Fit'].ImproveFit_Button.pack_forget()
        self.pageD['Non-Linear Fit'].SetConst_Button.pack_forget()
        
        for e in self.pageD['Non-Linear Fit'].constEntryWidgetL:
            e.pack_forget()
            del(e)
        
        for pagename in ['Data','Simple Fit','Spline','Math','Exhaustive Fit','Non-Linear Fit','Code Gen']:
            self.pageD[pagename].ShowHelp_Button_Click(None)
            self.pageD[pagename].pageFrame.update_idletasks()
        
        
        self.PlotWin.start_new_plot()
        #self.PlotWin.add_curve([1,2,3],[4,6,9], label='Sample Data', show_pts=1, show_line=1, 
        #    linewidth=2, markersize=20)
        #self.PlotWin.final_touches( title_str='Sample Plot', show_grid=True, show_legend=True)
        self.PlotWin.show_it()
Ejemplo n.º 3
0
        A = 101124.977819
        c = 1.00041249485
        d = 2.23356723474e-05
        n = 5.31856523127
        x = altitude (m)
        y = Pressure (Pa)
        Correlation Coefficient = 0.999996135864
        Standard Deviation = 88.761441745
        Percent Standard Deviation = 0.094401748723%
        
"""
from numpy import array, double
from xymath.xy_job import XY_Job
from xymath.gui.xygui import main as run_gui

XY = XY_Job()

alt_mArr = array([
    -1524, -1372, -1219, -1067, -914, -762, -610, -457, -305, -152, 0, 152,
    305, 457, 610, 762, 914, 1067, 1219, 1372, 1524, 1829, 2134, 2438, 2743,
    3048, 4572, 6096, 7620, 9144, 10668, 12192, 13716, 15240
],
                 dtype=double)

PaArr = 1000.0 * array([
    121, 119, 117, 115, 113, 111, 109, 107, 105, 103, 101, 99.5, 97.7, 96,
    94.2, 92.5, 90.8, 89.1, 87.5, 85.9, 84.3, 81.2, 78.2, 75.3, 72.4, 69.7,
    57.2, 46.6, 37.6, 30.1, 23.8, 18.7, 14.5, 11.1
],
                       dtype=double)
Ejemplo n.º 4
0
4) Select "y = c0 + c1*x" to duplicate the author's results
5) Go to "Data" Tab
6) Select "weight" of data point with concentration=0.6
    - Set that weight to 0.0
7) Go back to "Simple Fit" Tab and hit "Curve Fit"
    - Notice that the zero-weighted point is marked as such on the plot
    - As the author predicts, the fit is greatly improved
    - Surprisingly, XYmath shows the 3 term equation "y = c0 + c1*x + c2/x"
      to be superior to the 4 term equations as well as the quadratic.


"""
from numpy import array
from xymath.dataset import DataSet
from xymath.linfit import LinCurveFit
from xymath.xy_job import XY_Job
from xymath.gui.xygui import main as run_gui

concL = [0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1]
readingL = [1.54,2.03,3.17,3.67,4.89,6.73,6.74,7.87,8.86,10.35]
DS = DataSet(concL, readingL, xName='Concentration', yName='Instrument Reading')

print('\n\n')
print('='*55)

XY = XY_Job()
XY.define_dataset(concL, readingL, wtArr=None, xName='Concentration', 
                  yName='Instrument Reading', xUnits='', yUnits='')
run_gui( XY )

Ejemplo n.º 5
0
"""
This example demonstrates the proper use of project: xymath
"""
import sys
import os

sys.path.insert(
    0, os.path.abspath("../../"))  # needed to find xymath development version

from xymath.xy_job import XY_Job

# TODO: create working example of project xymath

my_class = XY_Job()
Ejemplo n.º 6
0
    def __init__(self, master, XYjob_inp=None):
        self.initComplete = 0
        #frame = Frame(master, width=753, height=536)
        #frame.pack()
        self.master = master
        self.allow_subWindows_to_close = 0
        self.x, self.y, self.w, self.h = -1, -1, -1, -1

        # bind master to <Configure> in order to handle any resizing, etc.
        # postpone self.master.bind("<Configure>", self.Master_Configure)
        self.master.bind('<Enter>', self.bindConfigure)

        self.master.title("XYmath")

        # make a Status Bar
        self.statusMessage = StringVar()
        self.statusMessage.set("")
        self.statusbar = Label(self.master,
                               textvariable=self.statusMessage,
                               bd=1,
                               relief=SUNKEN)
        self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)

        self.statusMessage.set("Welcome to XYmath")
        self.menuBar = Menu(master, relief="raised", bd=2)

        top_File = Menu(self.menuBar, tearoff=0)

        top_File.add("command", label="New", command=self.menu_File_New)
        top_File.add("command", label="Open", command=self.menu_File_Open)
        top_File.add("command", label="Import", command=self.menu_File_Import)
        top_File.add("command", label="Save", command=self.menu_File_Save)
        top_File.add("command", label="Exit", command=self.menu_Program_Exit)

        self.menuBar.add("cascade", label="File", menu=top_File)
        self.menuBar.add("command", label="About", command=self.menu_About)

        self.tab_frames = TabFrames(
            self.master,
            height=460,
            width=650,
            tabPixelWidthL=[60, 90, 60, 60, 110, 110, 60, 90],
            labelL=[
                'Data', 'Simple Fit', 'Spline', 'Math', 'Exhaustive Fit',
                'Non-Linear Fit', 'Plot', 'Code Gen'
            ])
        self.tab_frames.pack(anchor=NW, fill=BOTH, side=TOP, expand=True)

        # Main window is finished, start building tab_frames pages
        self.pageD = {}  # dictionary of tab_frames pages

        def setup_page(npage, PageObj):
            self.pageD[npage] = PageObj(self, self.tab_frames(npage))
            self.pageD[str(self.tab_frames.labelL[npage])] = self.pageD[npage]
            self.tab_frames.setLeaveCallback(
                npage, self.pageD[npage].leavePageCallback)
            self.tab_frames.setSelectCallback(
                npage, self.pageD[npage].selectPageCallback)

        # setup pages
        setup_page(0, PageData)  # setup page 0, Data page
        setup_page(1, SimplePage)  # setup page 1, Simple Curve Fit
        setup_page(2, SplinePage)  # setup page 2, Spline Curve Fit
        setup_page(3, MathPage)  # setup page 3, Math Page
        setup_page(4, ExhaustPage)  # setup page 4, Exhaustive Fit
        setup_page(5, NonLinFitPage)  # setup page 5, Non-Linear Fit
        setup_page(6, PagePlot)  # setup page 6, PagePlot
        setup_page(7, CodeGenPage)  # setup page 7, Code Generation Page

        master.config(menu=self.menuBar)

        if XYjob_inp is None:
            self.XYjob = XY_Job()  # XYjob may hold nonlinear fit object
        else:
            self.XYjob = XYjob_inp

        self.linear_fitL = []  # list of candidate linear fits
        self.selected_spline_objL = []  # list of candidate spline fits

        if self.XYjob.nonlin_fit:
            self.pageD['Non-Linear Fit'].EqnStr_Text.delete(1.0, END)
            self.pageD['Non-Linear Fit'].EqnStr_Text.insert(
                END, self.XYjob.nonlin_fit.rhs_eqnStr)

        # check for input file on command line
        if (XYjob_inp is None) and (len(sys.argv) == 2):
            fName = sys.argv[1]
            if not fName.endswith('.x_y'):
                fName += '.x_y'
            self.pathopen = os.path.abspath(fName)
            if os.path.isfile(
                    self.pathopen
            ):  # if file exists, read it as a definition file
                fInp = open(os.path.abspath(fName), 'rb')
                self.read_xyjob_from_file(fInp)
            else:
                # For erroneous file names, change status bar
                self.statusMessage.set("file:%s NOT FOUND" % fName)

        # Enter Data page to begin with
        #self.tab_frames.selectTab( self.tab_frames.buttonL[0] )
        master.protocol('WM_DELETE_WINDOW', self.cleanupOnQuit)

        milliseconds = 100
        self.master.after(milliseconds, self.littleInits)

        print(LICENSE)
Ejemplo n.º 7
0
class _Xygui(object):
    def cleanupOnQuit(self):
        if (not self.has_some_data()) or \
            self.AskYesNo( title='Data Saved Before Quitting?', \
            message='Do you want to exit XYmath?\n(Hit "Yes" ONLY IF your data is saved.)'):

            print('Doing final cleanup before quitting')

            self.allow_subWindows_to_close = 1
            try:
                self.PlotWin.cleanupOnQuit()
            except:
                pass

            try:
                self.master.destroy()  # called in PlotWin
            except:
                pass
            sys.exit(1)

    #def see_me(self):
    #    '''Hoping to force focus back to main window.'''
    #    print 'Hope to see you back at main.'
    #    self.master.geometry( '%dx%d+%i+%i'%(self.master.winfo_width(),self.master.winfo_height(),
    #        self.master.winfo_x(),self.master.winfo_y()))

    def __init__(self, master, XYjob_inp=None):
        self.initComplete = 0
        #frame = Frame(master, width=753, height=536)
        #frame.pack()
        self.master = master
        self.allow_subWindows_to_close = 0
        self.x, self.y, self.w, self.h = -1, -1, -1, -1

        # bind master to <Configure> in order to handle any resizing, etc.
        # postpone self.master.bind("<Configure>", self.Master_Configure)
        self.master.bind('<Enter>', self.bindConfigure)

        self.master.title("XYmath")

        # make a Status Bar
        self.statusMessage = StringVar()
        self.statusMessage.set("")
        self.statusbar = Label(self.master,
                               textvariable=self.statusMessage,
                               bd=1,
                               relief=SUNKEN)
        self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)

        self.statusMessage.set("Welcome to XYmath")
        self.menuBar = Menu(master, relief="raised", bd=2)

        top_File = Menu(self.menuBar, tearoff=0)

        top_File.add("command", label="New", command=self.menu_File_New)
        top_File.add("command", label="Open", command=self.menu_File_Open)
        top_File.add("command", label="Import", command=self.menu_File_Import)
        top_File.add("command", label="Save", command=self.menu_File_Save)
        top_File.add("command", label="Exit", command=self.menu_Program_Exit)

        self.menuBar.add("cascade", label="File", menu=top_File)
        self.menuBar.add("command", label="About", command=self.menu_About)

        self.tab_frames = TabFrames(
            self.master,
            height=460,
            width=650,
            tabPixelWidthL=[60, 90, 60, 60, 110, 110, 60, 90],
            labelL=[
                'Data', 'Simple Fit', 'Spline', 'Math', 'Exhaustive Fit',
                'Non-Linear Fit', 'Plot', 'Code Gen'
            ])
        self.tab_frames.pack(anchor=NW, fill=BOTH, side=TOP, expand=True)

        # Main window is finished, start building tab_frames pages
        self.pageD = {}  # dictionary of tab_frames pages

        def setup_page(npage, PageObj):
            self.pageD[npage] = PageObj(self, self.tab_frames(npage))
            self.pageD[str(self.tab_frames.labelL[npage])] = self.pageD[npage]
            self.tab_frames.setLeaveCallback(
                npage, self.pageD[npage].leavePageCallback)
            self.tab_frames.setSelectCallback(
                npage, self.pageD[npage].selectPageCallback)

        # setup pages
        setup_page(0, PageData)  # setup page 0, Data page
        setup_page(1, SimplePage)  # setup page 1, Simple Curve Fit
        setup_page(2, SplinePage)  # setup page 2, Spline Curve Fit
        setup_page(3, MathPage)  # setup page 3, Math Page
        setup_page(4, ExhaustPage)  # setup page 4, Exhaustive Fit
        setup_page(5, NonLinFitPage)  # setup page 5, Non-Linear Fit
        setup_page(6, PagePlot)  # setup page 6, PagePlot
        setup_page(7, CodeGenPage)  # setup page 7, Code Generation Page

        master.config(menu=self.menuBar)

        if XYjob_inp is None:
            self.XYjob = XY_Job()  # XYjob may hold nonlinear fit object
        else:
            self.XYjob = XYjob_inp

        self.linear_fitL = []  # list of candidate linear fits
        self.selected_spline_objL = []  # list of candidate spline fits

        if self.XYjob.nonlin_fit:
            self.pageD['Non-Linear Fit'].EqnStr_Text.delete(1.0, END)
            self.pageD['Non-Linear Fit'].EqnStr_Text.insert(
                END, self.XYjob.nonlin_fit.rhs_eqnStr)

        # check for input file on command line
        if (XYjob_inp is None) and (len(sys.argv) == 2):
            fName = sys.argv[1]
            if not fName.endswith('.x_y'):
                fName += '.x_y'
            self.pathopen = os.path.abspath(fName)
            if os.path.isfile(
                    self.pathopen
            ):  # if file exists, read it as a definition file
                fInp = open(os.path.abspath(fName), 'rb')
                self.read_xyjob_from_file(fInp)
            else:
                # For erroneous file names, change status bar
                self.statusMessage.set("file:%s NOT FOUND" % fName)

        # Enter Data page to begin with
        #self.tab_frames.selectTab( self.tab_frames.buttonL[0] )
        master.protocol('WM_DELETE_WINDOW', self.cleanupOnQuit)

        milliseconds = 100
        self.master.after(milliseconds, self.littleInits)

        print(LICENSE)

    def littleInits(self):
        self.PlotWin = PlotWindow(self.master, self)

        self.tab_frames.selectTab(self.tab_frames.buttonL[0])
        self.pageD[0].eg.focus_on(0, 0)

        # If transient, will minimize with main window AND be drawn on top
        #self.PlotWin.transient(self.master)

    def menu_Program_Exit(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_Program_Exit"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_Program_Exit")
        print("called menu_Program_Exit")

        self.cleanupOnQuit()

    def has_some_data(self):
        '''Return True if there is some data or curve fit being held in memory.'''
        print('Entering MathPage')
        XY = self.XYjob
        got_data = False

        if XY.nonlin_fit:
            print('Has a Non-Linear Fit')
            got_data = True

        for pagename in ['Simple Fit', 'Exhaustive Fit']:
            selected_linfitL = self.pageD[pagename].selected_linfitL
            for n, i in enumerate(selected_linfitL):
                print('Has a %s' % pagename)
                got_data = True

        for spline in self.selected_spline_objL:
            print('Has a Spline Fit')
            got_data = True

        DataPage = self.pageD['Data']
        if DataPage.Xname_Entry_StringVar.get() != 'x':
            print('Has x Name')
            got_data = True
        if DataPage.Xunits_Entry_StringVar.get() != '':
            print('Has x Units')
            got_data = True
        if DataPage.Yname_Entry_StringVar.get() != 'y':
            print('Has y Name')
            got_data = True
        if DataPage.Yunits_Entry_StringVar.get() != '':
            print('Has Y Units')
            got_data = True

        if DataPage.eg.num_active_wtfactors:
            print('Has Weight Factors')
            got_data = True

        for i in range(DataPage.eg.Nrows):
            if DataPage.eg.entryL[i][0].is_float(
            ) or DataPage.eg.entryL[i][1].is_float():
                print('Has Data in Entry Box')
                got_data = True

        if (not self.XYjob.dataset is None) or (
                not self.XYjob.linfit is None) or (
                    not self.XYjob.nonlin_fit is None):
            print('Has Initialized XYjob')
            got_data = True

        return got_data

    def clear_all_data(self):

        self.XYjob = XY_Job()  # XYjob may hold nonlinear fit object
        self.linear_fitL = []  # list of candidate linear fits
        self.selected_spline_objL = []  # list of candidate spline fits

        for pagename in ['Simple Fit', 'Exhaustive Fit']:
            self.pageD[pagename].selected_linfitL = []
            self.pageD[pagename].Equations_Listbox.delete(0, END)
            self.pageD[pagename].Pcentstddev_Listbox.delete(0, END)
            self.pageD[pagename].Stddev_Listbox.delete(0, END)

        self.pageD['Data'].clear_all_data()

        self.pageD['Code Gen'].Listbox_1.delete(0, END)
        self.pageD['Math'].Listbox_1.delete(0, END)
        self.pageD['Spline'].Listbox_1.selection_clear(0, 5)

        # remove any constant entry widgets and pack_forget Improve Button
        self.pageD['Non-Linear Fit'].ImproveFit_Button.pack_forget()
        self.pageD['Non-Linear Fit'].SetConst_Button.pack_forget()

        for e in self.pageD['Non-Linear Fit'].constEntryWidgetL:
            e.pack_forget()
            del (e)

        for pagename in [
                'Data', 'Simple Fit', 'Spline', 'Math', 'Exhaustive Fit',
                'Non-Linear Fit', 'Code Gen'
        ]:
            self.pageD[pagename].ShowHelp_Button_Click(None)
            self.pageD[pagename].pageFrame.update_idletasks()

        self.PlotWin.start_new_plot()
        #self.PlotWin.add_curve([1,2,3],[4,6,9], label='Sample Data', show_pts=1, show_line=1,
        #    linewidth=2, markersize=20)
        #self.PlotWin.final_touches( title_str='Sample Plot', show_grid=True, show_legend=True)
        self.PlotWin.show_it()

    def menu_File_New(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_File_New"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_File_New")
        print("called menu_File_New")
        if self.has_some_data():
            print('Has Some Data to be Cleared')
            if self.AskYesNo(
                    title='Clear All Data',
                    message='Do you want to clear all data from memory?'):
                self.clear_all_data()

    def menu_File_Open(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_File_Open"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_File_Open")
        print("called menu_File_Open")

        fInp = self.AskOpenFile(title='Open XYmath File',
                                mode='rb',
                                initialdir='.')
        if fInp:
            self.clear_all_data()
            self.read_xyjob_from_file(fInp)

    def read_xyjob_from_file(self, fInp):
        print('Opened file', os.path.basename(fInp.name))
        # fInp will be closed by read_job_from_file
        self.XYjob.read_job_from_file(fileObj=fInp)
        #self.pageD['Data'].place_xyjob_data()
        prefix = os.path.basename(self.XYjob.file_prefix)
        self.master.title("XYmath - %s" % prefix)
        name = os.path.basename(self.XYjob.file_name)
        self.statusMessage.set("Read file:%s" % name)

        if hasattr(self, 'PlotWin'):
            self.pageD['Data'].place_xyjob_data()

    def menu_File_Save(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_File_Save"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_File_Save")
        print("called menu_File_Save")

        if self.XYjob.file_prefix:
            initialfile = self.XYjob.file_prefix + '.x_y'
        else:
            initialfile = '*.x_y'

        fsave = self.AskSaveasFilename(title='Save XYmath File',
                                       initialfile=initialfile)

        if fsave:
            if not fsave.lower().endswith('.x_y'):
                fsave += '.x_y'

            self.pageD['Data'].put_entry_values_on_plot()

            self.XYjob.write_job_to_file(fname=fsave)
            print('Saving XYmath to:', fsave)
            prefix = os.path.basename(self.XYjob.file_prefix)
            self.master.title("XYmath - %s" % prefix)
            name = os.path.basename(self.XYjob.file_name)
            self.statusMessage.set("Read file:%s" % name)

    def bindConfigure(self, event):
        if not self.initComplete:
            self.master.bind("<Configure>", self.Master_Configure)
            self.initComplete = 1

    def Master_Configure(self, event):
        if event.widget != self.master:
            if self.w != -1:
                return
        x = int(self.master.winfo_x())
        y = int(self.master.winfo_y())
        w = int(self.master.winfo_width())
        h = int(self.master.winfo_height())
        if (self.x, self.y, self.w, self.h) == (-1, -1, -1, -1):
            self.x, self.y, self.w, self.h = x, y, w, h

        if self.w != w or self.h != h:
            print("Master reconfigured... make resize adjustments")
            self.w = w
            self.h = h

        #print '  -----------------   w,h=',w,h
        #self.tab_frames.lframe.configure(width=w, height=h)
        #self.tab_frames.frame.configure(width=w, height=h)
        #print 'winfo_reqwidth()=',self.tab_frames.winfo_reqwidth()
        #print 'winfo_reqheight()=',self.tab_frames.winfo_reqheight()
        #self.master.update_idletasks()

    # standard message dialogs... showinfo, showwarning, showerror
    def ShowInfo(self, title='Title', message='your message here.'):
        tkMessageBox.showinfo(title, message)
        return

    def ShowWarning(self, title='Title', message='your message here.'):
        tkMessageBox.showwarning(title, message)
        return

    def ShowError(self, title='Title', message='your message here.'):
        tkMessageBox.showerror(title, message)
        return

    # standard question dialogs... askquestion, askokcancel, askyesno, or askretrycancel
    # return True for OK, Yes, Retry, False for Cancel or No
    def AskYesNo(self, title='Title', message='your question here.'):
        return tkMessageBox.askyesno(title, message)

    def AskOK_Cancel(self, title='Title', message='your question here.'):
        return tkMessageBox.askokcancel(title, message)

    def AskRetryCancel(self, title='Title', message='your question here.'):
        return tkMessageBox.askretrycancel(title, message)

    # return "yes" for Yes, "no" for No
    def AskQuestion(self, title='Title', message='your question here.'):
        return tkMessageBox.askquestion(title, message)

    # standard file dialogs... askdirectory, askopenfile, asksaveasfilename

    # return a string containing directory name
    def AskDirectory(self, title='Choose Directory', initialdir="."):
        dirname = tkFileDialog.askdirectory(parent=self.master,
                                            initialdir=initialdir,
                                            title=title)
        return dirname  # <-- string

    # return an OPEN file type object OR None (opened using mode, 'r','rb','w','wb')
    # WARNING... opening file with mode 'w' or 'wb' will erase contents
    def AskOpenFile(self,
                    title='Open XYmath File',
                    mode='rb',
                    initialdir='.',
                    filetypes=None):
        if filetypes is None:
            filetypes = [('XYmath File', '*.x_y'), ('Any File', '*.*')]
        fileobj = tkFileDialog.askopenfile(parent=self.master,
                                           mode=mode,
                                           title=title,
                                           initialdir=initialdir,
                                           filetypes=filetypes)

        # if opened, then fileobj.name contains the name string
        return fileobj  # <-- an opened file, or the value None

    # return a string containing file name (the calling routine will need to open the file)
    def AskSaveasFilename(self,
                          title='Save File',
                          filetypes=None,
                          initialfile=''):
        if filetypes is None:
            filetypes = [('XYmath File', '*.x_y'), ('Any File', '*.*')]

        fileName = tkFileDialog.asksaveasfilename(parent=self.master,
                                                  filetypes=filetypes,
                                                  initialfile=initialfile,
                                                  title=title)
        return fileName  # <-- string

    # alarm function is called after specified number of milliseconds
    def SetAlarm(self, milliseconds=1000):
        self.master.after(milliseconds, self.Alarm)

    def Alarm(self):
        pass

        # >>>>>>insert any user code below this comment for section "standard_alarm"
        print("Alarm called")

    def menu_File_Import(self):
        dialog = _Importxy(self.master, "Import X,Y Data")
        if dialog.result:
            wtArr = None
            print('place_entries_into_dataset with wtArr = None')
            xL = dialog.result["xL"]
            yL = dialog.result["yL"]

            XY = self.XYjob
            XY.define_dataset(array(xL, dtype=double),
                              array(yL, dtype=double),
                              wtArr=wtArr,
                              xName=dialog.result["xName"],
                              yName=dialog.result["yName"],
                              xUnits='',
                              yUnits='',
                              timeStamp=time.time())

            XY.dataset.sort_by_x()

            self.pageD['Data'].place_xyjob_data()

    def menu_About(self):
        dialog = _About(self.master, "About XYmath")
Ejemplo n.º 8
0
 def setUp(self):
     unittest.TestCase.setUp(self)
     self.myclass = XY_Job()
Ejemplo n.º 9
0
cd_050 =  1/(1.0410141095741985 - 0.018737945262767248*gamma)
# Rup=0.75,  std=1.28366e-05
cd_075 =  1/(1.0211820293860214 - 0.006064881097850447*gamma)
# Rup=1,  std=1.01453e-05
cd_100 =  1/(1.0125848593169495 - 0.002058029259787154*gamma)
# Rup=1.5,  std=4.85485e-06
cd_150 =  1/(1.0059285328940355 - 0.00011367842090816805/gamma)
# Rup=2,  std=1.52664e-07
cd_200 =  0.9957021782441166 + 0.0006720167698767546/gamma

"""

gammaL = [1.1, 1.15, 1.2, 1.25, 1.3, 1.35, 1.4]

cdD = {} # index=RWTU, value=CD
cdD[0.5] = [0.9800142, 0.9809054, 0.981803, 0.9827062, 0.9836141, 0.9845261, 0.9854414]
cdD[0.75] = [0.9857159, 0.9859911, 0.9862749, 0.9865668, 0.9868662, 0.9871727, 0.9874859]
cdD[1] = [0.9897993, 0.989885, 0.989977, 0.9900752, 0.9901793, 0.990289, 0.990404]
cdD[1.5] = [0.9942151, 0.9942037, 0.9941956, 0.9941907, 0.9941889, 0.99419, 0.9941941]
cdD[2] = [0.9963129, 0.9962867, 0.9962624, 0.9962398, 0.996219, 0.9961998, 0.9961823]

RupL = sorted( list( cdD.keys() ) )

for Rup in RupL:
    job = XY_Job()
    yL = cdD[Rup]
    job.define_dataset( gammaL, yL, xName='gamma', yName='Cd')
    ordered_resultL = job.fit_dataset_to_common_eqns( run_both=1, sort_by_pcent=1, max_terms=2)
    print('# Rup=%g,  std=%g'%(Rup, job.linfit.std))
    print( 'cd_%s = '%(str(int(100*Rup)).zfill(3),), job.linfit.get_eqn_str_w_numbs() )
Ejemplo n.º 10
0
He makes an initial guess of p1=1 and p2=0.2 and gets an answer of:
p1 = 1.88184732
p2 = 0.70022901

With no initial guess, XYmath gets:
p1 = 1.88185084847
p2 = 0.70022981688

1) Launch XYmath with code below
2) Go to "Non-Linear Fit" Tab 
   - should see "p1*cos(p2*x) + p2*sin(p1*x)" in eqn box
3) Hit "Curve Fit"
4) See what happens when you hit "Improve Fit" a few times
5) Change to "Percent Error" and notice changes

"""

from xymath.xy_job import XY_Job
from xymath.gui.xygui import main as run_gui

XY = XY_Job()

xdata = [-2, -1.64, -1.33, -0.7, 0, 0.45, 1.2, 1.64, 2.32, 2.9]
ydata = [0.699369, 0.700462, 0.695354, 1.03905, 1.97389, 2.41143, 1.91091, 0.919576, -0.730975, -1.42001]

XY.define_dataset(xdata, ydata, wtArr=None, xName="x", yName="y", xUnits="", yUnits="")

XY.fit_dataset_to_nonlinear_eqn(run_best_pcent=0, rhs_eqnStr="p1*cos(p2*x) + p2*sin(p1*x)")

run_gui(XY)
Ejemplo n.º 11
0
p1 = 1.88185084847
p2 = 0.70022981688

1) Launch XYmath with code below
2) Go to "Non-Linear Fit" Tab 
   - should see "p1*cos(p2*x) + p2*sin(p1*x)" in eqn box
3) Hit "Curve Fit"
4) See what happens when you hit "Improve Fit" a few times
5) Change to "Percent Error" and notice changes

"""

from xymath.xy_job import XY_Job
from xymath.gui.xygui import main as run_gui

XY = XY_Job()

xdata = [-2, -1.64, -1.33, -0.7, 0, 0.45, 1.2, 1.64, 2.32, 2.9]
ydata = [
    0.699369, 0.700462, 0.695354, 1.03905, 1.97389, 2.41143, 1.91091, 0.919576,
    -0.730975, -1.42001
]

XY.define_dataset(xdata,
                  ydata,
                  wtArr=None,
                  xName='x',
                  yName='y',
                  xUnits='',
                  yUnits='')
Ejemplo n.º 12
0
    def __init__(self, master, XYjob_inp=None):
        self.initComplete = 0
        #frame = Frame(master, width=753, height=536)
        #frame.pack()
        self.master = master
        self.allow_subWindows_to_close = 0
        self.x, self.y, self.w, self.h = -1,-1,-1,-1
        
        # bind master to <Configure> in order to handle any resizing, etc.
        # postpone self.master.bind("<Configure>", self.Master_Configure)
        self.master.bind('<Enter>', self.bindConfigure)
        

        self.master.title("XYmath")
        
        # make a Status Bar
        self.statusMessage = StringVar()
        self.statusMessage.set("")
        self.statusbar = Label(self.master, textvariable=self.statusMessage, bd=1, relief=SUNKEN)
        self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)


        self.statusMessage.set("Welcome to XYmath")
        self.menuBar = Menu(master, relief = "raised", bd=2)

        top_File = Menu(self.menuBar, tearoff=0)

        top_File.add("command", label = "New", command = self.menu_File_New)
        top_File.add("command", label = "Open", command = self.menu_File_Open)
        top_File.add("command", label = "Import", command = self.menu_File_Import)
        top_File.add("command", label = "Save", command = self.menu_File_Save)
        top_File.add("command", label = "Exit", command = self.menu_Program_Exit)
        
        self.menuBar.add("cascade", label="File", menu=top_File)
        self.menuBar.add("command", label = "About", command = self.menu_About)



        self.tab_frames = TabFrames(self.master, height=460, width=650,
            tabPixelWidthL=[60,90,       60,      60,       110,           110,        60,    90], 
            labelL=['Data','Simple Fit','Spline','Math','Exhaustive Fit','Non-Linear Fit','Plot','Code Gen'])
        self.tab_frames.pack(anchor=NW, fill=BOTH, side=TOP, expand=True)
        
        # Main window is finished, start building tab_frames pages
        self.pageD = {} # dictionary of tab_frames pages
        
        def setup_page( npage, PageObj ):
            self.pageD[npage] = PageObj(self, self.tab_frames(npage))
            self.pageD[ str(self.tab_frames.labelL[npage]) ] = self.pageD[npage]
            self.tab_frames.setLeaveCallback(npage, self.pageD[npage].leavePageCallback)
            self.tab_frames.setSelectCallback(npage, self.pageD[npage].selectPageCallback)
        
        # setup pages
        setup_page(0, PageData)    # setup page 0, Data page
        setup_page(1, SimplePage)  # setup page 1, Simple Curve Fit
        setup_page(2, SplinePage)  # setup page 2, Spline Curve Fit
        setup_page(3, MathPage)    # setup page 3, Math Page
        setup_page(4, ExhaustPage) # setup page 4, Exhaustive Fit 
        setup_page(5, NonLinFitPage) # setup page 5, Non-Linear Fit 
        setup_page(6, PagePlot ) # setup page 6, PagePlot
        setup_page(7, CodeGenPage) # setup page 7, Code Generation Page

        master.config(menu=self.menuBar)
        
        if XYjob_inp is None:
            self.XYjob = XY_Job() # XYjob may hold nonlinear fit object
        else:
            self.XYjob = XYjob_inp
            
        self.linear_fitL = [] # list of candidate linear fits
        self.selected_spline_objL = [] # list of candidate spline fits
        
        if self.XYjob.nonlin_fit:
            self.pageD['Non-Linear Fit'].EqnStr_Text.delete(1.0, END)
            self.pageD['Non-Linear Fit'].EqnStr_Text.insert(END, self.XYjob.nonlin_fit.rhs_eqnStr)

        # check for input file on command line
        if (XYjob_inp is None) and (len( sys.argv ) == 2):
            fName = sys.argv[1]
            if not fName.endswith('.x_y'):
                fName += '.x_y'
            self.pathopen = os.path.abspath(fName)
            if os.path.isfile( self.pathopen ): # if file exists, read it as a definition file
                fInp = open( os.path.abspath(fName), 'rb' )
                self.read_xyjob_from_file(fInp)
            else:
                # For erroneous file names, change status bar
                self.statusMessage.set("file:%s NOT FOUND"%fName)

        # Enter Data page to begin with
        #self.tab_frames.selectTab( self.tab_frames.buttonL[0] )
        master.protocol('WM_DELETE_WINDOW', self.cleanupOnQuit)
        
        milliseconds=100
        self.master.after( milliseconds, self.littleInits )
        
        print(LICENSE)
Ejemplo n.º 13
0
class _Xygui(object):
    
        
    def cleanupOnQuit(self):
        if (not self.has_some_data()) or \
            self.AskYesNo( title='Data Saved Before Quitting?', \
            message='Do you want to exit XYmath?\n(Hit "Yes" ONLY IF your data is saved.)'):
            
            print('Doing final cleanup before quitting')
            
            
            self.allow_subWindows_to_close = 1
            try:
                self.PlotWin.cleanupOnQuit()
            except:
                pass
                
            try:
                self.master.destroy()  # called in PlotWin
            except:
                pass
            sys.exit(1)
    
    #def see_me(self):
    #    '''Hoping to force focus back to main window.'''
    #    print 'Hope to see you back at main.'
    #    self.master.geometry( '%dx%d+%i+%i'%(self.master.winfo_width(),self.master.winfo_height(),
    #        self.master.winfo_x(),self.master.winfo_y()))
        
    def __init__(self, master, XYjob_inp=None):
        self.initComplete = 0
        #frame = Frame(master, width=753, height=536)
        #frame.pack()
        self.master = master
        self.allow_subWindows_to_close = 0
        self.x, self.y, self.w, self.h = -1,-1,-1,-1
        
        # bind master to <Configure> in order to handle any resizing, etc.
        # postpone self.master.bind("<Configure>", self.Master_Configure)
        self.master.bind('<Enter>', self.bindConfigure)
        

        self.master.title("XYmath")
        
        # make a Status Bar
        self.statusMessage = StringVar()
        self.statusMessage.set("")
        self.statusbar = Label(self.master, textvariable=self.statusMessage, bd=1, relief=SUNKEN)
        self.statusbar.pack(anchor=SW, fill=X, side=BOTTOM)


        self.statusMessage.set("Welcome to XYmath")
        self.menuBar = Menu(master, relief = "raised", bd=2)

        top_File = Menu(self.menuBar, tearoff=0)

        top_File.add("command", label = "New", command = self.menu_File_New)
        top_File.add("command", label = "Open", command = self.menu_File_Open)
        top_File.add("command", label = "Import", command = self.menu_File_Import)
        top_File.add("command", label = "Save", command = self.menu_File_Save)
        top_File.add("command", label = "Exit", command = self.menu_Program_Exit)
        
        self.menuBar.add("cascade", label="File", menu=top_File)
        self.menuBar.add("command", label = "About", command = self.menu_About)



        self.tab_frames = TabFrames(self.master, height=460, width=650,
            tabPixelWidthL=[60,90,       60,      60,       110,           110,        60,    90], 
            labelL=['Data','Simple Fit','Spline','Math','Exhaustive Fit','Non-Linear Fit','Plot','Code Gen'])
        self.tab_frames.pack(anchor=NW, fill=BOTH, side=TOP, expand=True)
        
        # Main window is finished, start building tab_frames pages
        self.pageD = {} # dictionary of tab_frames pages
        
        def setup_page( npage, PageObj ):
            self.pageD[npage] = PageObj(self, self.tab_frames(npage))
            self.pageD[ str(self.tab_frames.labelL[npage]) ] = self.pageD[npage]
            self.tab_frames.setLeaveCallback(npage, self.pageD[npage].leavePageCallback)
            self.tab_frames.setSelectCallback(npage, self.pageD[npage].selectPageCallback)
        
        # setup pages
        setup_page(0, PageData)    # setup page 0, Data page
        setup_page(1, SimplePage)  # setup page 1, Simple Curve Fit
        setup_page(2, SplinePage)  # setup page 2, Spline Curve Fit
        setup_page(3, MathPage)    # setup page 3, Math Page
        setup_page(4, ExhaustPage) # setup page 4, Exhaustive Fit 
        setup_page(5, NonLinFitPage) # setup page 5, Non-Linear Fit 
        setup_page(6, PagePlot ) # setup page 6, PagePlot
        setup_page(7, CodeGenPage) # setup page 7, Code Generation Page

        master.config(menu=self.menuBar)
        
        if XYjob_inp is None:
            self.XYjob = XY_Job() # XYjob may hold nonlinear fit object
        else:
            self.XYjob = XYjob_inp
            
        self.linear_fitL = [] # list of candidate linear fits
        self.selected_spline_objL = [] # list of candidate spline fits
        
        if self.XYjob.nonlin_fit:
            self.pageD['Non-Linear Fit'].EqnStr_Text.delete(1.0, END)
            self.pageD['Non-Linear Fit'].EqnStr_Text.insert(END, self.XYjob.nonlin_fit.rhs_eqnStr)

        # check for input file on command line
        if (XYjob_inp is None) and (len( sys.argv ) == 2):
            fName = sys.argv[1]
            if not fName.endswith('.x_y'):
                fName += '.x_y'
            self.pathopen = os.path.abspath(fName)
            if os.path.isfile( self.pathopen ): # if file exists, read it as a definition file
                fInp = open( os.path.abspath(fName), 'rb' )
                self.read_xyjob_from_file(fInp)
            else:
                # For erroneous file names, change status bar
                self.statusMessage.set("file:%s NOT FOUND"%fName)

        # Enter Data page to begin with
        #self.tab_frames.selectTab( self.tab_frames.buttonL[0] )
        master.protocol('WM_DELETE_WINDOW', self.cleanupOnQuit)
        
        milliseconds=100
        self.master.after( milliseconds, self.littleInits )
        
        print(LICENSE)

    def littleInits(self):
        self.PlotWin = PlotWindow(self.master, self)
        
        self.tab_frames.selectTab( self.tab_frames.buttonL[0] )
        self.pageD[0].eg.focus_on(0,0)
        
        # If transient, will minimize with main window AND be drawn on top
        #self.PlotWin.transient(self.master) 
        
    def menu_Program_Exit(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_Program_Exit"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_Program_Exit")
        print("called menu_Program_Exit")
        
        self.cleanupOnQuit()

    def has_some_data(self):
        '''Return True if there is some data or curve fit being held in memory.'''
        print('Entering MathPage')
        XY = self.XYjob
        got_data = False
        
        if XY.nonlin_fit:
            print('Has a Non-Linear Fit')
            got_data = True
        
        for pagename in ['Simple Fit','Exhaustive Fit']:
            selected_linfitL = self.pageD[pagename].selected_linfitL
            for n,i in enumerate(selected_linfitL):
                print('Has a %s'%pagename)
                got_data = True
        
        for spline in self.selected_spline_objL:
            print('Has a Spline Fit')
            got_data = True
        
        DataPage = self.pageD['Data']
        if DataPage.Xname_Entry_StringVar.get() != 'x':
            print('Has x Name')
            got_data = True
        if DataPage.Xunits_Entry_StringVar.get() != '':
            print('Has x Units')
            got_data = True
        if DataPage.Yname_Entry_StringVar.get() != 'y':
            print('Has y Name')
            got_data = True
        if DataPage.Yunits_Entry_StringVar.get() != '':
            print('Has Y Units')
            got_data = True
            
        if DataPage.eg.num_active_wtfactors:
            print('Has Weight Factors')
            got_data = True
        
        for i in range(DataPage.eg.Nrows):
            if DataPage.eg.entryL[i][0].is_float() or DataPage.eg.entryL[i][1].is_float():
                print('Has Data in Entry Box')
                got_data = True
        
        if (not self.XYjob.dataset is None) or (not self.XYjob.linfit is None) or (not self.XYjob.nonlin_fit is None):
            print('Has Initialized XYjob')
            got_data = True
            
        
        return got_data

    def clear_all_data(self):

        self.XYjob = XY_Job() # XYjob may hold nonlinear fit object
        self.linear_fitL = [] # list of candidate linear fits
        self.selected_spline_objL = [] # list of candidate spline fits

        for pagename in ['Simple Fit','Exhaustive Fit']:
            self.pageD[pagename].selected_linfitL = []
            self.pageD[pagename].Equations_Listbox.delete(0, END)
            self.pageD[pagename].Pcentstddev_Listbox.delete(0, END)
            self.pageD[pagename].Stddev_Listbox.delete(0, END)


        self.pageD['Data'].clear_all_data()
            
        self.pageD['Code Gen'].Listbox_1.delete(0, END)
        self.pageD['Math'].Listbox_1.delete(0, END)
        self.pageD['Spline'].Listbox_1.selection_clear(0, 5)
        
        
        # remove any constant entry widgets and pack_forget Improve Button
        self.pageD['Non-Linear Fit'].ImproveFit_Button.pack_forget()
        self.pageD['Non-Linear Fit'].SetConst_Button.pack_forget()
        
        for e in self.pageD['Non-Linear Fit'].constEntryWidgetL:
            e.pack_forget()
            del(e)
        
        for pagename in ['Data','Simple Fit','Spline','Math','Exhaustive Fit','Non-Linear Fit','Code Gen']:
            self.pageD[pagename].ShowHelp_Button_Click(None)
            self.pageD[pagename].pageFrame.update_idletasks()
        
        
        self.PlotWin.start_new_plot()
        #self.PlotWin.add_curve([1,2,3],[4,6,9], label='Sample Data', show_pts=1, show_line=1, 
        #    linewidth=2, markersize=20)
        #self.PlotWin.final_touches( title_str='Sample Plot', show_grid=True, show_legend=True)
        self.PlotWin.show_it()
        

    def menu_File_New(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_File_New"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_File_New")
        print("called menu_File_New")
        if self.has_some_data():
            print('Has Some Data to be Cleared')
            if self.AskYesNo( title='Clear All Data', message='Do you want to clear all data from memory?'):
                self.clear_all_data()

    def menu_File_Open(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_File_Open"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_File_Open")
        print("called menu_File_Open")
        
        fInp = self.AskOpenFile(title='Open XYmath File', mode='rb', initialdir='.')
        if fInp:
            self.clear_all_data()
            self.read_xyjob_from_file(fInp)
            
    def read_xyjob_from_file(self, fInp):
        print('Opened file', os.path.basename( fInp.name ))
        # fInp will be closed by read_job_from_file
        self.XYjob.read_job_from_file(fileObj=fInp)
        #self.pageD['Data'].place_xyjob_data()
        prefix = os.path.basename(self.XYjob.file_prefix)
        self.master.title("XYmath - %s"%prefix)
        name = os.path.basename(self.XYjob.file_name)
        self.statusMessage.set("Read file:%s"%name)
        
        if hasattr(self,'PlotWin'):
            self.pageD['Data'].place_xyjob_data()
            
    def menu_File_Save(self):
        pass
        # >>>>>>insert any user code below this comment for section "menu_File_Save"
        # replace, delete, or comment-out the following
        self.statusMessage.set("called menu_File_Save")
        print("called menu_File_Save")
        
        if self.XYjob.file_prefix:
            initialfile = self.XYjob.file_prefix + '.x_y'
        else:
            initialfile = '*.x_y'
        
        fsave = self.AskSaveasFilename(title='Save XYmath File', initialfile=initialfile)
        
        if fsave:
            if not fsave.lower().endswith('.x_y'):
                fsave += '.x_y'
            
            self.pageD['Data'].put_entry_values_on_plot()
            
            self.XYjob.write_job_to_file( fname=fsave )
            print('Saving XYmath to:',fsave)
            prefix = os.path.basename(self.XYjob.file_prefix)
            self.master.title("XYmath - %s"%prefix)
            name = os.path.basename(self.XYjob.file_name)
            self.statusMessage.set("Read file:%s"%name)

    def bindConfigure(self, event):
        if not self.initComplete:
            self.master.bind("<Configure>", self.Master_Configure)
            self.initComplete = 1


    def Master_Configure(self, event):
        if event.widget != self.master:
            if self.w != -1:
                return
        x = int(self.master.winfo_x())
        y = int(self.master.winfo_y())
        w = int(self.master.winfo_width())
        h = int(self.master.winfo_height())
        if (self.x, self.y, self.w, self.h) == (-1,-1,-1,-1):
            self.x, self.y, self.w, self.h = x,y,w,h


        if self.w!=w or self.h!=h:
            print("Master reconfigured... make resize adjustments")
            self.w=w
            self.h=h
            
        #print '  -----------------   w,h=',w,h
        #self.tab_frames.lframe.configure(width=w, height=h)
        #self.tab_frames.frame.configure(width=w, height=h)
        #print 'winfo_reqwidth()=',self.tab_frames.winfo_reqwidth()
        #print 'winfo_reqheight()=',self.tab_frames.winfo_reqheight()
        #self.master.update_idletasks()

    # standard message dialogs... showinfo, showwarning, showerror
    def ShowInfo(self, title='Title', message='your message here.'):
        tkMessageBox.showinfo( title, message )
        return
    def ShowWarning(self, title='Title', message='your message here.'):
        tkMessageBox.showwarning( title, message )
        return
    def ShowError(self, title='Title', message='your message here.'):
        tkMessageBox.showerror( title, message )
        return
        
    # standard question dialogs... askquestion, askokcancel, askyesno, or askretrycancel
    # return True for OK, Yes, Retry, False for Cancel or No
    def AskYesNo(self, title='Title', message='your question here.'):
        return tkMessageBox.askyesno( title, message )
    def AskOK_Cancel(self, title='Title', message='your question here.'):
        return tkMessageBox.askokcancel( title, message )
    def AskRetryCancel(self, title='Title', message='your question here.'):
        return tkMessageBox.askretrycancel( title, message )
        
    # return "yes" for Yes, "no" for No
    def AskQuestion(self, title='Title', message='your question here.'):
        return tkMessageBox.askquestion( title, message )
    # standard file dialogs... askdirectory, askopenfile, asksaveasfilename

    # return a string containing directory name
    def AskDirectory(self, title='Choose Directory', initialdir="."):
        dirname = tkFileDialog.askdirectory(parent=self.master,initialdir=initialdir,title=title)
        return dirname # <-- string
        
    # return an OPEN file type object OR None (opened using mode, 'r','rb','w','wb')
    # WARNING... opening file with mode 'w' or 'wb' will erase contents
    def AskOpenFile(self, title='Open XYmath File', mode='rb', initialdir='.', filetypes=None):
        if filetypes is None:
            filetypes = [
                ('XYmath File','*.x_y'),
                ('Any File','*.*')]
        fileobj = tkFileDialog.askopenfile(parent=self.master,mode=mode,title=title,
            initialdir=initialdir, filetypes=filetypes)
        
        # if opened, then fileobj.name contains the name string
        return fileobj # <-- an opened file, or the value None
        
    # return a string containing file name (the calling routine will need to open the file)
    def AskSaveasFilename(self, title='Save File', filetypes=None, initialfile=''):
        if filetypes is None:
            filetypes = [
                ('XYmath File','*.x_y'),
                ('Any File','*.*')]

        fileName = tkFileDialog.asksaveasfilename(parent=self.master,filetypes=filetypes, initialfile=initialfile ,title=title)
        return fileName # <-- string
        
    # alarm function is called after specified number of milliseconds
    def SetAlarm(self, milliseconds=1000):
        self.master.after( milliseconds, self.Alarm )
    def Alarm(self): 
        pass

        # >>>>>>insert any user code below this comment for section "standard_alarm"
        print("Alarm called")
        
    def menu_File_Import(self):
        dialog = _Importxy(self.master, "Import X,Y Data")
        if dialog.result:
            wtArr = None
            print('place_entries_into_dataset with wtArr = None')
            xL = dialog.result["xL"]
            yL = dialog.result["yL"]
            
            XY = self.XYjob
            XY.define_dataset( array(xL, dtype=double), array(yL, dtype=double), wtArr=wtArr, 
                xName=dialog.result["xName"], yName=dialog.result["yName"],
                xUnits='', yUnits='', 
                timeStamp=time.time())
                
            XY.dataset.sort_by_x()
            
            self.pageD['Data'].place_xyjob_data()

    def menu_About(self):
        dialog = _About(self.master, "About XYmath")
Ejemplo n.º 14
0
        A = 101124.977819
        c = 1.00041249485
        d = 2.23356723474e-05
        n = 5.31856523127
        x = altitude (m)
        y = Pressure (Pa)
        Correlation Coefficient = 0.999996135864
        Standard Deviation = 88.761441745
        Percent Standard Deviation = 0.094401748723%
        
"""
from numpy import array, double
from xymath.xy_job import XY_Job
from xymath.gui.xygui import main as run_gui

XY = XY_Job()

alt_mArr = array([-1524,-1372,-1219,-1067,-914,-762,-610,-457,-305,-152,0,152,
           305,457,610,762,914,1067,1219,1372,1524,1829,2134,2438,2743,3048,4572,
           6096,7620,9144,10668,12192,13716,15240], dtype=double)

PaArr = 1000.0 * array([121,119,117,115,113,111,109,107,105,103,101,99.5,97.7,96,
        94.2,92.5,90.8,89.1,87.5,85.9,84.3,81.2,78.2,75.3,72.4,69.7,57.2,46.6,37.6,
        30.1,23.8,18.7,14.5,11.1], dtype=double)

XY.define_dataset(alt_mArr, PaArr, wtArr=None, xName='altitude', yName='Pressure', 
                  xUnits='m', yUnits='Pa')


guessD = {'A':100000, 'c':1, 'd':0.00001, 'n':4  }
    
Ejemplo n.º 15
0
    - Surprisingly, XYmath shows the 3 term equation "y = c0 + c1*x + c2/x"
      to be superior to the 4 term equations as well as the quadratic.


"""
from numpy import array
from xymath.dataset import DataSet
from xymath.linfit import LinCurveFit
from xymath.xy_job import XY_Job
from xymath.gui.xygui import main as run_gui

concL = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1]
readingL = [1.54, 2.03, 3.17, 3.67, 4.89, 6.73, 6.74, 7.87, 8.86, 10.35]
DS = DataSet(concL,
             readingL,
             xName='Concentration',
             yName='Instrument Reading')

print('\n\n')
print('=' * 55)

XY = XY_Job()
XY.define_dataset(concL,
                  readingL,
                  wtArr=None,
                  xName='Concentration',
                  yName='Instrument Reading',
                  xUnits='',
                  yUnits='')
run_gui(XY)