From 4463e9159d779610f66d1cc267ae49c06172f125 Mon Sep 17 00:00:00 2001
From: tomrink <rink@ssec.wisc.edu>
Date: Wed, 3 Feb 2021 13:39:48 -0600
Subject: [PATCH] snapshot...

---
 modules/amv/intercompare.py | 27 ++++++++++++++++++++++-----
 1 file changed, 22 insertions(+), 5 deletions(-)

diff --git a/modules/amv/intercompare.py b/modules/amv/intercompare.py
index 50e2a55b..9c8c137b 100644
--- a/modules/amv/intercompare.py
+++ b/modules/amv/intercompare.py
@@ -44,8 +44,13 @@ 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+'
+FLT_LVL = '/FL\s{0,1}\d+\s*'
+ICE_RPT = '/IC'
+ATYPE = '/TP'
+RMK = '/RM'
 
-def pireps(filename):
+
+def pireps(filename, lon_range=[-180, 180], lat_range=[-55, 55]):
     reports = []
     lats = []
     lons = []
@@ -53,11 +58,25 @@ def pireps(filename):
     times = []
     no_ice_reports = []
     ice_reports = []
+
+    # HEADER: VALID,URGENT,AIRCRAFT,REPORT,LAT,LON
+
     with open(filename) as file:
         cnt = 0
         for idx, line in enumerate(file):
             toks = line.split(',')
+            if toks[0] == 'VALID':  # Skip headers (concatenated files)
+                continue
+            if len(toks) != 6:  # Check for line format error
+                continue
             report = toks[3]
+            lat = float(toks[4])
+            lon = float(toks[5])
+
+            if lon < lon_range[0] or lon > lon_range[1]:
+                continue
+            if lat < lat_range[0] or lat > lat_range[1]:
+                continue
 
             # Flight level
             f_i = report.find('/FL')
@@ -77,8 +96,7 @@ def pireps(filename):
             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:
@@ -109,14 +127,13 @@ def pireps(filename):
 
                         fl = max(lvl_a, lvl_b)
 
-
                 reports.append(s)
                 lats.append(lat)
                 lons.append(lon)
                 alts.append(fl)
                 times.append(timestmp)
                 cnt += 1
-
+    print(len(ice_reports), len(no_ice_reports))
     lats = np.array(lats)
     lons = np.array(lons)
 
-- 
GitLab