예제 #1
0
def setupplot(secondax=False, **kwargs):
    ytickv = np.linspace(YR[0], YR[1], 6)
    yticknames = map('{:0.0f}'.format, ytickv)
    tmp = dict(
        ylabel='Temperature [c]',
        yr=minmax(ytickv),
        ytickv=ytickv,
        yticknames=yticknames,
    )
    tmp.update(kwargs)
    ax = setup(**tmp)

    if secondax:
        subplt = kwargs.get('subplt', None)
        f = lambda x: '{:0.0f}'.format(1.8 * x + 32.0)
        yticknames = map(f, ytickv)
        ax2 = ax.twinx()
        ax2.set_ylabel(r"Temperature [F]")
        ax2.set_ylim(minmax(ytickv))
        ax2.yaxis.set_major_locator(matplotlib.ticker.FixedLocator(ytickv))
        ax2.yaxis.set_major_formatter(
            matplotlib.ticker.FixedFormatter(yticknames))
        pylab.sca(ax)

        # setup(ax=ax.twinx(),
        #       subplt=subplt,
        #       ylabel='Temperature [F]',
        #       yr=minmax(ytickv), ytickv=ytickv, yticknames=yticknames)

    return ax
예제 #2
0
def setupplot(secondax=False, **kwargs):
    ytickv = np.linspace(YR[0],YR[1],6)
    yticknames = map('{:0.0f}'.format, ytickv)
    tmp = dict(
        ylabel='Temperature [c]',
        yr=minmax(ytickv), ytickv=ytickv,
        yticknames=yticknames,
    )
    tmp.update(kwargs)
    ax = setup(**tmp)
    
    if secondax:
        subplt = kwargs.get('subplt',None)
        f = lambda x: '{:0.0f}'.format(1.8*x + 32.0)
        yticknames = map(f, ytickv)
        ax2 = ax.twinx()
        ax2.set_ylabel(r"Temperature [F]")
        ax2.set_ylim(minmax(ytickv))
        ax2.yaxis.set_major_locator(matplotlib.ticker.FixedLocator(ytickv))
        ax2.yaxis.set_major_formatter(matplotlib.ticker.FixedFormatter(yticknames))
        pylab.sca(ax)
        
        # setup(ax=ax.twinx(),
        #       subplt=subplt,
        #       ylabel='Temperature [F]',
        #       yr=minmax(ytickv), ytickv=ytickv, yticknames=yticknames)
        
    
    return ax
예제 #3
0
파일: orient.py 프로젝트: bkurtz/PyGRBL
def getimrange(x, imrange):
    xmin,xmax = minmax(x)
    if imrange[0] > xmin:
        imrange[0] = xmin
    if imrange[1] < xmax:
        imrange[1] = xmax
    return imrange
예제 #4
0
def getimrange(x, imrange):
    xmin, xmax = minmax(x)
    if imrange[0] > xmin:
        imrange[0] = xmin
    if imrange[1] < xmax:
        imrange[1] = xmax
    return imrange
예제 #5
0
def fitgaussian(x, y, offset=0):
    '''Fit a gaussian to the data points x,y.  
    offset == the assumed floor for the gaussian (subtracted from 
    the y array).  Originally I fit for both the amplitude and offset
    however this sometimes caused issues due to the degeneracy. '''

    # set the parameters and some min values
    p = Parameters()
    # generally the background is 20-30, so require at least 10 above that
    p.add('amplitude', value=np.max(y) - offset, min=10)
    p.add('mean', value=np.mean(x), min=0)
    p.add('sigma', value=np.std(x), min=0)

    # minimise the fit.
    out = minimize(gauss2, p, args=(x, y - offset))
    # print the fit values and uncert.  I may want to check the
    # out.success value to ensure that everything worked.
    # report_errors(p)

    r = embiggen(minmax(x), 0.2)
    xx = np.arange(r[0], r[1], 0.1)
    return p, xx, gauss2(p, xx) + offset
