文件
AcousticSO/RANDI.py
T

53 行
2.1 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='tl client')
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 ("ETOPO1Path" not in paramData) or ("STPath" not in paramData) or\
("freq" not in paramData) or ("receiveDepth" not in paramData) or\
("lat" not in paramData) or ("lon" not in paramData) or\
("timeType" not in paramData) or\
("NThreads" not in paramData) or ("outParam" not in paramData):
print(f'{argfile}中的参数有误,请核实!')
return
ETOPO1Path = paramData["ETOPO1Path"]
STPath = paramData["STPath"]
freq = float(paramData["freq"])
receiveDepth = float(paramData["receiveDepth"])
lat = float(paramData["lat"])
lon = float(paramData["lon"])
timeType = paramData["timeType"]
NThreads = int(paramData["NThreads"])
outParam = paramData["outParam"]
from RANDIcore import call_RANDI
NL = call_RANDI(ETOPO1Path, STPath, outParam["outPath"], freq, receiveDepth,
lon, lat, timeType, NThreads)
print(round(NL,2))
outData = {
"param": paramData,
"noiseLevel": round(NL,2)
}
with open(("" if outParam["outPath"]=="" else outParam["outPath"] + "/")+"RANDIOut.json", 'w') as jsonFile:
json_data = json.dumps(outData, cls=MyEncoder, indent=2, ensure_ascii=False)
jsonFile.write(json_data)
if __name__ == '__main__':
main()