Ejemplo n.º 1
0
	def displayPca(self,inds):
		#display PCA largest ingradients of selectes sumples
		X = self.X
		U = self.U
		if(len(inds)==0):
			inds = random.sample(range(len(X)),10);
		samples = X[[inds]]
		pc = (samples*U)
		restore = pc*np.transpose(U)
		nSamples = len(pc)
		allMat = np.matrix([])
		nEvDisp = 10
		for k in range(nSamples):
			#find largest valuse
			sortIndex = np.argsort(-np.abs(pc[k]))[:,0:nEvDisp]
			a =  np.vstack([U[:,sortIndex[0,i]]*pc[k,sortIndex[0,i]] for i in range(nEvDisp)])
			# restore image
			b = np.sum(a,0)
			#append them
			if(len(allMat)==1):
				#start loop
				allMat = np.vstack([samples[k], a, b,restore[k] ])
			else:
				allMat = np.vstack([allMat, samples[k], a,b,restore[k]])
		f = dd.displayData(allMat,nSamples,nEvDisp+3)
		f.suptitle('PCA')
		self.pcaFig = f		
Ejemplo n.º 2
0
	def displayInput(self,nDisp,isRand):
		#display nDisp samples from input in a grid.
		X = self.X
		if isRand:
			XX = random.sample(np.matrix.tolist(X),nDisp)
		else:
			XX = X[:nDisp]
		f = dd.displayData(XX,[],[])
		f.suptitle('input samples')
		self.inFig = f
Ejemplo n.º 3
0
def detect_burr(data,
                pv,
                left=None,
                right=None,
                method=0,
                minimum_peak_distance=100):
    titles = data.columns
    titleList = titles.values.tolist()
    if pv in titleList:
        pvn = titleList.index(pv)
        sta = DisplayData.showStatistic(data)
        print("statistic data:")
        print(sta)
        # use boxplot define threshold
        iqr = sta.loc['75%'][titles[pvn]] - sta.loc['25%'][titles[pvn]]
        if left is None:
            left = sta.loc['25%'][titles[pvn]] - 1.5 * iqr
        if right is None:
            right = sta.loc['75%'][titles[pvn]] + 1.5 * iqr
        print('min edge:', left, 'max edge:', right)
        burrdata = data[((data[titles[pvn]]) < left) |
                        ((data[titles[pvn]]) > right)]
        LoadData.df2other(burrdata, 'csv', 'newfile.csv')
        y = data[titles[pvn]].values
        if method == 0:
            # find_peaks by scipy signal
            peaks, _ = signal.find_peaks(y, height=right)
            plt.plot(y, 'b', lw=1)
            plt.plot(peaks, y[peaks], "+", mec='r', mew=2, ms=8)
            plt.plot(np.zeros_like(y) + right, "--", color="gray")
            plt.title("find_peaks min_height:%7f" % right)
            plt.show()
        if method == 1:
            detect_peaks(y, mph=right, mpd=minimum_peak_distance, show=True)
        if method == 2:
            print('Detect peaks with minimum height and distance filters.')
            # thres=right/max(y)
            indexes = peakutils.peak.indexes(np.array(y),
                                             thres=right / max(y),
                                             min_dist=minimum_peak_distance)
            print('Peaks are: %s' % (indexes))
            plt.plot(y, 'b', lw=1)
            for i in indexes:
                plt.plot(i, y[i], "+", mec='r', mew=2, ms=8)
            plt.plot(np.zeros_like(y) + right, "--", color="gray")
            plt.title("peakutils.peak thres:%f ,minimum_peak_distance:%d" %
                      (right, minimum_peak_distance))
            plt.show()
    else:
        print("Wrong PV name, not in ", titleList)
	def nnTest(self,ds):
		#test network parameters with labeled dataSet
		p = self.predict(ds)
		y = ds.y
		inds = (p==y)
		print 'Success rate: ' ,float(inds.sum())/float(inds.size)*100,'%'
		#display correct sumples
		tInd = np.where(p==y)[0].tolist()[0]
		if len(tInd)>50:
			#randomly choose 50
			tInd = random.sample(tInd,50)
		dispMat = ds.X[tInd]
		f = dd.displayData(dispMat,[],[])
		f.suptitle('correct samples')
		self.correctFig = f
		#display error sumples
		errInd = np.where(p!=y)[0].tolist()[0]
		if len(errInd)>50:
			#randomly choose 50
			errInd = random.sample(errInd,50)
		dispMat = ds.X[errInd]
		f = dd.displayData(dispMat,[],[])
		f.suptitle('error samples')
		self.errFig = f
Ejemplo n.º 5
0
    for y in range(SA[0], SA[1], 5):
        for x in range(SA[2], SA[3], 5):
            get_data(x, y, x + 5, y + 5)
            #print (data)
            if data:
                count = data["cnt"]
                for i in range(count):
                    #print ("test")
                    loc = data["list"][i]["name"]  #location name
                    lat = data["list"][i]["coord"]["Lat"]  #Latitude
                    lon = data["list"][i]["coord"]["Lon"]  #Longitude
                    temp = data["list"][i]["main"][
                        "temp"]  #temperature (in celsius)
                    pressure = data["list"][i]["main"]["pressure"]  #pressure
                    humidity = data["list"][i]["main"]["humidity"]  #humidity
                    w_ID = data["list"][i]["weather"][0]["id"]  #Weather id
                    if (pressure > 900 and pressure < 1030):  #remove errors
                        plt.plot(lon, lat, 'ok', markersize=1, c='red')

                        #plt.text(lon, lat, loc, fontsize=12);
                        sql_insert_data(loc, lat, lon, temp, pressure,
                                        humidity, w_ID, time.time())

    print("Time Elapsed: ", time.time() - startTime)
    #plt.savefig('/images/EastCoast_{0}.png'.format(startTime))
    print("Creating map")
    DD.GenMap(startTime, time.time())
    #print("Waiting 10 minutes...")
    #time.sleep(600) #sleep 10 min
conn.close()