First commit after changed file framework
这个提交包含在:
@@ -0,0 +1,60 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import warnings
|
||||
warnings.filterwarnings('ignore')
|
||||
import argparse, json
|
||||
|
||||
def _argparse():
|
||||
parser = argparse.ArgumentParser(description='Wind Generated Noise Prediction')
|
||||
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 ("dataFile" not in paramData) or ("freq" not in paramData) or\
|
||||
("depth" not in paramData) or ("windSpeed" not in paramData) or\
|
||||
("month" not in paramData) or\
|
||||
("png" not in paramData) or \
|
||||
("outParam" not in paramData):
|
||||
print(f'{argfile}中的参数有误,请核实!')
|
||||
return
|
||||
dataFile = paramData["dataFile"]
|
||||
freq = float(paramData["freq"])
|
||||
depth = float(paramData["depth"])
|
||||
windSpeed = float(paramData["windSpeed"])
|
||||
month = int(paramData["month"])
|
||||
png = paramData["png"]
|
||||
outParam = paramData["outParam"]
|
||||
|
||||
from pyat.WGNPd import WGNPd
|
||||
from pyat.DataBase import DataBase
|
||||
import matplotlib.pyplot as plt
|
||||
import numpy as np
|
||||
|
||||
freq = 50 * np.power(2, np.arange(freq)/3)
|
||||
frequency, spl = WGNPd(dataFile, depth, windSpeed, month, freq)
|
||||
|
||||
#输出json文件
|
||||
outData = {}
|
||||
outData["param"] = paramData
|
||||
outData["descript"] = "frequency and noise level"
|
||||
frequency = np.around(frequency, decimals=0)
|
||||
spl = np.around(spl, decimals=2)
|
||||
outData["data"] = list(zip(frequency, spl))
|
||||
with open(("" if outParam["outPath"]=="" else outParam["outPath"] + "/")+"wgnpOut.json", 'w') as jsonFile:
|
||||
json.dump(outData, jsonFile, indent=2, ensure_ascii=False)
|
||||
|
||||
if png:
|
||||
plt.semilogx(freq, spl)
|
||||
plt.xlabel('Frequency / Hz')
|
||||
plt.ylabel('Noise Level / dB')
|
||||
plt.show()
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
在新工单中引用
屏蔽一个用户