thisLine = "%s%s%s%s%d" % (thisHour,param.separator,X,param.separator,int(round(float(V)))) key = X+":"+str(int(round(float(V)))) Hfile.append(thisLine) if key in Dfile.keys(): Dfile[key] +=1 else: Dfile[key] =1 file.close() ##################################### # open the output file ##################################### # pdfDirTag, pdfFileTag = fileLib.getDir(param.dataDirectory,param.pdfDirectory,network,station,location,channel) fileLib.makePath(pdfDirTag) thisPath = os.path.join(pdfDirTag,'Y'+thisYear) fileLib.makePath(thisPath) outputFile = os.path.join(thisPath,'D' + thisDOY + '.bin') print "[INFO] DAILY OUTPUT FILE: " + outputFile with open(outputFile, 'w') as outputFile: for key in sorted(Dfile.keys()): day,db = key.split(":") outputFile.write("%s%s%s%s%i\n" % (day,param.separator,db,param.separator,Dfile[key])) outputFile.close() if param.pdfHourlySave > 0: thisPath = os.path.join(thisPath,param.pdfHourlyDirectory) fileLib.makePath(thisPath) outputFile = os.path.join(thisPath,'H' + thisDOY + '.bin') print "[INFO] HOURLY OUTPUT FILE: " + outputFile
# psdDbDirTag, psdDbFileTag = fileLib.getDir(param.dataDirectory, param.psdDbDirectory, network, station, location, channel) print "\n[INFO] PSD DIR TAG: " + psdDbDirTag if VERBOSE > 0: print "\n[INFO] PSD FILE TAG: " + psdDbFileTag ##################################### # open the output file ##################################### # psdDirTag, psdFileTag = fileLib.getDir(param.dataDirectory, param.psdDirectory, network, station, location, channel) fileLib.makePath(psdDirTag) tagList = [ psdFileTag, startDateTime.split('.')[0], endDateTime.split('.')[0], xType ] outputFileName = fileLib.getFileName(param.namingConvention, psdDirTag, tagList) #outputFileName = os.path.join(psdDirTag,'.'.join([psdFileTag,startDateTime.split('.')[0],endDateTime.split('.')[0]+'_'+xType+'.txt'])) with open(outputFileName, 'w') as outputFile: ##################################### # loop through the windows ##################################### # for n in xrange(len(dataDaysList)):
# convert to dB # power = 10.0 * np.log10(power[0:(nSamp / 2) + 1]) smoothPSD = 10.0 * np.log10(smoothPSD) # # create output paths if they do not exist # if msgLib.param(param, 'outputValues').outputValues > 0: filePath, psdFileTag = fileLib.getDir( msgLib.param(param, 'dataDirectory').dataDirectory, msgLib.param(param, 'psdDbDirectory').psdDbDirectory, network, station, location, channel) filePath = os.path.join(filePath, segmentStartYear, segmentStartDOY) fileLib.makePath(filePath) # # output is based on the xType # if VERBOSE: print "trChannel.stats:", str(trChannel.stats) print "REQUEST:", segmentStart print "TRACE:", str(trChannel.stats.starttime).replace("Z", "") print "DELTA:", trChannel.stats.delta print "SAMPLES:", int( float(msgLib.param(param, 'windowLength').windowLength) / float(trChannel.stats.delta) + 1) tagList = [ psdFileTag,
print("\n[INFO] polarization DIR TAG: " + polarDbDirTag + "\n") if VERBOSE > 0: print("\n[INFO] polarization FILE TAG: " + polarDbFileTag) ##################################### # open the output file for each parameter ##################################### # thisPolarDirTag, polarFileTag = fileLib.getDir(param.dataDirectory, param.polarDirectory, network, station, location, channelDir) for pn in range(len(variableList)): variable = variableList[pn] print("[INFO] variable:", variable + "\n") polarDirTag = os.path.join(thisPolarDirTag, variable) fileLib.makePath(polarDirTag) tagList = [ polarFileTag, startDateTime.split('.')[0], endDateTime.split('.')[0], xType ] outputFileName = fileLib.getFileName(param.namingConvention, polarDirTag, tagList) try: with open(outputFileName, 'w') as outputFile: ##################################### # loop through the windows ##################################### # for n in range(len(dataDaysList)):
Hfile.append(thisLine) if key in Dfile.keys(): Dfile[key] += 1 else: Dfile[key] = 1 file.close() ##################################### # open the output file ##################################### # pdfDirTag, pdfFileTag = fileLib.getDir(param.dataDirectory, param.pdfDirectory, network, station, location, channel) fileLib.makePath(pdfDirTag) thisPath = os.path.join(pdfDirTag, 'Y' + thisYear) fileLib.makePath(thisPath) outputFile = os.path.join(thisPath, 'D' + thisDOY + '.bin') print "[INFO] DAILY OUTPUT FILE: " + outputFile with open(outputFile, 'w') as outputFile: for key in sorted(Dfile.keys()): day, db = key.split(":") outputFile.write( "%s%s%s%s%i\n" % (day, param.separator, db, param.separator, Dfile[key])) outputFile.close() if param.pdfHourlySave > 0: thisPath = os.path.join(thisPath, param.pdfHourlyDirectory) fileLib.makePath(thisPath)
if TIMING: t0 = fileLib.timeIt("SMOOTHING window "+str(msgLib.param(param,"octaveWindowWidth").octaveWindowWidth)+" shift "+str(msgLib.param(param,"octaveWindowShift").octaveWindowShift)+" DONE",t0) # # convert to dB # power = 10.0 * np.log10(power[0:(nSamp/2)+1]) smoothPSD = 10.0 * np.log10(smoothPSD) # # create output paths if they do not exist # if msgLib.param(param,'outputValues').outputValues > 0: filePath, psdFileTag = fileLib.getDir(msgLib.param(param,'dataDirectory').dataDirectory,msgLib.param(param,'psdDbDirectory').psdDbDirectory,network,station,location,channel) filePath = os.path.join(filePath,segmentStartYear,segmentStartDOY) fileLib.makePath(filePath) # # output is based on the xType # if VERBOSE: print "trChannel.stats:",str(trChannel.stats) print "REQUEST:",segmentStart print "TRACE:",str(trChannel.stats.starttime).replace("Z","") print "DELTA:",trChannel.stats.delta print "SAMPLES:",int(float(msgLib.param(param,'windowLength').windowLength)/float(trChannel.stats.delta) +1) tagList = [psdFileTag,str(trChannel.stats.starttime).replace("Z",""),str(msgLib.param(param,'windowLength').windowLength),xType] with open(fileLib.getFileName(msgLib.param(param,'namingConvention').namingConvention,filePath,tagList), "w") as file: #