diff --git a/modules/amv/intercompare.py b/modules/amv/intercompare.py index 89c7b06dcb9988f1a622055adbe75a3a8741a447..a013dd3a7ccd1efc0160444d6408d15df513424a 100644 --- a/modules/amv/intercompare.py +++ b/modules/amv/intercompare.py @@ -17,6 +17,7 @@ from netCDF4 import Dataset import datetime from datetime import timezone from util.util import LatLonTuple +import re # -- AMV intercompare stuff ------------------------------------------ # -------------------------------------------------------------------- @@ -41,6 +42,70 @@ amv_qif_idx = amv_hdr_list.index('qif') amv_centers_list = ['EUM', 'BRZ', 'JMA', 'KMA', 'NOA', 'NWC'] +NO_ICE = '\s*NEG\s*|\s*NONE\s*|\s*NEGATIVE\s*|\s*NO\s*' +ICE_LVL = '\d+-\d+|FL\d+-FL\d+' + +def pireps(filename): + reports = [] + lats = [] + lons = [] + alts = [] + no_ice_reports = [] + ice_reports = [] + with open(filename) as file: + all = 0 + cnt = 0 + for idx, line in enumerate(file): + all += 1 + toks = line.split(',') + report = toks[3] + + # Flight level + f_i = report.find('/FL') + if f_i >= 0: + fl = report[f_i+3:] + ti = fl.find('/TP') + fl = fl[:ti] + fl = fl.rstrip() + fl = fl.lstrip() + if fl.isnumeric(): + fl = float(fl) * 100 * 0.3048 # conv flight level to meters + else: + continue + + # Icing + ii = report.find('/IC') + if ii >= 0: + s = report[ii+3:] + ri = s.find('/RM') + lat = float(toks[4]) + lon = float(toks[5]) + if ri >= 0: + s = s[:ri] + else: + ri = s.find(',') + if ri >= 0: + s = s[:ri] + s = s.lstrip() + if s.find('N/A') >= 0: + continue + + if len(re.findall(NO_ICE, s)) != 0: + no_ice_reports.append(idx) + else: + ice_reports.append(idx) + + reports.append(s) + lats.append(lat) + lons.append(lon) + alts.append(fl) + cnt += 1 + + lats = np.array(lats) + lons = np.array(lons) + + print(len(ice_reports), len(no_ice_reports)) + def get_amv_nd(filename): header = None