61 行
2.2 KiB
Python
61 行
2.2 KiB
Python
# -*- coding: utf-8 -*-
|
|
import warnings
|
|
warnings.filterwarnings('ignore')
|
|
import argparse, json
|
|
from common import NoIndent, MyEncoder
|
|
import os, sys
|
|
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))+'/pyat')
|
|
|
|
def _argparse():
|
|
parser = argparse.ArgumentParser(description='Average Noise Spectral Level')
|
|
parser.add_argument('-a', '--argfile', action='store', dest='argfile', required=True, help='name of arguments file')
|
|
return parser.parse_args()
|
|
|
|
|
|
def main():
|
|
parser = _argparse()
|
|
argfile = parser.argfile
|
|
if argfile[-5:] != '.json':
|
|
print('输入的参数文件名有误')
|
|
return
|
|
with open(argfile,'r') as jsonFile:
|
|
paramData = json.load(jsonFile)
|
|
if ("soundFile" not in paramData) or ("sense" not in paramData) or\
|
|
("filter" not in paramData) or ("png" not in paramData) or\
|
|
("outParam" not in paramData):
|
|
print(f'{argfile}中的参数有误,请核实!')
|
|
return
|
|
soundFile = paramData["soundFile"]
|
|
M = float(paramData["sense"])
|
|
A = float(paramData["filter"])
|
|
png = paramData["png"]
|
|
outParam = paramData["outParam"]
|
|
|
|
from OANPd import call_oanp
|
|
from matplotlib import pyplot as plt
|
|
import numpy as np
|
|
|
|
[freq, spl, fC, spl_oct] = call_oanp(soundFile=soundFile, M=M , A=A)
|
|
# call_oanp(soundFile="./SAW2577_20200923_150000.wav", W=-164.0 , A=0, isPlot=isPlot)
|
|
|
|
#输出json文件
|
|
outData = {}
|
|
outData["param"] = paramData
|
|
outData["descript"] = "frequency and noise level"
|
|
outData["count"] = len(fC)
|
|
fC = np.around(fC, decimals=0)
|
|
spl_oct = np.around(spl_oct, decimals=2)
|
|
outData["data"] = NoIndent(list(zip(fC,spl_oct)))
|
|
with open(("" if outParam["outPath"]=="" else outParam["outPath"] + "/")+"oanpOut.json", 'w') as jsonFile:
|
|
json_data = json.dumps(outData, cls=MyEncoder, indent=2, ensure_ascii=False)
|
|
jsonFile.write(json_data)
|
|
|
|
if png:
|
|
plt.semilogx(freq[20:10000], spl[20:10000])
|
|
plt.semilogx(fC, spl_oct)
|
|
plt.xlabel("Frequency / Hz")
|
|
plt.ylabel("Noise Level / dB")
|
|
plt.show()
|
|
|
|
if __name__ == '__main__':
|
|
main() |