예제 #6
0
파일: orient.py 프로젝트: bkurtz/PyGRBL
def fitgaussian(x,y,offset=0):
    '''Fit a gaussian to the data points x,y.  
    offset == the assumed floor for the gaussian (subtracted from 
    the y array).  Originally I fit for both the amplitude and offset
    however this sometimes caused issues due to the degeneracy. '''
    
    # set the parameters and some min values
    p = Parameters()
    # generally the background is 20-30, so require at least 10 above that
    p.add('amplitude', value=np.max(y)-offset, min=10)
    p.add('mean', value=np.mean(x), min=0)
    p.add('sigma', value=np.std(x), min=0)
    
    
    # minimise the fit.
    out = minimize(gauss2, p, args=(x, y-offset) )
    # print the fit values and uncert.  I may want to check the 
    # out.success value to ensure that everything worked.
    # report_errors(p)
    
    r = embiggen(minmax(x),0.2)
    xx = np.arange(r[0], r[1], 0.1)
    return p, xx, gauss2(p,xx)+offset
예제 #7
0
def make():
    tag = 'Voltage'
    tag = 'CurrentCapacity'
    data = json.load(open(FILENAME,'r'))
    date = date2num([datetime.fromtimestamp(x['date']) for x in data if len(x) > 1])
    amp  = [x[tag] for x in data if len(x) > 1]
    
    damp = np.diff(amp)
    ddate = date[:-1] + np.diff(date)/2.0
    uii = np.where(damp > 2)
    dii = np.where(damp < -2)
    print len(data)
    
    
    plot_params = dict(
        marker = 's',
        markersize=2,
        alpha=0.2,
        linestyle='_',
        markeredgewidth=0,
        markeredgecolor='none',
    )
    
    xr = embiggen(minmax(date), 0.02, 'both')
    yr = [0,7000]
    dyr = [-80,80]
    if np.max(amp) > 7000:
        yr = [0,10000]
        dyr = [-100,100]
    
    setup(figsize=(16,8))
    
    setup(subplt=(2,3,1), autoticks=True,
          title='Last Recorded: {}'.format(num2date(date[-1])),
          xlabel='Date', xr=xr,
          ylabel=tag, yr=yr)
    pylab.plot(date, amp, **plot_params)
    dateticks('%Y-%m-%d')
    
    tmp = date % 7.0
    setup(subplt=(2,3,2), autoticks=True,
          title='Current Date: {}'.format(datetime.now()),
          xlabel='Day of Week', 
          xtickv=np.arange(7), xr=[-0.2,6.2], 
          xticknames='sun mon tue wed thur fri sat'.split(),
          ylabel=tag, yr=yr)
    pylab.plot(tmp, amp, **plot_params)
    
    tmp = (date % 1.0) * 24.0
    setup(subplt=(2,3,3), autoticks=True,
          xlabel='Hour of Day', xr=[-0.4,24.4],
          xtickv=np.arange(0,25,4), xtickrotate=dict(rotation=90, ha='center'),
          xticknames='mid 4am 8am noon 4pm 8pm  mid'.split(),
          ylabel=tag, yr=yr)
    pylab.plot(tmp, amp, **plot_params)
    # dateticks('%Y-%m-%d')
    
    
    
    
    setup(subplt=(2,3,4), autoticks=True, 
          xlabel='Date', xr=xr,
          ylabel='Delta', yr=dyr)
    pylab.plot(ddate, damp, **plot_params)
    dateticks('%Y-%m-%d', ha='center')
    
    
    tmp = (date % 7.0)[:-1]
    setup(subplt=(2,3,5), autoticks=True,
          xlabel='Day of Week',
          xtickv=np.arange(7), xr=[-0.2,6.2], 
          xticknames='sun mon tue wed thur fri sat'.split(),
          ylabel=tag, yr=dyr)
    pylab.plot(tmp, damp, **plot_params)
    hist(tmp[uii], np.linspace(0,7,90), alpha=0.5, norm=dyr[1], filled=True)
    hist(tmp[dii], np.linspace(0,7,90), alpha=0.5, norm=dyr[0], filled=True)
    
    tmp = ((date % 1.0) * 24.0)[:-1]
    setup(subplt=(2,3,6), autoticks=True,
          xlabel='Hour of Day', xr=[-0.4,24.4],
          xtickv=np.arange(0,25,4), xtickrotate=dict(rotation=90, ha='center'),
          xticknames='mid 4am 8am noon 4pm 8pm  mid'.split(),
          ylabel=tag, yr=dyr)
    pylab.plot(tmp, damp, **plot_params)
    hist(tmp[uii], np.linspace(0,24,50), alpha=0.5, norm=dyr[1], filled=True)
    hist(tmp[dii], np.linspace(0,24,50), alpha=0.5, norm=dyr[0], filled=True)
    # dateticks('%Y-%m-%d')
    
    
    
    # pylab.tight_layout()
    setup(hspace=0, wspace=0)
    pylab.show()