def magnetSplitSort(filter=True, average=True, bins=10, channel='67', debug=False, sortMethod='doubleSplitVcc', split=5.1067, nrings=3 ): if sortMethod=='help': print 'Possible sortMethods are: split=count out in two directions from the average, min=count up from the lowest value, max = count down from the highest value, data = sort by date and print some stuff relevant to calibration checking' return False if sortMethod=='doubleSplitVcc': summary = gS.getSummary(filter=filter, average=average) summary = sorted(summary, key=lambda magnet: magnet['Vcc']) #plt.plot([x['Vcc'] for x in summary]) #plt.show() count = 0 for magnet in summary: if magnet['Vcc']>Vsplit: break count = count+1 print 'count = ' +str(count) print 'rest = ' +str(len(summary)-count) thesummary = [summary[:count], summary[count:]] for i in [0,1]: thesummary[i] = sorted(thesummary[i], key=lambda magnet: magnet[channel]) #sizes = [124,123,121,118,115,110,105,98,91,84,75,67,58,48,37] sizes = [124, 124, 123, 123,121, 121,118, 118, 115, 115, 110, 110, 105, 105, 98, 98, 91, 91, 84, 84, 75, 75, 67, 67, 58, 58, 48, 48, 37, 37] rings = [16, 15, 17, 14, 18, 13, 19, 12, 20, 11, 21, 10, 22, 9, 23, 8, 24, 7, 25, 6, 26, 5, 27, 4, 28, 3, 29, 2, 30, 1] sizes =[x+2 for x in sizes] print sizes print 'there are this many rings ' +str(len(sizes)) print 'need a total of ' +str(sum(sizes)) #split up sizes depending on nrings. thesizes = [sizes[:len(sizes)-nrings], sizes[len(sizes)-nrings:]] if sortMethod=='doubleSplitDate': summary = gS.getSummary(filter=filter, average=average) summary = sorted(summary, key=lambda magnet: magnet['dtime']) #plt.plot([x['Vcc'] for x in summary]) #plt.show() count = 0 for magnet in summary: if magnet['dtime']>split: break count = count+1 print 'count = ' +str(count) print 'rest = ' +str(len(summary)-count) thesummary = [summary[:count], summary[count:]] for i in [0,1]: thesummary[i] = sorted(thesummary[i], key=lambda magnet: magnet[channel]) #sizes = [124,123,121,118,115,110,105,98,91,84,75,67,58,48,37] sizes = [124, 124, 123, 123,121, 121,118, 118, 115, 115, 110, 110, 105, 105, 98, 98, 91, 91, 84, 84, 75, 75, 67, 67, 58, 58, 48, 48, 37, 37] rings = [16, 15, 17, 14, 18, 13, 19, 12, 20, 11, 21, 10, 22, 9, 23, 8, 24, 7, 25, 6, 26, 5, 27, 4, 28, 3, 29, 2, 30, 1] sizes =[x+2 for x in sizes] print sizes print 'there are this many rings ' +str(len(sizes)) print 'need a total of ' +str(sum(sizes)) #split up sizes depending on nrings. thesizes = [sizes[:len(sizes)-nrings], sizes[len(sizes)-nrings:]] if True==True: binMagnets=[[],[]] for j in [0,1]: sizes=thesizes[j] summary = thesummary[j] print sizes halfway = int(len(summary)/2) start0 = halfway stop1 = halfway for i in range(len(thesizes[j])): if i%2==0: binMagnets2 = [] size = thesizes[j][i] print size stop0 = start0 + size binMagnets2.append(summary[start0:stop0]) print len(summary[start0:stop0]) if len(summary[start0:stop0]) < size: print 'you seem to have run out of magnets' start0 = stop0 #print len(binMagnets2) binMagnets.append(binMagnets2[0]) if i%2==1: binMagnets1 = [] size = thesizes[j][i] print size start1 = stop1 - size binMagnets1.append(summary[start1:stop1]) print len(summary[start1:stop1]) if len(summary[start1:stop1]) < size: print 'you seem to have run out of magnets' stop1 = start1 binMagnets.append(binMagnets1[0]) returner = binMagnets[0] returner.extend(binMagnets[1]) binMagnets = binMagnets[2:] for i in range(len(binMagnets)): for magnet in binMagnets[i]: magnet['RingNumber'] = rings[i] return binMagnets
# 4 functions import getTweets import getTopics import getSummary import getPolarity import installPackages #To install packages locally installPackages.installPackages() #Returns tweets: [{'name','tweet'}] tweetsObj = getTweets.getTweets('jpmorgan') #Returns topics: [{'name','phrase'}] topicsObj = getTopics.getTopics(tweetsObj) #Returns summary: [{'name','summary'}] summaryObj = getSummary.getSummary(topicsObj) #Returns polarity: [{'name',''polarity'}] polarityObj = getPolarity.getPolarity(summaryObj)
def magnetSort(filter=True, average=True, bins=10, channel='67', debug=False, sortMethod='split', Vsplit=5.1067, nrings=3, extra=2, size='3inch' ): if sortMethod=='doubleSplit': return magnetSplitSort(filter=filter, average=average, bins=bins, channel=channel, debug=debug, sortMethod=sortMethod, Vsplit=Vsplit, nrings=nrings, size=size) if sortMethod=='help': print 'Possible sortMethods are: split=count out in two directions from the average, min=count up from the lowest value, max = count down from the highest value, data = sort by date and print some stuff relevant to calibration checking' return False summary = gS.getSummary(filter=filter, average=average, size=size) #first, list the bin sizes. Note that this list needs to be filled twice (once for each cylinder) if size=='3inch': sizes = [124,123,121,118,115,110,105,98,91,84,75,67,58,48,37] if size=='2inch': sizes = [42, 26] if size=='1inch': sizes = [20] sizes = [x+extra for x in sizes] sizes.reverse() rsizes = sizes[:] sizes.reverse() if debug==True: print rsizes print sizes if sortMethod=='date': print summary[0] summary = sorted(summary, key=lambda magnet: magnet['Date']) #for x in summary: #print x['Date'] #plt.plot([x[channel] for x in summary]) #plt.show() fit = np.polyfit([x['Vcc'] for x in summary], [x[channel] for x in summary], 1) #print fit plt.scatter( [x['Vcc'] for x in summary], [x[channel] for x in summary]) plt.plot([x['Vcc'] for x in summary], np.polyval(fit, [x['Vcc'] for x in summary])) plt.show() if sortMethod=='min': summary = sorted(summary, key=lambda magnet: magnet[channel]) if debug==True: plt.plot([x[channel] for x in summary]) plt.show() plt.plot([x['MagnetNumber'] for x in summary]) plt.show() binsizes = rsizes binsizes.extend(sizes) if debug==True: print binsizes print sum(binsizes) binMagnets = [] start = 0 for size in binsizes: stop = start + size binMagnets.append(summary[start:stop]) #print len(summary[start:stop]) start = stop #binMagnets return binMagnets if sortMethod=='split': summary = sorted(summary, key=lambda magnet: magnet[channel]) halfway = int(len(summary)/2) start = halfway binMagnets2 = [] count=len(sizes)+1 #count up from the halfway for size in sizes: stop = start + size tempbin = summary[start:stop] for magnet in tempbin: magnet['RingNumber'] = count binMagnets2.append(tempbin) #print len(summary[start:stop]) start = stop count=count+1 #print len(binMagnets2) stop = halfway binMagnets1 = [] count=len(sizes) #count down from halfway for size in sizes: start = stop - size tempbin = summary[start:stop] for magnet in tempbin: magnet['RingNumber'] = count binMagnets1.append(tempbin) #print len(summary[start:stop]) if len(summary[start:stop]) < size: print 'you seem to have run out of magnets' stop = start count=count-1 #print len(binMagnets1) binMagnets1.reverse() binMagnets1.extend(binMagnets2) return binMagnets1
def reCal( filter=True, average=True, bins=10, channel="67", debug=False, width=150, deg=1, sortby="Vcc", binsize=0, Vcor=0, exp=5.086, ): summary = gS.getSummary(filter=filter, average=average) consistency = gC.getConsistency(filter=filter, average=average) if sortby == "Date": summary = sorted(summary, key=lambda magnet: magnet[sortby]) consistency = sorted(consistency, key=lambda magnet: magnet[sortby]) plt.scatter(range(len(summary)), [x[channel] for x in summary]) plt.scatter(range(len(consistency)), [x[channel] for x in consistency], color="tomato") plt.show() if binsize == 0 and sortby == "Vcc": print summary[0] summary = sorted(summary, key=lambda magnet: magnet[sortby]) consistency = sorted(consistency, key=lambda magnet: magnet[sortby]) # for x in summary: # print x['Date'] # plt.plot([x[channel] for x in summary]) # plt.show() sumfit = np.polyfit([x["Vcc"] - exp for x in summary], [x[channel] for x in summary], deg) plt.scatter([x["Vcc"] for x in summary], [x[channel] for x in summary]) plt.plot([x["Vcc"] for x in summary], np.polyval(sumfit, [x["Vcc"] - exp for x in summary])) # plt.show() confit = np.polyfit([x["Vcc"] for x in consistency], [x[channel] for x in consistency], deg) plt.scatter([x["Vcc"] for x in consistency], [x[channel] for x in consistency], color="tomato") plt.plot([x["Vcc"] for x in summary], np.polyval(confit, [x["Vcc"] for x in summary])) # plt.show() print "confit = " + str(confit) print "sumfit = " + str(sumfit) movave = [] vccave = [] summary = sorted(summary, key=lambda magnet: magnet[sortby]) for i in range(len(summary) - width): movave.append(np.average([x[channel] for x in summary][i : i + width])) vccave.append(np.average([x["Vcc"] for x in summary][i : i + width])) # plt.show() plt.scatter(vccave, movave) avefit = np.polyfit([x - exp for x in vccave], movave, deg) print "moveavefit = " + str(avefit) plt.plot([x["Vcc"] for x in summary], np.polyval(avefit, [x["Vcc"] - exp for x in summary])) plt.show() if binsize != 0 and sortby == "Vcc": summary = sorted(summary, key=lambda magnet: magnet[sortby]) consistency = sorted(consistency, key=lambda magnet: magnet[sortby]) binsizes = np.zeros(3000, int) for i in range(len(binsizes)): binsizes[i] = binsize print "binsizes = " + str(binsizes) binMagnets = [] start = 0 for size in binsizes: stop = start + size print "size = " + str(size) if len(summary[start:stop]) == 0: break binMagnets.append(summary[start:stop]) print len(summary[start:stop]) start = stop for magnets in binMagnets: sumfit = np.polyfit([x["Vcc"] - Vcor for x in magnets], [x[channel] for x in magnets], deg) print sumfit plt.scatter([x["Vcc"] - Vcor for x in magnets], [x[channel] for x in magnets]) plt.plot([x["Vcc"] - Vcor for x in magnets], np.polyval(sumfit, [x["Vcc"] - Vcor for x in magnets])) plt.show()