def graph_update_view(request): import mimetypes mimetypes.init() mimetypes.add_type("pde","text/processing") db = current_spectra.current_spectra(mode = 'r') spectrum, timestamp, mode = db.getCurrentSpectrum() spectime = time.localtime(timestamp) spectrum = spectrum[cnf.modes[mode]['low_chan']:cnf.modes[mode]['high_chan'] + 1] timeS = '%02i:%02i:%02i on %02i/%02i/%04i'%(spectime[3], spectime[4], spectime[5], spectime[2], spectime[1], spectime[0]) print mode print cnf.modes[mode]['low_chan'] print cnf.getFreqs(mode)[cnf.modes[mode]['low_chan']] print cnf.modes[mode]['high_chan'] + 1 print cnf.getFreqs(mode)[cnf.modes[mode]['high_chan'] + 1] freqs = cnf.getFreqs(mode)[cnf.modes[mode]['low_chan']:cnf.modes[mode]['high_chan'] + 1] / 10e5 db.close() miny = np.asscalar(spectrum.min()) maxy = np.asscalar(spectrum.max()) js = json.dumps(spectrum.tolist()) return {'spectrum':js,\ 'freqs':json.dumps(freqs.tolist()),\ 'maxx':freqs.max(),\ 'minx':freqs.min(),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"Spectrum taken at %s"%timeS,\ 'xaxis':"Frequency (Mhz)",\ 'yaxis':"Power (dBm)"}
def graph_update_view(request): db = current_spectra.current_spectra() spectrum, timestamp, mode = db.getCurrentSpectrum() spectime = time.localtime(timestamp) spectrum = cnf.Base64Decode(spectrum) timeS = '%02i:%02i:%02i on %02i/%02i/%04i'%(spectime[3], spectime[4], spectime[5], spectime[2], spectime[1], spectime[0]) miny = spectrum.min() maxy = spectrum.max() freqs = cnf.getFreqs(1)/ 10e6 data = np.empty((spectrum.size + freqs.size,), dtype=spectrum.dtype) data[0::2] = freqs data[1::2] = spectrum db.close() return {'data':json.dumps(data.tolist()),\ 'maxx':freqs.max(),\ 'minx':freqs.min(),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"Spectrum taken at %s"%timeS,\ 'xaxis':"Frequency (Mhz)",\ 'yaxis':"Power (dBm)"}
def graph_update_view(request): import mimetypes mimetypes.init() mimetypes.add_type("pde", "text/processing") db = current_spectra.current_spectra(mode='r') spectrum, timestamp, mode = db.getCurrentSpectrum() spectime = time.localtime(timestamp) spectrum = spectrum[cnf. modes[mode]['low_chan']:cnf.modes[mode]['high_chan'] + 1] timeS = '%02i:%02i:%02i on %02i/%02i/%04i' % (spectime[3], spectime[4], spectime[5], spectime[2], spectime[1], spectime[0]) print mode print cnf.modes[mode]['low_chan'] print cnf.getFreqs(mode)[cnf.modes[mode]['low_chan']] print cnf.modes[mode]['high_chan'] + 1 print cnf.getFreqs(mode)[cnf.modes[mode]['high_chan'] + 1] freqs = cnf.getFreqs( mode)[cnf.modes[mode]['low_chan']:cnf.modes[mode]['high_chan'] + 1] / 10e5 db.close() miny = np.asscalar(spectrum.min()) maxy = np.asscalar(spectrum.max()) js = json.dumps(spectrum.tolist()) return {'spectrum':js,\ 'freqs':json.dumps(freqs.tolist()),\ 'maxx':freqs.max(),\ 'minx':freqs.min(),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"Spectrum taken at %s"%timeS,\ 'xaxis':"Frequency (Mhz)",\ 'yaxis':"Power (dBm)"}
def graph_update_view(request): db = current_spectra.current_spectra() spectrum, timestamp, mode = db.getCurrentSpectrum() spectime = time.localtime(timestamp) spectrum = cnf.Base64Decode(spectrum) timeS = '%02i:%02i:%02i on %02i/%02i/%04i' % (spectime[3], spectime[4], spectime[5], spectime[2], spectime[1], spectime[0]) miny = spectrum.min() maxy = spectrum.max() freqs = cnf.getFreqs(1) / 10e6 data = np.empty((spectrum.size + freqs.size, ), dtype=spectrum.dtype) data[0::2] = freqs data[1::2] = spectrum db.close() return {'data':json.dumps(data.tolist()),\ 'maxx':freqs.max(),\ 'minx':freqs.min(),\ 'maxy':maxy,\ 'miny':miny,\ 'heading':"Spectrum taken at %s"%timeS,\ 'xaxis':"Frequency (Mhz)",\ 'yaxis':"Power (dBm)"}
def rfi_monitor_get_range(self, startTime, endTime, mode_chan): # self.cur.execute ("SELECT DISTINCT fileLocation FROM spectra WHERE timestamp >= %s AND timestamp < %s", (startTime, endTime)) # res = self.cur.fetchall() startTuple = datetime.datetime.fromtimestamp(startTime) endTuple = datetime.datetime.fromtimestamp(endTime) now = datetime.datetime.now() lastHour = datetime.datetime(now.year,now.month,now.day,now.hour) nHours = None timeDiff = endTuple - startTuple nSpectra = int(timeDiff.total_seconds()) nHours = int(nSpectra/3600) if nSpectra % 3600 > 0: nHours += 1 print "startTuple" print startTuple print "nHours = %i"%nHours fileName = "%02i.h5"%(startTuple.hour) #Filename is the hour of the observation path = os.path.join("%s/rfi_data"%conf.root_dir, str(startTuple.year), "%02i"%startTuple.month, "%02i"%startTuple.day,'') #Filepath year/month/day of the observation location = "%s%s"%(path,fileName) ret = None nSecs = startTuple.minute * 60 + startTuple.second print "nSpectra = %i"%nSpectra; ret = numpy.zeros((nSpectra,), dtype=numpy.float64) current = 0 if endTuple > lastHour: current = 1 mode = 0 channel = -1 indices = None try: f = h5py.File(location, 'r') print f['spectra'].shape for m_c in mode_chan: if m_c[0] in f['mode'][nSecs:3600]: mode = m_c[0] channel = m_c[1] indices = numpy.where(f['mode'][nSecs -1:3600] == mode) elif indices == None: indices = [] ret[0:3600 - nSecs + 1][indices] = f['spectra'][nSecs - 1:3600,channel][indices] nSecs = 3600 - nSecs print "GOT %s"%location print "max = %f"%numpy.max(ret) print "min = %f"%numpy.min(ret) except IOError as e: nSecs = 3600 - nSecs print e print "NO FILE %s"%location currentTime = startTuple + datetime.timedelta(hours=1) print "endtuple = %s, lastHour = %s"%(str(endTuple),str(lastHour)) for i in range(nHours - current): indices = None fileName = "%02i.h5"%(currentTime.hour) #Filename is the hour of the observation path = os.path.join("%s/rfi_data"%conf.root_dir, str(currentTime.year), "%02i"%currentTime.month, "%02i"%currentTime.day,'') #Filepath year/month/day of the observation location = "%s%s"%(path,fileName) print location print nSecs try: f = h5py.File(location, 'r') nS = 3600 print "ret.shape[0]" print ret.shape[0] if (ret.shape[0] - nSecs < 3600): nS = ret.shape[0] - nSecs for m_c in mode_chan: print "m_c = %s"%str(m_c) if m_c[0] in f['mode']: mode = m_c[0] channel = m_c[1] indices = numpy.where(f['mode'][:nS] == mode) elif indices == None: indices = [] print "indices" print indices if (ret.shape[0] != nSecs): ret[nSecs:nSecs + nS][indices] = f['spectra'][:nS,channel][indices] nSecs += 3600 print "max = %f"%numpy.max(ret) print "min = %f"%numpy.min(ret) except IOError as e: print e print location nSecs += 3600 print "nSecs = %s"%nSecs currentTime = currentTime + datetime.timedelta(hours=1) print "nSPectra = %s"%nSpectra print "nSecs = %s"%nSecs if current == 1: print "IN current" import rfDB2.current_spectra as current_spectra curr = current_spectra.current_spectra(mode = 'r'); print ("Getting %i mintues and %i seconds = %i seconds"%(endTuple.minute, endTuple.second, endTuple.minute * 60 + endTuple.second)) spectra, times = curr.getRangeMem(endTuple.minute * 60 + endTuple.second, endTime, mode_chan) print spectra.shape print spectra.shape # print "ret shape = %s and spectra shape = %s and spectra[:,channel].shape = %s"%(str(ret[nSecs:].shape), str(spectra.shape), str(spectra[:,channel].shape)) indices = times + int(endTuple.minute*60 + endTuple.second - endTime - 1) # print indices ret[nSecs:][indices] = spectra[:ret[nSecs:].shape[0]] # print "current min = %s and current max = %s"%(str(spectra[:,channel].min()), str(spectra[:,channel].max())) print ret[:5] print ret[-5:] print numpy.where(ret > 0.0) print (ret[numpy.where(ret > 0.0)]) # ret[nSecs - 1:] = spectra[:,channel] # nSecs += spectra[:,channel].size curr.close() print "max = %f"%numpy.max(ret) print "min = %f"%numpy.min(ret) #Replace zeroes with mean # mean = numpy.mean(ret[ret != 0.0], axis = 0) # ret[ret==0.0] = mean #Interpolate zeroes if channel != -1: z = numpy.where(ret==0.0)[0] nz = numpy.where (ret!=0.0)[0] ret[ret==0.0]=numpy.interp(z,nz,ret[nz]) z = numpy.where(ret > (100))[0] nz = numpy.where(ret < (100))[0] print z[0:5] print nz[0:5] ret[ret > 10 ** 2]=numpy.interp(z,nz,ret[nz]) print "check" print "nSPectra = %s"%nSpectra print "nSecs = %s"%nSecs print ret.shape print "max = %f"%numpy.max(ret) print "min = %f"%numpy.min(ret) return ret